1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; then metadata checks MDn were added manually.
3 ; RUN: opt -passes='loop(unswitch),verify<loops>' -S < %s | FileCheck %s
4 ; RUN: opt -enable-mssa-loop-dependency=true -verify-memoryssa -passes='loop(unswitch),verify<loops>' -S < %s | FileCheck %s
6 declare void @some_func()
8 ; Test for a trivially unswitchable switch with non-default case exiting.
9 define i32 @test2(i32* %var, i32 %cond1, i32 %cond2) {
10 ; CHECK-LABEL: @test2(
12 ; CHECK-NEXT: switch i32 [[COND2:%.*]], label [[ENTRY_SPLIT:%.*]] [
13 ; CHECK-NEXT: i32 2, label [[LOOP_EXIT2:%.*]]
14 ; CHECK-NEXT: ], !prof ![[MD0:[0-9]+]]
16 ; CHECK-NEXT: br label [[LOOP_BEGIN:%.*]]
18 ; CHECK-NEXT: [[VAR_VAL:%.*]] = load i32, i32* [[VAR:%.*]]
19 ; CHECK-NEXT: switch i32 [[COND2]], label [[LOOP2:%.*]] [
20 ; CHECK-NEXT: i32 0, label [[LOOP0:%.*]]
21 ; CHECK-NEXT: i32 1, label [[LOOP1:%.*]]
22 ; CHECK-NEXT: ], !prof ![[MD1:[0-9]+]]
24 ; CHECK-NEXT: call void @some_func()
25 ; CHECK-NEXT: br label [[LOOP_LATCH:%.*]]
27 ; CHECK-NEXT: call void @some_func()
28 ; CHECK-NEXT: br label [[LOOP_LATCH]]
30 ; CHECK-NEXT: call void @some_func()
31 ; CHECK-NEXT: br label [[LOOP_LATCH]]
33 ; CHECK-NEXT: br label [[LOOP_BEGIN]]
35 ; CHECK-NEXT: ret i32 0
37 ; CHECK-NEXT: ret i32 0
39 ; CHECK-NEXT: ret i32 0
45 %var_val = load i32, i32* %var
46 switch i32 %cond2, label %loop2 [
49 i32 2, label %loop_exit2
50 ], !prof !{!"branch_weights", i32 99, i32 100, i32 101, i32 102}
53 call void @some_func()
57 call void @some_func()
61 call void @some_func()
77 ; Test for a trivially unswitchable switch with only the default case exiting.
78 define i32 @test3(i32* %var, i32 %cond1, i32 %cond2) {
79 ; CHECK-LABEL: @test3(
81 ; CHECK-NEXT: switch i32 [[COND2:%.*]], label [[LOOP_EXIT2:%.*]] [
82 ; CHECK-NEXT: i32 0, label [[ENTRY_SPLIT:%.*]]
83 ; CHECK-NEXT: i32 1, label [[ENTRY_SPLIT]]
84 ; CHECK-NEXT: i32 2, label [[ENTRY_SPLIT]]
85 ; CHECK-NEXT: ], !prof ![[MD2:[0-9]+]]
87 ; CHECK-NEXT: br label [[LOOP_BEGIN:%.*]]
89 ; CHECK-NEXT: [[VAR_VAL:%.*]] = load i32, i32* [[VAR:%.*]]
90 ; CHECK-NEXT: switch i32 [[COND2]], label [[LOOP2:%.*]] [
91 ; CHECK-NEXT: i32 0, label [[LOOP0:%.*]]
92 ; CHECK-NEXT: i32 1, label [[LOOP1:%.*]]
93 ; CHECK-NEXT: ], !prof ![[MD3:[0-9]+]]
95 ; CHECK-NEXT: call void @some_func()
96 ; CHECK-NEXT: br label [[LOOP_LATCH:%.*]]
98 ; CHECK-NEXT: call void @some_func()
99 ; CHECK-NEXT: br label [[LOOP_LATCH]]
101 ; CHECK-NEXT: call void @some_func()
102 ; CHECK-NEXT: br label [[LOOP_LATCH]]
104 ; CHECK-NEXT: br label [[LOOP_BEGIN]]
106 ; CHECK-NEXT: ret i32 0
108 ; CHECK-NEXT: ret i32 0
110 ; CHECK-NEXT: ret i32 0
116 %var_val = load i32, i32* %var
117 switch i32 %cond2, label %loop_exit2 [
121 ], !prof !{!"branch_weights", i32 99, i32 100, i32 101, i32 102}
124 call void @some_func()
128 call void @some_func()
132 call void @some_func()
148 ; Test for a trivially unswitchable switch with multiple exiting cases and
149 ; multiple looping cases.
150 define i32 @test4(i32* %var, i32 %cond1, i32 %cond2) {
151 ; CHECK-LABEL: @test4(
153 ; CHECK-NEXT: switch i32 [[COND2:%.*]], label [[LOOP_EXIT2:%.*]] [
154 ; CHECK-NEXT: i32 13, label [[LOOP_EXIT1:%.*]]
155 ; CHECK-NEXT: i32 42, label [[LOOP_EXIT3:%.*]]
156 ; CHECK-NEXT: i32 0, label [[ENTRY_SPLIT:%.*]]
157 ; CHECK-NEXT: i32 1, label [[ENTRY_SPLIT]]
158 ; CHECK-NEXT: i32 2, label [[ENTRY_SPLIT]]
159 ; CHECK-NEXT: ], !prof ![[MD4:[0-9]+]]
160 ; CHECK: entry.split:
161 ; CHECK-NEXT: br label [[LOOP_BEGIN:%.*]]
163 ; CHECK-NEXT: [[VAR_VAL:%.*]] = load i32, i32* [[VAR:%.*]]
164 ; CHECK-NEXT: switch i32 [[COND2]], label [[LOOP2:%.*]] [
165 ; CHECK-NEXT: i32 0, label [[LOOP0:%.*]]
166 ; CHECK-NEXT: i32 1, label [[LOOP1:%.*]]
167 ; CHECK-NEXT: ], !prof ![[MD3:[0-9]+]]
169 ; CHECK-NEXT: call void @some_func()
170 ; CHECK-NEXT: br label [[LOOP_LATCH:%.*]]
172 ; CHECK-NEXT: call void @some_func()
173 ; CHECK-NEXT: br label [[LOOP_LATCH]]
175 ; CHECK-NEXT: call void @some_func()
176 ; CHECK-NEXT: br label [[LOOP_LATCH]]
178 ; CHECK-NEXT: br label [[LOOP_BEGIN]]
180 ; CHECK-NEXT: ret i32 0
182 ; CHECK-NEXT: ret i32 0
184 ; CHECK-NEXT: ret i32 0
190 %var_val = load i32, i32* %var
191 switch i32 %cond2, label %loop_exit2 [
194 i32 13, label %loop_exit1
196 i32 42, label %loop_exit3
197 ], !prof !{!"branch_weights", i32 99, i32 100, i32 101, i32 113, i32 102, i32 142}
200 call void @some_func()
204 call void @some_func()
208 call void @some_func()
224 ; CHECK: ![[MD0]] = !{!"branch_weights", i32 300, i32 102}
225 ; CHECK: ![[MD1]] = !{!"branch_weights", i32 99, i32 100, i32 101}
226 ; CHECK: ![[MD2]] = !{!"branch_weights", i32 99, i32 100, i32 101, i32 102}
227 ; CHECK: ![[MD3]] = !{!"branch_weights", i32 102, i32 100, i32 101}
228 ; CHECK: ![[MD4]] = !{!"branch_weights", i32 99, i32 113, i32 142, i32 100, i32 101, i32 102}