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
; RUN: opt < %s -S -basicaa -licm -enable-mssa-loop-dependency=false | FileCheck -check-prefixes=CHECK,AST %s
; RUN: opt < %s -S -basicaa -licm -enable-mssa-loop-dependency=true  | FileCheck -check-prefixes=CHECK,MSSA %s
; RUN: opt -aa-pipeline=basic-aa -passes='require<opt-remark-emit>,loop(licm)' < %s -S | FileCheck -check-prefixes=CHECK,AST %s
; RUN: opt -aa-pipeline=basic-aa -passes='require<opt-remark-emit>,loop-mssa(licm)' < %s -S | FileCheck -check-prefixes=CHECK,MSSA %s

; Check that we can hoist unordered loads
define i32 @test1(i32* nocapture %y) nounwind uwtable ssp {
entry:
  br label %loop

loop:
  %i = phi i32 [ %inc, %loop ], [ 0, %entry ]
  %val = load atomic i32, i32* %y unordered, align 4
  %inc = add nsw i32 %i, 1
  %exitcond = icmp eq i32 %inc, %val
  br i1 %exitcond, label %end, label %loop

end:
  ret i32 %val
; CHECK-LABEL: define i32 @test1(
; CHECK: load atomic
; CHECK-NEXT: br label %loop
}

; Check that we don't sink/hoist monotonic loads
; (Strictly speaking, it's not forbidden, but it's supposed to be possible to
; use monotonic for spinlock-like constructs.)
define i32 @test2(i32* nocapture %y) nounwind uwtable ssp {
entry:
  br label %loop

loop:
  %val = load atomic i32, i32* %y monotonic, align 4
  %exitcond = icmp ne i32 %val, 0
  br i1 %exitcond, label %end, label %loop

end:
  ret i32 %val
; CHECK-LABEL: define i32 @test2(
; CHECK: load atomic
; CHECK-NEXT: %exitcond = icmp ne
; CHECK-NEXT: br i1 %exitcond, label %end, label %loop
}

; Check that we hoist unordered around monotonic.
; (The noalias shouldn't be necessary in theory, but LICM isn't quite that
; smart yet.)
define i32 @test3(i32* nocapture noalias %x, i32* nocapture %y) nounwind uwtable ssp {
entry:
  br label %loop

loop:
  %vala = load atomic i32, i32* %y monotonic, align 4
  %valb = load atomic i32, i32* %x unordered, align 4
  %exitcond = icmp ne i32 %vala, %valb
  br i1 %exitcond, label %end, label %loop

end:
  ret i32 %vala
; CHECK-LABEL: define i32 @test3(
; CHECK: load atomic i32, i32* %x unordered
; CHECK-NEXT: br label %loop
}

; We can sink an unordered store
define i32 @test4(i32* nocapture noalias %x, i32* nocapture %y) nounwind uwtable ssp {
entry:
  br label %loop

loop:
  %vala = load atomic i32, i32* %y monotonic, align 4
  store atomic i32 %vala, i32* %x unordered, align 4
  %exitcond = icmp ne i32 %vala, 0
  br i1 %exitcond, label %end, label %loop

end:
  ret i32 %vala
; CHECK-LABEL: define i32 @test4(
; CHECK-LABEL: loop:
; CHECK: load atomic i32, i32* %y monotonic
; CHECK-NOT: store
; CHECK-LABEL: end:
; CHECK-NEXT:   %[[LCSSAPHI:.*]] = phi i32 [ %vala
; CHECK:   store atomic i32 %[[LCSSAPHI]], i32* %x unordered, align 4
}

; We currently don't handle ordered atomics.
define i32 @test5(i32* nocapture noalias %x, i32* nocapture %y) nounwind uwtable ssp {
entry:
  br label %loop

loop:
  %vala = load atomic i32, i32* %y monotonic, align 4
  store atomic i32 %vala, i32* %x release, align 4
  %exitcond = icmp ne i32 %vala, 0
  br i1 %exitcond, label %end, label %loop

end:
  ret i32 %vala
; CHECK-LABEL: define i32 @test5(
; CHECK: load atomic i32, i32* %y monotonic
; CHECK-NEXT: store atomic
}

; We currently don't touch volatiles
define i32 @test6(i32* nocapture noalias %x, i32* nocapture %y) nounwind uwtable ssp {
entry:
  br label %loop

loop:
  %vala = load atomic i32, i32* %y monotonic, align 4
  store volatile i32 %vala, i32* %x, align 4
  %exitcond = icmp ne i32 %vala, 0
  br i1 %exitcond, label %end, label %loop

end:
  ret i32 %vala
; CHECK-LABEL: define i32 @test6(
; CHECK: load atomic i32, i32* %y monotonic
; CHECK-NEXT: store volatile
}

; We currently don't touch volatiles
define i32 @test6b(i32* nocapture noalias %x, i32* nocapture %y) nounwind uwtable ssp {
entry:
  br label %loop

loop:
  %vala = load atomic i32, i32* %y monotonic, align 4
  store atomic volatile i32 %vala, i32* %x unordered, align 4
  %exitcond = icmp ne i32 %vala, 0
  br i1 %exitcond, label %end, label %loop

end:
  ret i32 %vala
; CHECK-LABEL: define i32 @test6b(
; CHECK: load atomic i32, i32* %y monotonic
; CHECK-NEXT: store atomic volatile
}

; Mixing unorder atomics and normal loads/stores is
; current unimplemented
define i32 @test7(i32* nocapture noalias %x, i32* nocapture %y) nounwind uwtable ssp {
entry:
  br label %loop

loop:
  store i32 5, i32* %x
  %vala = load atomic i32, i32* %y monotonic, align 4
  store atomic i32 %vala, i32* %x unordered, align 4
  %exitcond = icmp ne i32 %vala, 0
  br i1 %exitcond, label %end, label %loop

end:
  ret i32 %vala
; CHECK-LABEL: define i32 @test7(
; CHECK: store i32 5, i32* %x
; CHECK-NEXT: load atomic i32, i32* %y
; CHECK-NEXT: store atomic i32
}

; Three provably noalias locations - we can sink normal and unordered, but
;  not monotonic
define i32 @test7b(i32* nocapture noalias %x, i32* nocapture %y, i32* noalias nocapture %z) nounwind uwtable ssp {
entry:
  br label %loop

loop:
  store i32 5, i32* %x
  %vala = load atomic i32, i32* %y monotonic, align 4
  store atomic i32 %vala, i32* %z unordered, align 4
  %exitcond = icmp ne i32 %vala, 0
  br i1 %exitcond, label %end, label %loop

end:
  ret i32 %vala
; CHECK-LABEL: define i32 @test7b(
; AST-LABEL: entry:
; AST: store i32 5, i32* %x
; CHECK-LABEL: loop:
; CHECK: load atomic i32, i32* %y monotonic
; CHECK-LABEL: end:
; MSSA: store i32 5, i32* %x
; CHECK: store atomic i32 %{{.+}}, i32* %z unordered, align 4
}


define i32 @test8(i32* nocapture noalias %x, i32* nocapture %y) {
entry:
  br label %loop

loop:
  %vala = load atomic i32, i32* %y monotonic, align 4
  store atomic i32 %vala, i32* %x unordered, align 4
  fence release
  %exitcond = icmp ne i32 %vala, 0
  br i1 %exitcond, label %end, label %loop

end:
  ret i32 %vala
; CHECK-LABEL: define i32 @test8(
; CHECK-LABEL: loop:
; CHECK: load atomic i32, i32* %y monotonic
; CHECK-NEXT: store atomic
; CHECK-NEXT: fence
}

; Exact semantics of monotonic accesses are a bit vague in the C++ spec,
; for the moment, be conservative and don't touch them.
define i32 @test9(i32* nocapture noalias %x, i32* nocapture %y) {
entry:
  br label %loop

loop:
  %vala = load atomic i32, i32* %y monotonic, align 4
  store atomic i32 %vala, i32* %x monotonic, align 4
  %exitcond = icmp ne i32 %vala, 0
  br i1 %exitcond, label %end, label %loop

end:
  ret i32 %vala
; CHECK-LABEL: define i32 @test9(
; CHECK-LABEL: loop:
; CHECK: load atomic i32, i32* %y monotonic
; CHECK-NEXT:   store atomic i32 %vala, i32* %x monotonic, align 4
}