1 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
2 ; RUN: llc -mtriple=riscv32 -mattr=+xtheadmac -mattr=+m -verify-machineinstrs < %s \
3 ; RUN: | FileCheck %s -check-prefix=RV32XTHEADMAC
4 ; RUN: llc -mtriple=riscv64 -mattr=+xtheadmac -mattr=+m -verify-machineinstrs < %s \
5 ; RUN: | FileCheck %s -check-prefix=RV64XTHEADMAC
7 define i32 @mula_i32(i32 %a, i32 %b, i32 %c) {
8 ; RV32XTHEADMAC-LABEL: mula_i32:
9 ; RV32XTHEADMAC: # %bb.0:
10 ; RV32XTHEADMAC-NEXT: th.mula a0, a1, a2
11 ; RV32XTHEADMAC-NEXT: ret
13 ; RV64XTHEADMAC-LABEL: mula_i32:
14 ; RV64XTHEADMAC: # %bb.0:
15 ; RV64XTHEADMAC-NEXT: th.mulaw a0, a1, a2
16 ; RV64XTHEADMAC-NEXT: ret
22 define i32 @muls_i32(i32 %a, i32 %b, i32 %c) {
23 ; RV32XTHEADMAC-LABEL: muls_i32:
24 ; RV32XTHEADMAC: # %bb.0:
25 ; RV32XTHEADMAC-NEXT: th.muls a0, a1, a2
26 ; RV32XTHEADMAC-NEXT: ret
28 ; RV64XTHEADMAC-LABEL: muls_i32:
29 ; RV64XTHEADMAC: # %bb.0:
30 ; RV64XTHEADMAC-NEXT: th.mulsw a0, a1, a2
31 ; RV64XTHEADMAC-NEXT: ret
37 define i64 @mula_i64(i64 %a, i64 %b, i64 %c) {
38 ; RV32XTHEADMAC-LABEL: mula_i64:
39 ; RV32XTHEADMAC: # %bb.0:
40 ; RV32XTHEADMAC-NEXT: mulhu a6, a2, a4
41 ; RV32XTHEADMAC-NEXT: th.mula a6, a2, a5
42 ; RV32XTHEADMAC-NEXT: th.mula a6, a3, a4
43 ; RV32XTHEADMAC-NEXT: mv a3, a0
44 ; RV32XTHEADMAC-NEXT: th.mula a3, a2, a4
45 ; RV32XTHEADMAC-NEXT: sltu a0, a3, a0
46 ; RV32XTHEADMAC-NEXT: add a0, a1, a0
47 ; RV32XTHEADMAC-NEXT: add a1, a0, a6
48 ; RV32XTHEADMAC-NEXT: mv a0, a3
49 ; RV32XTHEADMAC-NEXT: ret
51 ; RV64XTHEADMAC-LABEL: mula_i64:
52 ; RV64XTHEADMAC: # %bb.0:
53 ; RV64XTHEADMAC-NEXT: th.mula a0, a1, a2
54 ; RV64XTHEADMAC-NEXT: ret
60 define i64 @mulaw_i64(i32 %a, i32 %b, i32 %c) {
61 ; RV32XTHEADMAC-LABEL: mulaw_i64:
62 ; RV32XTHEADMAC: # %bb.0:
63 ; RV32XTHEADMAC-NEXT: th.mula a0, a1, a2
64 ; RV32XTHEADMAC-NEXT: srai a1, a0, 31
65 ; RV32XTHEADMAC-NEXT: ret
67 ; RV64XTHEADMAC-LABEL: mulaw_i64:
68 ; RV64XTHEADMAC: # %bb.0:
69 ; RV64XTHEADMAC-NEXT: th.mulaw a0, a1, a2
70 ; RV64XTHEADMAC-NEXT: ret
73 %f = sext i32 %e to i64
77 define i64 @mulah_i64(i32 %a, i16 %b, i16 %c) {
78 ; RV32XTHEADMAC-LABEL: mulah_i64:
79 ; RV32XTHEADMAC: # %bb.0:
80 ; RV32XTHEADMAC-NEXT: th.mulah a0, a1, a2
81 ; RV32XTHEADMAC-NEXT: srai a1, a0, 31
82 ; RV32XTHEADMAC-NEXT: ret
84 ; RV64XTHEADMAC-LABEL: mulah_i64:
85 ; RV64XTHEADMAC: # %bb.0:
86 ; RV64XTHEADMAC-NEXT: th.mulah a0, a1, a2
87 ; RV64XTHEADMAC-NEXT: ret
88 %d = sext i16 %b to i32
89 %e = sext i16 %c to i32
92 %h = sext i32 %g to i64
96 define i64 @muls_i64(i64 %a, i64 %b, i64 %c) {
97 ; RV32XTHEADMAC-LABEL: muls_i64:
98 ; RV32XTHEADMAC: # %bb.0:
99 ; RV32XTHEADMAC-NEXT: mulhu a6, a2, a4
100 ; RV32XTHEADMAC-NEXT: th.mula a6, a2, a5
101 ; RV32XTHEADMAC-NEXT: th.mula a6, a3, a4
102 ; RV32XTHEADMAC-NEXT: mul a3, a2, a4
103 ; RV32XTHEADMAC-NEXT: sltu a3, a0, a3
104 ; RV32XTHEADMAC-NEXT: th.muls a0, a2, a4
105 ; RV32XTHEADMAC-NEXT: sub a1, a1, a3
106 ; RV32XTHEADMAC-NEXT: sub a1, a1, a6
107 ; RV32XTHEADMAC-NEXT: ret
109 ; RV64XTHEADMAC-LABEL: muls_i64:
110 ; RV64XTHEADMAC: # %bb.0:
111 ; RV64XTHEADMAC-NEXT: th.muls a0, a1, a2
112 ; RV64XTHEADMAC-NEXT: ret
118 define i64 @mulsw_i64(i32 %a, i32 %b, i32 %c) {
119 ; RV32XTHEADMAC-LABEL: mulsw_i64:
120 ; RV32XTHEADMAC: # %bb.0:
121 ; RV32XTHEADMAC-NEXT: th.muls a0, a1, a2
122 ; RV32XTHEADMAC-NEXT: srai a1, a0, 31
123 ; RV32XTHEADMAC-NEXT: ret
125 ; RV64XTHEADMAC-LABEL: mulsw_i64:
126 ; RV64XTHEADMAC: # %bb.0:
127 ; RV64XTHEADMAC-NEXT: th.mulsw a0, a1, a2
128 ; RV64XTHEADMAC-NEXT: ret
131 %f = sext i32 %e to i64
135 define i64 @mulsh_i64(i32 %a, i16 %b, i16 %c) {
136 ; RV32XTHEADMAC-LABEL: mulsh_i64:
137 ; RV32XTHEADMAC: # %bb.0:
138 ; RV32XTHEADMAC-NEXT: th.mulsh a0, a1, a2
139 ; RV32XTHEADMAC-NEXT: srai a1, a0, 31
140 ; RV32XTHEADMAC-NEXT: ret
142 ; RV64XTHEADMAC-LABEL: mulsh_i64:
143 ; RV64XTHEADMAC: # %bb.0:
144 ; RV64XTHEADMAC-NEXT: th.mulsh a0, a1, a2
145 ; RV64XTHEADMAC-NEXT: ret
146 %d = sext i16 %b to i32
147 %e = sext i16 %c to i32
150 %h = sext i32 %g to i64
154 define i32 @commutative1(i32 %A, i32 %B, i32 %C) {
155 ; RV32XTHEADMAC-LABEL: commutative1:
156 ; RV32XTHEADMAC: # %bb.0:
157 ; RV32XTHEADMAC-NEXT: th.mula a2, a1, a0
158 ; RV32XTHEADMAC-NEXT: mv a0, a2
159 ; RV32XTHEADMAC-NEXT: ret
161 ; RV64XTHEADMAC-LABEL: commutative1:
162 ; RV64XTHEADMAC: # %bb.0:
163 ; RV64XTHEADMAC-NEXT: th.mulaw a2, a1, a0
164 ; RV64XTHEADMAC-NEXT: mv a0, a2
165 ; RV64XTHEADMAC-NEXT: ret
166 %mul = mul nsw i32 %B, %A
167 %add = add i32 %mul, %C
171 define i32 @commutative2(i32 %A, i32 %B, i32 %C) {
172 ; RV32XTHEADMAC-LABEL: commutative2:
173 ; RV32XTHEADMAC: # %bb.0:
174 ; RV32XTHEADMAC-NEXT: th.mula a0, a1, a2
175 ; RV32XTHEADMAC-NEXT: ret
177 ; RV64XTHEADMAC-LABEL: commutative2:
178 ; RV64XTHEADMAC: # %bb.0:
179 ; RV64XTHEADMAC-NEXT: th.mulaw a0, a1, a2
180 ; RV64XTHEADMAC-NEXT: ret
181 %mul = mul nsw i32 %B, %C
182 %add = add i32 %mul, %A
186 define i32 @commutative3(i32 %A, i32 %B, i32 %C) {
187 ; RV32XTHEADMAC-LABEL: commutative3:
188 ; RV32XTHEADMAC: # %bb.0:
189 ; RV32XTHEADMAC-NEXT: th.mula a1, a2, a0
190 ; RV32XTHEADMAC-NEXT: mv a0, a1
191 ; RV32XTHEADMAC-NEXT: ret
193 ; RV64XTHEADMAC-LABEL: commutative3:
194 ; RV64XTHEADMAC: # %bb.0:
195 ; RV64XTHEADMAC-NEXT: th.mulaw a1, a2, a0
196 ; RV64XTHEADMAC-NEXT: mv a0, a1
197 ; RV64XTHEADMAC-NEXT: ret
198 %mul = mul nsw i32 %C, %A
199 %add = add i32 %mul, %B