Skip to content

Commit 5df9112

Browse files
committed
Reland "[LoopPredication] Add testcase showing BPI computation. NFC"
This relands commit 16a62d4. Relanded after fixing CHECK-LINES for opt pipeline output to be more general (based on failures seen in buildbot).
1 parent 61e25d2 commit 5df9112

File tree

1 file changed

+65
-0
lines changed

1 file changed

+65
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
; RUN: opt -mtriple=x86_64 -passes='require<scalar-evolution>,require<branch-prob>,loop-mssa(loop-predication,licm,simple-loop-unswitch<nontrivial>,loop-simplifycfg)' -debug-pass-manager -debug-only=branch-prob -S < %s 2>&1 | FileCheck %s
2+
3+
; REQUIRES: asserts
4+
5+
declare void @llvm.experimental.guard(i1, ...)
6+
7+
; CHECK: Running pass: RequireAnalysisPass<llvm::BranchProbabilityAnalysis
8+
; CHECK-NEXT: Running analysis: BranchProbabilityAnalysis on unsigned_loop_0_to_n_ult_check
9+
; CHECK-NEXT: Running analysis: PostDominatorTreeAnalysis on unsigned_loop_0_to_n_ult_check
10+
; CHECK-NEXT: ---- Branch Probability Info : unsigned_loop_0_to_n_ult_check ----
11+
; CHECK: Running pass: LoopSimplifyPass on unsigned_loop_0_to_n_ult_check
12+
; CHECK: Running pass: LoopPredicationPass on Loop at depth 1
13+
; CHECK-NEXT: ---- Branch Probability Info : unsigned_loop_0_to_n_ult_check ----
14+
; CHECK: Running pass: LICMPass on Loop at depth 1
15+
; CHECK-NEXT: Running pass: SimpleLoopUnswitchPass on Loop at depth 1
16+
; CHECK-NEXT: Running pass: LoopPredicationPass on Loop at depth 1
17+
; CHECK-NEXT: ---- Branch Probability Info : unsigned_loop_0_to_n_ult_check ----
18+
; CHECK: Running pass: LICMPass on Loop at depth 1
19+
; CHECK-NEXT: Running pass: SimpleLoopUnswitchPass on Loop at depth 1
20+
; CHECK-NEXT: Running pass: LoopSimplifyCFGPass on Loop at depth 1
21+
; CHECK-NEXT: Invalidating analysis: BranchProbabilityAnalysis on unsigned_loop_0_to_n_ult_check
22+
23+
24+
define i32 @unsigned_loop_0_to_n_ult_check(i32* %array, i32 %length, i32 %n) {
25+
entry:
26+
%tmp5 = icmp eq i32 %n, 0
27+
br i1 %tmp5, label %exit, label %loop.preheader
28+
29+
loop.preheader: ; preds = %entry
30+
br label %loop
31+
32+
loop: ; preds = %guarded, %loop.preheader
33+
%loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
34+
%i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
35+
%within.bounds = icmp ult i32 %i, %length
36+
%widenable_cond = call i1 @llvm.experimental.widenable.condition()
37+
%exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond
38+
br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
39+
40+
deopt: ; preds = %loop
41+
%deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
42+
ret i32 %deoptcall
43+
44+
guarded: ; preds = %loop
45+
%i.i64 = zext i32 %i to i64
46+
%array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64
47+
%array.i = load i32, i32* %array.i.ptr, align 4
48+
%loop.acc.next = add i32 %loop.acc, %array.i
49+
%i.next = add nuw i32 %i, 1
50+
%continue = icmp ult i32 %i.next, %n
51+
br i1 %continue, label %loop, label %exit, !prof !2
52+
53+
exit: ; preds = %guarded, %entry
54+
%result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
55+
ret i32 %result
56+
}
57+
58+
declare i32 @llvm.experimental.deoptimize.i32(...)
59+
declare i1 @llvm.experimental.widenable.condition() #0
60+
61+
attributes #0 = { inaccessiblememonly nounwind }
62+
63+
!0 = !{!"branch_weights", i32 1048576, i32 1}
64+
!1 = !{i32 1, i32 -2147483648}
65+
!2 = !{!"branch_weights", i32 1024, i32 1}

0 commit comments

Comments
 (0)