|
| 1 | +; RUN: opt -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 analysis: ScalarEvolutionAnalysis on unsigned_loop_0_to_n_ult_check |
| 8 | +; CHECK-NEXT: Running analysis: TargetLibraryAnalysis on unsigned_loop_0_to_n_ult_check |
| 9 | +; CHECK-NEXT: Running analysis: AssumptionAnalysis on unsigned_loop_0_to_n_ult_check |
| 10 | +; CHECK-NEXT: Running analysis: DominatorTreeAnalysis on unsigned_loop_0_to_n_ult_check |
| 11 | +; CHECK-NEXT: Running analysis: LoopAnalysis on unsigned_loop_0_to_n_ult_check |
| 12 | +; CHECK-NEXT: Running pass: RequireAnalysisPass<llvm::BranchProbabilityAnalysis, llvm::Function> on unsigned_loop_0_to_n_ult_check |
| 13 | +; CHECK-NEXT: Running analysis: BranchProbabilityAnalysis on unsigned_loop_0_to_n_ult_check |
| 14 | +; CHECK-NEXT: Running analysis: PostDominatorTreeAnalysis on unsigned_loop_0_to_n_ult_check |
| 15 | +; CHECK-NEXT: ---- Branch Probability Info : unsigned_loop_0_to_n_ult_check ---- |
| 16 | +; CHECK: Running pass: LoopSimplifyPass on unsigned_loop_0_to_n_ult_check |
| 17 | +; CHECK: Running pass: LoopPredicationPass on Loop at depth 1 |
| 18 | +; CHECK-NEXT: ---- Branch Probability Info : unsigned_loop_0_to_n_ult_check ---- |
| 19 | +; CHECK: Running pass: LICMPass on Loop at depth 1 |
| 20 | +; CHECK-NEXT: Running pass: SimpleLoopUnswitchPass on Loop at depth 1 |
| 21 | +; CHECK-NEXT: Running pass: LoopPredicationPass on Loop at depth 1 |
| 22 | +; CHECK-NEXT: ---- Branch Probability Info : unsigned_loop_0_to_n_ult_check ---- |
| 23 | +; CHECK: Running pass: LICMPass on Loop at depth 1 |
| 24 | +; CHECK-NEXT: Running pass: SimpleLoopUnswitchPass on Loop at depth 1 |
| 25 | +; CHECK-NEXT: Running pass: LoopSimplifyCFGPass on Loop at depth 1 |
| 26 | +; CHECK-NEXT: Invalidating analysis: BranchProbabilityAnalysis on unsigned_loop_0_to_n_ult_check |
| 27 | + |
| 28 | + |
| 29 | +define i32 @unsigned_loop_0_to_n_ult_check(i32* %array, i32 %length, i32 %n) { |
| 30 | +entry: |
| 31 | + %tmp5 = icmp eq i32 %n, 0 |
| 32 | + br i1 %tmp5, label %exit, label %loop.preheader |
| 33 | + |
| 34 | +loop.preheader: ; preds = %entry |
| 35 | + br label %loop |
| 36 | + |
| 37 | +loop: ; preds = %guarded, %loop.preheader |
| 38 | + %loop.acc = phi i32 [ %loop.acc.next, %guarded ], [ 0, %loop.preheader ] |
| 39 | + %i = phi i32 [ %i.next, %guarded ], [ 0, %loop.preheader ] |
| 40 | + %within.bounds = icmp ult i32 %i, %length |
| 41 | + %widenable_cond = call i1 @llvm.experimental.widenable.condition() |
| 42 | + %exiplicit_guard_cond = and i1 %within.bounds, %widenable_cond |
| 43 | + br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0 |
| 44 | + |
| 45 | +deopt: ; preds = %loop |
| 46 | + %deoptcall = call i32 (...) @llvm.experimental.deoptimize.i32(i32 9) [ "deopt"() ] |
| 47 | + ret i32 %deoptcall |
| 48 | + |
| 49 | +guarded: ; preds = %loop |
| 50 | + %i.i64 = zext i32 %i to i64 |
| 51 | + %array.i.ptr = getelementptr inbounds i32, i32* %array, i64 %i.i64 |
| 52 | + %array.i = load i32, i32* %array.i.ptr, align 4 |
| 53 | + %loop.acc.next = add i32 %loop.acc, %array.i |
| 54 | + %i.next = add nuw i32 %i, 1 |
| 55 | + %continue = icmp ult i32 %i.next, %n |
| 56 | + br i1 %continue, label %loop, label %exit, !prof !2 |
| 57 | + |
| 58 | +exit: ; preds = %guarded, %entry |
| 59 | + %result = phi i32 [ 0, %entry ], [ %loop.acc.next, %guarded ] |
| 60 | + ret i32 %result |
| 61 | +} |
| 62 | + |
| 63 | +declare i32 @llvm.experimental.deoptimize.i32(...) |
| 64 | +declare i1 @llvm.experimental.widenable.condition() #0 |
| 65 | + |
| 66 | +attributes #0 = { inaccessiblememonly nounwind } |
| 67 | + |
| 68 | +!0 = !{!"branch_weights", i32 1048576, i32 1} |
| 69 | +!1 = !{i32 1, i32 -2147483648} |
| 70 | +!2 = !{!"branch_weights", i32 1024, i32 1} |
0 commit comments