1 ; RUN: opt -mtriple=x86_64 -passes='loop-mssa(loop-predication,licm,simple-loop-unswitch<nontrivial>,loop-simplifycfg)' -debug-pass-manager -debug-only=branch-prob -S < %s 2>&1 | FileCheck %s
5 ; This test is to solely check that we do not run BPI every single time loop
6 ; predication is invoked (since BPI is preserved as part of
7 ; LoopStandardAnalysisResults).
8 declare void @llvm.experimental.guard(i1, ...)
10 ; CHECK: Running pass: LoopPredicationPass on loop
11 ; CHECK-NEXT: Running pass: LICMPass on loop
12 ; CHECK-NEXT: Running pass: SimpleLoopUnswitchPass on loop
13 ; CHECK-NEXT: Running analysis: OuterAnalysisManagerProxy
14 ; CHECK-NEXT: Running pass: LoopPredicationPass on loop
15 ; CHECK-NEXT: Running pass: LICMPass on loop
16 ; CHECK-NEXT: Running pass: SimpleLoopUnswitchPass on loop
17 ; CHECK-NEXT: Running pass: LoopSimplifyCFGPass on loop
19 define i32 @unsigned_loop_0_to_n_ult_check(ptr %array, i32 %length, i32 %n) {
21 %tmp5 = icmp eq i32 %n, 0
22 br i1 %tmp5, label %exit, label %loop.preheader
24 loop.preheader: ; preds = %entry
27 loop: ; preds = %guarded, %loop.preheader
28 %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ]
29 %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ]
30 %within.bounds = icmp ult i32 %i, %length
31 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
32 %exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond
33 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
35 deopt: ; preds = %loop
36 %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ]
39 guarded: ; preds = %loop
40 %i.i64 = zext i32 %i to i64
41 %array.i.ptr = getelementptr inbounds i32, ptr %array, i64 %i.i64
42 %array.i = load i32, ptr %array.i.ptr, align 4
43 %loop.acc.next = add i32 %loop.acc, %array.i
44 %i.next = add nuw i32 %i, 1
45 %continue = icmp ult i32 %i.next, %n
46 br i1 %continue, label %loop, label %exit, !prof !2
48 exit: ; preds = %guarded, %entry
49 %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ]
53 declare i32 @llvm.experimental.deoptimize.i32(...)
54 declare i1 @llvm.experimental.widenable.condition() #0
56 attributes #0 = { inaccessiblememonly nounwind }
58 !0 = !{!"branch_weights", i32 1048576, i32 1}
59 !1 = !{i32 1, i32 -2147483648}
60 !2 = !{!"branch_weights", i32 1024, i32 1}