@@ -1498,6 +1498,15 @@ Constant *JumpThreadingPass::evaluateOnPredecessorEdge(BasicBlock *BB,
1498
1498
BasicBlock *PredPredBB,
1499
1499
Value *V,
1500
1500
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
+
1501
1510
BasicBlock *PredBB = BB->getSinglePredecessor ();
1502
1511
assert (PredBB && " Expected a single predecessor" );
1503
1512
@@ -1525,14 +1534,16 @@ Constant *JumpThreadingPass::evaluateOnPredecessorEdge(BasicBlock *BB,
1525
1534
// instructions in unreachable code and check before going into recursion.
1526
1535
if (CmpInst *CondCmp = dyn_cast<CmpInst>(V)) {
1527
1536
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);
1536
1547
if (Op0 && Op1) {
1537
1548
return ConstantFoldCompareInstOperands (CondCmp->getPredicate (), Op0,
1538
1549
Op1, DL);
0 commit comments