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
  199
  200
  201
  202
  203
  204
  205
  206
  207
  208
  209
  210
  211
  212
  213
  214
  215
  216
  217
  218
  219
  220
  221
  222
  223
  224
  225
  226
  227
  228
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
;       then metadata checks MDn were added manually.
; RUN: opt -passes='loop(unswitch),verify<loops>' -S < %s | FileCheck %s
; RUN: opt -verify-memoryssa -passes='loop-mssa(unswitch),verify<loops>' -S < %s | FileCheck %s

declare void @some_func()

; Test for a trivially unswitchable switch with non-default case exiting.
define i32 @test2(i32* %var, i32 %cond1, i32 %cond2) {
; CHECK-LABEL: @test2(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    switch i32 [[COND2:%.*]], label [[ENTRY_SPLIT:%.*]] [
; CHECK-NEXT:    i32 2, label [[LOOP_EXIT2:%.*]]
; CHECK-NEXT:    ], !prof ![[MD0:[0-9]+]]
; CHECK:       entry.split:
; CHECK-NEXT:    br label [[LOOP_BEGIN:%.*]]
; CHECK:       loop_begin:
; CHECK-NEXT:    [[VAR_VAL:%.*]] = load i32, i32* [[VAR:%.*]]
; CHECK-NEXT:    switch i32 [[COND2]], label [[LOOP2:%.*]] [
; CHECK-NEXT:    i32 0, label [[LOOP0:%.*]]
; CHECK-NEXT:    i32 1, label [[LOOP1:%.*]]
; CHECK-NEXT:    ], !prof ![[MD1:[0-9]+]]
; CHECK:       loop0:
; CHECK-NEXT:    call void @some_func()
; CHECK-NEXT:    br label [[LOOP_LATCH:%.*]]
; CHECK:       loop1:
; CHECK-NEXT:    call void @some_func()
; CHECK-NEXT:    br label [[LOOP_LATCH]]
; CHECK:       loop2:
; CHECK-NEXT:    call void @some_func()
; CHECK-NEXT:    br label [[LOOP_LATCH]]
; CHECK:       loop_latch:
; CHECK-NEXT:    br label [[LOOP_BEGIN]]
; CHECK:       loop_exit1:
; CHECK-NEXT:    ret i32 0
; CHECK:       loop_exit2:
; CHECK-NEXT:    ret i32 0
; CHECK:       loop_exit3:
; CHECK-NEXT:    ret i32 0
;
entry:
  br label %loop_begin

loop_begin:
  %var_val = load i32, i32* %var
  switch i32 %cond2, label %loop2 [
  i32 0, label %loop0
  i32 1, label %loop1
  i32 2, label %loop_exit2
  ], !prof !{!"branch_weights", i32 99, i32 100, i32 101, i32 102}

loop0:
  call void @some_func()
  br label %loop_latch

loop1:
  call void @some_func()
  br label %loop_latch

loop2:
  call void @some_func()
  br label %loop_latch

loop_latch:
  br label %loop_begin

loop_exit1:
  ret i32 0

loop_exit2:
  ret i32 0

loop_exit3:
  ret i32 0
}

; Test for a trivially unswitchable switch with only the default case exiting.
define i32 @test3(i32* %var, i32 %cond1, i32 %cond2) {
; CHECK-LABEL: @test3(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    switch i32 [[COND2:%.*]], label [[LOOP_EXIT2:%.*]] [
; CHECK-NEXT:    i32 0, label [[ENTRY_SPLIT:%.*]]
; CHECK-NEXT:    i32 1, label [[ENTRY_SPLIT]]
; CHECK-NEXT:    i32 2, label [[ENTRY_SPLIT]]
; CHECK-NEXT:    ], !prof ![[MD2:[0-9]+]]
; CHECK:       entry.split:
; CHECK-NEXT:    br label [[LOOP_BEGIN:%.*]]
; CHECK:       loop_begin:
; CHECK-NEXT:    [[VAR_VAL:%.*]] = load i32, i32* [[VAR:%.*]]
; CHECK-NEXT:    switch i32 [[COND2]], label [[LOOP2:%.*]] [
; CHECK-NEXT:    i32 0, label [[LOOP0:%.*]]
; CHECK-NEXT:    i32 1, label [[LOOP1:%.*]]
; CHECK-NEXT:    ], !prof ![[MD3:[0-9]+]]
; CHECK:       loop0:
; CHECK-NEXT:    call void @some_func()
; CHECK-NEXT:    br label [[LOOP_LATCH:%.*]]
; CHECK:       loop1:
; CHECK-NEXT:    call void @some_func()
; CHECK-NEXT:    br label [[LOOP_LATCH]]
; CHECK:       loop2:
; CHECK-NEXT:    call void @some_func()
; CHECK-NEXT:    br label [[LOOP_LATCH]]
; CHECK:       loop_latch:
; CHECK-NEXT:    br label [[LOOP_BEGIN]]
; CHECK:       loop_exit1:
; CHECK-NEXT:    ret i32 0
; CHECK:       loop_exit2:
; CHECK-NEXT:    ret i32 0
; CHECK:       loop_exit3:
; CHECK-NEXT:    ret i32 0
;
entry:
  br label %loop_begin

loop_begin:
  %var_val = load i32, i32* %var
  switch i32 %cond2, label %loop_exit2 [
  i32 0, label %loop0
  i32 1, label %loop1
  i32 2, label %loop2
  ], !prof !{!"branch_weights", i32 99, i32 100, i32 101, i32 102}

loop0:
  call void @some_func()
  br label %loop_latch

loop1:
  call void @some_func()
  br label %loop_latch

loop2:
  call void @some_func()
  br label %loop_latch

loop_latch:
  br label %loop_begin

loop_exit1:
  ret i32 0

loop_exit2:
  ret i32 0

loop_exit3:
  ret i32 0
}

; Test for a trivially unswitchable switch with multiple exiting cases and
; multiple looping cases.
define i32 @test4(i32* %var, i32 %cond1, i32 %cond2) {
; CHECK-LABEL: @test4(
; CHECK-NEXT:  entry:
; CHECK-NEXT:    switch i32 [[COND2:%.*]], label [[LOOP_EXIT2:%.*]] [
; CHECK-NEXT:    i32 13, label [[LOOP_EXIT1:%.*]]
; CHECK-NEXT:    i32 42, label [[LOOP_EXIT3:%.*]]
; CHECK-NEXT:    i32 0, label [[ENTRY_SPLIT:%.*]]
; CHECK-NEXT:    i32 1, label [[ENTRY_SPLIT]]
; CHECK-NEXT:    i32 2, label [[ENTRY_SPLIT]]
; CHECK-NEXT:    ], !prof ![[MD4:[0-9]+]]
; CHECK:       entry.split:
; CHECK-NEXT:    br label [[LOOP_BEGIN:%.*]]
; CHECK:       loop_begin:
; CHECK-NEXT:    [[VAR_VAL:%.*]] = load i32, i32* [[VAR:%.*]]
; CHECK-NEXT:    switch i32 [[COND2]], label [[LOOP2:%.*]] [
; CHECK-NEXT:    i32 0, label [[LOOP0:%.*]]
; CHECK-NEXT:    i32 1, label [[LOOP1:%.*]]
; CHECK-NEXT:    ], !prof ![[MD3:[0-9]+]]
; CHECK:       loop0:
; CHECK-NEXT:    call void @some_func()
; CHECK-NEXT:    br label [[LOOP_LATCH:%.*]]
; CHECK:       loop1:
; CHECK-NEXT:    call void @some_func()
; CHECK-NEXT:    br label [[LOOP_LATCH]]
; CHECK:       loop2:
; CHECK-NEXT:    call void @some_func()
; CHECK-NEXT:    br label [[LOOP_LATCH]]
; CHECK:       loop_latch:
; CHECK-NEXT:    br label [[LOOP_BEGIN]]
; CHECK:       loop_exit1:
; CHECK-NEXT:    ret i32 0
; CHECK:       loop_exit2:
; CHECK-NEXT:    ret i32 0
; CHECK:       loop_exit3:
; CHECK-NEXT:    ret i32 0
;
entry:
  br label %loop_begin

loop_begin:
  %var_val = load i32, i32* %var
  switch i32 %cond2, label %loop_exit2 [
  i32 0, label %loop0
  i32 1, label %loop1
  i32 13, label %loop_exit1
  i32 2, label %loop2
  i32 42, label %loop_exit3
  ], !prof !{!"branch_weights", i32 99, i32 100, i32 101, i32 113, i32 102, i32 142}

loop0:
  call void @some_func()
  br label %loop_latch

loop1:
  call void @some_func()
  br label %loop_latch

loop2:
  call void @some_func()
  br label %loop_latch

loop_latch:
  br label %loop_begin

loop_exit1:
  ret i32 0

loop_exit2:
  ret i32 0

loop_exit3:
  ret i32 0
}

; CHECK: ![[MD0]] = !{!"branch_weights", i32 300, i32 102}
; CHECK: ![[MD1]] = !{!"branch_weights", i32 99, i32 100, i32 101}
; CHECK: ![[MD2]] = !{!"branch_weights", i32 99, i32 100, i32 101, i32 102}
; CHECK: ![[MD3]] = !{!"branch_weights", i32 102, i32 100, i32 101}
; CHECK: ![[MD4]] = !{!"branch_weights", i32 99, i32 113, i32 142, i32 100, i32 101, i32 102}