|
14 | 14 | #include "llvm/ADT/DenseMap.h" |
15 | 15 | #include "llvm/ADT/MapVector.h" |
16 | 16 | #include "llvm/ADT/STLExtras.h" |
| 17 | +#include "llvm/ADT/ScopeExit.h" |
17 | 18 | #include "llvm/ADT/SmallPtrSet.h" |
18 | 19 | #include "llvm/ADT/SmallVector.h" |
19 | 20 | #include "llvm/ADT/Statistic.h" |
@@ -1507,6 +1508,7 @@ Constant *JumpThreadingPass::evaluateOnPredecessorEdge( |
1507 | 1508 | SmallPtrSet<Value *, 8> &Visited) { |
1508 | 1509 | if (!Visited.insert(V).second) |
1509 | 1510 | return nullptr; |
| 1511 | + auto _ = make_scope_exit([&Visited, V]() { Visited.erase(V); }); |
1510 | 1512 |
|
1511 | 1513 | BasicBlock *PredBB = BB->getSinglePredecessor(); |
1512 | 1514 | assert(PredBB && "Expected a single predecessor"); |
@@ -1535,16 +1537,10 @@ Constant *JumpThreadingPass::evaluateOnPredecessorEdge( |
1535 | 1537 | // instructions in unreachable code and check before going into recursion. |
1536 | 1538 | if (CmpInst *CondCmp = dyn_cast<CmpInst>(V)) { |
1537 | 1539 | if (CondCmp->getParent() == BB) { |
1538 | | - Constant *Op0 = nullptr; |
1539 | | - Constant *Op1 = nullptr; |
1540 | | - if (Value *V0 = CondCmp->getOperand(0); !Visited.contains(V0)) { |
1541 | | - Op0 = evaluateOnPredecessorEdge(BB, PredPredBB, V0, DL, Visited); |
1542 | | - Visited.erase(V0); |
1543 | | - } |
1544 | | - if (Value *V1 = CondCmp->getOperand(1); !Visited.contains(V1)) { |
1545 | | - Op1 = evaluateOnPredecessorEdge(BB, PredPredBB, V1, DL, Visited); |
1546 | | - Visited.erase(V1); |
1547 | | - } |
| 1540 | + Constant *Op0 = evaluateOnPredecessorEdge( |
| 1541 | + BB, PredPredBB, CondCmp->getOperand(0), DL, Visited); |
| 1542 | + Constant *Op1 = evaluateOnPredecessorEdge( |
| 1543 | + BB, PredPredBB, CondCmp->getOperand(1), DL, Visited); |
1548 | 1544 | if (Op0 && Op1) { |
1549 | 1545 | return ConstantFoldCompareInstOperands(CondCmp->getPredicate(), Op0, |
1550 | 1546 | Op1, DL); |
|
0 commit comments