@@ -1339,6 +1339,7 @@ static Value *simplifyUsingControlFlow(InstCombiner &Self, PHINode &PN,
1339
1339
auto *Input = cast<ConstantInt>(std::get<0 >(Pair));
1340
1340
BasicBlock *Pred = std::get<1 >(Pair);
1341
1341
auto IsCorrectInput = [&](ConstantInt *Input) {
1342
+ Instruction::CastOps TempCastType = CastType;
1342
1343
if (CastType != Instruction::BitCast) {
1343
1344
APInt InputValue = Input->getValue ();
1344
1345
if (CastType == Instruction::Trunc)
@@ -1347,7 +1348,7 @@ static Value *simplifyUsingControlFlow(InstCombiner &Self, PHINode &PN,
1347
1348
InputValue.isIntN (CondBitWidth))
1348
1349
InputValue = InputValue.trunc (CondBitWidth);
1349
1350
else if (InputValue.isSignedIntN (CondBitWidth)) {
1350
- CastType = Instruction::SExt;
1351
+ TempCastType = Instruction::SExt;
1351
1352
InputValue = InputValue.trunc (CondBitWidth);
1352
1353
} else
1353
1354
return false ;
@@ -1357,9 +1358,12 @@ static Value *simplifyUsingControlFlow(InstCombiner &Self, PHINode &PN,
1357
1358
// This edge cannot be a multi-edge, as that would imply that multiple
1358
1359
// different condition values follow the same edge.
1359
1360
auto It = SuccForValue.find (Input);
1360
- return It != SuccForValue.end () && SuccCount[It->second ] == 1 &&
1361
- DT.dominates (BasicBlockEdge (IDom, It->second ),
1362
- BasicBlockEdge (Pred, BB));
1361
+ bool Result = It != SuccForValue.end () && SuccCount[It->second ] == 1 &&
1362
+ DT.dominates (BasicBlockEdge (IDom, It->second ),
1363
+ BasicBlockEdge (Pred, BB));
1364
+ if (Result)
1365
+ CastType = TempCastType;
1366
+ return Result;
1363
1367
};
1364
1368
1365
1369
// Depending on the constant, the condition may need to be inverted.
0 commit comments