OLD | NEW |
(Empty) | |
| 1 ; RUN: opt -nacl-rewrite-atomics -S < %s | FileCheck %s |
| 2 |
| 3 ; Each of these tests validates that the corresponding legacy GCC-style builtins |
| 4 ; are properly rewritten to NaCl atomic builtins. Only the GCC-style builtins |
| 5 ; that have corresponding primitives in C11/C++11 and which emit different code |
| 6 ; are tested. These legacy GCC-builtins only support sequential-consistency |
| 7 ; (enum value 6). |
| 8 ; |
| 9 ; test_* tests the corresponding __sync_* builtin. See: |
| 10 ; http://gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/_005f_005fsync-Builtins.html |
| 11 |
| 12 target datalayout = "p:32:32:32" |
| 13 |
| 14 ; CHECK-LABEL: @test_fetch_and_add_i8 |
| 15 define zeroext i8 @test_fetch_and_add_i8(i8* %ptr, i8 zeroext %value) { |
| 16 ; CHECK-NEXT: %res = call i8 @llvm.nacl.atomic.rmw.i8(i32 1, i8* %ptr, i8 %val
ue, i32 6) |
| 17 %res = atomicrmw add i8* %ptr, i8 %value seq_cst |
| 18 ret i8 %res ; CHECK-NEXT: ret i8 %res |
| 19 } |
| 20 |
| 21 ; CHECK-LABEL: @test_fetch_and_add_i16 |
| 22 define zeroext i16 @test_fetch_and_add_i16(i16* %ptr, i16 zeroext %value) { |
| 23 ; CHECK-NEXT: %res = call i16 @llvm.nacl.atomic.rmw.i16(i32 1, i16* %ptr, i16
%value, i32 6) |
| 24 %res = atomicrmw add i16* %ptr, i16 %value seq_cst |
| 25 ret i16 %res ; CHECK-NEXT: ret i16 %res |
| 26 } |
| 27 |
| 28 ; CHECK-LABEL: @test_fetch_and_add_i32 |
| 29 define i32 @test_fetch_and_add_i32(i32* %ptr, i32 %value) { |
| 30 ; CHECK-NEXT: %res = call i32 @llvm.nacl.atomic.rmw.i32(i32 1, i32* %ptr, i32
%value, i32 6) |
| 31 %res = atomicrmw add i32* %ptr, i32 %value seq_cst |
| 32 ret i32 %res ; CHECK-NEXT: ret i32 %res |
| 33 } |
| 34 |
| 35 ; CHECK-LABEL: @test_fetch_and_add_i64 |
| 36 define i64 @test_fetch_and_add_i64(i64* %ptr, i64 %value) { |
| 37 ; CHECK-NEXT: %res = call i64 @llvm.nacl.atomic.rmw.i64(i32 1, i64* %ptr, i64
%value, i32 6) |
| 38 %res = atomicrmw add i64* %ptr, i64 %value seq_cst |
| 39 ret i64 %res ; CHECK-NEXT: ret i64 %res |
| 40 } |
| 41 |
| 42 ; CHECK-LABEL: @test_fetch_and_sub_i8 |
| 43 define zeroext i8 @test_fetch_and_sub_i8(i8* %ptr, i8 zeroext %value) { |
| 44 ; CHECK-NEXT: %res = call i8 @llvm.nacl.atomic.rmw.i8(i32 2, i8* %ptr, i8 %val
ue, i32 6) |
| 45 %res = atomicrmw sub i8* %ptr, i8 %value seq_cst |
| 46 ret i8 %res ; CHECK-NEXT: ret i8 %res |
| 47 } |
| 48 |
| 49 ; CHECK-LABEL: @test_fetch_and_sub_i16 |
| 50 define zeroext i16 @test_fetch_and_sub_i16(i16* %ptr, i16 zeroext %value) { |
| 51 ; CHECK-NEXT: %res = call i16 @llvm.nacl.atomic.rmw.i16(i32 2, i16* %ptr, i16
%value, i32 6) |
| 52 %res = atomicrmw sub i16* %ptr, i16 %value seq_cst |
| 53 ret i16 %res ; CHECK-NEXT: ret i16 %res |
| 54 } |
| 55 |
| 56 ; CHECK-LABEL: @test_fetch_and_sub_i32 |
| 57 define i32 @test_fetch_and_sub_i32(i32* %ptr, i32 %value) { |
| 58 ; CHECK-NEXT: %res = call i32 @llvm.nacl.atomic.rmw.i32(i32 2, i32* %ptr, i32
%value, i32 6) |
| 59 %res = atomicrmw sub i32* %ptr, i32 %value seq_cst |
| 60 ret i32 %res ; CHECK-NEXT: ret i32 %res |
| 61 } |
| 62 |
| 63 ; CHECK-LABEL: @test_fetch_and_sub_i64 |
| 64 define i64 @test_fetch_and_sub_i64(i64* %ptr, i64 %value) { |
| 65 ; CHECK-NEXT: %res = call i64 @llvm.nacl.atomic.rmw.i64(i32 2, i64* %ptr, i64
%value, i32 6) |
| 66 %res = atomicrmw sub i64* %ptr, i64 %value seq_cst |
| 67 ret i64 %res ; CHECK-NEXT: ret i64 %res |
| 68 } |
| 69 |
| 70 ; CHECK-LABEL: @test_fetch_and_or_i8 |
| 71 define zeroext i8 @test_fetch_and_or_i8(i8* %ptr, i8 zeroext %value) { |
| 72 ; CHECK-NEXT: %res = call i8 @llvm.nacl.atomic.rmw.i8(i32 3, i8* %ptr, i8 %val
ue, i32 6) |
| 73 %res = atomicrmw or i8* %ptr, i8 %value seq_cst |
| 74 ret i8 %res ; CHECK-NEXT: ret i8 %res |
| 75 } |
| 76 |
| 77 ; CHECK-LABEL: @test_fetch_and_or_i16 |
| 78 define zeroext i16 @test_fetch_and_or_i16(i16* %ptr, i16 zeroext %value) { |
| 79 ; CHECK-NEXT: %res = call i16 @llvm.nacl.atomic.rmw.i16(i32 3, i16* %ptr, i16
%value, i32 6) |
| 80 %res = atomicrmw or i16* %ptr, i16 %value seq_cst |
| 81 ret i16 %res ; CHECK-NEXT: ret i16 %res |
| 82 } |
| 83 |
| 84 ; CHECK-LABEL: @test_fetch_and_or_i32 |
| 85 define i32 @test_fetch_and_or_i32(i32* %ptr, i32 %value) { |
| 86 ; CHECK-NEXT: %res = call i32 @llvm.nacl.atomic.rmw.i32(i32 3, i32* %ptr, i32
%value, i32 6) |
| 87 %res = atomicrmw or i32* %ptr, i32 %value seq_cst |
| 88 ret i32 %res ; CHECK-NEXT: ret i32 %res |
| 89 } |
| 90 |
| 91 ; CHECK-LABEL: @test_fetch_and_or_i64 |
| 92 define i64 @test_fetch_and_or_i64(i64* %ptr, i64 %value) { |
| 93 ; CHECK-NEXT: %res = call i64 @llvm.nacl.atomic.rmw.i64(i32 3, i64* %ptr, i64
%value, i32 6) |
| 94 %res = atomicrmw or i64* %ptr, i64 %value seq_cst |
| 95 ret i64 %res ; CHECK-NEXT: ret i64 %res |
| 96 } |
| 97 |
| 98 ; CHECK-LABEL: @test_fetch_and_and_i8 |
| 99 define zeroext i8 @test_fetch_and_and_i8(i8* %ptr, i8 zeroext %value) { |
| 100 ; CHECK-NEXT: %res = call i8 @llvm.nacl.atomic.rmw.i8(i32 4, i8* %ptr, i8 %val
ue, i32 6) |
| 101 %res = atomicrmw and i8* %ptr, i8 %value seq_cst |
| 102 ret i8 %res ; CHECK-NEXT: ret i8 %res |
| 103 } |
| 104 |
| 105 ; CHECK-LABEL: @test_fetch_and_and_i16 |
| 106 define zeroext i16 @test_fetch_and_and_i16(i16* %ptr, i16 zeroext %value) { |
| 107 ; CHECK-NEXT: %res = call i16 @llvm.nacl.atomic.rmw.i16(i32 4, i16* %ptr, i16
%value, i32 6) |
| 108 %res = atomicrmw and i16* %ptr, i16 %value seq_cst |
| 109 ret i16 %res ; CHECK-NEXT: ret i16 %res |
| 110 } |
| 111 |
| 112 ; CHECK-LABEL: @test_fetch_and_and_i32 |
| 113 define i32 @test_fetch_and_and_i32(i32* %ptr, i32 %value) { |
| 114 ; CHECK-NEXT: %res = call i32 @llvm.nacl.atomic.rmw.i32(i32 4, i32* %ptr, i32
%value, i32 6) |
| 115 %res = atomicrmw and i32* %ptr, i32 %value seq_cst |
| 116 ret i32 %res ; CHECK-NEXT: ret i32 %res |
| 117 } |
| 118 |
| 119 ; CHECK-LABEL: @test_fetch_and_and_i64 |
| 120 define i64 @test_fetch_and_and_i64(i64* %ptr, i64 %value) { |
| 121 ; CHECK-NEXT: %res = call i64 @llvm.nacl.atomic.rmw.i64(i32 4, i64* %ptr, i64
%value, i32 6) |
| 122 %res = atomicrmw and i64* %ptr, i64 %value seq_cst |
| 123 ret i64 %res ; CHECK-NEXT: ret i64 %res |
| 124 |
| 125 } |
| 126 |
| 127 ; CHECK-LABEL: @test_fetch_and_xor_i8 |
| 128 define zeroext i8 @test_fetch_and_xor_i8(i8* %ptr, i8 zeroext %value) { |
| 129 ; CHECK-NEXT: %res = call i8 @llvm.nacl.atomic.rmw.i8(i32 5, i8* %ptr, i8 %val
ue, i32 6) |
| 130 %res = atomicrmw xor i8* %ptr, i8 %value seq_cst |
| 131 ret i8 %res ; CHECK-NEXT: ret i8 %res |
| 132 |
| 133 } |
| 134 |
| 135 ; CHECK-LABEL: @test_fetch_and_xor_i16 |
| 136 define zeroext i16 @test_fetch_and_xor_i16(i16* %ptr, i16 zeroext %value) { |
| 137 ; CHECK-NEXT: %res = call i16 @llvm.nacl.atomic.rmw.i16(i32 5, i16* %ptr, i16
%value, i32 6) |
| 138 %res = atomicrmw xor i16* %ptr, i16 %value seq_cst |
| 139 ret i16 %res ; CHECK-NEXT: ret i16 %res |
| 140 } |
| 141 |
| 142 ; CHECK-LABEL: @test_fetch_and_xor_i32 |
| 143 define i32 @test_fetch_and_xor_i32(i32* %ptr, i32 %value) { |
| 144 ; CHECK-NEXT: %res = call i32 @llvm.nacl.atomic.rmw.i32(i32 5, i32* %ptr, i32
%value, i32 6) |
| 145 %res = atomicrmw xor i32* %ptr, i32 %value seq_cst |
| 146 ret i32 %res ; CHECK-NEXT: ret i32 %res |
| 147 } |
| 148 |
| 149 ; CHECK-LABEL: @test_fetch_and_xor_i64 |
| 150 define i64 @test_fetch_and_xor_i64(i64* %ptr, i64 %value) { |
| 151 ; CHECK-NEXT: %res = call i64 @llvm.nacl.atomic.rmw.i64(i32 5, i64* %ptr, i64
%value, i32 6) |
| 152 %res = atomicrmw xor i64* %ptr, i64 %value seq_cst |
| 153 ret i64 %res ; CHECK-NEXT: ret i64 %res |
| 154 } |
OLD | NEW |