xref: /aosp_15_r20/external/llvm/test/CodeGen/X86/atomic_op.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llc < %s -mcpu=generic -march=x86 -mattr=+cmov,cx16 -verify-machineinstrs | FileCheck %s
2*9880d681SAndroid Build Coastguard Worker
3*9880d681SAndroid Build Coastguard Workertarget datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
4*9880d681SAndroid Build Coastguard Worker
5*9880d681SAndroid Build Coastguard Workerdefine void @func(i32 %argc, i8** %argv) nounwind {
6*9880d681SAndroid Build Coastguard Workerentry:
7*9880d681SAndroid Build Coastguard Worker	%argc.addr = alloca i32		; <i32*> [#uses=1]
8*9880d681SAndroid Build Coastguard Worker	%argv.addr = alloca i8**		; <i8***> [#uses=1]
9*9880d681SAndroid Build Coastguard Worker	%val1 = alloca i32		; <i32*> [#uses=2]
10*9880d681SAndroid Build Coastguard Worker	%val2 = alloca i32		; <i32*> [#uses=15]
11*9880d681SAndroid Build Coastguard Worker	%andt = alloca i32		; <i32*> [#uses=2]
12*9880d681SAndroid Build Coastguard Worker	%ort = alloca i32		; <i32*> [#uses=2]
13*9880d681SAndroid Build Coastguard Worker	%xort = alloca i32		; <i32*> [#uses=2]
14*9880d681SAndroid Build Coastguard Worker	%old = alloca i32		; <i32*> [#uses=18]
15*9880d681SAndroid Build Coastguard Worker	%temp = alloca i32		; <i32*> [#uses=2]
16*9880d681SAndroid Build Coastguard Worker	%temp64 = alloca i64
17*9880d681SAndroid Build Coastguard Worker	store i32 %argc, i32* %argc.addr
18*9880d681SAndroid Build Coastguard Worker	store i8** %argv, i8*** %argv.addr
19*9880d681SAndroid Build Coastguard Worker	store i32 0, i32* %val1
20*9880d681SAndroid Build Coastguard Worker	store i32 31, i32* %val2
21*9880d681SAndroid Build Coastguard Worker	store i32 3855, i32* %andt
22*9880d681SAndroid Build Coastguard Worker	store i32 3855, i32* %ort
23*9880d681SAndroid Build Coastguard Worker	store i32 3855, i32* %xort
24*9880d681SAndroid Build Coastguard Worker	store i32 4, i32* %temp
25*9880d681SAndroid Build Coastguard Worker	%tmp = load i32, i32* %temp
26*9880d681SAndroid Build Coastguard Worker        ; CHECK: lock
27*9880d681SAndroid Build Coastguard Worker        ; CHECK: xaddl
28*9880d681SAndroid Build Coastguard Worker  %0 = atomicrmw add i32* %val1, i32 %tmp monotonic
29*9880d681SAndroid Build Coastguard Worker	store i32 %0, i32* %old
30*9880d681SAndroid Build Coastguard Worker        ; CHECK: lock
31*9880d681SAndroid Build Coastguard Worker        ; CHECK: xaddl
32*9880d681SAndroid Build Coastguard Worker  %1 = atomicrmw sub i32* %val2, i32 30 monotonic
33*9880d681SAndroid Build Coastguard Worker	store i32 %1, i32* %old
34*9880d681SAndroid Build Coastguard Worker        ; CHECK: lock
35*9880d681SAndroid Build Coastguard Worker        ; CHECK: xaddl
36*9880d681SAndroid Build Coastguard Worker  %2 = atomicrmw add i32* %val2, i32 1 monotonic
37*9880d681SAndroid Build Coastguard Worker	store i32 %2, i32* %old
38*9880d681SAndroid Build Coastguard Worker        ; CHECK: lock
39*9880d681SAndroid Build Coastguard Worker        ; CHECK: xaddl
40*9880d681SAndroid Build Coastguard Worker  %3 = atomicrmw sub i32* %val2, i32 1 monotonic
41*9880d681SAndroid Build Coastguard Worker	store i32 %3, i32* %old
42*9880d681SAndroid Build Coastguard Worker        ; CHECK: andl
43*9880d681SAndroid Build Coastguard Worker        ; CHECK: lock
44*9880d681SAndroid Build Coastguard Worker        ; CHECK: cmpxchgl
45*9880d681SAndroid Build Coastguard Worker  %4 = atomicrmw and i32* %andt, i32 4080 monotonic
46*9880d681SAndroid Build Coastguard Worker	store i32 %4, i32* %old
47*9880d681SAndroid Build Coastguard Worker        ; CHECK: orl
48*9880d681SAndroid Build Coastguard Worker        ; CHECK: lock
49*9880d681SAndroid Build Coastguard Worker        ; CHECK: cmpxchgl
50*9880d681SAndroid Build Coastguard Worker  %5 = atomicrmw or i32* %ort, i32 4080 monotonic
51*9880d681SAndroid Build Coastguard Worker	store i32 %5, i32* %old
52*9880d681SAndroid Build Coastguard Worker        ; CHECK: xorl
53*9880d681SAndroid Build Coastguard Worker        ; CHECK: lock
54*9880d681SAndroid Build Coastguard Worker        ; CHECK: cmpxchgl
55*9880d681SAndroid Build Coastguard Worker  %6 = atomicrmw xor i32* %xort, i32 4080 monotonic
56*9880d681SAndroid Build Coastguard Worker	store i32 %6, i32* %old
57*9880d681SAndroid Build Coastguard Worker        ; CHECK: cmov
58*9880d681SAndroid Build Coastguard Worker        ; CHECK: lock
59*9880d681SAndroid Build Coastguard Worker        ; CHECK: cmpxchgl
60*9880d681SAndroid Build Coastguard Worker  %7 = atomicrmw min i32* %val2, i32 16 monotonic
61*9880d681SAndroid Build Coastguard Worker	store i32 %7, i32* %old
62*9880d681SAndroid Build Coastguard Worker	%neg = sub i32 0, 1		; <i32> [#uses=1]
63*9880d681SAndroid Build Coastguard Worker        ; CHECK: cmov
64*9880d681SAndroid Build Coastguard Worker        ; CHECK: lock
65*9880d681SAndroid Build Coastguard Worker        ; CHECK: cmpxchgl
66*9880d681SAndroid Build Coastguard Worker  %8 = atomicrmw min i32* %val2, i32 %neg monotonic
67*9880d681SAndroid Build Coastguard Worker	store i32 %8, i32* %old
68*9880d681SAndroid Build Coastguard Worker        ; CHECK: cmov
69*9880d681SAndroid Build Coastguard Worker        ; CHECK: lock
70*9880d681SAndroid Build Coastguard Worker        ; CHECK: cmpxchgl
71*9880d681SAndroid Build Coastguard Worker  %9 = atomicrmw max i32* %val2, i32 1 monotonic
72*9880d681SAndroid Build Coastguard Worker	store i32 %9, i32* %old
73*9880d681SAndroid Build Coastguard Worker        ; CHECK: cmov
74*9880d681SAndroid Build Coastguard Worker        ; CHECK: lock
75*9880d681SAndroid Build Coastguard Worker        ; CHECK: cmpxchgl
76*9880d681SAndroid Build Coastguard Worker  %10 = atomicrmw max i32* %val2, i32 0 monotonic
77*9880d681SAndroid Build Coastguard Worker	store i32 %10, i32* %old
78*9880d681SAndroid Build Coastguard Worker        ; CHECK: cmov
79*9880d681SAndroid Build Coastguard Worker        ; CHECK: lock
80*9880d681SAndroid Build Coastguard Worker        ; CHECK: cmpxchgl
81*9880d681SAndroid Build Coastguard Worker  %11 = atomicrmw umax i32* %val2, i32 65535 monotonic
82*9880d681SAndroid Build Coastguard Worker	store i32 %11, i32* %old
83*9880d681SAndroid Build Coastguard Worker        ; CHECK: cmov
84*9880d681SAndroid Build Coastguard Worker        ; CHECK: lock
85*9880d681SAndroid Build Coastguard Worker        ; CHECK: cmpxchgl
86*9880d681SAndroid Build Coastguard Worker  %12 = atomicrmw umax i32* %val2, i32 10 monotonic
87*9880d681SAndroid Build Coastguard Worker	store i32 %12, i32* %old
88*9880d681SAndroid Build Coastguard Worker        ; CHECK: cmov
89*9880d681SAndroid Build Coastguard Worker        ; CHECK: lock
90*9880d681SAndroid Build Coastguard Worker        ; CHECK: cmpxchgl
91*9880d681SAndroid Build Coastguard Worker  %13 = atomicrmw umin i32* %val2, i32 1 monotonic
92*9880d681SAndroid Build Coastguard Worker	store i32 %13, i32* %old
93*9880d681SAndroid Build Coastguard Worker        ; CHECK: cmov
94*9880d681SAndroid Build Coastguard Worker        ; CHECK: lock
95*9880d681SAndroid Build Coastguard Worker        ; CHECK: cmpxchgl
96*9880d681SAndroid Build Coastguard Worker  %14 = atomicrmw umin i32* %val2, i32 10 monotonic
97*9880d681SAndroid Build Coastguard Worker	store i32 %14, i32* %old
98*9880d681SAndroid Build Coastguard Worker        ; CHECK: xchgl   %{{.*}}, {{.*}}(%esp)
99*9880d681SAndroid Build Coastguard Worker  %15 = atomicrmw xchg i32* %val2, i32 1976 monotonic
100*9880d681SAndroid Build Coastguard Worker	store i32 %15, i32* %old
101*9880d681SAndroid Build Coastguard Worker	%neg1 = sub i32 0, 10		; <i32> [#uses=1]
102*9880d681SAndroid Build Coastguard Worker        ; CHECK: lock
103*9880d681SAndroid Build Coastguard Worker        ; CHECK: cmpxchgl
104*9880d681SAndroid Build Coastguard Worker  %pair16 = cmpxchg i32* %val2, i32 %neg1, i32 1 monotonic monotonic
105*9880d681SAndroid Build Coastguard Worker  %16 = extractvalue { i32, i1 } %pair16, 0
106*9880d681SAndroid Build Coastguard Worker	store i32 %16, i32* %old
107*9880d681SAndroid Build Coastguard Worker        ; CHECK: lock
108*9880d681SAndroid Build Coastguard Worker        ; CHECK: cmpxchgl
109*9880d681SAndroid Build Coastguard Worker  %pair17 = cmpxchg i32* %val2, i32 1976, i32 1 monotonic monotonic
110*9880d681SAndroid Build Coastguard Worker  %17 = extractvalue { i32, i1 } %pair17, 0
111*9880d681SAndroid Build Coastguard Worker	store i32 %17, i32* %old
112*9880d681SAndroid Build Coastguard Worker        ; CHECK: movl  [[R17atomic:.*]], %eax
113*9880d681SAndroid Build Coastguard Worker        ; CHECK: movl %eax, %[[R17mask:[a-z]*]]
114*9880d681SAndroid Build Coastguard Worker        ; CHECK: notl %[[R17mask]]
115*9880d681SAndroid Build Coastguard Worker        ; CHECK: orl $-1402, %[[R17mask]]
116*9880d681SAndroid Build Coastguard Worker        ; CHECK: lock
117*9880d681SAndroid Build Coastguard Worker        ; CHECK: cmpxchgl	%[[R17mask]], [[R17atomic]]
118*9880d681SAndroid Build Coastguard Worker        ; CHECK: jne
119*9880d681SAndroid Build Coastguard Worker        ; CHECK: movl	%eax,
120*9880d681SAndroid Build Coastguard Worker  %18 = atomicrmw nand i32* %val2, i32 1401 monotonic
121*9880d681SAndroid Build Coastguard Worker  store i32 %18, i32* %old
122*9880d681SAndroid Build Coastguard Worker        ; CHECK: notl
123*9880d681SAndroid Build Coastguard Worker        ; CHECK: notl
124*9880d681SAndroid Build Coastguard Worker        ; CHECK: orl $252645135
125*9880d681SAndroid Build Coastguard Worker        ; CHECK: orl $252645135
126*9880d681SAndroid Build Coastguard Worker        ; CHECK: lock
127*9880d681SAndroid Build Coastguard Worker        ; CHECK: cmpxchg8b
128*9880d681SAndroid Build Coastguard Worker  %19 = atomicrmw nand i64* %temp64, i64 17361641481138401520 monotonic
129*9880d681SAndroid Build Coastguard Worker  store i64 %19, i64* %temp64
130*9880d681SAndroid Build Coastguard Worker	ret void
131*9880d681SAndroid Build Coastguard Worker}
132*9880d681SAndroid Build Coastguard Worker
133*9880d681SAndroid Build Coastguard Workerdefine void @test2(i32 addrspace(256)* nocapture %P) nounwind {
134*9880d681SAndroid Build Coastguard Workerentry:
135*9880d681SAndroid Build Coastguard Worker; CHECK: lock
136*9880d681SAndroid Build Coastguard Worker; CHECK:	cmpxchgl	%{{.*}}, %gs:(%{{.*}})
137*9880d681SAndroid Build Coastguard Worker
138*9880d681SAndroid Build Coastguard Worker  %pair0 = cmpxchg i32 addrspace(256)* %P, i32 0, i32 1 monotonic monotonic
139*9880d681SAndroid Build Coastguard Worker  %0 = extractvalue { i32, i1 } %pair0, 0
140*9880d681SAndroid Build Coastguard Worker  ret void
141*9880d681SAndroid Build Coastguard Worker}
142