1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 3
2 ; RUN: opt -S -loop-predication-skip-profitability-checks=false -passes='require<scalar-evolution>,loop-mssa(loop-predication)' %s | FileCheck %s
4 target triple = "x86_64-unknown-linux-gnu"
6 ; Function Attrs: nocallback nofree nosync willreturn
7 declare void @llvm.experimental.guard(i1, ...) #0
9 ; Check that LoopPredication doesn't crash on all-zero branch weights
11 ; CHECK-LABEL: define void @foo() {
13 ; CHECK-NEXT: br label [[HEADER:%.*]]
15 ; CHECK-NEXT: [[J2:%.*]] = phi i64 [ 0, [[ENTRY:%.*]] ], [ [[J_NEXT:%.*]], [[LATCH:%.*]] ]
16 ; CHECK-NEXT: call void (i1, ...) @llvm.experimental.guard(i1 false, i32 0) [ "deopt"() ]
17 ; CHECK-NEXT: [[J_NEXT]] = add i64 [[J2]], 1
18 ; CHECK-NEXT: br i1 false, label [[LATCH]], label [[EXIT:%.*]]
20 ; CHECK-NEXT: [[SPECULATE_TRIP_COUNT:%.*]] = icmp ult i64 [[J2]], 0
21 ; CHECK-NEXT: br i1 [[SPECULATE_TRIP_COUNT]], label [[HEADER]], label [[COMMON_RET_LOOPEXIT:%.*]], !prof [[PROF0:![0-9]+]]
22 ; CHECK: common.ret.loopexit:
23 ; CHECK-NEXT: br label [[COMMON_RET:%.*]]
25 ; CHECK-NEXT: ret void
27 ; CHECK-NEXT: br label [[COMMON_RET]]
32 Header: ; preds = %Latch, %entry
33 %j2 = phi i64 [ 0, %entry ], [ %j.next, %Latch ]
34 call void (i1, ...) @llvm.experimental.guard(i1 false, i32 0) [ "deopt"() ]
35 %j.next = add i64 %j2, 1
36 br i1 false, label %Latch, label %exit
38 Latch: ; preds = %Header
39 %speculate_trip_count = icmp ult i64 %j2, 0
40 br i1 %speculate_trip_count, label %Header, label %common.ret, !prof !0
42 common.ret: ; preds = %exit, %Latch
45 exit: ; preds = %Header
49 attributes #0 = { nocallback nofree nosync willreturn }
51 !0 = !{!"branch_weights", i32 0, i32 0}