Skip to content

Commit 5cacf4e

Browse files
committed
[JumpThreading] Avoid use of ConstantExpr::getCast()
Use the constant folding API instead.
1 parent 0468fa0 commit 5cacf4e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

llvm/lib/Transforms/Scalar/JumpThreading.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,8 @@ bool JumpThreadingPass::computeValueKnownInPredecessorsImpl(
568568
Value *V, BasicBlock *BB, PredValueInfo &Result,
569569
ConstantPreference Preference, DenseSet<Value *> &RecursionSet,
570570
Instruction *CxtI) {
571+
const DataLayout &DL = BB->getModule()->getDataLayout();
572+
571573
// This method walks up use-def chains recursively. Because of this, we could
572574
// get into an infinite loop going around loops in the use-def chain. To
573575
// prevent this, keep track of what (value, block) pairs we've already visited
@@ -635,16 +637,19 @@ bool JumpThreadingPass::computeValueKnownInPredecessorsImpl(
635637
// Handle Cast instructions.
636638
if (CastInst *CI = dyn_cast<CastInst>(I)) {
637639
Value *Source = CI->getOperand(0);
638-
computeValueKnownInPredecessorsImpl(Source, BB, Result, Preference,
640+
PredValueInfoTy Vals;
641+
computeValueKnownInPredecessorsImpl(Source, BB, Vals, Preference,
639642
RecursionSet, CxtI);
640-
if (Result.empty())
643+
if (Vals.empty())
641644
return false;
642645

643646
// Convert the known values.
644-
for (auto &R : Result)
645-
R.first = ConstantExpr::getCast(CI->getOpcode(), R.first, CI->getType());
647+
for (auto &Val : Vals)
648+
if (Constant *Folded = ConstantFoldCastOperand(CI->getOpcode(), Val.first,
649+
CI->getType(), DL))
650+
Result.emplace_back(Folded, Val.second);
646651

647-
return true;
652+
return !Result.empty();
648653
}
649654

650655
if (FreezeInst *FI = dyn_cast<FreezeInst>(I)) {
@@ -726,7 +731,6 @@ bool JumpThreadingPass::computeValueKnownInPredecessorsImpl(
726731
if (Preference != WantInteger)
727732
return false;
728733
if (ConstantInt *CI = dyn_cast<ConstantInt>(BO->getOperand(1))) {
729-
const DataLayout &DL = BO->getModule()->getDataLayout();
730734
PredValueInfoTy LHSVals;
731735
computeValueKnownInPredecessorsImpl(BO->getOperand(0), BB, LHSVals,
732736
WantInteger, RecursionSet, CxtI);

0 commit comments

Comments
 (0)