1 ; RUN: opt -S -disable-output -unroll-partial-threshold=16 -debug-only=loop-unroll -passes='loop-unroll<runtime>' < %s 2>&1 | FileCheck %s
5 ; This test is needed to make sure that the guard cost remains the same,
6 ; independently on guard representation form (either intrinsic call or branch with
7 ; widenable condition).
9 define void @test_guard_as_intrinsic(ptr %arr, i64 %n, i64 %bound) {
10 ; CHECK-LABEL: Loop Unroll: F[test_guard_as_intrinsic] Loop %loop
11 ; CHECK-NEXT: Loop Size = 8
12 ; CHECK-NEXT: runtime unrolling with count: 2
17 %iv = phi i64 [0, %entry], [%iv.next, %loop]
18 %gep = getelementptr i64, ptr %arr, i64 %iv
19 %bound_check = icmp ult i64 %iv, %bound
20 call void(i1, ...) @llvm.experimental.guard(i1 %bound_check) [ "deopt"() ]
21 store i64 %iv, ptr %gep, align 8
22 store i64 %iv, ptr %gep, align 8
23 %iv.next = add i64 %iv, 1
24 %loop_cond = icmp ult i64 %iv, %n
25 br i1 %loop_cond, label %loop, label %exit
31 define void @test_guard_as_branch(ptr %arr, i64 %n, i64 %bound) {
32 ; CHECK-LABEL: Loop Unroll: F[test_guard_as_branch] Loop %loop
33 ; CHECK-NEXT: Loop Size = 8
34 ; CHECK-NEXT: runtime unrolling with count: 2
38 loop: ; preds = %guarded, %entry
39 %iv = phi i64 [ 0, %entry ], [ %iv.next, %guarded ]
40 %gep = getelementptr i64, ptr %arr, i64 %iv
41 %bound_check = icmp ult i64 %iv, %bound
42 %widenable_cond = call i1 @llvm.experimental.widenable.condition()
43 %exiplicit_guard_cond = and i1 %bound_check, %widenable_cond
44 br i1 %exiplicit_guard_cond, label %guarded, label %deopt, !prof !0
46 deopt: ; preds = %loop
47 call void (...) @llvm.experimental.deoptimize.isVoid() [ "deopt"() ]
50 guarded: ; preds = %loop
51 store i64 %iv, ptr %gep, align 8
52 store i64 %iv, ptr %gep, align 8
53 %iv.next = add i64 %iv, 1
54 %loop_cond = icmp ult i64 %iv, %n
55 br i1 %loop_cond, label %loop, label %exit
57 exit: ; preds = %guarded
61 ; Function Attrs: nocallback nofree nosync willreturn
62 declare void @llvm.experimental.guard(i1, ...) #0
64 declare void @llvm.experimental.deoptimize.isVoid(...)
66 ; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(inaccessiblemem: readwrite)
67 declare i1 @llvm.experimental.widenable.condition() #1
69 !0 = !{!"branch_weights", i32 1048576, i32 1}