• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2; RUN: opt -S -make-guards-explicit < %s        | FileCheck %s
3; RUN: opt -S -passes=make-guards-explicit < %s | FileCheck %s
4
5declare void @llvm.experimental.guard(i1,...)
6
7; Check that a sole guard can be turned into explicit guards form.
8define void @trivial_guard(i1 %cond) {
9; CHECK-LABEL: @trivial_guard(
10; CHECK-NEXT:  entry:
11; CHECK-NEXT:    [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
12; CHECK-NEXT:    [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[COND:%.*]], [[WIDENABLE_COND]]
13; CHECK-NEXT:    br i1 [[EXIPLICIT_GUARD_COND]], label [[GUARDED:%.*]], label [[DEOPT:%.*]], !prof !0
14; CHECK:       deopt:
15; CHECK-NEXT:    call void (...) @llvm.experimental.deoptimize.isVoid() [ "deopt"(i32 123, i64 456) ]
16; CHECK-NEXT:    ret void
17; CHECK:       guarded:
18; CHECK-NEXT:    ret void
19;
20entry:
21  call void(i1, ...) @llvm.experimental.guard(i1 %cond) [ "deopt"(i32 123, i64 456) ]
22  ret void
23}
24
25; Check that a sequence of guards can be turned into explicit guards form.
26define void @trivial_guard_sequence(i1 %cond1, i1 %cond2, i1 %cond3) {
27; CHECK-LABEL: @trivial_guard_sequence(
28; CHECK-NEXT:  entry:
29; CHECK-NEXT:    [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
30; CHECK-NEXT:    [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[COND1:%.*]], [[WIDENABLE_COND]]
31; CHECK-NEXT:    br i1 [[EXIPLICIT_GUARD_COND]], label [[GUARDED:%.*]], label [[DEOPT:%.*]], !prof !0
32; CHECK:       deopt:
33; CHECK-NEXT:    call void (...) @llvm.experimental.deoptimize.isVoid() [ "deopt"(i32 123, i64 456) ]
34; CHECK-NEXT:    ret void
35; CHECK:       guarded:
36; CHECK-NEXT:    [[WIDENABLE_COND3:%.*]] = call i1 @llvm.experimental.widenable.condition()
37; CHECK-NEXT:    [[EXIPLICIT_GUARD_COND4:%.*]] = and i1 [[COND2:%.*]], [[WIDENABLE_COND3]]
38; CHECK-NEXT:    br i1 [[EXIPLICIT_GUARD_COND4]], label [[GUARDED1:%.*]], label [[DEOPT2:%.*]], !prof !0
39; CHECK:       deopt2:
40; CHECK-NEXT:    call void (...) @llvm.experimental.deoptimize.isVoid() [ "deopt"(i32 789, i64 123) ]
41; CHECK-NEXT:    ret void
42; CHECK:       guarded1:
43; CHECK-NEXT:    [[WIDENABLE_COND7:%.*]] = call i1 @llvm.experimental.widenable.condition()
44; CHECK-NEXT:    [[EXIPLICIT_GUARD_COND8:%.*]] = and i1 [[COND3:%.*]], [[WIDENABLE_COND7]]
45; CHECK-NEXT:    br i1 [[EXIPLICIT_GUARD_COND8]], label [[GUARDED5:%.*]], label [[DEOPT6:%.*]], !prof !0
46; CHECK:       deopt6:
47; CHECK-NEXT:    call void (...) @llvm.experimental.deoptimize.isVoid() [ "deopt"(i32 456, i64 789) ]
48; CHECK-NEXT:    ret void
49; CHECK:       guarded5:
50; CHECK-NEXT:    ret void
51;
52entry:
53  call void(i1, ...) @llvm.experimental.guard(i1 %cond1) [ "deopt"(i32 123, i64 456) ]
54  call void(i1, ...) @llvm.experimental.guard(i1 %cond2) [ "deopt"(i32 789, i64 123) ]
55  call void(i1, ...) @llvm.experimental.guard(i1 %cond3) [ "deopt"(i32 456, i64 789) ]
56  ret void
57}
58
59; Check that all instructions between the guards preserve.
60define void @split_block_contents(i1 %cond1, i1 %cond2, i1 %cond3, i32* %p) {
61; CHECK-LABEL: @split_block_contents(
62; CHECK-NEXT:  entry:
63; CHECK-NEXT:    store i32 0, i32* [[P:%.*]]
64; CHECK-NEXT:    [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
65; CHECK-NEXT:    [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[COND1:%.*]], [[WIDENABLE_COND]]
66; CHECK-NEXT:    br i1 [[EXIPLICIT_GUARD_COND]], label [[GUARDED:%.*]], label [[DEOPT:%.*]], !prof !0
67; CHECK:       deopt:
68; CHECK-NEXT:    call void (...) @llvm.experimental.deoptimize.isVoid() [ "deopt"(i32 123, i64 456) ]
69; CHECK-NEXT:    ret void
70; CHECK:       guarded:
71; CHECK-NEXT:    store i32 1, i32* [[P]]
72; CHECK-NEXT:    [[WIDENABLE_COND3:%.*]] = call i1 @llvm.experimental.widenable.condition()
73; CHECK-NEXT:    [[EXIPLICIT_GUARD_COND4:%.*]] = and i1 [[COND2:%.*]], [[WIDENABLE_COND3]]
74; CHECK-NEXT:    br i1 [[EXIPLICIT_GUARD_COND4]], label [[GUARDED1:%.*]], label [[DEOPT2:%.*]], !prof !0
75; CHECK:       deopt2:
76; CHECK-NEXT:    call void (...) @llvm.experimental.deoptimize.isVoid() [ "deopt"(i32 789, i64 123) ]
77; CHECK-NEXT:    ret void
78; CHECK:       guarded1:
79; CHECK-NEXT:    store i32 2, i32* [[P]]
80; CHECK-NEXT:    [[WIDENABLE_COND7:%.*]] = call i1 @llvm.experimental.widenable.condition()
81; CHECK-NEXT:    [[EXIPLICIT_GUARD_COND8:%.*]] = and i1 [[COND3:%.*]], [[WIDENABLE_COND7]]
82; CHECK-NEXT:    br i1 [[EXIPLICIT_GUARD_COND8]], label [[GUARDED5:%.*]], label [[DEOPT6:%.*]], !prof !0
83; CHECK:       deopt6:
84; CHECK-NEXT:    call void (...) @llvm.experimental.deoptimize.isVoid() [ "deopt"(i32 456, i64 789) ]
85; CHECK-NEXT:    ret void
86; CHECK:       guarded5:
87; CHECK-NEXT:    store i32 3, i32* [[P]]
88; CHECK-NEXT:    ret void
89;
90entry:
91  store i32 0, i32* %p
92  call void(i1, ...) @llvm.experimental.guard(i1 %cond1) [ "deopt"(i32 123, i64 456) ]
93  store i32 1, i32* %p
94  call void(i1, ...) @llvm.experimental.guard(i1 %cond2) [ "deopt"(i32 789, i64 123) ]
95  store i32 2, i32* %p
96  call void(i1, ...) @llvm.experimental.guard(i1 %cond3) [ "deopt"(i32 456, i64 789) ]
97  store i32 3, i32* %p
98  ret void
99}
100
101; Check that the guard can split a loop properly.
102define void @split_loop(i1 %cond, i32 %N, i32 %M) {
103; CHECK-LABEL: @split_loop(
104; CHECK-NEXT:  entry:
105; CHECK-NEXT:    br label [[LOOP:%.*]]
106; CHECK:       loop:
107; CHECK-NEXT:    [[IV:%.*]] = phi i32 [ 0, [[ENTRY:%.*]] ], [ [[IV_NEXT:%.*]], [[GUARDED:%.*]] ]
108; CHECK-NEXT:    [[GUARD_COND:%.*]] = icmp slt i32 [[IV]], [[N:%.*]]
109; CHECK-NEXT:    [[WIDENABLE_COND:%.*]] = call i1 @llvm.experimental.widenable.condition()
110; CHECK-NEXT:    [[EXIPLICIT_GUARD_COND:%.*]] = and i1 [[GUARD_COND]], [[WIDENABLE_COND]]
111; CHECK-NEXT:    br i1 [[EXIPLICIT_GUARD_COND]], label [[GUARDED]], label [[DEOPT:%.*]], !prof !0
112; CHECK:       deopt:
113; CHECK-NEXT:    call void (...) @llvm.experimental.deoptimize.isVoid() [ "deopt"(i32 123, i64 456) ]
114; CHECK-NEXT:    ret void
115; CHECK:       guarded:
116; CHECK-NEXT:    [[LOOP_COND:%.*]] = icmp slt i32 [[IV]], [[M:%.*]]
117; CHECK-NEXT:    [[IV_NEXT]] = add i32 [[IV]], 1
118; CHECK-NEXT:    br i1 [[LOOP_COND]], label [[LOOP]], label [[EXIT:%.*]]
119; CHECK:       exit:
120; CHECK-NEXT:    ret void
121;
122entry:
123  br label %loop
124
125loop:
126  %iv = phi i32 [ 0, %entry ], [ %iv.next, %loop ]
127  %guard_cond = icmp slt i32 %iv, %N
128  call void(i1, ...) @llvm.experimental.guard(i1 %guard_cond) [ "deopt"(i32 123, i64 456) ]
129  %loop_cond = icmp slt i32 %iv, %M
130  %iv.next = add i32 %iv, 1
131  br i1 %loop_cond, label %loop, label %exit
132
133exit:
134  ret void
135}
136