1 ; RUN: opt < %s -S -speculative-execution \
2 ; RUN: -spec-exec-max-speculation-cost 4 -spec-exec-max-not-hoisted 3 \
4 ; RUN: opt < %s -S -passes='speculative-execution' \
5 ; RUN: -spec-exec-max-speculation-cost 4 -spec-exec-max-not-hoisted 3 \
8 target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
10 ; Hoist in if-then pattern.
11 define void @ifThen() {
12 ; CHECK-LABEL: @ifThen(
13 ; CHECK: %x = add i32 2, 3
15 br i1 true, label %a, label %b
27 ; Hoist in if-else pattern.
28 define void @ifElse() {
29 ; CHECK-LABEL: @ifElse(
30 ; CHECK: %x = add i32 2, 3
32 br i1 true, label %b, label %a
44 ; Hoist in if-then-else pattern if it is equivalent to if-then.
45 define void @ifElseThenAsIfThen() {
46 ; CHECK-LABEL: @ifElseThenAsIfThen(
47 ; CHECK: %x = add i32 2, 3
49 br i1 true, label %a, label %b
63 ; Hoist in if-then-else pattern if it is equivalent to if-else.
64 define void @ifElseThenAsIfElse() {
65 ; CHECK-LABEL: @ifElseThenAsIfElse(
66 ; CHECK: %x = add i32 2, 3
68 br i1 true, label %b, label %a
82 ; Do not hoist if-then-else pattern if it is not equivalent to if-then
84 define void @ifElseThen() {
85 ; CHECK-LABEL: @ifElseThen(
87 br i1 true, label %a, label %b
104 ; Do not hoist loads and do not hoist an instruction past a definition of
106 define void @doNotHoistPastDef() {
107 ; CHECK-LABEL: @doNotHoistPastDef(
108 br i1 true, label %b, label %a
114 %def = load i32, i32* null
116 %use = add i32 %def, 0
123 ; Case with nothing to speculate.
124 define void @nothingToSpeculate() {
125 ; CHECK-LABEL: @nothingToSpeculate(
126 br i1 true, label %b, label %a
130 %def = load i32, i32* null
137 ; Still hoist if an operand is defined before the block or is itself hoisted.
138 define void @hoistIfNotPastDef() {
139 ; CHECK-LABEL: @hoistIfNotPastDef(
141 %x = load i32, i32* null
142 ; CHECK: %y = add i32 %x, 1
143 ; CHECK: %z = add i32 %y, 1
145 br i1 true, label %b, label %a
156 ; Do not hoist if the speculation cost is too high.
157 define void @costTooHigh() {
158 ; CHECK-LABEL: @costTooHigh(
160 br i1 true, label %b, label %a
179 ; Do not hoist if too many instructions are left behind.
180 define void @tooMuchLeftBehind() {
181 ; CHECK-LABEL: @tooMuchLeftBehind(
183 br i1 true, label %b, label %a
187 %x = load i32, i32* null