Skip to content

Commit 03ae290

Browse files
committed
implement feedback
1 parent 548f359 commit 03ae290

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

llvm/include/llvm/Transforms/Scalar/JumpThreading.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ class JumpThreadingPass : public PassInfoMixin<JumpThreadingPass> {
147147

148148
Constant *evaluateOnPredecessorEdge(BasicBlock *BB, BasicBlock *PredPredBB,
149149
Value *cond, const DataLayout &DL);
150+
Constant *evaluateOnPredecessorEdge(BasicBlock *BB, BasicBlock *PredPredBB,
151+
Value *cond, const DataLayout &DL,
152+
SmallPtrSet<Value *, 8> &Visited);
150153
bool maybethreadThroughTwoBasicBlocks(BasicBlock *BB, Value *Cond);
151154
void threadThroughTwoBasicBlocks(BasicBlock *PredPredBB, BasicBlock *PredBB,
152155
BasicBlock *BB, BasicBlock *SuccBB);

llvm/lib/Transforms/Scalar/JumpThreading.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)