|
| 1 | +// Code generation of atomic operations for LLVM 12 |
| 2 | +// ignore-llvm-version: 13 - 99 |
| 3 | +// compile-flags: -O |
| 4 | +#![crate_type = "lib"] |
| 5 | + |
| 6 | +use std::sync::atomic::{AtomicI32, Ordering::*}; |
| 7 | + |
| 8 | +// CHECK-LABEL: @compare_exchange |
| 9 | +#[no_mangle] |
| 10 | +pub fn compare_exchange(a: &AtomicI32) { |
| 11 | + // CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 10 monotonic monotonic |
| 12 | + // CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 11 acquire acquire |
| 13 | + // CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 12 seq_cst seq_cst |
| 14 | + let _ = a.compare_exchange(0, 10, Relaxed, Relaxed); |
| 15 | + let _ = a.compare_exchange(0, 11, Relaxed, Acquire); |
| 16 | + let _ = a.compare_exchange(0, 12, Relaxed, SeqCst); |
| 17 | + |
| 18 | + // CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 20 release monotonic |
| 19 | + // CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 21 acq_rel acquire |
| 20 | + // CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 22 seq_cst seq_cst |
| 21 | + let _ = a.compare_exchange(0, 20, Release, Relaxed); |
| 22 | + let _ = a.compare_exchange(0, 21, Release, Acquire); |
| 23 | + let _ = a.compare_exchange(0, 22, Release, SeqCst); |
| 24 | + |
| 25 | + // CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 30 acquire monotonic |
| 26 | + // CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 31 acquire acquire |
| 27 | + // CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 32 seq_cst seq_cst |
| 28 | + let _ = a.compare_exchange(0, 30, Acquire, Relaxed); |
| 29 | + let _ = a.compare_exchange(0, 31, Acquire, Acquire); |
| 30 | + let _ = a.compare_exchange(0, 32, Acquire, SeqCst); |
| 31 | + |
| 32 | + // CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 40 acq_rel monotonic |
| 33 | + // CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 41 acq_rel acquire |
| 34 | + // CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 42 seq_cst seq_cst |
| 35 | + let _ = a.compare_exchange(0, 40, AcqRel, Relaxed); |
| 36 | + let _ = a.compare_exchange(0, 41, AcqRel, Acquire); |
| 37 | + let _ = a.compare_exchange(0, 42, AcqRel, SeqCst); |
| 38 | + |
| 39 | + // CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 50 seq_cst monotonic |
| 40 | + // CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 51 seq_cst acquire |
| 41 | + // CHECK: cmpxchg i32* %{{.*}}, i32 0, i32 52 seq_cst seq_cst |
| 42 | + let _ = a.compare_exchange(0, 50, SeqCst, Relaxed); |
| 43 | + let _ = a.compare_exchange(0, 51, SeqCst, Acquire); |
| 44 | + let _ = a.compare_exchange(0, 52, SeqCst, SeqCst); |
| 45 | +} |
| 46 | + |
| 47 | +// CHECK-LABEL: @compare_exchange_weak |
| 48 | +#[no_mangle] |
| 49 | +pub fn compare_exchange_weak(w: &AtomicI32) { |
| 50 | + // CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 10 monotonic monotonic |
| 51 | + // CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 11 acquire acquire |
| 52 | + // CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 12 seq_cst seq_cst |
| 53 | + let _ = w.compare_exchange_weak(1, 10, Relaxed, Relaxed); |
| 54 | + let _ = w.compare_exchange_weak(1, 11, Relaxed, Acquire); |
| 55 | + let _ = w.compare_exchange_weak(1, 12, Relaxed, SeqCst); |
| 56 | + |
| 57 | + // CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 20 release monotonic |
| 58 | + // CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 21 acq_rel acquire |
| 59 | + // CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 22 seq_cst seq_cst |
| 60 | + let _ = w.compare_exchange_weak(1, 20, Release, Relaxed); |
| 61 | + let _ = w.compare_exchange_weak(1, 21, Release, Acquire); |
| 62 | + let _ = w.compare_exchange_weak(1, 22, Release, SeqCst); |
| 63 | + |
| 64 | + // CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 30 acquire monotonic |
| 65 | + // CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 31 acquire acquire |
| 66 | + // CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 32 seq_cst seq_cst |
| 67 | + let _ = w.compare_exchange_weak(1, 30, Acquire, Relaxed); |
| 68 | + let _ = w.compare_exchange_weak(1, 31, Acquire, Acquire); |
| 69 | + let _ = w.compare_exchange_weak(1, 32, Acquire, SeqCst); |
| 70 | + |
| 71 | + // CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 40 acq_rel monotonic |
| 72 | + // CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 41 acq_rel acquire |
| 73 | + // CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 42 seq_cst seq_cst |
| 74 | + let _ = w.compare_exchange_weak(1, 40, AcqRel, Relaxed); |
| 75 | + let _ = w.compare_exchange_weak(1, 41, AcqRel, Acquire); |
| 76 | + let _ = w.compare_exchange_weak(1, 42, AcqRel, SeqCst); |
| 77 | + |
| 78 | + // CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 50 seq_cst monotonic |
| 79 | + // CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 51 seq_cst acquire |
| 80 | + // CHECK: cmpxchg weak i32* %{{.*}}, i32 1, i32 52 seq_cst seq_cst |
| 81 | + let _ = w.compare_exchange_weak(1, 50, SeqCst, Relaxed); |
| 82 | + let _ = w.compare_exchange_weak(1, 51, SeqCst, Acquire); |
| 83 | + let _ = w.compare_exchange_weak(1, 52, SeqCst, SeqCst); |
| 84 | +} |
0 commit comments