@@ -568,6 +568,8 @@ bool JumpThreadingPass::computeValueKnownInPredecessorsImpl(
568
568
Value *V, BasicBlock *BB, PredValueInfo &Result,
569
569
ConstantPreference Preference, DenseSet<Value *> &RecursionSet,
570
570
Instruction *CxtI) {
571
+ const DataLayout &DL = BB->getModule ()->getDataLayout ();
572
+
571
573
// This method walks up use-def chains recursively. Because of this, we could
572
574
// get into an infinite loop going around loops in the use-def chain. To
573
575
// prevent this, keep track of what (value, block) pairs we've already visited
@@ -635,16 +637,19 @@ bool JumpThreadingPass::computeValueKnownInPredecessorsImpl(
635
637
// Handle Cast instructions.
636
638
if (CastInst *CI = dyn_cast<CastInst>(I)) {
637
639
Value *Source = CI->getOperand (0 );
638
- computeValueKnownInPredecessorsImpl (Source, BB, Result, Preference,
640
+ PredValueInfoTy Vals;
641
+ computeValueKnownInPredecessorsImpl (Source, BB, Vals, Preference,
639
642
RecursionSet, CxtI);
640
- if (Result .empty ())
643
+ if (Vals .empty ())
641
644
return false ;
642
645
643
646
// 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 );
646
651
647
- return true ;
652
+ return !Result. empty () ;
648
653
}
649
654
650
655
if (FreezeInst *FI = dyn_cast<FreezeInst>(I)) {
@@ -726,7 +731,6 @@ bool JumpThreadingPass::computeValueKnownInPredecessorsImpl(
726
731
if (Preference != WantInteger)
727
732
return false ;
728
733
if (ConstantInt *CI = dyn_cast<ConstantInt>(BO->getOperand (1 ))) {
729
- const DataLayout &DL = BO->getModule ()->getDataLayout ();
730
734
PredValueInfoTy LHSVals;
731
735
computeValueKnownInPredecessorsImpl (BO->getOperand (0 ), BB, LHSVals,
732
736
WantInteger, RecursionSet, CxtI);
0 commit comments