1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -verify-machineinstrs --riscv-no-aliases < %s \
3 ; RUN: | FileCheck -check-prefixes=RV32I %s
4 ; RUN: llc -mtriple=riscv64 -verify-machineinstrs --riscv-no-aliases < %s \
5 ; RUN: | FileCheck -check-prefixes=RV64I %s
6 ; RUN: llc -mtriple=riscv32 -mattr=+c -verify-machineinstrs --riscv-no-aliases \
7 ; RUN: < %s | FileCheck -check-prefixes=RV32C %s
8 ; RUN: llc -mtriple=riscv64 -mattr=+c -verify-machineinstrs --riscv-no-aliases \
9 ; RUN: < %s | FileCheck -check-prefixes=RV64C %s
11 ; These test that constant adds are not moved after shifts by DAGCombine,
12 ; if the constant is cheaper to materialise before it has been shifted.
14 define signext i32 @add_small_const(i32 signext %a) nounwind {
15 ; RV32I-LABEL: add_small_const:
17 ; RV32I-NEXT: addi a0, a0, 1
18 ; RV32I-NEXT: slli a0, a0, 24
19 ; RV32I-NEXT: srai a0, a0, 24
20 ; RV32I-NEXT: jalr zero, 0(ra)
22 ; RV64I-LABEL: add_small_const:
24 ; RV64I-NEXT: addiw a0, a0, 1
25 ; RV64I-NEXT: slli a0, a0, 56
26 ; RV64I-NEXT: srai a0, a0, 56
27 ; RV64I-NEXT: jalr zero, 0(ra)
29 ; RV32C-LABEL: add_small_const:
31 ; RV32C-NEXT: c.addi a0, 1
32 ; RV32C-NEXT: c.slli a0, 24
33 ; RV32C-NEXT: c.srai a0, 24
36 ; RV64C-LABEL: add_small_const:
38 ; RV64C-NEXT: c.addiw a0, 1
39 ; RV64C-NEXT: c.slli a0, 56
40 ; RV64C-NEXT: c.srai a0, 56
48 define signext i32 @add_large_const(i32 signext %a) nounwind {
49 ; RV32I-LABEL: add_large_const:
51 ; RV32I-NEXT: slli a0, a0, 16
52 ; RV32I-NEXT: lui a1, 65520
53 ; RV32I-NEXT: add a0, a0, a1
54 ; RV32I-NEXT: srai a0, a0, 16
55 ; RV32I-NEXT: jalr zero, 0(ra)
57 ; RV64I-LABEL: add_large_const:
59 ; RV64I-NEXT: slli a0, a0, 48
60 ; RV64I-NEXT: lui a1, 4095
61 ; RV64I-NEXT: slli a1, a1, 36
62 ; RV64I-NEXT: add a0, a0, a1
63 ; RV64I-NEXT: srai a0, a0, 48
64 ; RV64I-NEXT: jalr zero, 0(ra)
66 ; RV32C-LABEL: add_large_const:
68 ; RV32C-NEXT: c.slli a0, 16
69 ; RV32C-NEXT: lui a1, 65520
70 ; RV32C-NEXT: c.add a0, a1
71 ; RV32C-NEXT: c.srai a0, 16
74 ; RV64C-LABEL: add_large_const:
76 ; RV64C-NEXT: c.lui a1, 1
77 ; RV64C-NEXT: c.addiw a1, -1
78 ; RV64C-NEXT: c.addw a0, a1
79 ; RV64C-NEXT: c.slli a0, 48
80 ; RV64C-NEXT: c.srai a0, 48
88 define signext i32 @add_huge_const(i32 signext %a) nounwind {
89 ; RV32I-LABEL: add_huge_const:
91 ; RV32I-NEXT: slli a0, a0, 16
92 ; RV32I-NEXT: lui a1, 524272
93 ; RV32I-NEXT: add a0, a0, a1
94 ; RV32I-NEXT: srai a0, a0, 16
95 ; RV32I-NEXT: jalr zero, 0(ra)
97 ; RV64I-LABEL: add_huge_const:
99 ; RV64I-NEXT: slli a0, a0, 48
100 ; RV64I-NEXT: lui a1, 32767
101 ; RV64I-NEXT: slli a1, a1, 36
102 ; RV64I-NEXT: add a0, a0, a1
103 ; RV64I-NEXT: srai a0, a0, 48
104 ; RV64I-NEXT: jalr zero, 0(ra)
106 ; RV32C-LABEL: add_huge_const:
108 ; RV32C-NEXT: c.slli a0, 16
109 ; RV32C-NEXT: lui a1, 524272
110 ; RV32C-NEXT: c.add a0, a1
111 ; RV32C-NEXT: c.srai a0, 16
112 ; RV32C-NEXT: c.jr ra
114 ; RV64C-LABEL: add_huge_const:
116 ; RV64C-NEXT: c.lui a1, 8
117 ; RV64C-NEXT: c.addiw a1, -1
118 ; RV64C-NEXT: c.addw a0, a1
119 ; RV64C-NEXT: c.slli a0, 48
120 ; RV64C-NEXT: c.srai a0, 48
121 ; RV64C-NEXT: c.jr ra
122 %1 = add i32 %a, 32767
128 define signext i24 @add_non_machine_type(i24 signext %a) nounwind {
129 ; RV32I-LABEL: add_non_machine_type:
131 ; RV32I-NEXT: addi a0, a0, 256
132 ; RV32I-NEXT: slli a0, a0, 20
133 ; RV32I-NEXT: srai a0, a0, 8
134 ; RV32I-NEXT: jalr zero, 0(ra)
136 ; RV64I-LABEL: add_non_machine_type:
138 ; RV64I-NEXT: addiw a0, a0, 256
139 ; RV64I-NEXT: slli a0, a0, 52
140 ; RV64I-NEXT: srai a0, a0, 40
141 ; RV64I-NEXT: jalr zero, 0(ra)
143 ; RV32C-LABEL: add_non_machine_type:
145 ; RV32C-NEXT: addi a0, a0, 256
146 ; RV32C-NEXT: c.slli a0, 20
147 ; RV32C-NEXT: c.srai a0, 8
148 ; RV32C-NEXT: c.jr ra
150 ; RV64C-LABEL: add_non_machine_type:
152 ; RV64C-NEXT: addiw a0, a0, 256
153 ; RV64C-NEXT: c.slli a0, 52
154 ; RV64C-NEXT: c.srai a0, 40
155 ; RV64C-NEXT: c.jr ra
161 define i128 @add_wide_operand(i128 %a) nounwind {
162 ; RV32I-LABEL: add_wide_operand:
164 ; RV32I-NEXT: lw a2, 0(a1)
165 ; RV32I-NEXT: lw a3, 4(a1)
166 ; RV32I-NEXT: lw a4, 12(a1)
167 ; RV32I-NEXT: lw a1, 8(a1)
168 ; RV32I-NEXT: srli a5, a2, 29
169 ; RV32I-NEXT: slli a6, a3, 3
170 ; RV32I-NEXT: or a5, a6, a5
171 ; RV32I-NEXT: srli a3, a3, 29
172 ; RV32I-NEXT: slli a6, a1, 3
173 ; RV32I-NEXT: or a3, a6, a3
174 ; RV32I-NEXT: srli a1, a1, 29
175 ; RV32I-NEXT: slli a4, a4, 3
176 ; RV32I-NEXT: or a1, a4, a1
177 ; RV32I-NEXT: slli a2, a2, 3
178 ; RV32I-NEXT: lui a4, 128
179 ; RV32I-NEXT: add a1, a1, a4
180 ; RV32I-NEXT: sw a2, 0(a0)
181 ; RV32I-NEXT: sw a3, 8(a0)
182 ; RV32I-NEXT: sw a5, 4(a0)
183 ; RV32I-NEXT: sw a1, 12(a0)
184 ; RV32I-NEXT: jalr zero, 0(ra)
186 ; RV64I-LABEL: add_wide_operand:
188 ; RV64I-NEXT: srli a2, a0, 61
189 ; RV64I-NEXT: slli a1, a1, 3
190 ; RV64I-NEXT: or a1, a1, a2
191 ; RV64I-NEXT: slli a0, a0, 3
192 ; RV64I-NEXT: addi a2, zero, 1
193 ; RV64I-NEXT: slli a2, a2, 51
194 ; RV64I-NEXT: add a1, a1, a2
195 ; RV64I-NEXT: jalr zero, 0(ra)
197 ; RV32C-LABEL: add_wide_operand:
199 ; RV32C-NEXT: c.lw a2, 4(a1)
200 ; RV32C-NEXT: c.lw a3, 12(a1)
201 ; RV32C-NEXT: c.lw a4, 0(a1)
202 ; RV32C-NEXT: c.lw a1, 8(a1)
203 ; RV32C-NEXT: c.lui a5, 16
204 ; RV32C-NEXT: c.add a3, a5
205 ; RV32C-NEXT: c.slli a3, 3
206 ; RV32C-NEXT: srli a5, a1, 29
207 ; RV32C-NEXT: or a6, a3, a5
208 ; RV32C-NEXT: srli a5, a4, 29
209 ; RV32C-NEXT: slli a3, a2, 3
210 ; RV32C-NEXT: c.or a3, a5
211 ; RV32C-NEXT: c.srli a2, 29
212 ; RV32C-NEXT: c.slli a1, 3
213 ; RV32C-NEXT: c.or a1, a2
214 ; RV32C-NEXT: slli a2, a4, 3
215 ; RV32C-NEXT: c.sw a2, 0(a0)
216 ; RV32C-NEXT: c.sw a1, 8(a0)
217 ; RV32C-NEXT: c.sw a3, 4(a0)
218 ; RV32C-NEXT: sw a6, 12(a0)
219 ; RV32C-NEXT: c.jr ra
221 ; RV64C-LABEL: add_wide_operand:
223 ; RV64C-NEXT: srli a2, a0, 61
224 ; RV64C-NEXT: c.slli a1, 3
225 ; RV64C-NEXT: c.or a1, a2
226 ; RV64C-NEXT: c.slli a0, 3
227 ; RV64C-NEXT: c.li a2, 1
228 ; RV64C-NEXT: c.slli a2, 51
229 ; RV64C-NEXT: c.add a1, a2
230 ; RV64C-NEXT: c.jr ra
231 %1 = add i128 %a, 5192296858534827628530496329220096