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
  229
  230
  231
  232
  233
  234
  235
  236
  237
  238
  239
  240
  241
  242
  243
  244
  245
  246
  247
  248
  249
  250
  251
  252
  253
  254
  255
  256
  257
; RUN: opt -S %s -atomic-expand | FileCheck %s

;;; NOTE: this test is actually target-independent -- any target which
;;; doesn't support inline atomics can be used. (E.g. X86 i386 would
;;; work, if LLVM is properly taught about what it's missing vs i586.)

;target datalayout = "e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128"
;target triple = "i386-unknown-unknown"
target datalayout = "e-m:e-p:32:32-i64:64-f128:64-n32-S64"
target triple = "sparc-unknown-unknown"

;; First, check the sized calls. Except for cmpxchg, these are fairly
;; straightforward.

; CHECK-LABEL: @test_load_i16(
; CHECK:  %1 = bitcast i16* %arg to i8*
; CHECK:  %2 = call i16 @__atomic_load_2(i8* %1, i32 5)
; CHECK:  ret i16 %2
define i16 @test_load_i16(i16* %arg) {
  %ret = load atomic i16, i16* %arg seq_cst, align 4
  ret i16 %ret
}

; CHECK-LABEL: @test_store_i16(
; CHECK:  %1 = bitcast i16* %arg to i8*
; CHECK:  call void @__atomic_store_2(i8* %1, i16 %val, i32 5)
; CHECK:  ret void
define void @test_store_i16(i16* %arg, i16 %val) {
  store atomic i16 %val, i16* %arg seq_cst, align 4
  ret void
}

; CHECK-LABEL: @test_exchange_i16(
; CHECK:  %1 = bitcast i16* %arg to i8*
; CHECK:  %2 = call i16 @__atomic_exchange_2(i8* %1, i16 %val, i32 5)
; CHECK:  ret i16 %2
define i16 @test_exchange_i16(i16* %arg, i16 %val) {
  %ret = atomicrmw xchg i16* %arg, i16 %val seq_cst
  ret i16 %ret
}

; CHECK-LABEL: @test_cmpxchg_i16(
; CHECK:  %1 = bitcast i16* %arg to i8*
; CHECK:  %2 = alloca i16, align 2
; CHECK:  %3 = bitcast i16* %2 to i8*
; CHECK:  call void @llvm.lifetime.start.p0i8(i64 2, i8* %3)
; CHECK:  store i16 %old, i16* %2, align 2
; CHECK:  %4 = call zeroext i1 @__atomic_compare_exchange_2(i8* %1, i8* %3, i16 %new, i32 5, i32 0)
; CHECK:  %5 = load i16, i16* %2, align 2
; CHECK:  call void @llvm.lifetime.end.p0i8(i64 2, i8* %3)
; CHECK:  %6 = insertvalue { i16, i1 } undef, i16 %5, 0
; CHECK:  %7 = insertvalue { i16, i1 } %6, i1 %4, 1
; CHECK:  %ret = extractvalue { i16, i1 } %7, 0
; CHECK:  ret i16 %ret
define i16 @test_cmpxchg_i16(i16* %arg, i16 %old, i16 %new) {
  %ret_succ = cmpxchg i16* %arg, i16 %old, i16 %new seq_cst monotonic
  %ret = extractvalue { i16, i1 } %ret_succ, 0
  ret i16 %ret
}

; CHECK-LABEL: @test_add_i16(
; CHECK:  %1 = bitcast i16* %arg to i8*
; CHECK:  %2 = call i16 @__atomic_fetch_add_2(i8* %1, i16 %val, i32 5)
; CHECK:  ret i16 %2
define i16 @test_add_i16(i16* %arg, i16 %val) {
  %ret = atomicrmw add i16* %arg, i16 %val seq_cst
  ret i16 %ret
}


;; Now, check the output for the unsized libcalls. i128 is used for
;; these tests because the "16" suffixed functions aren't available on
;; 32-bit i386.

; CHECK-LABEL: @test_load_i128(
; CHECK:  %1 = bitcast i128* %arg to i8*
; CHECK:  %2 = alloca i128, align 8
; CHECK:  %3 = bitcast i128* %2 to i8*
; CHECK:  call void @llvm.lifetime.start.p0i8(i64 16, i8* %3)
; CHECK:  call void @__atomic_load(i32 16, i8* %1, i8* %3, i32 5)
; CHECK:  %4 = load i128, i128* %2, align 8
; CHECK:  call void @llvm.lifetime.end.p0i8(i64 16, i8* %3)
; CHECK:  ret i128 %4
define i128 @test_load_i128(i128* %arg) {
  %ret = load atomic i128, i128* %arg seq_cst, align 16
  ret i128 %ret
}

; CHECK-LABEL @test_store_i128(
; CHECK:  %1 = bitcast i128* %arg to i8*
; CHECK:  %2 = alloca i128, align 8
; CHECK:  %3 = bitcast i128* %2 to i8*
; CHECK:  call void @llvm.lifetime.start.p0i8(i64 16, i8* %3)
; CHECK:  store i128 %val, i128* %2, align 8
; CHECK:  call void @__atomic_store(i32 16, i8* %1, i8* %3, i32 5)
; CHECK:  call void @llvm.lifetime.end.p0i8(i64 16, i8* %3)
; CHECK:  ret void
define void @test_store_i128(i128* %arg, i128 %val) {
  store atomic i128 %val, i128* %arg seq_cst, align 16
  ret void
}

; CHECK-LABEL: @test_exchange_i128(
; CHECK:  %1 = bitcast i128* %arg to i8*
; CHECK:  %2 = alloca i128, align 8
; CHECK:  %3 = bitcast i128* %2 to i8*
; CHECK:  call void @llvm.lifetime.start.p0i8(i64 16, i8* %3)
; CHECK:  store i128 %val, i128* %2, align 8
; CHECK:  %4 = alloca i128, align 8
; CHECK:  %5 = bitcast i128* %4 to i8*
; CHECK:  call void @llvm.lifetime.start.p0i8(i64 16, i8* %5)
; CHECK:  call void @__atomic_exchange(i32 16, i8* %1, i8* %3, i8* %5, i32 5)
; CHECK:  call void @llvm.lifetime.end.p0i8(i64 16, i8* %3)
; CHECK:  %6 = load i128, i128* %4, align 8
; CHECK:  call void @llvm.lifetime.end.p0i8(i64 16, i8* %5)
; CHECK:  ret i128 %6
define i128 @test_exchange_i128(i128* %arg, i128 %val) {
  %ret = atomicrmw xchg i128* %arg, i128 %val seq_cst
  ret i128 %ret
}

; CHECK-LABEL: @test_cmpxchg_i128(
; CHECK:  %1 = bitcast i128* %arg to i8*
; CHECK:  %2 = alloca i128, align 8
; CHECK:  %3 = bitcast i128* %2 to i8*
; CHECK:  call void @llvm.lifetime.start.p0i8(i64 16, i8* %3)
; CHECK:  store i128 %old, i128* %2, align 8
; CHECK:  %4 = alloca i128, align 8
; CHECK:  %5 = bitcast i128* %4 to i8*
; CHECK:  call void @llvm.lifetime.start.p0i8(i64 16, i8* %5)
; CHECK:  store i128 %new, i128* %4, align 8
; CHECK:  %6 = call zeroext i1 @__atomic_compare_exchange(i32 16, i8* %1, i8* %3, i8* %5, i32 5, i32 0)
; CHECK:  call void @llvm.lifetime.end.p0i8(i64 16, i8* %5)
; CHECK:  %7 = load i128, i128* %2, align 8
; CHECK:  call void @llvm.lifetime.end.p0i8(i64 16, i8* %3)
; CHECK:  %8 = insertvalue { i128, i1 } undef, i128 %7, 0
; CHECK:  %9 = insertvalue { i128, i1 } %8, i1 %6, 1
; CHECK:  %ret = extractvalue { i128, i1 } %9, 0
; CHECK:  ret i128 %ret
define i128 @test_cmpxchg_i128(i128* %arg, i128 %old, i128 %new) {
  %ret_succ = cmpxchg i128* %arg, i128 %old, i128 %new seq_cst monotonic
  %ret = extractvalue { i128, i1 } %ret_succ, 0
  ret i128 %ret
}

; This one is a verbose expansion, as there is no generic
; __atomic_fetch_add function, so it needs to expand to a cmpxchg
; loop, which then itself expands into a libcall.

; CHECK-LABEL: @test_add_i128(
; CHECK:  %1 = alloca i128, align 8
; CHECK:  %2 = alloca i128, align 8
; CHECK:  %3 = load i128, i128* %arg, align 16
; CHECK:  br label %atomicrmw.start
; CHECK:atomicrmw.start:
; CHECK:  %loaded = phi i128 [ %3, %0 ], [ %newloaded, %atomicrmw.start ]
; CHECK:  %new = add i128 %loaded, %val
; CHECK:  %4 = bitcast i128* %arg to i8*
; CHECK:  %5 = bitcast i128* %1 to i8*
; CHECK:  call void @llvm.lifetime.start.p0i8(i64 16, i8* %5)
; CHECK:  store i128 %loaded, i128* %1, align 8
; CHECK:  %6 = bitcast i128* %2 to i8*
; CHECK:  call void @llvm.lifetime.start.p0i8(i64 16, i8* %6)
; CHECK:  store i128 %new, i128* %2, align 8
; CHECK:  %7 = call zeroext i1 @__atomic_compare_exchange(i32 16, i8* %4, i8* %5, i8* %6, i32 5, i32 5)
; CHECK:  call void @llvm.lifetime.end.p0i8(i64 16, i8* %6)
; CHECK:  %8 = load i128, i128* %1, align 8
; CHECK:  call void @llvm.lifetime.end.p0i8(i64 16, i8* %5)
; CHECK:  %9 = insertvalue { i128, i1 } undef, i128 %8, 0
; CHECK:  %10 = insertvalue { i128, i1 } %9, i1 %7, 1
; CHECK:  %success = extractvalue { i128, i1 } %10, 1
; CHECK:  %newloaded = extractvalue { i128, i1 } %10, 0
; CHECK:  br i1 %success, label %atomicrmw.end, label %atomicrmw.start
; CHECK:atomicrmw.end:
; CHECK:  ret i128 %newloaded
define i128 @test_add_i128(i128* %arg, i128 %val) {
  %ret = atomicrmw add i128* %arg, i128 %val seq_cst
  ret i128 %ret
}

;; Ensure that non-integer types get bitcast correctly on the way in and out of a libcall:

; CHECK-LABEL: @test_load_double(
; CHECK:  %1 = bitcast double* %arg to i8*
; CHECK:  %2 = call i64 @__atomic_load_8(i8* %1, i32 5)
; CHECK:  %3 = bitcast i64 %2 to double
; CHECK:  ret double %3
define double @test_load_double(double* %arg, double %val) {
  %1 = load atomic double, double* %arg seq_cst, align 16
  ret double %1
}

; CHECK-LABEL: @test_store_double(
; CHECK:  %1 = bitcast double* %arg to i8*
; CHECK:  %2 = bitcast double %val to i64
; CHECK:  call void @__atomic_store_8(i8* %1, i64 %2, i32 5)
; CHECK:  ret void
define void @test_store_double(double* %arg, double %val) {
  store atomic double %val, double* %arg seq_cst, align 16
  ret void
}

; CHECK-LABEL: @test_cmpxchg_ptr(
; CHECK:   %1 = bitcast i16** %arg to i8*
; CHECK:   %2 = alloca i16*, align 4
; CHECK:   %3 = bitcast i16** %2 to i8*
; CHECK:   call void @llvm.lifetime.start.p0i8(i64 4, i8* %3)
; CHECK:   store i16* %old, i16** %2, align 4
; CHECK:   %4 = ptrtoint i16* %new to i32
; CHECK:   %5 = call zeroext i1 @__atomic_compare_exchange_4(i8* %1, i8* %3, i32 %4, i32 5, i32 2)
; CHECK:   %6 = load i16*, i16** %2, align 4
; CHECK:   call void @llvm.lifetime.end.p0i8(i64 4, i8* %3)
; CHECK:   %7 = insertvalue { i16*, i1 } undef, i16* %6, 0
; CHECK:   %8 = insertvalue { i16*, i1 } %7, i1 %5, 1
; CHECK:   %ret = extractvalue { i16*, i1 } %8, 0
; CHECK:   ret i16* %ret
; CHECK: }
define i16* @test_cmpxchg_ptr(i16** %arg, i16* %old, i16* %new) {
  %ret_succ = cmpxchg i16** %arg, i16* %old, i16* %new seq_cst acquire
  %ret = extractvalue { i16*, i1 } %ret_succ, 0
  ret i16* %ret
}

;; ...and for a non-integer type of large size too.

; CHECK-LABEL: @test_store_fp128
; CHECK:   %1 = bitcast fp128* %arg to i8*
; CHECK:  %2 = alloca fp128, align 8
; CHECK:  %3 = bitcast fp128* %2 to i8*
; CHECK:  call void @llvm.lifetime.start.p0i8(i64 16, i8* %3)
; CHECK:  store fp128 %val, fp128* %2, align 8
; CHECK:  call void @__atomic_store(i32 16, i8* %1, i8* %3, i32 5)
; CHECK:  call void @llvm.lifetime.end.p0i8(i64 16, i8* %3)
; CHECK:  ret void
define void @test_store_fp128(fp128* %arg, fp128 %val) {
  store atomic fp128 %val, fp128* %arg seq_cst, align 16
  ret void
}

;; Unaligned loads and stores should be expanded to the generic
;; libcall, just like large loads/stores, and not a specialized one.
;; NOTE: atomicrmw and cmpxchg don't yet support an align attribute;
;; when such support is added, they should also be tested here.

; CHECK-LABEL: @test_unaligned_load_i16(
; CHECK:  __atomic_load(
define i16 @test_unaligned_load_i16(i16* %arg) {
  %ret = load atomic i16, i16* %arg seq_cst, align 1
  ret i16 %ret
}

; CHECK-LABEL: @test_unaligned_store_i16(
; CHECK: __atomic_store(
define void @test_unaligned_store_i16(i16* %arg, i16 %val) {
  store atomic i16 %val, i16* %arg seq_cst, align 1
  ret void
}