Skip to content

Commit 1ae1449

Browse files
committed
use make_scope_exit
1 parent 643cb86 commit 1ae1449

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

llvm/lib/Transforms/Scalar/JumpThreading.cpp

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "llvm/ADT/DenseMap.h"
1515
#include "llvm/ADT/MapVector.h"
1616
#include "llvm/ADT/STLExtras.h"
17+
#include "llvm/ADT/ScopeExit.h"
1718
#include "llvm/ADT/SmallPtrSet.h"
1819
#include "llvm/ADT/SmallVector.h"
1920
#include "llvm/ADT/Statistic.h"
@@ -1507,6 +1508,7 @@ Constant *JumpThreadingPass::evaluateOnPredecessorEdge(
15071508
SmallPtrSet<Value *, 8> &Visited) {
15081509
if (!Visited.insert(V).second)
15091510
return nullptr;
1511+
auto _ = make_scope_exit([&Visited, V]() { Visited.erase(V); });
15101512

15111513
BasicBlock *PredBB = BB->getSinglePredecessor();
15121514
assert(PredBB && "Expected a single predecessor");
@@ -1535,16 +1537,10 @@ Constant *JumpThreadingPass::evaluateOnPredecessorEdge(
15351537
// instructions in unreachable code and check before going into recursion.
15361538
if (CmpInst *CondCmp = dyn_cast<CmpInst>(V)) {
15371539
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);
15481544
if (Op0 && Op1) {
15491545
return ConstantFoldCompareInstOperands(CondCmp->getPredicate(), Op0,
15501546
Op1, DL);

0 commit comments

Comments
 (0)