@@ -3190,6 +3190,7 @@ bool simplifyToSelectValue(SILBasicBlock *MergeBlock, unsigned ArgNum,
3190
3190
}
3191
3191
3192
3192
SmallVector<std::pair<SILValue, SILValue>, 8 > Cases;
3193
+ llvm::SmallDenseMap<SILValue, SILValue> CaseLiteralsToResultMap;
3193
3194
SILValue defaultResult;
3194
3195
3195
3196
// The block of the first input value compare. It dominates all other blocks
@@ -3202,7 +3203,23 @@ bool simplifyToSelectValue(SILBasicBlock *MergeBlock, unsigned ArgNum,
3202
3203
auto *BrInst = cast<CondBranchInst>(CaseInfo.CmpOrDefault ->getTerminator ());
3203
3204
if (FoundCmpBlocks.count (BrInst->getFalseBB ()) != 1 )
3204
3205
return false ;
3205
- Cases.push_back ({CaseInfo.Literal , CaseInfo.Result });
3206
+ // Ignore duplicate cases
3207
+ if (CaseLiteralsToResultMap.find (CaseInfo.Literal ) ==
3208
+ CaseLiteralsToResultMap.end ()) {
3209
+ CaseLiteralsToResultMap.insert ({CaseInfo.Literal , CaseInfo.Result });
3210
+ Cases.push_back ({CaseInfo.Literal , CaseInfo.Result });
3211
+ } else {
3212
+ // Check if the result value matches
3213
+ EnumInst *PrevResult =
3214
+ dyn_cast<EnumInst>(CaseLiteralsToResultMap[CaseInfo.Literal ]);
3215
+ assert (PrevResult && " Prev. case result is not an EnumInst" );
3216
+ EnumInst *CurrResult = dyn_cast<EnumInst>(CaseInfo.Result );
3217
+ assert (CurrResult && " Curr. case result is not an EnumInst" );
3218
+ if (PrevResult->getElement () != CurrResult->getElement ()) {
3219
+ // result value does not match - bail
3220
+ return false ;
3221
+ }
3222
+ }
3206
3223
SILBasicBlock *Pred = CaseInfo.CmpOrDefault ->getSinglePredecessor ();
3207
3224
if (!Pred || FoundCmpBlocks.count (Pred) == 0 ) {
3208
3225
// There may be only a single block whose predecessor we didn't see. And
0 commit comments