reference, declarationdefinition
definition → references, declarations, derived classes, virtual overrides
reference to multiple definitions → definitions
unreferenced
    1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78
   79
   80
   81
   82
   83
   84
   85
   86
   87
   88
   89
   90
   91
   92
   93
   94
   95
   96
   97
   98
   99
  100
  101
  102
  103
  104
  105
  106
  107
  108
  109
  110
  111
  112
  113
  114
  115
  116
  117
  118
  119
  120
  121
  122
  123
  124
  125
  126
  127
  128
  129
  130
  131
  132
  133
  134
  135
  136
  137
  138
  139
  140
  141
  142
  143
  144
  145
  146
  147
  148
  149
  150
  151
  152
  153
  154
  155
  156
  157
  158
  159
  160
  161
  162
  163
  164
  165
  166
  167
  168
  169
  170
  171
  172
  173
  174
  175
  176
  177
  178
  179
  180
  181
  182
  183
  184
  185
  186
  187
  188
  189
  190
  191
  192
  193
  194
  195
  196
  197
  198
; RUN: opt < %s -S -speculative-execution \
; RUN:   -spec-exec-max-speculation-cost 4 -spec-exec-max-not-hoisted 3 \
; RUN:   | FileCheck %s
; RUN: opt < %s -S -passes='speculative-execution' \
; RUN:   -spec-exec-max-speculation-cost 4 -spec-exec-max-not-hoisted 3 \
; RUN:   | FileCheck %s

target datalayout = "e-i64:64-v16:16-v32:32-n16:32:64"

; Hoist in if-then pattern.
define void @ifThen() {
; CHECK-LABEL: @ifThen(
; CHECK: %x = add i32 2, 3
; CHECK: br i1 true
  br i1 true, label %a, label %b
; CHECK: a:
a:
  %x = add i32 2, 3
; CHECK: br label
  br label %b
; CHECK: b:
b:
; CHECK: ret void
  ret void
}

; Hoist in if-else pattern.
define void @ifElse() {
; CHECK-LABEL: @ifElse(
; CHECK: %x = add i32 2, 3
; CHECK: br i1 true
  br i1 true, label %b, label %a
; CHECK: a:
a:
  %x = add i32 2, 3
; CHECK: br label
  br label %b
; CHECK: b:
b:
; CHECK: ret void
  ret void
}

; Hoist in if-then-else pattern if it is equivalent to if-then.
define void @ifElseThenAsIfThen() {
; CHECK-LABEL: @ifElseThenAsIfThen(
; CHECK: %x = add i32 2, 3
; CHECK: br
  br i1 true, label %a, label %b
; CHECK: a:
a:
  %x = add i32 2, 3
; CHECK: br label
  br label %c
; CHECK: b:
b:
  br label %c
; CHECK: c
c:
  ret void
}

; Hoist in if-then-else pattern if it is equivalent to if-else.
define void @ifElseThenAsIfElse() {
; CHECK-LABEL: @ifElseThenAsIfElse(
; CHECK: %x = add i32 2, 3
; CHECK: br
  br i1 true, label %b, label %a
; CHECK: a:
a:
  %x = add i32 2, 3
; CHECK: br label
  br label %c
; CHECK: b:
b:
  br label %c
; CHECK: c
c:
  ret void
}

; Do not hoist if-then-else pattern if it is not equivalent to if-then
; or if-else.
define void @ifElseThen() {
; CHECK-LABEL: @ifElseThen(
; CHECK: br
  br i1 true, label %a, label %b
; CHECK: a:
a:
; CHECK: %x = add
  %x = add i32 2, 3
; CHECK: br label
  br label %c
; CHECK: b:
b:
; CHECK: %y = add
  %y = add i32 2, 3
  br label %c
; CHECK: c
c:
  ret void
}

; Do not hoist loads and do not hoist an instruction past a definition of
; an operand.
define void @doNotHoistPastDef() {
; CHECK-LABEL: @doNotHoistPastDef(
  br i1 true, label %b, label %a
; CHECK-NOT: load
; CHECK-NOT: add
; CHECK: a:
a:
; CHECK: %def = load
  %def = load i32, i32* null
; CHECK: %use = add
  %use = add i32 %def, 0
  br label %b
; CHECK: b:
b:
  ret void
}

; Case with nothing to speculate.
define void @nothingToSpeculate() {
; CHECK-LABEL: @nothingToSpeculate(
  br i1 true, label %b, label %a
; CHECK: a:
a:
; CHECK: %def = load
  %def = load i32, i32* null
  br label %b
; CHECK: b:
b:
  ret void
}

; Still hoist if an operand is defined before the block or is itself hoisted.
define void @hoistIfNotPastDef() {
; CHECK-LABEL: @hoistIfNotPastDef(
; CHECK: %x = load
  %x = load i32, i32* null
; CHECK: %y = add i32 %x, 1
; CHECK: %z = add i32 %y, 1
; CHECK: br
  br i1 true, label %b, label %a
; CHECK: a:
a:
  %y = add i32 %x, 1
  %z = add i32 %y, 1
  br label %b
; CHECK: b:
b:
  ret void
}

; Do not hoist if the speculation cost is too high.
define void @costTooHigh() {
; CHECK-LABEL: @costTooHigh(
; CHECK: br
  br i1 true, label %b, label %a
; CHECK: a:
a:
; CHECK: %r1 = add
  %r1 = add i32 1, 1
; CHECK: %r2 = add
  %r2 = add i32 1, 1
; CHECK: %r3 = add
  %r3 = add i32 1, 1
; CHECK: %r4 = add
  %r4 = add i32 1, 1
; CHECK: %r5 = add
  %r5 = add i32 1, 1
  br label %b
; CHECK: b:
b:
  ret void
}

; Do not hoist if too many instructions are left behind.
define void @tooMuchLeftBehind() {
; CHECK-LABEL: @tooMuchLeftBehind(
; CHECK: br
  br i1 true, label %b, label %a
; CHECK: a:
a:
; CHECK: %x = load
  %x = load i32, i32* null
; CHECK: %r1 = add
  %r1 = add i32 %x, 1
; CHECK: %r2 = add
  %r2 = add i32 %x, 1
; CHECK: %r3 = add
  %r3 = add i32 %x, 1
  br label %b
; CHECK: b:
b:
  ret void
}