1 ; RUN: opt < %s -S -passes=speculative-execution \
2 ; RUN: -spec-exec-max-speculation-cost 4 -spec-exec-max-not-hoisted 3 \
5 target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"
7 ; Hoist in if-then pattern.
8 define void @ifThen() {
9 ; CHECK-LABEL: @ifThen(
10 ; CHECK: %x = add i32 2, 3
12 br i1 true, label %a, label %b
24 ; Hoist in if-else pattern.
25 define void @ifElse() {
26 ; CHECK-LABEL: @ifElse(
27 ; CHECK: %x = add i32 2, 3
29 br i1 true, label %b, label %a
41 ; Hoist in if-then-else pattern if it is equivalent to if-then.
42 define void @ifElseThenAsIfThen() {
43 ; CHECK-LABEL: @ifElseThenAsIfThen(
44 ; CHECK: %x = add i32 2, 3
46 br i1 true, label %a, label %b
60 ; Hoist in if-then-else pattern if it is equivalent to if-else.
61 define void @ifElseThenAsIfElse() {
62 ; CHECK-LABEL: @ifElseThenAsIfElse(
63 ; CHECK: %x = add i32 2, 3
65 br i1 true, label %b, label %a
79 ; Do not hoist if-then-else pattern if it is not equivalent to if-then
81 define void @ifElseThen() {
82 ; CHECK-LABEL: @ifElseThen(
84 br i1 true, label %a, label %b
101 ; Do not hoist loads and do not hoist an instruction past a definition of
103 define void @doNotHoistPastDef() {
104 ; CHECK-LABEL: @doNotHoistPastDef(
105 br i1 true, label %b, label %a
111 %def = load i32, ptr null
113 %use = add i32 %def, 0
120 ; Case with nothing to speculate.
121 define void @nothingToSpeculate() {
122 ; CHECK-LABEL: @nothingToSpeculate(
123 br i1 true, label %b, label %a
127 %def = load i32, ptr null
134 ; Still hoist if an operand is defined before the block or is itself hoisted.
135 define void @hoistIfNotPastDef() {
136 ; CHECK-LABEL: @hoistIfNotPastDef(
138 %x = load i32, ptr null
139 ; CHECK: %y = add i32 %x, 1
140 ; CHECK: %z = add i32 %y, 1
142 br i1 true, label %b, label %a
153 ; Do not hoist if the speculation cost is too high.
154 define void @costTooHigh() {
155 ; CHECK-LABEL: @costTooHigh(
157 br i1 true, label %b, label %a
176 ; Do not hoist if too many instructions are left behind.
177 define void @tooMuchLeftBehind() {
178 ; CHECK-LABEL: @tooMuchLeftBehind(
180 br i1 true, label %b, label %a
184 %x = load i32, ptr null