1 ; RUN: llc -mtriple=arm-eabi %s -o - | FileCheck %s -check-prefix=CHECK --check-prefix=CHECK-LE
2 ; RUN: llc -mtriple=armv7-eabi %s -o - | FileCheck %s --check-prefix=CHECK-V7-LE
3 ; RUN: llc -mtriple=armeb-eabi %s -o - | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-BE
4 ; RUN: llc -mtriple=armebv7-eabi %s -o - | FileCheck %s -check-prefix=CHECK-V7-BE
5 ; RUN: llc -mtriple=thumbv6-eabi %s -o - | FileCheck %s -check-prefix=CHECK-V6-THUMB
6 ; RUN: llc -mtriple=thumbv6t2-eabi %s -o - | FileCheck %s -check-prefix=CHECK-V6-THUMB2
7 ; RUN: llc -mtriple=thumbv7-eabi %s -o - | FileCheck %s -check-prefix=CHECK-V7-THUMB
8 ; RUN: llc -mtriple=thumbebv7-eabi %s -o - | FileCheck %s -check-prefix=CHECK-V7-THUMB-BE
9 ; Check generated signed and unsigned multiply accumulate long.
11 define i64 @MACLongTest1(i32 %a, i32 %b, i64 %c) {
12 ;CHECK-LABEL: MACLongTest1:
13 ;CHECK-V6-THUMB-NOT: umlal
14 ;CHECK-LE: umlal [[RDLO:r[0-9]+]], [[RDHI:r[0-9]+]], [[LHS:r[0-9]+]], [[RHS:r[0-9]+]]
15 ;CHECK-LE: mov r0, [[RDLO]]
16 ;CHECK-LE: mov r1, [[RDHI]]
17 ;CHECK-BE: umlal [[RDLO:r[0-9]+]], [[RDHI:r[0-9]+]], [[LHS:r[0-9]+]], [[RHS:r[0-9]+]]
18 ;CHECK-BE: mov r0, [[RDHI]]
19 ;CHECK-BE: mov r1, [[RDLO]]
20 ;CHECK-V6-THUMB2: umlal [[RDLO:r[0-9]+]], [[RDHI:r[0-9]+]], [[LHS:r[0-9]+]], [[RHS:r[0-9]+]]
21 ;CHECK-V6-THUMB2: mov r0, [[RDLO]]
22 ;CHECK-V6-THUMB2: mov r1, [[RDHI]]
23 ;CHECK-V7-THUMB2: umlal [[RDLO:r[0-9]+]], [[RDHI:r[0-9]+]], [[LHS:r[0-9]+]], [[RHS:r[0-9]+]]
24 ;CHECK-V7-THUMB2: mov r0, [[RDLO]]
25 ;CHECK-V7-THUMB2: mov r1, [[RDHI]]
26 ;CHECK-V7-THUMB2-BE: umlal [[RDLO:r[0-9]+]], [[RDHI:r[0-9]+]], [[LHS:r[0-9]+]], [[RHS:r[0-9]+]]
27 ;CHECK-V7-THUMB2-BE: mov r0, [[RDHI]]
28 ;CHECK-V7-THUMB2-BE: mov r1, [[RDLO]]
29 %conv = zext i32 %a to i64
30 %conv1 = zext i32 %b to i64
31 %mul = mul i64 %conv1, %conv
32 %add = add i64 %mul, %c
36 define i64 @MACLongTest2(i32 %a, i32 %b, i64 %c) {
37 ;CHECK-LABEL: MACLongTest2:
38 ;CHECK-LE: smlal [[RDLO:r[0-9]+]], [[RDHI:r[0-9]+]], [[LHS:r[0-9]+]], [[RHS:r[0-9]+]]
39 ;CHECK-LE: mov r0, [[RDLO]]
40 ;CHECK-LE: mov r1, [[RDHI]]
41 ;CHECK-BE: smlal [[RDLO:r[0-9]+]], [[RDHI:r[0-9]+]], [[LHS:r[0-9]+]], [[RHS:r[0-9]+]]
42 ;CHECK-BE: mov r0, [[RDHI]]
43 ;CHECK-BE: mov r1, [[RDLO]]
44 ;CHECK-V6-THUMB2: smlal [[RDLO:r[0-9]+]], [[RDHI:r[0-9]+]], [[LHS:r[0-9]+]], [[RHS:r[0-9]+]]
45 ;CHECK-V6-THUMB2: mov r0, [[RDLO]]
46 ;CHECK-V6-THUMB2: mov r1, [[RDHI]]
47 ;CHECK-V7-THUMB2: smlal [[RDLO:r[0-9]+]], [[RDHI:r[0-9]+]], [[LHS:r[0-9]+]], [[RHS:r[0-9]+]]
48 ;CHECK-V7-THUMB2: mov r0, [[RDLO]]
49 ;CHECK-V7-THUMB2: mov r1, [[RDHI]]
50 ;CHECK-V7-THUMB2-BE: smlal [[RDLO:r[0-9]+]], [[RDHI:r[0-9]+]], [[LHS:r[0-9]+]], [[RHS:r[0-9]+]]
51 ;CHECK-V7-THUMB2-BE: mov r0, [[RDHI]]
52 ;CHECK-V7-THUMB2-BE: mov r1, [[RDLO]]
53 %conv = sext i32 %a to i64
54 %conv1 = sext i32 %b to i64
55 %mul = mul nsw i64 %conv1, %conv
56 %add = add nsw i64 %mul, %c
60 ; Two things to check here: the @earlyclobber constraint (on <= v5) and the "$Rd = $R" ones.
61 ; + Without @earlyclobber the v7 code is natural. With it, the first two
62 ; registers must be distinct from the third.
63 ; + Without "$Rd = $R", this can be satisfied without a mov before the umlal
64 ; by trying to use 6 different registers in the MachineInstr. The natural
65 ; evolution of this attempt currently leaves only two movs in the final
66 ; function, both after the umlal. With it, *some* move has to happen
68 define i64 @MACLongTest3(i32 %a, i32 %b, i32 %c) {
69 ;CHECK-LABEL: MACLongTest3:
70 ;CHECK-LE: mov [[RDHI:r[0-9]+]], #0
71 ;CHECK-LE: umlal [[RDLO:r[0-9]+]], [[RDHI]], r1, r0
72 ;CHECK-LE: mov r0, [[RDLO]]
73 ;CHECK-LE: mov r1, [[RDHI]]
74 ;CHECK-BE: mov [[RDHI:r[0-9]+]], #0
75 ;CHECK-BE: umlal [[RDLO:r[0-9]+]], [[RDHI]], r1, r0
76 ;CHECK-BE: mov r0, [[RDHI]]
77 ;CHECK-BE: mov r1, [[RDLO]]
78 ;CHECK-V6-THUMB2: umlal
79 ;CHECK-V7-THUMB: umlal
80 ;CHECK-V6-THUMB-NOT: umlal
81 %conv = zext i32 %b to i64
82 %conv1 = zext i32 %a to i64
83 %mul = mul i64 %conv, %conv1
84 %conv2 = zext i32 %c to i64
85 %add = add i64 %mul, %conv2
89 define i64 @MACLongTest4(i32 %a, i32 %b, i32 %c) {
90 ;CHECK-LABEL: MACLongTest4:
91 ;CHECK-V6-THUMB-NOT: smlal
92 ;CHECK-V6-THUMB2: smlal
93 ;CHECK-V7-THUMB: smlal
94 ;CHECK-LE: asr [[RDHI:r[0-9]+]], [[RDLO:r[0-9]+]], #31
95 ;CHECK-LE: smlal [[RDLO]], [[RDHI]], r1, r0
96 ;CHECK-LE: mov r0, [[RDLO]]
97 ;CHECK-LE: mov r1, [[RDHI]]
98 ;CHECK-BE: asr [[RDHI:r[0-9]+]], [[RDLO:r[0-9]+]], #31
99 ;CHECK-BE: smlal [[RDLO]], [[RDHI]], r1, r0
100 ;CHECK-BE: mov r0, [[RDHI]]
101 ;CHECK-BE: mov r1, [[RDLO]]
102 %conv = sext i32 %b to i64
103 %conv1 = sext i32 %a to i64
104 %mul = mul nsw i64 %conv, %conv1
105 %conv2 = sext i32 %c to i64
106 %add = add nsw i64 %mul, %conv2
110 define i64 @MACLongTest6(i32 %a, i32 %b, i32 %c, i32 %d) {
111 ;CHECK-LABEL: MACLongTest6:
112 ;CHECK-V6-THUMB-NOT: smull
113 ;CHECK-V6-THUMB-NOT: smlal
114 ;CHECK: smull r12, lr, r1, r0
115 ;CHECK: smlal r12, lr, r3, r2
116 ;CHECK-V7: smull [[RDLO:r[0-9]+]], [[RDHI:r[0-9]+]], r1, r0
117 ;CHECK-V7: smlal [[RDLO]], [[RDHI]], [[Rn:r[0-9]+]], [[Rm:r[0-9]+]]
118 ;CHECK-V7-THUMB: smull [[RDLO:r[0-9]+]], [[RDHI:r[0-9]+]], r1, r0
119 ;CHECK-V7-THUMB: smlal [[RDLO]], [[RDHI]], [[Rn:r[0-9]+]], [[Rm:r[0-9]+]]
120 ;CHECK-V6-THUMB2: smull [[RDLO:r[0-9]+]], [[RDHI:r[0-9]+]], r1, r0
121 ;CHECK-V6-THUMB2: smlal [[RDLO]], [[RDHI]], [[Rn:r[0-9]+]], [[Rm:r[0-9]+]]
122 %conv = sext i32 %a to i64
123 %conv1 = sext i32 %b to i64
124 %mul = mul nsw i64 %conv1, %conv
125 %conv2 = sext i32 %c to i64
126 %conv3 = sext i32 %d to i64
127 %mul4 = mul nsw i64 %conv3, %conv2
128 %add = add nsw i64 %mul4, %mul
132 define i64 @MACLongTest7(i64 %acc, i32 %lhs, i32 %rhs) {
133 ;CHECK-LABEL: MACLongTest7:
135 ;CHECK-V6-THUMB2-NOT: smlal
136 ;CHECK-V7-THUMB-NOT: smlal
137 ;CHECK-V6-THUMB-NOT: smlal
138 %conv = sext i32 %lhs to i64
139 %conv1 = sext i32 %rhs to i64
140 %mul = mul nsw i64 %conv1, %conv
141 %shl = shl i64 %mul, 32
142 %shr = lshr i64 %mul, 32
143 %or = or i64 %shl, %shr
144 %add = add i64 %or, %acc
148 define i64 @MACLongTest8(i64 %acc, i32 %lhs, i32 %rhs) {
149 ;CHECK-LABEL: MACLongTest8:
151 ;CHECK-V6-THUMB2-NOT: smlal
152 ;CHECK-V7-THUMB-NOT: smlal
153 ;CHECK-V6-THUMB-NOT: smlal
154 %conv = zext i32 %lhs to i64
155 %conv1 = zext i32 %rhs to i64
156 %mul = mul nuw i64 %conv1, %conv
157 %and = and i64 %mul, 4294967295
158 %shl = shl i64 %mul, 32
159 %or = or i64 %and, %shl
160 %add = add i64 %or, %acc
164 define i64 @MACLongTest9(i32 %lhs, i32 %rhs, i32 %lo, i32 %hi) {
165 ;CHECK-LABEL: MACLongTest9:
166 ;CHECK-V7-LE: umaal [[RDLO:r[0-9]+]], [[RDHI:r[0-9]+]], [[LHS:r[0-9]+]], [[RHS:r[0-9]+]]
167 ;CHECK-V7-LE: mov r0, [[RDLO]]
168 ;CHECK-V7-LE: mov r1, [[RDHI]]
169 ;CHECK-V7-BE: umaal [[RDLO:r[0-9]+]], [[RDHI:r[0-9]+]], [[LHS:r[0-9]+]], [[RHS:r[0-9]+]]
170 ;CHECK-V7-BE: mov r0, [[RDHI]]
171 ;CHECK-V7-BE: mov r1, [[RDLO]]
172 ;CHECK-V6-THUMB2: umaal [[RDLO:r[0-9]+]], [[RDHI:r[0-9]+]], [[LHS:r[0-9]+]], [[RHS:r[0-9]+]]
173 ;CHECK-V6-THUMB2: mov r0, [[RDLO]]
174 ;CHECK-V6-THUMB2: mov r1, [[RDHI]]
175 ;CHECK-V7-THUMB: umaal [[RDLO:r[0-9]+]], [[RDHI:r[0-9]+]], [[LHS:r[0-9]+]], [[RHS:r[0-9]+]]
176 ;CHECK-V7-THUMB: mov r0, [[RDLO]]
177 ;CHECK-V7-THUMB: mov r1, [[RDHI]]
178 ;CHECK-V7-THUMB-BE: umaal [[RDLO:r[0-9]+]], [[RDHI:r[0-9]+]], [[LHS:r[0-9]+]], [[RHS:r[0-9]+]]
179 ;CHECK-V7-THUMB-BE: mov r0, [[RDHI]]
180 ;CHECK-V7-THUMB-BE: mov r1, [[RDLO]]
182 ;CHECK-V6-THUMB-NOT: umaal
183 %conv = zext i32 %lhs to i64
184 %conv1 = zext i32 %rhs to i64
185 %mul = mul nuw i64 %conv1, %conv
186 %conv2 = zext i32 %lo to i64
187 %add = add i64 %mul, %conv2
188 %conv3 = zext i32 %hi to i64
189 %add2 = add i64 %add, %conv3
193 define i64 @MACLongTest10(i32 %lhs, i32 %rhs, i32 %lo, i32 %hi) {
194 ;CHECK-LABEL: MACLongTest10:
195 ;CHECK-V7-LE: umaal [[RDLO:r[0-9]+]], [[RDHI:r[0-9]+]], [[LHS:r[0-9]+]], [[RHS:r[0-9]+]]
196 ;CHECK-V7-LE: mov r0, [[RDLO]]
197 ;CHECK-V7-LE: mov r1, [[RDHI]]
198 ;CHECK-V7-BE: umaal [[RDLO:r[0-9]+]], [[RDHI:r[0-9]+]], [[LHS:r[0-9]+]], [[RHS:r[0-9]+]]
199 ;CHECK-V7-BE: mov r0, [[RDHI]]
200 ;CHECK-V7-BE: mov r1, [[RDLO]]
201 ;CHECK-V6-THUMB2: umaal [[RDLO:r[0-9]+]], [[RDHI:r[0-9]+]], [[LHS:r[0-9]+]], [[RHS:r[0-9]+]]
202 ;CHECK-V6-THUMB2: mov r0, [[RDLO]]
203 ;CHECK-V6-THUMB2: mov r1, [[RDHI]]
204 ;CHECK-V7-THUMB: umaal [[RDLO:r[0-9]+]], [[RDHI:r[0-9]+]], [[LHS:r[0-9]+]], [[RHS:r[0-9]+]]
205 ;CHECK-V7-THUMB: mov r0, [[RDLO]]
206 ;CHECK-V7-THUMB: mov r1, [[RDHI]]
207 ;CHECK-V7-THUMB-BE: umaal [[RDLO:r[0-9]+]], [[RDHI:r[0-9]+]], [[LHS:r[0-9]+]], [[RHS:r[0-9]+]]
208 ;CHECK-V7-THUMB-BE: mov r0, [[RDHI]]
209 ;CHECK-V7-THUMB-BE: mov r1, [[RDLO]]
211 ;CHECK-V6-THUMB-NOT:umaal
212 %conv = zext i32 %lhs to i64
213 %conv1 = zext i32 %rhs to i64
214 %mul = mul nuw i64 %conv1, %conv
215 %conv2 = zext i32 %lo to i64
216 %conv3 = zext i32 %hi to i64
217 %add = add i64 %conv2, %conv3
218 %add2 = add i64 %add, %mul