blob: 8f124c89db4babbac508362de8e79ce487ccf984 [file] [log] [blame]
Daniel Sanders0d972702016-06-24 12:23:17 +00001; RUN: llc -march=mips64el -mcpu=mips4 -verify-machineinstrs < %s | FileCheck -check-prefixes=ALL,MIPS4,ACCMULDIV %s
2; RUN: llc -march=mips64el -mcpu=mips64 -verify-machineinstrs < %s | FileCheck -check-prefixes=ALL,HAS-DCLO,ACCMULDIV %s
3; RUN: llc -march=mips64el -mcpu=mips64r2 -verify-machineinstrs < %s | FileCheck -check-prefixes=ALL,HAS-DCLO,ACCMULDIV %s
4; RUN: llc -march=mips64el -mcpu=mips64r6 -verify-machineinstrs < %s | FileCheck -check-prefixes=ALL,HAS-DCLO,GPRMULDIV %s
Akira Hatanaka86c3c792013-10-15 01:06:30 +00005
6@gll0 = common global i64 0, align 8
7@gll1 = common global i64 0, align 8
Akira Hatanaka36036412011-09-29 20:37:56 +00008
9define i64 @f0(i64 %a0, i64 %a1) nounwind readnone {
10entry:
Daniel Sanders8bb4c852014-06-11 15:48:00 +000011; ALL-LABEL: f0:
12; ALL: daddu $2, ${{[45]}}, ${{[45]}}
Akira Hatanaka36036412011-09-29 20:37:56 +000013 %add = add nsw i64 %a1, %a0
14 ret i64 %add
15}
16
17define i64 @f1(i64 %a0, i64 %a1) nounwind readnone {
18entry:
Daniel Sanders8bb4c852014-06-11 15:48:00 +000019; ALL-LABEL: f1:
20; ALL: dsubu $2, $4, $5
Akira Hatanaka36036412011-09-29 20:37:56 +000021 %sub = sub nsw i64 %a0, %a1
22 ret i64 %sub
23}
24
25define i64 @f4(i64 %a0, i64 %a1) nounwind readnone {
26entry:
Daniel Sanders8bb4c852014-06-11 15:48:00 +000027; ALL-LABEL: f4:
28; ALL: and $2, ${{[45]}}, ${{[45]}}
Akira Hatanaka36036412011-09-29 20:37:56 +000029 %and = and i64 %a1, %a0
30 ret i64 %and
31}
32
33define i64 @f5(i64 %a0, i64 %a1) nounwind readnone {
34entry:
Daniel Sanders8bb4c852014-06-11 15:48:00 +000035; ALL-LABEL: f5:
36; ALL: or $2, ${{[45]}}, ${{[45]}}
Akira Hatanaka36036412011-09-29 20:37:56 +000037 %or = or i64 %a1, %a0
38 ret i64 %or
39}
40
41define i64 @f6(i64 %a0, i64 %a1) nounwind readnone {
42entry:
Daniel Sanders8bb4c852014-06-11 15:48:00 +000043; ALL-LABEL: f6:
44; ALL: xor $2, ${{[45]}}, ${{[45]}}
Akira Hatanaka36036412011-09-29 20:37:56 +000045 %xor = xor i64 %a1, %a0
46 ret i64 %xor
47}
Akira Hatanaka7769a772011-09-30 02:08:54 +000048
49define i64 @f7(i64 %a0) nounwind readnone {
50entry:
Daniel Sanders8bb4c852014-06-11 15:48:00 +000051; ALL-LABEL: f7:
52; ALL: daddiu $2, $4, 20
Akira Hatanaka7769a772011-09-30 02:08:54 +000053 %add = add nsw i64 %a0, 20
54 ret i64 %add
55}
56
57define i64 @f8(i64 %a0) nounwind readnone {
58entry:
Daniel Sanders8bb4c852014-06-11 15:48:00 +000059; ALL-LABEL: f8:
60; ALL: daddiu $2, $4, -20
Akira Hatanaka7769a772011-09-30 02:08:54 +000061 %sub = add nsw i64 %a0, -20
62 ret i64 %sub
63}
64
65define i64 @f9(i64 %a0) nounwind readnone {
66entry:
Daniel Sanders8bb4c852014-06-11 15:48:00 +000067; ALL-LABEL: f9:
68; ALL: andi $2, $4, 20
Akira Hatanaka7769a772011-09-30 02:08:54 +000069 %and = and i64 %a0, 20
70 ret i64 %and
71}
72
73define i64 @f10(i64 %a0) nounwind readnone {
74entry:
Daniel Sanders8bb4c852014-06-11 15:48:00 +000075; ALL-LABEL: f10:
76; ALL: ori $2, $4, 20
Akira Hatanaka7769a772011-09-30 02:08:54 +000077 %or = or i64 %a0, 20
78 ret i64 %or
79}
80
81define i64 @f11(i64 %a0) nounwind readnone {
82entry:
Daniel Sanders8bb4c852014-06-11 15:48:00 +000083; ALL-LABEL: f11:
84; ALL: xori $2, $4, 20
Akira Hatanaka7769a772011-09-30 02:08:54 +000085 %xor = xor i64 %a0, 20
86 ret i64 %xor
87}
88
Akira Hatanakaa279d9b2011-10-03 20:01:11 +000089define i64 @f12(i64 %a, i64 %b) nounwind readnone {
90entry:
Daniel Sanders8bb4c852014-06-11 15:48:00 +000091; ALL-LABEL: f12:
Daniel Sanders00463112014-06-16 13:18:59 +000092
93; ACCMULDIV: mult ${{[45]}}, ${{[45]}}
94; GPRMULDIV: dmul $2, ${{[45]}}, ${{[45]}}
95
Akira Hatanakaa279d9b2011-10-03 20:01:11 +000096 %mul = mul nsw i64 %b, %a
97 ret i64 %mul
98}
99
100define i64 @f13(i64 %a, i64 %b) nounwind readnone {
101entry:
Daniel Sanders8bb4c852014-06-11 15:48:00 +0000102; ALL-LABEL: f13:
Daniel Sanders00463112014-06-16 13:18:59 +0000103
104; ACCMULDIV: mult ${{[45]}}, ${{[45]}}
105; GPRMULDIV: dmul $2, ${{[45]}}, ${{[45]}}
106
Akira Hatanakaa279d9b2011-10-03 20:01:11 +0000107 %mul = mul i64 %b, %a
108 ret i64 %mul
109}
Akira Hatanakab1538f92011-10-03 21:06:13 +0000110
111define i64 @f14(i64 %a, i64 %b) nounwind readnone {
112entry:
Daniel Sanders8bb4c852014-06-11 15:48:00 +0000113; ALL-LABEL: f14:
114; ALL-DAG: ld $[[P0:[0-9]+]], %got_disp(gll0)(
115; ALL-DAG: ld $[[P1:[0-9]+]], %got_disp(gll1)(
116; ALL-DAG: ld $[[T0:[0-9]+]], 0($[[P0]])
117; ALL-DAG: ld $[[T1:[0-9]+]], 0($[[P1]])
Daniel Sanders00463112014-06-16 13:18:59 +0000118
119; ACCMULDIV: ddiv $zero, $[[T0]], $[[T1]]
120; ACCMULDIV: teq $[[T1]], $zero, 7
121; ACCMULDIV: mflo $2
122
123; GPRMULDIV: ddiv $2, $[[T0]], $[[T1]]
124; GPRMULDIV: teq $[[T1]], $zero, 7
125
David Blaikiea79ac142015-02-27 21:17:42 +0000126 %0 = load i64, i64* @gll0, align 8
127 %1 = load i64, i64* @gll1, align 8
Akira Hatanaka86c3c792013-10-15 01:06:30 +0000128 %div = sdiv i64 %0, %1
Akira Hatanakab1538f92011-10-03 21:06:13 +0000129 ret i64 %div
130}
131
Akira Hatanaka86c3c792013-10-15 01:06:30 +0000132define i64 @f15() nounwind readnone {
Akira Hatanakab1538f92011-10-03 21:06:13 +0000133entry:
Daniel Sanders8bb4c852014-06-11 15:48:00 +0000134; ALL-LABEL: f15:
135; ALL-DAG: ld $[[P0:[0-9]+]], %got_disp(gll0)(
136; ALL-DAG: ld $[[P1:[0-9]+]], %got_disp(gll1)(
137; ALL-DAG: ld $[[T0:[0-9]+]], 0($[[P0]])
138; ALL-DAG: ld $[[T1:[0-9]+]], 0($[[P1]])
Daniel Sanders00463112014-06-16 13:18:59 +0000139
140; ACCMULDIV: ddivu $zero, $[[T0]], $[[T1]]
141; ACCMULDIV: teq $[[T1]], $zero, 7
142; ACCMULDIV: mflo $2
143
144; GPRMULDIV: ddivu $2, $[[T0]], $[[T1]]
145; GPRMULDIV: teq $[[T1]], $zero, 7
146
David Blaikiea79ac142015-02-27 21:17:42 +0000147 %0 = load i64, i64* @gll0, align 8
148 %1 = load i64, i64* @gll1, align 8
Akira Hatanaka86c3c792013-10-15 01:06:30 +0000149 %div = udiv i64 %0, %1
Akira Hatanakab1538f92011-10-03 21:06:13 +0000150 ret i64 %div
151}
152
153define i64 @f16(i64 %a, i64 %b) nounwind readnone {
154entry:
Daniel Sanders8bb4c852014-06-11 15:48:00 +0000155; ALL-LABEL: f16:
Daniel Sanders00463112014-06-16 13:18:59 +0000156
157; ACCMULDIV: ddiv $zero, $4, $5
158; ACCMULDIV: teq $5, $zero, 7
159; ACCMULDIV: mfhi $2
160
161; GPRMULDIV: dmod $2, $4, $5
162; GPRMULDIV: teq $5, $zero, 7
163
Akira Hatanakab1538f92011-10-03 21:06:13 +0000164 %rem = srem i64 %a, %b
165 ret i64 %rem
166}
167
168define i64 @f17(i64 %a, i64 %b) nounwind readnone {
169entry:
Daniel Sanders8bb4c852014-06-11 15:48:00 +0000170; ALL-LABEL: f17:
Daniel Sanders00463112014-06-16 13:18:59 +0000171
172; ACCMULDIV: ddivu $zero, $4, $5
173; ACCMULDIV: teq $5, $zero, 7
174; ACCMULDIV: mfhi $2
175
176; GPRMULDIV: dmodu $2, $4, $5
177; GPRMULDIV: teq $5, $zero, 7
178
Akira Hatanakab1538f92011-10-03 21:06:13 +0000179 %rem = urem i64 %a, %b
180 ret i64 %rem
181}
182
Chandler Carruth6b0e34c2011-12-12 11:59:10 +0000183declare i64 @llvm.ctlz.i64(i64, i1) nounwind readnone
Akira Hatanaka48a72ca2011-10-03 21:16:50 +0000184
Akira Hatanaka48a72ca2011-10-03 21:16:50 +0000185define i64 @f18(i64 %X) nounwind readnone {
186entry:
Daniel Sanders8bb4c852014-06-11 15:48:00 +0000187; ALL-LABEL: f18:
Daniel Sanders3d849352014-04-14 15:44:42 +0000188
189; The MIPS4 version is too long to reasonably test. At least check we don't get dclz
Daniel Sanders8bb4c852014-06-11 15:48:00 +0000190; MIPS4-NOT: dclz
Daniel Sanders3d849352014-04-14 15:44:42 +0000191
Daniel Sanders00463112014-06-16 13:18:59 +0000192; HAS-DCLO: dclz $2, $4
193
Chandler Carruth6b0e34c2011-12-12 11:59:10 +0000194 %tmp1 = tail call i64 @llvm.ctlz.i64(i64 %X, i1 true)
Akira Hatanaka48a72ca2011-10-03 21:16:50 +0000195 ret i64 %tmp1
196}
197
Akira Hatanaka48a72ca2011-10-03 21:16:50 +0000198define i64 @f19(i64 %X) nounwind readnone {
199entry:
Daniel Sanders8bb4c852014-06-11 15:48:00 +0000200; ALL-LABEL: f19:
Daniel Sanders3d849352014-04-14 15:44:42 +0000201
202; The MIPS4 version is too long to reasonably test. At least check we don't get dclo
Daniel Sanders8bb4c852014-06-11 15:48:00 +0000203; MIPS4-NOT: dclo
Daniel Sanders3d849352014-04-14 15:44:42 +0000204
Daniel Sanders00463112014-06-16 13:18:59 +0000205; HAS-DCLO: dclo $2, $4
206
Akira Hatanaka48a72ca2011-10-03 21:16:50 +0000207 %neg = xor i64 %X, -1
Chandler Carruth6b0e34c2011-12-12 11:59:10 +0000208 %tmp1 = tail call i64 @llvm.ctlz.i64(i64 %neg, i1 true)
Akira Hatanaka48a72ca2011-10-03 21:16:50 +0000209 ret i64 %tmp1
210}
211
Akira Hatanakac3a63572011-10-03 21:23:18 +0000212define i64 @f20(i64 %a, i64 %b) nounwind readnone {
213entry:
Daniel Sanders8bb4c852014-06-11 15:48:00 +0000214; ALL-LABEL: f20:
215; ALL: nor $2, ${{[45]}}, ${{[45]}}
Akira Hatanakac3a63572011-10-03 21:23:18 +0000216 %or = or i64 %b, %a
217 %neg = xor i64 %or, -1
218 ret i64 %neg
219}