[Sparc]: Use cmp instruction instead of subcc to compare integers.
[oota-llvm.git] / test / CodeGen / SPARC / 64bit.ll
1 ; RUN: llc < %s -march=sparcv9 -disable-sparc-delay-filler -disable-sparc-leaf-proc | FileCheck %s
2 ; RUN: llc < %s -march=sparcv9  | FileCheck %s -check-prefix=OPT
3
4 ; CHECK: ret2:
5 ; CHECK: or %g0, %i1, %i0
6
7 ; OPT: ret2:
8 ; OPT: jmp %o7+8
9 ; OPT: or %g0, %o1, %o0
10 define i64 @ret2(i64 %a, i64 %b) {
11   ret i64 %b
12 }
13
14 ; CHECK: shl_imm
15 ; CHECK: sllx %i0, 7, %i0
16
17 ; OPT: shl_imm:
18 ; OPT: jmp %o7+8
19 ; OPT: sllx %o0, 7, %o0
20 define i64 @shl_imm(i64 %a) {
21   %x = shl i64 %a, 7
22   ret i64 %x
23 }
24
25 ; CHECK: sra_reg
26 ; CHECK: srax %i0, %i1, %i0
27
28 ; OPT: sra_reg:
29 ; OPT: jmp %o7+8
30 ; OPT: srax %o0, %o1, %o0
31 define i64 @sra_reg(i64 %a, i64 %b) {
32   %x = ashr i64 %a, %b
33   ret i64 %x
34 }
35
36 ; Immediate materialization. Many of these patterns could actually be merged
37 ; into the restore instruction:
38 ;
39 ;     restore %g0, %g0, %o0
40 ;
41 ; CHECK: ret_imm0
42 ; CHECK: or %g0, 0, %i0
43
44 ; OPT: ret_imm0
45 ; OPT: jmp %o7+8
46 ; OPT: or %g0, 0, %o0
47 define i64 @ret_imm0() {
48   ret i64 0
49 }
50
51 ; CHECK: ret_simm13
52 ; CHECK: or %g0, -4096, %i0
53
54 ; OPT:   ret_simm13
55 ; OPT:   jmp %o7+8
56 ; OPT:   or %g0, -4096, %o0
57 define i64 @ret_simm13() {
58   ret i64 -4096
59 }
60
61 ; CHECK: ret_sethi
62 ; CHECK: sethi 4, %i0
63 ; CHECK-NOT: or
64 ; CHECK: restore
65
66 ; OPT:  ret_sethi
67 ; OPT:  jmp %o7+8
68 ; OPT:  sethi 4, %o0
69 define i64 @ret_sethi() {
70   ret i64 4096
71 }
72
73 ; CHECK: ret_sethi_or
74 ; CHECK: sethi 4, [[R:%[goli][0-7]]]
75 ; CHECK: or [[R]], 1, %i0
76
77 ; OPT: ret_sethi_or
78 ; OPT: sethi 4, [[R:%[go][0-7]]]
79 ; OPT: jmp %o7+8
80 ; OPT: or [[R]], 1, %o0
81
82 define i64 @ret_sethi_or() {
83   ret i64 4097
84 }
85
86 ; CHECK: ret_nimm33
87 ; CHECK: sethi 4, [[R:%[goli][0-7]]]
88 ; CHECK: xor [[R]], -4, %i0
89
90 ; OPT: ret_nimm33
91 ; OPT: sethi 4, [[R:%[go][0-7]]]
92 ; OPT: jmp %o7+8
93 ; OPT: xor [[R]], -4, %o0
94
95 define i64 @ret_nimm33() {
96   ret i64 -4100
97 }
98
99 ; CHECK: ret_bigimm
100 ; CHECK: sethi
101 ; CHECK: sethi
102 define i64 @ret_bigimm() {
103   ret i64 6800754272627607872
104 }
105
106 ; CHECK: ret_bigimm2
107 ; CHECK: sethi 1048576
108 define i64 @ret_bigimm2() {
109   ret i64 4611686018427387904 ; 0x4000000000000000
110 }
111
112 ; CHECK: reg_reg_alu
113 ; CHECK: add %i0, %i1, [[R0:%[goli][0-7]]]
114 ; CHECK: sub [[R0]], %i2, [[R1:%[goli][0-7]]]
115 ; CHECK: andn [[R1]], %i0, %i0
116 define i64 @reg_reg_alu(i64 %x, i64 %y, i64 %z) {
117   %a = add i64 %x, %y
118   %b = sub i64 %a, %z
119   %c = xor i64 %x, -1
120   %d = and i64 %b, %c
121   ret i64 %d
122 }
123
124 ; CHECK: reg_imm_alu
125 ; CHECK: add %i0, -5, [[R0:%[goli][0-7]]]
126 ; CHECK: xor [[R0]], 2, %i0
127 define i64 @reg_imm_alu(i64 %x, i64 %y, i64 %z) {
128   %a = add i64 %x, -5
129   %b = xor i64 %a, 2
130   ret i64 %b
131 }
132
133 ; CHECK: loads
134 ; CHECK: ldx [%i0]
135 ; CHECK: stx %
136 ; CHECK: ld [%i1]
137 ; CHECK: st %
138 ; CHECK: ldsw [%i2]
139 ; CHECK: stx %
140 ; CHECK: ldsh [%i3]
141 ; CHECK: sth %
142 define i64 @loads(i64* %p, i32* %q, i32* %r, i16* %s) {
143   %a = load i64* %p
144   %ai = add i64 1, %a
145   store i64 %ai, i64* %p
146   %b = load i32* %q
147   %b2 = zext i32 %b to i64
148   %bi = trunc i64 %ai to i32
149   store i32 %bi, i32* %q
150   %c = load i32* %r
151   %c2 = sext i32 %c to i64
152   store i64 %ai, i64* %p
153   %d = load i16* %s
154   %d2 = sext i16 %d to i64
155   %di = trunc i64 %ai to i16
156   store i16 %di, i16* %s
157
158   %x1 = add i64 %a, %b2
159   %x2 = add i64 %c2, %d2
160   %x3 = add i64 %x1, %x2
161   ret i64 %x3
162 }
163
164 ; CHECK: stores
165 ; CHECK: ldx [%i0+8], [[R:%[goli][0-7]]]
166 ; CHECK: stx [[R]], [%i0+16]
167 ; CHECK: st [[R]], [%i1+-8]
168 ; CHECK: sth [[R]], [%i2+40]
169 ; CHECK: stb [[R]], [%i3+-20]
170 define void @stores(i64* %p, i32* %q, i16* %r, i8* %s) {
171   %p1 = getelementptr i64* %p, i64 1
172   %p2 = getelementptr i64* %p, i64 2
173   %pv = load i64* %p1
174   store i64 %pv, i64* %p2
175
176   %q2 = getelementptr i32* %q, i32 -2
177   %qv = trunc i64 %pv to i32
178   store i32 %qv, i32* %q2
179
180   %r2 = getelementptr i16* %r, i16 20
181   %rv = trunc i64 %pv to i16
182   store i16 %rv, i16* %r2
183
184   %s2 = getelementptr i8* %s, i8 -20
185   %sv = trunc i64 %pv to i8
186   store i8 %sv, i8* %s2
187
188   ret void
189 }
190
191 ; CHECK: promote_shifts
192 ; CHECK: ldub [%i0], [[R:%[goli][0-7]]]
193 ; CHECK: sll [[R]], [[R]], %i0
194 define i8 @promote_shifts(i8* %p) {
195   %L24 = load i8* %p
196   %L32 = load i8* %p
197   %B36 = shl i8 %L24, %L32
198   ret i8 %B36
199 }
200
201 ; CHECK: multiply
202 ; CHECK: mulx %i0, %i1, %i0
203 define i64 @multiply(i64 %a, i64 %b) {
204   %r = mul i64 %a, %b
205   ret i64 %r
206 }
207
208 ; CHECK: signed_divide
209 ; CHECK: sdivx %i0, %i1, %i0
210 define i64 @signed_divide(i64 %a, i64 %b) {
211   %r = sdiv i64 %a, %b
212   ret i64 %r
213 }
214
215 ; CHECK: unsigned_divide
216 ; CHECK: udivx %i0, %i1, %i0
217 define i64 @unsigned_divide(i64 %a, i64 %b) {
218   %r = udiv i64 %a, %b
219   ret i64 %r
220 }
221
222 define void @access_fi() {
223 entry:
224   %b = alloca [32 x i8], align 1
225   %arraydecay = getelementptr inbounds [32 x i8]* %b, i64 0, i64 0
226   call void @g(i8* %arraydecay) #2
227   ret void
228 }
229
230 declare void @g(i8*)
231
232 ; CHECK: expand_setcc
233 ; CHECK: cmp %i0, 1
234 ; CHECK: movl %xcc, 1,
235 define i32 @expand_setcc(i64 %a) {
236   %cond = icmp sle i64 %a, 0
237   %cast2 = zext i1 %cond to i32
238   %RV = sub i32 1, %cast2
239   ret i32 %RV
240 }
241
242 ; CHECK: spill_i64
243 ; CHECK: stx
244 ; CHECK: ldx
245 define i64 @spill_i64(i64 %x) {
246   call void asm sideeffect "", "~{i0},~{i1},~{i2},~{i3},~{i4},~{i5},~{o0},~{o1},~{o2},~{o3},~{o4},~{o5},~{o7},~{l0},~{l1},~{l2},~{l3},~{l4},~{l5},~{l6},~{l7},~{g1},~{g2},~{g3},~{g4},~{g5},~{g6},~{g7}"()
247   ret i64 %x
248 }
249
250 ; CHECK: bitcast_i64_f64
251 ; CHECK: std
252 ; CHECK: ldx
253 define i64 @bitcast_i64_f64(double %x) {
254   %y = bitcast double %x to i64
255   ret i64 %y
256 }
257
258 ; CHECK: bitcast_f64_i64
259 ; CHECK: stx
260 ; CHECK: ldd
261 define double @bitcast_f64_i64(i64 %x) {
262   %y = bitcast i64 %x to double
263   ret double %y
264 }
265
266 ; CHECK: store_zero:
267 ; CHECK: stx %g0, [%i0]
268 ; CHECK: stx %g0, [%i1+8]
269
270 ; OPT:  store_zero:
271 ; OPT:  stx %g0, [%o0]
272 ; OPT:  stx %g0, [%o1+8]
273 define i64 @store_zero(i64* nocapture %a, i64* nocapture %b) {
274 entry:
275   store i64 0, i64* %a, align 8
276   %0 = getelementptr inbounds i64* %b, i32 1
277   store i64 0, i64* %0, align 8
278   ret i64 0
279 }