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
|
; RUN: llc < %s -march=bpfel -mcpu=v3 -verify-machineinstrs -show-mc-encoding | FileCheck %s
;
; Source:
; int test_load_add_32(int *p, int v) {
; return __sync_fetch_and_add(p, v);
; }
; int test_load_add_64(long *p, long v) {
; return __sync_fetch_and_add(p, v);
; }
; int test_load_sub_32(int *p, int v) {
; return __sync_fetch_and_sub(p, v);
; }
; int test_load_sub_64(long *p, long v) {
; return __sync_fetch_and_sub(p, v);
; }
; // from https://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Atomic-Builtins.html
; // __sync_lock_test_and_set() actually does atomic xchg and returns
; // old contents.
; int test_xchg_32(int *p, int v) {
; return __sync_lock_test_and_set(p, v);
; }
; int test_xchg_64(long *p, long v) {
; return __sync_lock_test_and_set(p, v);
; }
; int test_cas_32(int *p, int old, int new) {
; return __sync_val_compare_and_swap(p, old, new);
; }
; long test_cas_64(long *p, long old, long new) {
; return __sync_val_compare_and_swap(p, old, new);
; }
; int test_load_and_32(int *p, int v) {
; return __sync_fetch_and_and(p, v);
; }
; int test_load_and_64(long *p, long v) {
; return __sync_fetch_and_and(p, v);
; }
; int test_load_or_32(int *p, int v) {
; return __sync_fetch_and_or(p, v);
; }
; int test_load_or_64(long *p, long v) {
; return __sync_fetch_and_or(p, v);
; }
; int test_load_xor_32(int *p, int v) {
; return __sync_fetch_and_xor(p, v);
; }
; int test_load_xor_64(long *p, long v) {
; return __sync_fetch_and_xor(p, v);
; }
; int test_atomic_xor_32(int *p, int v) {
; __sync_fetch_and_xor(p, v);
; return 0;
; }
; int test_atomic_xor_64(long *p, long v) {
; __sync_fetch_and_xor(p, v);
; return 0;
; }
; int test_atomic_and_64(long *p, long v) {
; __sync_fetch_and_and(p, v);
; return 0;
; }
; int test_atomic_or_64(long *p, long v) {
; __sync_fetch_and_or(p, v);
; return 0;
; }
; CHECK-LABEL: test_load_add_32
; CHECK: w0 = w2
; CHECK: w0 = atomic_fetch_add((u32 *)(r1 + 0), w0)
; CHECK: encoding: [0xc3,0x01,0x00,0x00,0x01,0x00,0x00,0x00]
define dso_local i32 @test_load_add_32(i32* nocapture %p, i32 %v) local_unnamed_addr {
entry:
%0 = atomicrmw add i32* %p, i32 %v seq_cst
ret i32 %0
}
; CHECK-LABEL: test_load_add_64
; CHECK: r0 = r2
; CHECK: r0 = atomic_fetch_add((u64 *)(r1 + 0), r0)
; CHECK: encoding: [0xdb,0x01,0x00,0x00,0x01,0x00,0x00,0x00]
define dso_local i32 @test_load_add_64(i64* nocapture %p, i64 %v) local_unnamed_addr {
entry:
%0 = atomicrmw add i64* %p, i64 %v seq_cst
%conv = trunc i64 %0 to i32
ret i32 %conv
}
; CHECK-LABEL: test_load_sub_32
; CHECK: w0 = w2
; CHECK: w0 = -w0
; CHECK: w0 = atomic_fetch_add((u32 *)(r1 + 0), w0)
; CHECK: encoding: [0xc3,0x01,0x00,0x00,0x01,0x00,0x00,0x00]
define dso_local i32 @test_load_sub_32(i32* nocapture %p, i32 %v) local_unnamed_addr {
entry:
%0 = atomicrmw sub i32* %p, i32 %v seq_cst
ret i32 %0
}
; CHECK-LABEL: test_load_sub_64
; CHECK: r0 = r2
; CHECK: r0 = -r0
; CHECK: r0 = atomic_fetch_add((u64 *)(r1 + 0), r0)
; CHECK: encoding: [0xdb,0x01,0x00,0x00,0x01,0x00,0x00,0x00]
define dso_local i32 @test_load_sub_64(i64* nocapture %p, i64 %v) local_unnamed_addr {
entry:
%0 = atomicrmw sub i64* %p, i64 %v seq_cst
%conv = trunc i64 %0 to i32
ret i32 %conv
}
; CHECK-LABEL: test_xchg_32
; CHECK: w0 = w2
; CHECK: w0 = xchg32_32(r1 + 0, w0)
; CHECK: encoding: [0xc3,0x01,0x00,0x00,0xe1,0x00,0x00,0x00]
define dso_local i32 @test_xchg_32(i32* nocapture %p, i32 %v) local_unnamed_addr {
entry:
%0 = atomicrmw xchg i32* %p, i32 %v seq_cst
ret i32 %0
}
; CHECK-LABEL: test_xchg_64
; CHECK: r0 = r2
; CHECK: r0 = xchg_64(r1 + 0, r0)
; CHECK: encoding: [0xdb,0x01,0x00,0x00,0xe1,0x00,0x00,0x00]
define dso_local i32 @test_xchg_64(i64* nocapture %p, i64 %v) local_unnamed_addr {
entry:
%0 = atomicrmw xchg i64* %p, i64 %v seq_cst
%conv = trunc i64 %0 to i32
ret i32 %conv
}
; CHECK-LABEL: test_cas_32
; CHECK: w0 = w2
; CHECK: w0 = cmpxchg32_32(r1 + 0, w0, w3)
; CHECK: encoding: [0xc3,0x31,0x00,0x00,0xf1,0x00,0x00,0x00]
define dso_local i32 @test_cas_32(i32* nocapture %p, i32 %old, i32 %new) local_unnamed_addr {
entry:
%0 = cmpxchg i32* %p, i32 %old, i32 %new seq_cst seq_cst
%1 = extractvalue { i32, i1 } %0, 0
ret i32 %1
}
; CHECK-LABEL: test_cas_64
; CHECK: r0 = r2
; CHECK: r0 = cmpxchg_64(r1 + 0, r0, r3)
; CHECK: encoding: [0xdb,0x31,0x00,0x00,0xf1,0x00,0x00,0x00]
define dso_local i64 @test_cas_64(i64* nocapture %p, i64 %old, i64 %new) local_unnamed_addr {
entry:
%0 = cmpxchg i64* %p, i64 %old, i64 %new seq_cst seq_cst
%1 = extractvalue { i64, i1 } %0, 0
ret i64 %1
}
; CHECK-LABEL: test_load_and_32
; CHECK: w0 = w2
; CHECK: w0 = atomic_fetch_and((u32 *)(r1 + 0), w0)
; CHECK: encoding: [0xc3,0x01,0x00,0x00,0x51,0x00,0x00,0x00]
define dso_local i32 @test_load_and_32(i32* nocapture %p, i32 %v) local_unnamed_addr {
entry:
%0 = atomicrmw and i32* %p, i32 %v seq_cst
ret i32 %0
}
; CHECK-LABEL: test_load_and_64
; CHECK: r0 = r2
; CHECK: r0 = atomic_fetch_and((u64 *)(r1 + 0), r0)
; CHECK: encoding: [0xdb,0x01,0x00,0x00,0x51,0x00,0x00,0x00]
define dso_local i32 @test_load_and_64(i64* nocapture %p, i64 %v) local_unnamed_addr {
entry:
%0 = atomicrmw and i64* %p, i64 %v seq_cst
%conv = trunc i64 %0 to i32
ret i32 %conv
}
; CHECK-LABEL: test_load_or_32
; CHECK: w0 = w2
; CHECK: w0 = atomic_fetch_or((u32 *)(r1 + 0), w0)
; CHECK: encoding: [0xc3,0x01,0x00,0x00,0x41,0x00,0x00,0x00]
define dso_local i32 @test_load_or_32(i32* nocapture %p, i32 %v) local_unnamed_addr {
entry:
%0 = atomicrmw or i32* %p, i32 %v seq_cst
ret i32 %0
}
; CHECK-LABEL: test_load_or_64
; CHECK: r0 = r2
; CHECK: r0 = atomic_fetch_or((u64 *)(r1 + 0), r0)
; CHECK: encoding: [0xdb,0x01,0x00,0x00,0x41,0x00,0x00,0x00]
define dso_local i32 @test_load_or_64(i64* nocapture %p, i64 %v) local_unnamed_addr {
entry:
%0 = atomicrmw or i64* %p, i64 %v seq_cst
%conv = trunc i64 %0 to i32
ret i32 %conv
}
; CHECK-LABEL: test_load_xor_32
; CHECK: w0 = w2
; CHECK: w0 = atomic_fetch_xor((u32 *)(r1 + 0), w0)
; CHECK: encoding: [0xc3,0x01,0x00,0x00,0xa1,0x00,0x00,0x00]
define dso_local i32 @test_load_xor_32(i32* nocapture %p, i32 %v) local_unnamed_addr {
entry:
%0 = atomicrmw xor i32* %p, i32 %v seq_cst
ret i32 %0
}
; CHECK-LABEL: test_load_xor_64
; CHECK: r0 = r2
; CHECK: r0 = atomic_fetch_xor((u64 *)(r1 + 0), r0)
; CHECK: encoding: [0xdb,0x01,0x00,0x00,0xa1,0x00,0x00,0x00]
define dso_local i32 @test_load_xor_64(i64* nocapture %p, i64 %v) local_unnamed_addr {
entry:
%0 = atomicrmw xor i64* %p, i64 %v seq_cst
%conv = trunc i64 %0 to i32
ret i32 %conv
}
; CHECK-LABEL: test_atomic_xor_32
; CHECK: lock *(u32 *)(r1 + 0) ^= w2
; CHECK: encoding: [0xc3,0x21,0x00,0x00,0xa0,0x00,0x00,0x00]
; CHECK: w0 = 0
define dso_local i32 @test_atomic_xor_32(i32* nocapture %p, i32 %v) local_unnamed_addr {
entry:
%0 = atomicrmw xor i32* %p, i32 %v seq_cst
ret i32 0
}
; CHECK-LABEL: test_atomic_xor_64
; CHECK: lock *(u64 *)(r1 + 0) ^= r2
; CHECK: encoding: [0xdb,0x21,0x00,0x00,0xa0,0x00,0x00,0x00]
; CHECK: w0 = 0
define dso_local i32 @test_atomic_xor_64(i64* nocapture %p, i64 %v) local_unnamed_addr {
entry:
%0 = atomicrmw xor i64* %p, i64 %v seq_cst
ret i32 0
}
; CHECK-LABEL: test_atomic_and_64
; CHECK: lock *(u64 *)(r1 + 0) &= r2
; CHECK: encoding: [0xdb,0x21,0x00,0x00,0x50,0x00,0x00,0x00]
; CHECK: w0 = 0
define dso_local i32 @test_atomic_and_64(i64* nocapture %p, i64 %v) local_unnamed_addr {
entry:
%0 = atomicrmw and i64* %p, i64 %v seq_cst
ret i32 0
}
; CHECK-LABEL: test_atomic_or_64
; CHECK: lock *(u64 *)(r1 + 0) |= r2
; CHECK: encoding: [0xdb,0x21,0x00,0x00,0x40,0x00,0x00,0x00]
; CHECK: w0 = 0
define dso_local i32 @test_atomic_or_64(i64* nocapture %p, i64 %v) local_unnamed_addr {
entry:
%0 = atomicrmw or i64* %p, i64 %v seq_cst
ret i32 0
}
|