Skip to content

Commit de6ae29

Browse files
committed
implemented feedback
1 parent 60f2856 commit de6ae29

File tree

2 files changed

+68
-10
lines changed

2 files changed

+68
-10
lines changed

llvm/lib/Transforms/Scalar/JumpThreading.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1534,16 +1534,16 @@ Constant *JumpThreadingPass::evaluateOnPredecessorEdge(
15341534
// instructions in unreachable code and check before going into recursion.
15351535
if (CmpInst *CondCmp = dyn_cast<CmpInst>(V)) {
15361536
if (CondCmp->getParent() == BB) {
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);
1537+
Constant *Op0 = nullptr;
1538+
Constant *Op1 = nullptr;
1539+
if (Value *V0 = CondCmp->getOperand(0); !Visited.contains(V0)) {
1540+
Op0 = evaluateOnPredecessorEdge(BB, PredPredBB, V0, DL, Visited);
1541+
Visited.erase(V0);
1542+
}
1543+
if (Value *V1 = CondCmp->getOperand(1); !Visited.contains(V1)) {
1544+
Op1 = evaluateOnPredecessorEdge(BB, PredPredBB, V1, DL, Visited);
1545+
Visited.erase(V1);
1546+
}
15471547
if (Op0 && Op1) {
15481548
return ConstantFoldCompareInstOperands(CondCmp->getPredicate(), Op0,
15491549
Op1, DL);

llvm/test/Transforms/JumpThreading/unreachable-loops.ll

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,62 @@ F7: ; No predecessors!
239239
br label %BB5
240240
}
241241

242+
; Same as above, but with multiple icmps referencing the same PHI node.
243+
244+
define i32 @recursive_icmp_mult(ptr %ptr) {
245+
; CHECK-LABEL: @recursive_icmp_mult(
246+
; CHECK-NEXT: [[A9:%.*]] = alloca i1, align 1
247+
; CHECK-NEXT: br label [[F6:%.*]]
248+
; CHECK: T3:
249+
; CHECK-NEXT: br label [[BB5:%.*]]
250+
; CHECK: BB5:
251+
; CHECK-NEXT: [[L10:%.*]] = load i1, ptr [[A9]], align 1
252+
; CHECK-NEXT: br i1 [[L10]], label [[BB6:%.*]], label [[F6]]
253+
; CHECK: BB6:
254+
; CHECK-NEXT: [[LGV3:%.*]] = load i1, ptr [[PTR:%.*]], align 1
255+
; CHECK-NEXT: [[C4:%.*]] = icmp sle i1 [[C6:%.*]], true
256+
; CHECK-NEXT: [[C5:%.*]] = icmp sle i1 [[C6]], false
257+
; CHECK-NEXT: [[C6]] = icmp sle i1 [[C4]], [[C5]]
258+
; CHECK-NEXT: store i1 [[C6]], ptr [[PTR]], align 1
259+
; CHECK-NEXT: br i1 [[C6]], label [[F6]], label [[T3:%.*]]
260+
; CHECK: F6:
261+
; CHECK-NEXT: ret i32 0
262+
; CHECK: F7:
263+
; CHECK-NEXT: br label [[BB5]]
264+
;
265+
%A9 = alloca i1, align 1
266+
br i1 false, label %BB4, label %F6
267+
268+
BB4: ; preds = %0
269+
br i1 false, label %F6, label %F1
270+
271+
F1: ; preds = %BB4
272+
br i1 false, label %T4, label %T3
273+
274+
T3: ; preds = %T4, %BB6, %F1
275+
%L6 = load i1, ptr %ptr, align 1
276+
br label %BB5
277+
278+
BB5: ; preds = %F7, %T3
279+
%L10 = load i1, ptr %A9, align 1
280+
br i1 %L10, label %BB6, label %F6
281+
282+
BB6: ; preds = %BB5
283+
%LGV3 = load i1, ptr %ptr, align 1
284+
%C4 = icmp sle i1 %L6, true
285+
%C5 = icmp sle i1 %L6, false
286+
%C6 = icmp sle i1 %C4, %C5
287+
store i1 %C6, ptr %ptr, align 1
288+
br i1 %L6, label %F6, label %T3
289+
290+
T4: ; preds = %F1
291+
br label %T3
292+
293+
F6: ; preds = %BB6, %BB5, %BB4, %0
294+
ret i32 0
295+
296+
F7: ; No predecessors!
297+
br label %BB5
298+
}
299+
242300
!0 = !{!"branch_weights", i32 2146410443, i32 1073205}

0 commit comments

Comments
 (0)