@@ -1498,6 +1498,15 @@ Constant *JumpThreadingPass::evaluateOnPredecessorEdge(BasicBlock *BB,
14981498 BasicBlock *PredPredBB,
14991499 Value *V,
15001500 const DataLayout &DL) {
1501+ SmallPtrSet<Value *, 8 > Visited;
1502+ return evaluateOnPredecessorEdge (BB, PredPredBB, V, DL, Visited);
1503+ }
1504+
1505+ Constant *JumpThreadingPass::evaluateOnPredecessorEdge (
1506+ BasicBlock *BB, BasicBlock *PredPredBB, Value *V, const DataLayout &DL,
1507+ SmallPtrSet<Value *, 8 > &Visited) {
1508+ Visited.insert (V);
1509+
15011510 BasicBlock *PredBB = BB->getSinglePredecessor ();
15021511 assert (PredBB && " Expected a single predecessor" );
15031512
@@ -1525,14 +1534,16 @@ Constant *JumpThreadingPass::evaluateOnPredecessorEdge(BasicBlock *BB,
15251534 // instructions in unreachable code and check before going into recursion.
15261535 if (CmpInst *CondCmp = dyn_cast<CmpInst>(V)) {
15271536 if (CondCmp->getParent () == BB) {
1528- Constant *Op0 = CondCmp->getOperand (0 ) == CondCmp
1529- ? nullptr
1530- : evaluateOnPredecessorEdge (
1531- BB, PredPredBB, CondCmp->getOperand (0 ), DL);
1532- Constant *Op1 = CondCmp->getOperand (1 ) == CondCmp
1533- ? nullptr
1534- : evaluateOnPredecessorEdge (
1535- BB, PredPredBB, CondCmp->getOperand (1 ), DL);
1537+ Constant *Op0 =
1538+ Visited.contains (CondCmp->getOperand (0 ))
1539+ ? nullptr
1540+ : evaluateOnPredecessorEdge (BB, PredPredBB,
1541+ CondCmp->getOperand (0 ), DL, Visited);
1542+ Constant *Op1 =
1543+ Visited.contains (CondCmp->getOperand (1 ))
1544+ ? nullptr
1545+ : evaluateOnPredecessorEdge (BB, PredPredBB,
1546+ CondCmp->getOperand (1 ), DL, Visited);
15361547 if (Op0 && Op1) {
15371548 return ConstantFoldCompareInstOperands (CondCmp->getPredicate (), Op0,
15381549 Op1, DL);
0 commit comments