1 //==- HexagonPatterns.td - Target Description for Hexagon -*- tablegen -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
13 // (3) Extend/truncate
19 // (9) Arithmetic/bitwise
29 // Guidelines (in no particular order):
30 // 1. Avoid relying on pattern ordering to give preference to one pattern
31 // over another, prefer using AddedComplexity instead. The reason for
32 // this is to avoid unintended conseqeuences (caused by altering the
33 // order) when making changes. The current order of patterns in this
34 // file obviously does play some role, but none of the ordering was
35 // deliberately chosen (other than to create a logical structure of
36 // this file). When making changes, adding AddedComplexity to existing
37 // patterns may be needed.
38 // 2. Maintain the logical structure of the file, try to put new patterns
39 // in designated sections.
40 // 3. Do not use A2_combinew instruction directly, use Combinew fragment
41 // instead. It uses REG_SEQUENCE, which is more amenable to optimizations.
42 // 4. Most selection macros are based on PatFrags. For DAGs that involve
43 // SDNodes, use pf1/pf2 to convert them to PatFrags. Use common frags
44 // whenever possible (see the Definitions section). When adding new
45 // macro, try to make is general to enable reuse across sections.
46 // 5. Compound instructions (e.g. Rx+Rs*Rt) are generated under the condition
47 // that the nested operation has only one use. Having it separated in case
48 // of multiple uses avoids duplication of (processor) work.
49 // 6. The v4 vector instructions (64-bit) are treated as core instructions,
50 // for example, A2_vaddh is in the "arithmetic" section with A2_add.
51 // 7. When adding a pattern for an instruction with a constant-extendable
52 // operand, allow all possible kinds of inputs for the immediate value
53 // (see AnyImm/anyimm and their variants in the Definitions section).
56 // --(0) Definitions -----------------------------------------------------
59 // This complex pattern exists only to create a machine instruction operand
60 // of type "frame index". There doesn't seem to be a way to do that directly
62 def AddrFI: ComplexPattern<i32, 1, "SelectAddrFI", [frameindex], []>;
64 // These complex patterns are not strictly necessary, since global address
65 // folding will happen during DAG combining. For distinguishing between GA
66 // and GP, pat frags with HexagonCONST32 and HexagonCONST32_GP can be used.
67 def AddrGA: ComplexPattern<i32, 1, "SelectAddrGA", [], []>;
68 def AddrGP: ComplexPattern<i32, 1, "SelectAddrGP", [], []>;
69 def AnyImm: ComplexPattern<i32, 1, "SelectAnyImm", [], []>;
70 def AnyInt: ComplexPattern<i32, 1, "SelectAnyInt", [], []>;
72 // Global address or a constant being a multiple of 2^n.
73 def AnyImm0: ComplexPattern<i32, 1, "SelectAnyImm0", [], []>;
74 def AnyImm1: ComplexPattern<i32, 1, "SelectAnyImm1", [], []>;
75 def AnyImm2: ComplexPattern<i32, 1, "SelectAnyImm2", [], []>;
76 def AnyImm3: ComplexPattern<i32, 1, "SelectAnyImm3", [], []>;
80 def V2I1: PatLeaf<(v2i1 PredRegs:$R)>;
81 def V4I1: PatLeaf<(v4i1 PredRegs:$R)>;
82 def V8I1: PatLeaf<(v8i1 PredRegs:$R)>;
83 def V4I8: PatLeaf<(v4i8 IntRegs:$R)>;
84 def V2I16: PatLeaf<(v2i16 IntRegs:$R)>;
86 def V8I8: PatLeaf<(v8i8 DoubleRegs:$R)>;
87 def V4I16: PatLeaf<(v4i16 DoubleRegs:$R)>;
88 def V2I32: PatLeaf<(v2i32 DoubleRegs:$R)>;
90 def HQ8: PatLeaf<(VecQ8 HvxQR:$R)>;
91 def HQ16: PatLeaf<(VecQ16 HvxQR:$R)>;
92 def HQ32: PatLeaf<(VecQ32 HvxQR:$R)>;
94 def HVI8: PatLeaf<(VecI8 HvxVR:$R)>;
95 def HVI16: PatLeaf<(VecI16 HvxVR:$R)>;
96 def HVI32: PatLeaf<(VecI32 HvxVR:$R)>;
98 def HWI8: PatLeaf<(VecPI8 HvxWR:$R)>;
99 def HWI16: PatLeaf<(VecPI16 HvxWR:$R)>;
100 def HWI32: PatLeaf<(VecPI32 HvxWR:$R)>;
103 SDTypeProfile<1, 0, [SDTCisVec<0>]>;
105 SDTypeProfile<1, 3, [SDTCisVec<0>, SDTCisVec<1>, SDTCisSameAs<1,2>,
108 def HexagonPTRUE: SDNode<"HexagonISD::PTRUE", SDTVecLeaf>;
109 def HexagonPFALSE: SDNode<"HexagonISD::PFALSE", SDTVecLeaf>;
110 def HexagonVALIGN: SDNode<"HexagonISD::VALIGN", SDTVecVecIntOp>;
111 def HexagonVALIGNADDR: SDNode<"HexagonISD::VALIGNADDR", SDTIntUnaryOp>;
113 def ptrue: PatFrag<(ops), (HexagonPTRUE)>;
114 def pfalse: PatFrag<(ops), (HexagonPFALSE)>;
115 def pnot: PatFrag<(ops node:$Pu), (xor node:$Pu, ptrue)>;
117 def valign: PatFrag<(ops node:$Vt, node:$Vs, node:$Ru),
118 (HexagonVALIGN node:$Vt, node:$Vs, node:$Ru)>;
119 def valignaddr: PatFrag<(ops node:$Addr), (HexagonVALIGNADDR node:$Addr)>;
121 // Pattern fragments to extract the low and high subregisters from a
123 def LoReg: OutPatFrag<(ops node:$Rs), (EXTRACT_SUBREG (i64 $Rs), isub_lo)>;
124 def HiReg: OutPatFrag<(ops node:$Rs), (EXTRACT_SUBREG (i64 $Rs), isub_hi)>;
126 def IsOrAdd: PatFrag<(ops node:$A, node:$B), (or node:$A, node:$B), [{
127 return isOrEquivalentToAdd(N);
130 def IsPow2_32: PatLeaf<(i32 imm), [{
131 uint32_t V = N->getZExtValue();
132 return isPowerOf2_32(V);
135 def IsPow2_64: PatLeaf<(i64 imm), [{
136 uint64_t V = N->getZExtValue();
137 return isPowerOf2_64(V);
140 def IsNPow2_32: PatLeaf<(i32 imm), [{
141 uint32_t NV = ~N->getZExtValue();
142 return isPowerOf2_32(NV);
145 def IsPow2_64L: PatLeaf<(i64 imm), [{
146 uint64_t V = N->getZExtValue();
147 return isPowerOf2_64(V) && Log2_64(V) < 32;
150 def IsPow2_64H: PatLeaf<(i64 imm), [{
151 uint64_t V = N->getZExtValue();
152 return isPowerOf2_64(V) && Log2_64(V) >= 32;
155 def IsNPow2_64L: PatLeaf<(i64 imm), [{
156 uint64_t NV = ~N->getZExtValue();
157 return isPowerOf2_64(NV) && Log2_64(NV) < 32;
160 def IsNPow2_64H: PatLeaf<(i64 imm), [{
161 uint64_t NV = ~N->getZExtValue();
162 return isPowerOf2_64(NV) && Log2_64(NV) >= 32;
165 class IsUGT<int Width, int Arg>: PatLeaf<(i32 imm),
166 "uint64_t V = N->getZExtValue();" #
167 "return isUInt<" # Width # ">(V) && V > " # Arg # ";"
170 def SDEC1: SDNodeXForm<imm, [{
171 int32_t V = N->getSExtValue();
172 return CurDAG->getTargetConstant(V-1, SDLoc(N), MVT::i32);
175 def UDEC1: SDNodeXForm<imm, [{
176 uint32_t V = N->getZExtValue();
178 return CurDAG->getTargetConstant(V-1, SDLoc(N), MVT::i32);
181 def UDEC32: SDNodeXForm<imm, [{
182 uint32_t V = N->getZExtValue();
184 return CurDAG->getTargetConstant(V-32, SDLoc(N), MVT::i32);
187 class Subi<int From>: SDNodeXForm<imm,
188 "int32_t V = " # From # " - N->getSExtValue();" #
189 "return CurDAG->getTargetConstant(V, SDLoc(N), MVT::i32);"
192 def Log2_32: SDNodeXForm<imm, [{
193 uint32_t V = N->getZExtValue();
194 return CurDAG->getTargetConstant(Log2_32(V), SDLoc(N), MVT::i32);
197 def Log2_64: SDNodeXForm<imm, [{
198 uint64_t V = N->getZExtValue();
199 return CurDAG->getTargetConstant(Log2_64(V), SDLoc(N), MVT::i32);
202 def LogN2_32: SDNodeXForm<imm, [{
203 uint32_t NV = ~N->getZExtValue();
204 return CurDAG->getTargetConstant(Log2_32(NV), SDLoc(N), MVT::i32);
207 def LogN2_64: SDNodeXForm<imm, [{
208 uint64_t NV = ~N->getZExtValue();
209 return CurDAG->getTargetConstant(Log2_64(NV), SDLoc(N), MVT::i32);
212 def NegImm8: SDNodeXForm<imm, [{
213 int8_t NV = -N->getSExtValue();
214 return CurDAG->getTargetConstant(NV, SDLoc(N), MVT::i32);
217 def NegImm16: SDNodeXForm<imm, [{
218 int16_t NV = -N->getSExtValue();
219 return CurDAG->getTargetConstant(NV, SDLoc(N), MVT::i32);
222 def NegImm32: SDNodeXForm<imm, [{
223 int32_t NV = -N->getSExtValue();
224 return CurDAG->getTargetConstant(NV, SDLoc(N), MVT::i32);
228 // Helpers for type promotions/contractions.
229 def I1toI32: OutPatFrag<(ops node:$Rs), (C2_muxii (i1 $Rs), 1, 0)>;
230 def I32toI1: OutPatFrag<(ops node:$Rs), (i1 (C2_cmpgtui (i32 $Rs), (i32 0)))>;
231 def ToZext64: OutPatFrag<(ops node:$Rs), (i64 (A4_combineir 0, (i32 $Rs)))>;
232 def ToSext64: OutPatFrag<(ops node:$Rs), (i64 (A2_sxtw (i32 $Rs)))>;
233 def ToAext64: OutPatFrag<(ops node:$Rs),
234 (REG_SEQUENCE DoubleRegs, (i32 (IMPLICIT_DEF)), isub_hi, (i32 $Rs), isub_lo)>;
236 def Combinew: OutPatFrag<(ops node:$Rs, node:$Rt),
237 (REG_SEQUENCE DoubleRegs, $Rs, isub_hi, $Rt, isub_lo)>;
239 def addrga: PatLeaf<(i32 AddrGA:$Addr)>;
240 def addrgp: PatLeaf<(i32 AddrGP:$Addr)>;
241 def anyimm: PatLeaf<(i32 AnyImm:$Imm)>;
242 def anyint: PatLeaf<(i32 AnyInt:$Imm)>;
244 // Global address or an aligned constant.
245 def anyimm0: PatLeaf<(i32 AnyImm0:$Addr)>;
246 def anyimm1: PatLeaf<(i32 AnyImm1:$Addr)>;
247 def anyimm2: PatLeaf<(i32 AnyImm2:$Addr)>;
248 def anyimm3: PatLeaf<(i32 AnyImm3:$Addr)>;
250 def f32ImmPred : PatLeaf<(f32 fpimm:$F)>;
251 def f64ImmPred : PatLeaf<(f64 fpimm:$F)>;
253 // This complex pattern is really only to detect various forms of
254 // sign-extension i32->i64. The selected value will be of type i64
255 // whose low word is the value being extended. The high word is
257 def Usxtw: ComplexPattern<i64, 1, "DetectUseSxtw", [], []>;
259 def Aext64: PatFrag<(ops node:$Rs), (i64 (anyext node:$Rs))>;
260 def Zext64: PatFrag<(ops node:$Rs), (i64 (zext node:$Rs))>;
261 def Sext64: PatLeaf<(i64 Usxtw:$Rs)>;
263 def azext: PatFrags<(ops node:$Rs), [(zext node:$Rs), (anyext node:$Rs)]>;
264 def asext: PatFrags<(ops node:$Rs), [(sext node:$Rs), (anyext node:$Rs)]>;
266 def: Pat<(IsOrAdd (i32 AddrFI:$Rs), s32_0ImmPred:$off),
267 (PS_fi (i32 AddrFI:$Rs), imm:$off)>;
270 // Converters from unary/binary SDNode to PatFrag.
271 class pf1<SDNode Op> : PatFrag<(ops node:$a), (Op node:$a)>;
272 class pf2<SDNode Op> : PatFrag<(ops node:$a, node:$b), (Op node:$a, node:$b)>;
274 class Not2<PatFrag P>
275 : PatFrag<(ops node:$A, node:$B), (P node:$A, (not node:$B))>;
277 // If there is a constant operand that feeds the and/or instruction,
278 // do not generate the compound instructions.
279 // It is not always profitable, as some times we end up with a transfer.
280 // Check the below example.
281 // ra = #65820; rb = lsr(rb, #8); rc ^= and (rb, ra)
282 // Instead this is preferable.
283 // ra = and (#65820, lsr(ra, #8)); rb = xor(rb, ra)
284 class Su_ni1<PatFrag Op>
285 : PatFrag<Op.Operands, !head(Op.Fragments), [{
287 // Check if Op1 is an immediate operand.
288 SDValue Op1 = N->getOperand(1);
289 return !isa<ConstantSDNode>(Op1);
292 Op.OperandTransform>;
295 : PatFrag<Op.Operands, !head(Op.Fragments), [{ return hasOneUse(N); }],
296 Op.OperandTransform>;
298 // Main selection macros.
300 class OpR_R_pat<InstHexagon MI, PatFrag Op, ValueType ResVT, PatFrag RegPred>
301 : Pat<(ResVT (Op RegPred:$Rs)), (MI RegPred:$Rs)>;
303 class OpR_RI_pat<InstHexagon MI, PatFrag Op, ValueType ResType,
304 PatFrag RegPred, PatFrag ImmPred>
305 : Pat<(ResType (Op RegPred:$Rs, ImmPred:$I)),
306 (MI RegPred:$Rs, imm:$I)>;
308 class OpR_RR_pat<InstHexagon MI, PatFrag Op, ValueType ResType,
309 PatFrag RsPred, PatFrag RtPred = RsPred>
310 : Pat<(ResType (Op RsPred:$Rs, RtPred:$Rt)),
311 (MI RsPred:$Rs, RtPred:$Rt)>;
313 class AccRRI_pat<InstHexagon MI, PatFrag AccOp, PatFrag Op,
314 PatFrag RegPred, PatFrag ImmPred>
315 : Pat<(AccOp RegPred:$Rx, (Op RegPred:$Rs, ImmPred:$I)),
316 (MI RegPred:$Rx, RegPred:$Rs, imm:$I)>;
318 class AccRRR_pat<InstHexagon MI, PatFrag AccOp, PatFrag Op,
319 PatFrag RxPred, PatFrag RsPred, PatFrag RtPred>
320 : Pat<(AccOp RxPred:$Rx, (Op RsPred:$Rs, RtPred:$Rt)),
321 (MI RxPred:$Rx, RsPred:$Rs, RtPred:$Rt)>;
323 multiclass SelMinMax_pats<PatFrag CmpOp, PatFrag Val,
324 InstHexagon InstA, InstHexagon InstB> {
325 def: Pat<(select (i1 (CmpOp Val:$A, Val:$B)), Val:$A, Val:$B),
326 (InstA Val:$A, Val:$B)>;
327 def: Pat<(select (i1 (CmpOp Val:$A, Val:$B)), Val:$B, Val:$A),
328 (InstB Val:$A, Val:$B)>;
331 multiclass MinMax_pats<InstHexagon PickT, InstHexagon PickS,
332 PatFrag Sel, PatFrag CmpOp,
333 ValueType CmpType, PatFrag CmpPred> {
334 def: Pat<(Sel (CmpType (CmpOp CmpPred:$Vs, CmpPred:$Vt)),
335 CmpPred:$Vt, CmpPred:$Vs),
336 (PickT CmpPred:$Vs, CmpPred:$Vt)>;
337 def: Pat<(Sel (CmpType (CmpOp CmpPred:$Vs, CmpPred:$Vt)),
338 CmpPred:$Vs, CmpPred:$Vt),
339 (PickS CmpPred:$Vs, CmpPred:$Vt)>;
343 // Frags for commonly used SDNodes.
344 def Add: pf2<add>; def And: pf2<and>; def Sra: pf2<sra>;
345 def Sub: pf2<sub>; def Or: pf2<or>; def Srl: pf2<srl>;
346 def Mul: pf2<mul>; def Xor: pf2<xor>; def Shl: pf2<shl>;
350 // --(1) Immediate -------------------------------------------------------
353 def SDTHexagonCONST32
354 : SDTypeProfile<1, 1, [SDTCisVT<0, i32>, SDTCisVT<1, i32>, SDTCisPtrTy<0>]>;
356 def HexagonJT: SDNode<"HexagonISD::JT", SDTIntUnaryOp>;
357 def HexagonCP: SDNode<"HexagonISD::CP", SDTIntUnaryOp>;
358 def HexagonCONST32: SDNode<"HexagonISD::CONST32", SDTHexagonCONST32>;
359 def HexagonCONST32_GP: SDNode<"HexagonISD::CONST32_GP", SDTHexagonCONST32>;
361 def TruncI64ToI32: SDNodeXForm<imm, [{
362 return CurDAG->getTargetConstant(N->getSExtValue(), SDLoc(N), MVT::i32);
365 def: Pat<(s32_0ImmPred:$s16), (A2_tfrsi imm:$s16)>;
366 def: Pat<(s8_0Imm64Pred:$s8), (A2_tfrpi (TruncI64ToI32 $s8))>;
368 def: Pat<(HexagonCONST32 tglobaltlsaddr:$A), (A2_tfrsi imm:$A)>;
369 def: Pat<(HexagonCONST32 bbl:$A), (A2_tfrsi imm:$A)>;
370 def: Pat<(HexagonCONST32 tglobaladdr:$A), (A2_tfrsi imm:$A)>;
371 def: Pat<(HexagonCONST32_GP tblockaddress:$A), (A2_tfrsi imm:$A)>;
372 def: Pat<(HexagonCONST32_GP tglobaladdr:$A), (A2_tfrsi imm:$A)>;
373 def: Pat<(HexagonJT tjumptable:$A), (A2_tfrsi imm:$A)>;
374 def: Pat<(HexagonCP tconstpool:$A), (A2_tfrsi imm:$A)>;
375 // The HVX load patterns also match CP directly. Make sure that if
376 // the selection of this opcode changes, it's updated in all places.
378 def: Pat<(i1 0), (PS_false)>;
379 def: Pat<(i1 1), (PS_true)>;
380 def: Pat<(i64 imm:$v), (CONST64 imm:$v)>;
382 def ftoi : SDNodeXForm<fpimm, [{
383 APInt I = N->getValueAPF().bitcastToAPInt();
384 return CurDAG->getTargetConstant(I.getZExtValue(), SDLoc(N),
385 MVT::getIntegerVT(I.getBitWidth()));
388 def: Pat<(f32ImmPred:$f), (A2_tfrsi (ftoi $f))>;
389 def: Pat<(f64ImmPred:$f), (CONST64 (ftoi $f))>;
391 def ToI32: OutPatFrag<(ops node:$V), (A2_tfrsi $V)>;
393 // --(2) Type cast -------------------------------------------------------
396 def: OpR_R_pat<F2_conv_sf2df, pf1<fpextend>, f64, F32>;
397 def: OpR_R_pat<F2_conv_df2sf, pf1<fpround>, f32, F64>;
399 def: OpR_R_pat<F2_conv_w2sf, pf1<sint_to_fp>, f32, I32>;
400 def: OpR_R_pat<F2_conv_d2sf, pf1<sint_to_fp>, f32, I64>;
401 def: OpR_R_pat<F2_conv_w2df, pf1<sint_to_fp>, f64, I32>;
402 def: OpR_R_pat<F2_conv_d2df, pf1<sint_to_fp>, f64, I64>;
404 def: OpR_R_pat<F2_conv_uw2sf, pf1<uint_to_fp>, f32, I32>;
405 def: OpR_R_pat<F2_conv_ud2sf, pf1<uint_to_fp>, f32, I64>;
406 def: OpR_R_pat<F2_conv_uw2df, pf1<uint_to_fp>, f64, I32>;
407 def: OpR_R_pat<F2_conv_ud2df, pf1<uint_to_fp>, f64, I64>;
409 def: OpR_R_pat<F2_conv_sf2w_chop, pf1<fp_to_sint>, i32, F32>;
410 def: OpR_R_pat<F2_conv_df2w_chop, pf1<fp_to_sint>, i32, F64>;
411 def: OpR_R_pat<F2_conv_sf2d_chop, pf1<fp_to_sint>, i64, F32>;
412 def: OpR_R_pat<F2_conv_df2d_chop, pf1<fp_to_sint>, i64, F64>;
414 def: OpR_R_pat<F2_conv_sf2uw_chop, pf1<fp_to_uint>, i32, F32>;
415 def: OpR_R_pat<F2_conv_df2uw_chop, pf1<fp_to_uint>, i32, F64>;
416 def: OpR_R_pat<F2_conv_sf2ud_chop, pf1<fp_to_uint>, i64, F32>;
417 def: OpR_R_pat<F2_conv_df2ud_chop, pf1<fp_to_uint>, i64, F64>;
419 // Bitcast is different than [fp|sint|uint]_to_[sint|uint|fp].
420 def: Pat<(i32 (bitconvert F32:$v)), (I32:$v)>;
421 def: Pat<(f32 (bitconvert I32:$v)), (F32:$v)>;
422 def: Pat<(i64 (bitconvert F64:$v)), (I64:$v)>;
423 def: Pat<(f64 (bitconvert I64:$v)), (F64:$v)>;
425 multiclass Cast_pat<ValueType Ta, ValueType Tb, RegisterClass RC> {
426 def: Pat<(Tb (bitconvert (Ta RC:$Rs))), (Tb RC:$Rs)>;
427 def: Pat<(Ta (bitconvert (Tb RC:$Rs))), (Ta RC:$Rs)>;
430 // Bit convert vector types to integers.
431 defm: Cast_pat<v4i8, i32, IntRegs>;
432 defm: Cast_pat<v2i16, i32, IntRegs>;
433 defm: Cast_pat<v8i8, i64, DoubleRegs>;
434 defm: Cast_pat<v4i16, i64, DoubleRegs>;
435 defm: Cast_pat<v2i32, i64, DoubleRegs>;
438 // --(3) Extend/truncate -------------------------------------------------
441 def: Pat<(sext_inreg I32:$Rs, i8), (A2_sxtb I32:$Rs)>;
442 def: Pat<(sext_inreg I32:$Rs, i16), (A2_sxth I32:$Rs)>;
443 def: Pat<(sext_inreg I64:$Rs, i32), (A2_sxtw (LoReg $Rs))>;
444 def: Pat<(sext_inreg I64:$Rs, i16), (A2_sxtw (A2_sxth (LoReg $Rs)))>;
445 def: Pat<(sext_inreg I64:$Rs, i8), (A2_sxtw (A2_sxtb (LoReg $Rs)))>;
447 def: Pat<(i64 (sext I32:$Rs)), (A2_sxtw I32:$Rs)>;
448 def: Pat<(Zext64 I32:$Rs), (ToZext64 $Rs)>;
449 def: Pat<(Aext64 I32:$Rs), (ToZext64 $Rs)>;
451 def: Pat<(i32 (trunc I64:$Rs)), (LoReg $Rs)>;
452 def: Pat<(i1 (trunc I32:$Rs)), (S2_tstbit_i I32:$Rs, 0)>;
453 def: Pat<(i1 (trunc I64:$Rs)), (S2_tstbit_i (LoReg $Rs), 0)>;
455 let AddedComplexity = 20 in {
456 def: Pat<(and I32:$Rs, 255), (A2_zxtb I32:$Rs)>;
457 def: Pat<(and I32:$Rs, 65535), (A2_zxth I32:$Rs)>;
460 // Extensions from i1 or vectors of i1.
461 def: Pat<(i32 (azext I1:$Pu)), (C2_muxii I1:$Pu, 1, 0)>;
462 def: Pat<(i64 (azext I1:$Pu)), (ToZext64 (C2_muxii I1:$Pu, 1, 0))>;
463 def: Pat<(i32 (sext I1:$Pu)), (C2_muxii I1:$Pu, -1, 0)>;
464 def: Pat<(i64 (sext I1:$Pu)), (Combinew (C2_muxii PredRegs:$Pu, -1, 0),
465 (C2_muxii PredRegs:$Pu, -1, 0))>;
467 def: Pat<(v2i16 (sext V2I1:$Pu)), (S2_vtrunehb (C2_mask V2I1:$Pu))>;
468 def: Pat<(v2i32 (sext V2I1:$Pu)), (C2_mask V2I1:$Pu)>;
469 def: Pat<(v4i8 (sext V4I1:$Pu)), (S2_vtrunehb (C2_mask V4I1:$Pu))>;
470 def: Pat<(v4i16 (sext V4I1:$Pu)), (C2_mask V4I1:$Pu)>;
471 def: Pat<(v8i8 (sext V8I1:$Pu)), (C2_mask V8I1:$Pu)>;
473 def Vsplatpi: OutPatFrag<(ops node:$V),
474 (Combinew (A2_tfrsi $V), (A2_tfrsi $V))>;
476 def: Pat<(v2i16 (azext V2I1:$Pu)),
477 (A2_andir (LoReg (C2_mask V2I1:$Pu)), (i32 0x00010001))>;
478 def: Pat<(v2i32 (azext V2I1:$Pu)),
479 (A2_andp (C2_mask V2I1:$Pu), (A2_combineii (i32 1), (i32 1)))>;
480 def: Pat<(v4i8 (azext V4I1:$Pu)),
481 (A2_andir (LoReg (C2_mask V4I1:$Pu)), (i32 0x01010101))>;
482 def: Pat<(v4i16 (azext V4I1:$Pu)),
483 (A2_andp (C2_mask V4I1:$Pu), (Vsplatpi (i32 0x00010001)))>;
484 def: Pat<(v8i8 (azext V8I1:$Pu)),
485 (A2_andp (C2_mask V8I1:$Pu), (Vsplatpi (i32 0x01010101)))>;
487 def: Pat<(v4i16 (azext V4I8:$Rs)), (S2_vzxtbh V4I8:$Rs)>;
488 def: Pat<(v2i32 (azext V2I16:$Rs)), (S2_vzxthw V2I16:$Rs)>;
489 def: Pat<(v4i16 (sext V4I8:$Rs)), (S2_vsxtbh V4I8:$Rs)>;
490 def: Pat<(v2i32 (sext V2I16:$Rs)), (S2_vsxthw V2I16:$Rs)>;
492 def: Pat<(v2i32 (sext_inreg V2I32:$Rs, v2i8)),
493 (Combinew (A2_sxtb (HiReg $Rs)), (A2_sxtb (LoReg $Rs)))>;
495 def: Pat<(v2i32 (sext_inreg V2I32:$Rs, v2i16)),
496 (Combinew (A2_sxth (HiReg $Rs)), (A2_sxth (LoReg $Rs)))>;
498 // Truncate: from vector B copy all 'E'ven 'B'yte elements:
499 // A[0] = B[0]; A[1] = B[2]; A[2] = B[4]; A[3] = B[6];
500 def: Pat<(v4i8 (trunc V4I16:$Rs)),
501 (S2_vtrunehb V4I16:$Rs)>;
503 // Truncate: from vector B copy all 'O'dd 'B'yte elements:
504 // A[0] = B[1]; A[1] = B[3]; A[2] = B[5]; A[3] = B[7];
507 // Truncate: from vectors B and C copy all 'E'ven 'H'alf-word elements:
508 // A[0] = B[0]; A[1] = B[2]; A[2] = C[0]; A[3] = C[2];
511 def: Pat<(v2i16 (trunc V2I32:$Rs)),
512 (A2_combine_ll (HiReg $Rs), (LoReg $Rs))>;
515 // --(4) Logical ---------------------------------------------------------
518 def: Pat<(not I1:$Ps), (C2_not I1:$Ps)>;
519 def: Pat<(pnot V2I1:$Ps), (C2_not V2I1:$Ps)>;
520 def: Pat<(pnot V4I1:$Ps), (C2_not V4I1:$Ps)>;
521 def: Pat<(pnot V8I1:$Ps), (C2_not V8I1:$Ps)>;
522 def: Pat<(add I1:$Ps, -1), (C2_not I1:$Ps)>;
524 multiclass BoolOpR_RR_pat<InstHexagon MI, PatFrag Op> {
525 def: OpR_RR_pat<MI, Op, i1, I1>;
526 def: OpR_RR_pat<MI, Op, v2i1, V2I1>;
527 def: OpR_RR_pat<MI, Op, v4i1, V4I1>;
528 def: OpR_RR_pat<MI, Op, v8i1, V8I1>;
531 multiclass BoolAccRRR_pat<InstHexagon MI, PatFrag AccOp, PatFrag Op> {
532 def: AccRRR_pat<MI, AccOp, Op, I1, I1, I1>;
533 def: AccRRR_pat<MI, AccOp, Op, V2I1, V2I1, V2I1>;
534 def: AccRRR_pat<MI, AccOp, Op, V4I1, V4I1, V4I1>;
535 def: AccRRR_pat<MI, AccOp, Op, V8I1, V8I1, V8I1>;
538 defm: BoolOpR_RR_pat<C2_and, And>;
539 defm: BoolOpR_RR_pat<C2_or, Or>;
540 defm: BoolOpR_RR_pat<C2_xor, Xor>;
541 defm: BoolOpR_RR_pat<C2_andn, Not2<And>>;
542 defm: BoolOpR_RR_pat<C2_orn, Not2<Or>>;
544 // op(Ps, op(Pt, Pu))
545 defm: BoolAccRRR_pat<C4_and_and, And, Su<And>>;
546 defm: BoolAccRRR_pat<C4_and_or, And, Su<Or>>;
547 defm: BoolAccRRR_pat<C4_or_and, Or, Su<And>>;
548 defm: BoolAccRRR_pat<C4_or_or, Or, Su<Or>>;
550 // op(Ps, op(Pt, ~Pu))
551 defm: BoolAccRRR_pat<C4_and_andn, And, Su<Not2<And>>>;
552 defm: BoolAccRRR_pat<C4_and_orn, And, Su<Not2<Or>>>;
553 defm: BoolAccRRR_pat<C4_or_andn, Or, Su<Not2<And>>>;
554 defm: BoolAccRRR_pat<C4_or_orn, Or, Su<Not2<Or>>>;
557 // --(5) Compare ---------------------------------------------------------
560 // Avoid negated comparisons, i.e. those of form "Pd = !cmp(...)".
561 // These cannot form compounds (e.g. J4_cmpeqi_tp0_jump_nt).
563 def: OpR_RI_pat<C2_cmpeqi, seteq, i1, I32, anyimm>;
564 def: OpR_RI_pat<C2_cmpgti, setgt, i1, I32, anyimm>;
565 def: OpR_RI_pat<C2_cmpgtui, setugt, i1, I32, anyimm>;
567 def: Pat<(i1 (setge I32:$Rs, s32_0ImmPred:$s10)),
568 (C2_cmpgti I32:$Rs, (SDEC1 imm:$s10))>;
569 def: Pat<(i1 (setuge I32:$Rs, u32_0ImmPred:$u9)),
570 (C2_cmpgtui I32:$Rs, (UDEC1 imm:$u9))>;
572 def: Pat<(i1 (setlt I32:$Rs, s32_0ImmPred:$s10)),
573 (C2_not (C2_cmpgti I32:$Rs, (SDEC1 imm:$s10)))>;
574 def: Pat<(i1 (setult I32:$Rs, u32_0ImmPred:$u9)),
575 (C2_not (C2_cmpgtui I32:$Rs, (UDEC1 imm:$u9)))>;
577 // Patfrag to convert the usual comparison patfrags (e.g. setlt) to ones
578 // that reverse the order of the operands.
579 class RevCmp<PatFrag F>
580 : PatFrag<(ops node:$rhs, node:$lhs), !head(F.Fragments), F.PredicateCode,
583 def: OpR_RR_pat<C2_cmpeq, seteq, i1, I32>;
584 def: OpR_RR_pat<C2_cmpgt, setgt, i1, I32>;
585 def: OpR_RR_pat<C2_cmpgtu, setugt, i1, I32>;
586 def: OpR_RR_pat<C2_cmpgt, RevCmp<setlt>, i1, I32>;
587 def: OpR_RR_pat<C2_cmpgtu, RevCmp<setult>, i1, I32>;
588 def: OpR_RR_pat<C2_cmpeqp, seteq, i1, I64>;
589 def: OpR_RR_pat<C2_cmpgtp, setgt, i1, I64>;
590 def: OpR_RR_pat<C2_cmpgtup, setugt, i1, I64>;
591 def: OpR_RR_pat<C2_cmpgtp, RevCmp<setlt>, i1, I64>;
592 def: OpR_RR_pat<C2_cmpgtup, RevCmp<setult>, i1, I64>;
593 def: OpR_RR_pat<A2_vcmpbeq, seteq, i1, V8I8>;
594 def: OpR_RR_pat<A2_vcmpbeq, seteq, v8i1, V8I8>;
595 def: OpR_RR_pat<A4_vcmpbgt, RevCmp<setlt>, i1, V8I8>;
596 def: OpR_RR_pat<A4_vcmpbgt, RevCmp<setlt>, v8i1, V8I8>;
597 def: OpR_RR_pat<A4_vcmpbgt, setgt, i1, V8I8>;
598 def: OpR_RR_pat<A4_vcmpbgt, setgt, v8i1, V8I8>;
599 def: OpR_RR_pat<A2_vcmpbgtu, RevCmp<setult>, i1, V8I8>;
600 def: OpR_RR_pat<A2_vcmpbgtu, RevCmp<setult>, v8i1, V8I8>;
601 def: OpR_RR_pat<A2_vcmpbgtu, setugt, i1, V8I8>;
602 def: OpR_RR_pat<A2_vcmpbgtu, setugt, v8i1, V8I8>;
603 def: OpR_RR_pat<A2_vcmpheq, seteq, i1, V4I16>;
604 def: OpR_RR_pat<A2_vcmpheq, seteq, v4i1, V4I16>;
605 def: OpR_RR_pat<A2_vcmphgt, RevCmp<setlt>, i1, V4I16>;
606 def: OpR_RR_pat<A2_vcmphgt, RevCmp<setlt>, v4i1, V4I16>;
607 def: OpR_RR_pat<A2_vcmphgt, setgt, i1, V4I16>;
608 def: OpR_RR_pat<A2_vcmphgt, setgt, v4i1, V4I16>;
609 def: OpR_RR_pat<A2_vcmphgtu, RevCmp<setult>, i1, V4I16>;
610 def: OpR_RR_pat<A2_vcmphgtu, RevCmp<setult>, v4i1, V4I16>;
611 def: OpR_RR_pat<A2_vcmphgtu, setugt, i1, V4I16>;
612 def: OpR_RR_pat<A2_vcmphgtu, setugt, v4i1, V4I16>;
613 def: OpR_RR_pat<A2_vcmpweq, seteq, i1, V2I32>;
614 def: OpR_RR_pat<A2_vcmpweq, seteq, v2i1, V2I32>;
615 def: OpR_RR_pat<A2_vcmpwgt, RevCmp<setlt>, i1, V2I32>;
616 def: OpR_RR_pat<A2_vcmpwgt, RevCmp<setlt>, v2i1, V2I32>;
617 def: OpR_RR_pat<A2_vcmpwgt, setgt, i1, V2I32>;
618 def: OpR_RR_pat<A2_vcmpwgt, setgt, v2i1, V2I32>;
619 def: OpR_RR_pat<A2_vcmpwgtu, RevCmp<setult>, i1, V2I32>;
620 def: OpR_RR_pat<A2_vcmpwgtu, RevCmp<setult>, v2i1, V2I32>;
621 def: OpR_RR_pat<A2_vcmpwgtu, setugt, i1, V2I32>;
622 def: OpR_RR_pat<A2_vcmpwgtu, setugt, v2i1, V2I32>;
624 def: OpR_RR_pat<F2_sfcmpeq, seteq, i1, F32>;
625 def: OpR_RR_pat<F2_sfcmpgt, setgt, i1, F32>;
626 def: OpR_RR_pat<F2_sfcmpge, setge, i1, F32>;
627 def: OpR_RR_pat<F2_sfcmpeq, setoeq, i1, F32>;
628 def: OpR_RR_pat<F2_sfcmpgt, setogt, i1, F32>;
629 def: OpR_RR_pat<F2_sfcmpge, setoge, i1, F32>;
630 def: OpR_RR_pat<F2_sfcmpgt, RevCmp<setolt>, i1, F32>;
631 def: OpR_RR_pat<F2_sfcmpge, RevCmp<setole>, i1, F32>;
632 def: OpR_RR_pat<F2_sfcmpgt, RevCmp<setlt>, i1, F32>;
633 def: OpR_RR_pat<F2_sfcmpge, RevCmp<setle>, i1, F32>;
634 def: OpR_RR_pat<F2_sfcmpuo, setuo, i1, F32>;
636 def: OpR_RR_pat<F2_dfcmpeq, seteq, i1, F64>;
637 def: OpR_RR_pat<F2_dfcmpgt, setgt, i1, F64>;
638 def: OpR_RR_pat<F2_dfcmpge, setge, i1, F64>;
639 def: OpR_RR_pat<F2_dfcmpeq, setoeq, i1, F64>;
640 def: OpR_RR_pat<F2_dfcmpgt, setogt, i1, F64>;
641 def: OpR_RR_pat<F2_dfcmpge, setoge, i1, F64>;
642 def: OpR_RR_pat<F2_dfcmpgt, RevCmp<setolt>, i1, F64>;
643 def: OpR_RR_pat<F2_dfcmpge, RevCmp<setole>, i1, F64>;
644 def: OpR_RR_pat<F2_dfcmpgt, RevCmp<setlt>, i1, F64>;
645 def: OpR_RR_pat<F2_dfcmpge, RevCmp<setle>, i1, F64>;
646 def: OpR_RR_pat<F2_dfcmpuo, setuo, i1, F64>;
648 // Avoid C4_cmpneqi, C4_cmpltei, C4_cmplteui, since they cannot form compounds.
650 def: Pat<(i1 (setne I32:$Rs, anyimm:$u5)),
651 (C2_not (C2_cmpeqi I32:$Rs, imm:$u5))>;
652 def: Pat<(i1 (setle I32:$Rs, anyimm:$u5)),
653 (C2_not (C2_cmpgti I32:$Rs, imm:$u5))>;
654 def: Pat<(i1 (setule I32:$Rs, anyimm:$u5)),
655 (C2_not (C2_cmpgtui I32:$Rs, imm:$u5))>;
657 class OpmR_RR_pat<PatFrag Output, PatFrag Op, ValueType ResType,
658 PatFrag RsPred, PatFrag RtPred = RsPred>
659 : Pat<(ResType (Op RsPred:$Rs, RtPred:$Rt)),
660 (Output RsPred:$Rs, RtPred:$Rt)>;
662 class Outn<InstHexagon MI>
663 : OutPatFrag<(ops node:$Rs, node:$Rt),
664 (C2_not (MI $Rs, $Rt))>;
666 def: OpmR_RR_pat<Outn<C2_cmpeq>, setne, i1, I32>;
667 def: OpmR_RR_pat<Outn<C2_cmpgt>, setle, i1, I32>;
668 def: OpmR_RR_pat<Outn<C2_cmpgtu>, setule, i1, I32>;
669 def: OpmR_RR_pat<Outn<C2_cmpgt>, RevCmp<setge>, i1, I32>;
670 def: OpmR_RR_pat<Outn<C2_cmpgtu>, RevCmp<setuge>, i1, I32>;
671 def: OpmR_RR_pat<Outn<C2_cmpeqp>, setne, i1, I64>;
672 def: OpmR_RR_pat<Outn<C2_cmpgtp>, setle, i1, I64>;
673 def: OpmR_RR_pat<Outn<C2_cmpgtup>, setule, i1, I64>;
674 def: OpmR_RR_pat<Outn<C2_cmpgtp>, RevCmp<setge>, i1, I64>;
675 def: OpmR_RR_pat<Outn<C2_cmpgtup>, RevCmp<setuge>, i1, I64>;
676 def: OpmR_RR_pat<Outn<A2_vcmpbeq>, setne, v8i1, V8I8>;
677 def: OpmR_RR_pat<Outn<A4_vcmpbgt>, setle, v8i1, V8I8>;
678 def: OpmR_RR_pat<Outn<A2_vcmpbgtu>, setule, v8i1, V8I8>;
679 def: OpmR_RR_pat<Outn<A4_vcmpbgt>, RevCmp<setge>, v8i1, V8I8>;
680 def: OpmR_RR_pat<Outn<A2_vcmpbgtu>, RevCmp<setuge>, v8i1, V8I8>;
681 def: OpmR_RR_pat<Outn<A2_vcmpheq>, setne, v4i1, V4I16>;
682 def: OpmR_RR_pat<Outn<A2_vcmphgt>, setle, v4i1, V4I16>;
683 def: OpmR_RR_pat<Outn<A2_vcmphgtu>, setule, v4i1, V4I16>;
684 def: OpmR_RR_pat<Outn<A2_vcmphgt>, RevCmp<setge>, v4i1, V4I16>;
685 def: OpmR_RR_pat<Outn<A2_vcmphgtu>, RevCmp<setuge>, v4i1, V4I16>;
686 def: OpmR_RR_pat<Outn<A2_vcmpweq>, setne, v2i1, V2I32>;
687 def: OpmR_RR_pat<Outn<A2_vcmpwgt>, setle, v2i1, V2I32>;
688 def: OpmR_RR_pat<Outn<A2_vcmpwgtu>, setule, v2i1, V2I32>;
689 def: OpmR_RR_pat<Outn<A2_vcmpwgt>, RevCmp<setge>, v2i1, V2I32>;
690 def: OpmR_RR_pat<Outn<A2_vcmpwgtu>, RevCmp<setuge>, v2i1, V2I32>;
692 let AddedComplexity = 100 in {
693 def: Pat<(i1 (seteq (and (xor I32:$Rs, I32:$Rt), 255), 0)),
694 (A4_cmpbeq IntRegs:$Rs, IntRegs:$Rt)>;
695 def: Pat<(i1 (setne (and (xor I32:$Rs, I32:$Rt), 255), 0)),
696 (C2_not (A4_cmpbeq IntRegs:$Rs, IntRegs:$Rt))>;
697 def: Pat<(i1 (seteq (and (xor I32:$Rs, I32:$Rt), 65535), 0)),
698 (A4_cmpheq IntRegs:$Rs, IntRegs:$Rt)>;
699 def: Pat<(i1 (setne (and (xor I32:$Rs, I32:$Rt), 65535), 0)),
700 (C2_not (A4_cmpheq IntRegs:$Rs, IntRegs:$Rt))>;
703 // PatFrag for AsserZext which takes the original type as a parameter.
704 def SDTAssertZext: SDTypeProfile<1, 2, [SDTCisInt<0>, SDTCisSameAs<0,1>]>;
705 def AssertZextSD: SDNode<"ISD::AssertZext", SDTAssertZext>;
706 class AssertZext<ValueType T>: PatFrag<(ops node:$A), (AssertZextSD $A, T)>;
708 multiclass Cmpb_pat<InstHexagon MI, PatFrag Op, PatFrag AssertExt,
709 PatLeaf ImmPred, int Mask> {
710 def: Pat<(i1 (Op (and I32:$Rs, Mask), ImmPred:$I)),
711 (MI I32:$Rs, imm:$I)>;
712 def: Pat<(i1 (Op (AssertExt I32:$Rs), ImmPred:$I)),
713 (MI I32:$Rs, imm:$I)>;
716 multiclass CmpbN_pat<InstHexagon MI, PatFrag Op, PatFrag AssertExt,
717 PatLeaf ImmPred, int Mask> {
718 def: Pat<(i1 (Op (and I32:$Rs, Mask), ImmPred:$I)),
719 (C2_not (MI I32:$Rs, imm:$I))>;
720 def: Pat<(i1 (Op (AssertExt I32:$Rs), ImmPred:$I)),
721 (C2_not (MI I32:$Rs, imm:$I))>;
724 multiclass CmpbND_pat<InstHexagon MI, PatFrag Op, PatFrag AssertExt,
725 PatLeaf ImmPred, int Mask> {
726 def: Pat<(i1 (Op (and I32:$Rs, Mask), ImmPred:$I)),
727 (C2_not (MI I32:$Rs, (UDEC1 imm:$I)))>;
728 def: Pat<(i1 (Op (AssertExt I32:$Rs), ImmPred:$I)),
729 (C2_not (MI I32:$Rs, (UDEC1 imm:$I)))>;
732 let AddedComplexity = 200 in {
733 defm: Cmpb_pat <A4_cmpbeqi, seteq, AssertZext<i8>, IsUGT<8,31>, 255>;
734 defm: CmpbN_pat <A4_cmpbeqi, setne, AssertZext<i8>, IsUGT<8,31>, 255>;
735 defm: Cmpb_pat <A4_cmpbgtui, setugt, AssertZext<i8>, IsUGT<32,31>, 255>;
736 defm: CmpbN_pat <A4_cmpbgtui, setule, AssertZext<i8>, IsUGT<32,31>, 255>;
737 defm: Cmpb_pat <A4_cmphgtui, setugt, AssertZext<i16>, IsUGT<32,31>, 65535>;
738 defm: CmpbN_pat <A4_cmphgtui, setule, AssertZext<i16>, IsUGT<32,31>, 65535>;
739 defm: CmpbND_pat<A4_cmpbgtui, setult, AssertZext<i8>, IsUGT<32,32>, 255>;
740 defm: CmpbND_pat<A4_cmphgtui, setult, AssertZext<i16>, IsUGT<32,32>, 65535>;
743 def: Pat<(i32 (zext (i1 (seteq I32:$Rs, I32:$Rt)))),
744 (A4_rcmpeq I32:$Rs, I32:$Rt)>;
745 def: Pat<(i32 (zext (i1 (setne I32:$Rs, I32:$Rt)))),
746 (A4_rcmpneq I32:$Rs, I32:$Rt)>;
747 def: Pat<(i32 (zext (i1 (seteq I32:$Rs, anyimm:$s8)))),
748 (A4_rcmpeqi I32:$Rs, imm:$s8)>;
749 def: Pat<(i32 (zext (i1 (setne I32:$Rs, anyimm:$s8)))),
750 (A4_rcmpneqi I32:$Rs, imm:$s8)>;
752 def: Pat<(i1 (seteq I1:$Ps, (i1 -1))), (I1:$Ps)>;
753 def: Pat<(i1 (setne I1:$Ps, (i1 -1))), (C2_not I1:$Ps)>;
754 def: Pat<(i1 (seteq I1:$Ps, I1:$Pt)), (C2_xor I1:$Ps, (C2_not I1:$Pt))>;
755 def: Pat<(i1 (setne I1:$Ps, I1:$Pt)), (C2_xor I1:$Ps, I1:$Pt)>;
757 // Floating-point comparisons with checks for ordered/unordered status.
759 class T3<InstHexagon MI1, InstHexagon MI2, InstHexagon MI3>
760 : OutPatFrag<(ops node:$Rs, node:$Rt),
761 (MI1 (MI2 $Rs, $Rt), (MI3 $Rs, $Rt))>;
763 class Cmpuf<InstHexagon MI>: T3<C2_or, F2_sfcmpuo, MI>;
764 class Cmpud<InstHexagon MI>: T3<C2_or, F2_dfcmpuo, MI>;
766 class Cmpufn<InstHexagon MI>: T3<C2_orn, F2_sfcmpuo, MI>;
767 class Cmpudn<InstHexagon MI>: T3<C2_orn, F2_dfcmpuo, MI>;
769 def: OpmR_RR_pat<Cmpuf<F2_sfcmpeq>, setueq, i1, F32>;
770 def: OpmR_RR_pat<Cmpuf<F2_sfcmpge>, setuge, i1, F32>;
771 def: OpmR_RR_pat<Cmpuf<F2_sfcmpgt>, setugt, i1, F32>;
772 def: OpmR_RR_pat<Cmpuf<F2_sfcmpge>, RevCmp<setule>, i1, F32>;
773 def: OpmR_RR_pat<Cmpuf<F2_sfcmpgt>, RevCmp<setult>, i1, F32>;
774 def: OpmR_RR_pat<Cmpufn<F2_sfcmpeq>, setune, i1, F32>;
776 def: OpmR_RR_pat<Cmpud<F2_dfcmpeq>, setueq, i1, F64>;
777 def: OpmR_RR_pat<Cmpud<F2_dfcmpge>, setuge, i1, F64>;
778 def: OpmR_RR_pat<Cmpud<F2_dfcmpgt>, setugt, i1, F64>;
779 def: OpmR_RR_pat<Cmpud<F2_dfcmpge>, RevCmp<setule>, i1, F64>;
780 def: OpmR_RR_pat<Cmpud<F2_dfcmpgt>, RevCmp<setult>, i1, F64>;
781 def: OpmR_RR_pat<Cmpudn<F2_dfcmpeq>, setune, i1, F64>;
783 def: OpmR_RR_pat<Outn<F2_sfcmpeq>, setone, i1, F32>;
784 def: OpmR_RR_pat<Outn<F2_sfcmpeq>, setne, i1, F32>;
786 def: OpmR_RR_pat<Outn<F2_dfcmpeq>, setone, i1, F64>;
787 def: OpmR_RR_pat<Outn<F2_dfcmpeq>, setne, i1, F64>;
789 def: OpmR_RR_pat<Outn<F2_sfcmpuo>, seto, i1, F32>;
790 def: OpmR_RR_pat<Outn<F2_dfcmpuo>, seto, i1, F64>;
793 // --(6) Select ----------------------------------------------------------
796 def: Pat<(select I1:$Pu, I32:$Rs, I32:$Rt),
797 (C2_mux I1:$Pu, I32:$Rs, I32:$Rt)>;
798 def: Pat<(select I1:$Pu, anyimm:$s8, I32:$Rs),
799 (C2_muxri I1:$Pu, imm:$s8, I32:$Rs)>;
800 def: Pat<(select I1:$Pu, I32:$Rs, anyimm:$s8),
801 (C2_muxir I1:$Pu, I32:$Rs, imm:$s8)>;
802 def: Pat<(select I1:$Pu, anyimm:$s8, s8_0ImmPred:$S8),
803 (C2_muxii I1:$Pu, imm:$s8, imm:$S8)>;
805 def: Pat<(select (not I1:$Pu), I32:$Rs, I32:$Rt),
806 (C2_mux I1:$Pu, I32:$Rt, I32:$Rs)>;
807 def: Pat<(select (not I1:$Pu), s8_0ImmPred:$S8, anyimm:$s8),
808 (C2_muxii I1:$Pu, imm:$s8, imm:$S8)>;
809 def: Pat<(select (not I1:$Pu), anyimm:$s8, I32:$Rs),
810 (C2_muxir I1:$Pu, I32:$Rs, imm:$s8)>;
811 def: Pat<(select (not I1:$Pu), I32:$Rs, anyimm:$s8),
812 (C2_muxri I1:$Pu, imm:$s8, I32:$Rs)>;
814 // Map from a 64-bit select to an emulated 64-bit mux.
815 // Hexagon does not support 64-bit MUXes; so emulate with combines.
816 def: Pat<(select I1:$Pu, I64:$Rs, I64:$Rt),
817 (Combinew (C2_mux I1:$Pu, (HiReg $Rs), (HiReg $Rt)),
818 (C2_mux I1:$Pu, (LoReg $Rs), (LoReg $Rt)))>;
820 def: Pat<(select I1:$Pu, F32:$Rs, f32ImmPred:$I),
821 (C2_muxir I1:$Pu, F32:$Rs, (ftoi $I))>;
822 def: Pat<(select I1:$Pu, f32ImmPred:$I, F32:$Rt),
823 (C2_muxri I1:$Pu, (ftoi $I), F32:$Rt)>;
824 def: Pat<(select I1:$Pu, F32:$Rs, F32:$Rt),
825 (C2_mux I1:$Pu, F32:$Rs, F32:$Rt)>;
826 def: Pat<(select I1:$Pu, F64:$Rs, F64:$Rt),
827 (Combinew (C2_mux I1:$Pu, (HiReg $Rs), (HiReg $Rt)),
828 (C2_mux I1:$Pu, (LoReg $Rs), (LoReg $Rt)))>;
830 def: Pat<(select (i1 (setult F32:$Ra, F32:$Rb)), F32:$Rs, F32:$Rt),
831 (C2_mux (F2_sfcmpgt F32:$Rb, F32:$Ra), F32:$Rs, F32:$Rt)>;
832 def: Pat<(select (i1 (setult F64:$Ra, F64:$Rb)), F64:$Rs, F64:$Rt),
833 (C2_vmux (F2_dfcmpgt F64:$Rb, F64:$Ra), F64:$Rs, F64:$Rt)>;
835 def: Pat<(select (not I1:$Pu), f32ImmPred:$I, F32:$Rs),
836 (C2_muxir I1:$Pu, F32:$Rs, (ftoi $I))>;
837 def: Pat<(select (not I1:$Pu), F32:$Rt, f32ImmPred:$I),
838 (C2_muxri I1:$Pu, (ftoi $I), F32:$Rt)>;
840 def: Pat<(vselect V8I1:$Pu, V8I8:$Rs, V8I8:$Rt),
841 (C2_vmux V8I1:$Pu, V8I8:$Rs, V8I8:$Rt)>;
842 def: Pat<(vselect V4I1:$Pu, V4I16:$Rs, V4I16:$Rt),
843 (C2_vmux V4I1:$Pu, V4I16:$Rs, V4I16:$Rt)>;
844 def: Pat<(vselect V2I1:$Pu, V2I32:$Rs, V2I32:$Rt),
845 (C2_vmux V2I1:$Pu, V2I32:$Rs, V2I32:$Rt)>;
847 def: Pat<(vselect (pnot V8I1:$Pu), V8I8:$Rs, V8I8:$Rt),
848 (C2_vmux V8I1:$Pu, V8I8:$Rt, V8I8:$Rs)>;
849 def: Pat<(vselect (pnot V4I1:$Pu), V4I16:$Rs, V4I16:$Rt),
850 (C2_vmux V4I1:$Pu, V4I16:$Rt, V4I16:$Rs)>;
851 def: Pat<(vselect (pnot V2I1:$Pu), V2I32:$Rs, V2I32:$Rt),
852 (C2_vmux V2I1:$Pu, V2I32:$Rt, V2I32:$Rs)>;
855 // From LegalizeDAG.cpp: (Pu ? Pv : Pw) <=> (Pu & Pv) | (!Pu & Pw).
856 def: Pat<(select I1:$Pu, I1:$Pv, I1:$Pw),
857 (C2_or (C2_and I1:$Pu, I1:$Pv),
858 (C2_andn I1:$Pw, I1:$Pu))>;
861 def IsPosHalf : PatLeaf<(i32 IntRegs:$a), [{
862 return isPositiveHalfWord(N);
865 multiclass SelMinMax16_pats<PatFrag CmpOp, InstHexagon InstA,
867 def: Pat<(sext_inreg (select (i1 (CmpOp IsPosHalf:$Rs, IsPosHalf:$Rt)),
868 IsPosHalf:$Rs, IsPosHalf:$Rt), i16),
869 (InstA IntRegs:$Rs, IntRegs:$Rt)>;
870 def: Pat<(sext_inreg (select (i1 (CmpOp IsPosHalf:$Rs, IsPosHalf:$Rt)),
871 IsPosHalf:$Rt, IsPosHalf:$Rs), i16),
872 (InstB IntRegs:$Rs, IntRegs:$Rt)>;
875 let AddedComplexity = 200 in {
876 defm: SelMinMax16_pats<setge, A2_max, A2_min>;
877 defm: SelMinMax16_pats<setgt, A2_max, A2_min>;
878 defm: SelMinMax16_pats<setle, A2_min, A2_max>;
879 defm: SelMinMax16_pats<setlt, A2_min, A2_max>;
880 defm: SelMinMax16_pats<setuge, A2_maxu, A2_minu>;
881 defm: SelMinMax16_pats<setugt, A2_maxu, A2_minu>;
882 defm: SelMinMax16_pats<setule, A2_minu, A2_maxu>;
883 defm: SelMinMax16_pats<setult, A2_minu, A2_maxu>;
886 let AddedComplexity = 200 in {
887 defm: MinMax_pats<A2_min, A2_max, select, setgt, i1, I32>;
888 defm: MinMax_pats<A2_min, A2_max, select, setge, i1, I32>;
889 defm: MinMax_pats<A2_max, A2_min, select, setlt, i1, I32>;
890 defm: MinMax_pats<A2_max, A2_min, select, setle, i1, I32>;
891 defm: MinMax_pats<A2_minu, A2_maxu, select, setugt, i1, I32>;
892 defm: MinMax_pats<A2_minu, A2_maxu, select, setuge, i1, I32>;
893 defm: MinMax_pats<A2_maxu, A2_minu, select, setult, i1, I32>;
894 defm: MinMax_pats<A2_maxu, A2_minu, select, setule, i1, I32>;
896 defm: MinMax_pats<A2_minp, A2_maxp, select, setgt, i1, I64>;
897 defm: MinMax_pats<A2_minp, A2_maxp, select, setge, i1, I64>;
898 defm: MinMax_pats<A2_maxp, A2_minp, select, setlt, i1, I64>;
899 defm: MinMax_pats<A2_maxp, A2_minp, select, setle, i1, I64>;
900 defm: MinMax_pats<A2_minup, A2_maxup, select, setugt, i1, I64>;
901 defm: MinMax_pats<A2_minup, A2_maxup, select, setuge, i1, I64>;
902 defm: MinMax_pats<A2_maxup, A2_minup, select, setult, i1, I64>;
903 defm: MinMax_pats<A2_maxup, A2_minup, select, setule, i1, I64>;
906 let AddedComplexity = 100 in {
907 defm: MinMax_pats<F2_sfmin, F2_sfmax, select, setogt, i1, F32>;
908 defm: MinMax_pats<F2_sfmin, F2_sfmax, select, setoge, i1, F32>;
909 defm: MinMax_pats<F2_sfmax, F2_sfmin, select, setolt, i1, F32>;
910 defm: MinMax_pats<F2_sfmax, F2_sfmin, select, setole, i1, F32>;
913 defm: MinMax_pats<A2_vminb, A2_vmaxb, vselect, setgt, v8i1, V8I8>;
914 defm: MinMax_pats<A2_vminb, A2_vmaxb, vselect, setge, v8i1, V8I8>;
915 defm: MinMax_pats<A2_vminh, A2_vmaxh, vselect, setgt, v4i1, V4I16>;
916 defm: MinMax_pats<A2_vminh, A2_vmaxh, vselect, setge, v4i1, V4I16>;
917 defm: MinMax_pats<A2_vminw, A2_vmaxw, vselect, setgt, v2i1, V2I32>;
918 defm: MinMax_pats<A2_vminw, A2_vmaxw, vselect, setge, v2i1, V2I32>;
919 defm: MinMax_pats<A2_vminub, A2_vmaxub, vselect, setugt, v8i1, V8I8>;
920 defm: MinMax_pats<A2_vminub, A2_vmaxub, vselect, setuge, v8i1, V8I8>;
921 defm: MinMax_pats<A2_vminuh, A2_vmaxuh, vselect, setugt, v4i1, V4I16>;
922 defm: MinMax_pats<A2_vminuh, A2_vmaxuh, vselect, setuge, v4i1, V4I16>;
923 defm: MinMax_pats<A2_vminuw, A2_vmaxuw, vselect, setugt, v2i1, V2I32>;
924 defm: MinMax_pats<A2_vminuw, A2_vmaxuw, vselect, setuge, v2i1, V2I32>;
926 // --(7) Insert/extract --------------------------------------------------
929 def SDTHexagonINSERT:
930 SDTypeProfile<1, 4, [SDTCisSameAs<0, 1>, SDTCisSameAs<0, 2>,
931 SDTCisInt<0>, SDTCisVT<3, i32>, SDTCisVT<4, i32>]>;
932 def HexagonINSERT: SDNode<"HexagonISD::INSERT", SDTHexagonINSERT>;
934 let AddedComplexity = 10 in {
935 def: Pat<(HexagonINSERT I32:$Rs, I32:$Rt, u5_0ImmPred:$u1, u5_0ImmPred:$u2),
936 (S2_insert I32:$Rs, I32:$Rt, imm:$u1, imm:$u2)>;
937 def: Pat<(HexagonINSERT I64:$Rs, I64:$Rt, u6_0ImmPred:$u1, u6_0ImmPred:$u2),
938 (S2_insertp I64:$Rs, I64:$Rt, imm:$u1, imm:$u2)>;
940 def: Pat<(HexagonINSERT I32:$Rs, I32:$Rt, I32:$Width, I32:$Off),
941 (S2_insert_rp I32:$Rs, I32:$Rt, (Combinew $Width, $Off))>;
942 def: Pat<(HexagonINSERT I64:$Rs, I64:$Rt, I32:$Width, I32:$Off),
943 (S2_insertp_rp I64:$Rs, I64:$Rt, (Combinew $Width, $Off))>;
945 def SDTHexagonEXTRACTU
946 : SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisInt<0>, SDTCisInt<1>,
947 SDTCisVT<2, i32>, SDTCisVT<3, i32>]>;
948 def HexagonEXTRACTU: SDNode<"HexagonISD::EXTRACTU", SDTHexagonEXTRACTU>;
950 let AddedComplexity = 10 in {
951 def: Pat<(HexagonEXTRACTU I32:$Rs, u5_0ImmPred:$u5, u5_0ImmPred:$U5),
952 (S2_extractu I32:$Rs, imm:$u5, imm:$U5)>;
953 def: Pat<(HexagonEXTRACTU I64:$Rs, u6_0ImmPred:$u6, u6_0ImmPred:$U6),
954 (S2_extractup I64:$Rs, imm:$u6, imm:$U6)>;
956 def: Pat<(HexagonEXTRACTU I32:$Rs, I32:$Width, I32:$Off),
957 (S2_extractu_rp I32:$Rs, (Combinew $Width, $Off))>;
958 def: Pat<(HexagonEXTRACTU I64:$Rs, I32:$Width, I32:$Off),
959 (S2_extractup_rp I64:$Rs, (Combinew $Width, $Off))>;
961 def SDTHexagonVSPLAT:
962 SDTypeProfile<1, 1, [SDTCisVec<0>, SDTCisVT<1, i32>]>;
964 def HexagonVSPLAT: SDNode<"HexagonISD::VSPLAT", SDTHexagonVSPLAT>;
966 def: Pat<(v4i8 (HexagonVSPLAT I32:$Rs)), (S2_vsplatrb I32:$Rs)>;
967 def: Pat<(v4i16 (HexagonVSPLAT I32:$Rs)), (S2_vsplatrh I32:$Rs)>;
968 def: Pat<(v2i32 (HexagonVSPLAT s8_0ImmPred:$s8)),
969 (A2_combineii imm:$s8, imm:$s8)>;
970 def: Pat<(v2i32 (HexagonVSPLAT I32:$Rs)), (Combinew I32:$Rs, I32:$Rs)>;
972 let AddedComplexity = 10 in
973 def: Pat<(v8i8 (HexagonVSPLAT I32:$Rs)), (S6_vsplatrbp I32:$Rs)>,
975 def: Pat<(v8i8 (HexagonVSPLAT I32:$Rs)),
976 (Combinew (S2_vsplatrb I32:$Rs), (S2_vsplatrb I32:$Rs))>;
979 // --(8) Shift/permute ---------------------------------------------------
982 def SDTHexagonI64I32I32: SDTypeProfile<1, 2,
983 [SDTCisVT<0, i64>, SDTCisVT<1, i32>, SDTCisSameAs<1, 2>]>;
985 def HexagonCOMBINE: SDNode<"HexagonISD::COMBINE", SDTHexagonI64I32I32>;
987 def: Pat<(HexagonCOMBINE I32:$Rs, I32:$Rt), (Combinew $Rs, $Rt)>;
989 // The complexity of the combines involving immediates should be greater
990 // than the complexity of the combine with two registers.
991 let AddedComplexity = 50 in {
992 def: Pat<(HexagonCOMBINE I32:$Rs, anyimm:$s8),
993 (A4_combineri IntRegs:$Rs, imm:$s8)>;
994 def: Pat<(HexagonCOMBINE anyimm:$s8, I32:$Rs),
995 (A4_combineir imm:$s8, IntRegs:$Rs)>;
998 // The complexity of the combine with two immediates should be greater than
999 // the complexity of a combine involving a register.
1000 let AddedComplexity = 75 in {
1001 def: Pat<(HexagonCOMBINE s8_0ImmPred:$s8, anyimm:$u6),
1002 (A4_combineii imm:$s8, imm:$u6)>;
1003 def: Pat<(HexagonCOMBINE anyimm:$s8, s8_0ImmPred:$S8),
1004 (A2_combineii imm:$s8, imm:$S8)>;
1007 def: Pat<(bswap I32:$Rs), (A2_swiz I32:$Rs)>;
1008 def: Pat<(bswap I64:$Rss), (Combinew (A2_swiz (LoReg $Rss)),
1009 (A2_swiz (HiReg $Rss)))>;
1011 def: Pat<(shl s6_0ImmPred:$s6, I32:$Rt), (S4_lsli imm:$s6, I32:$Rt)>;
1012 def: Pat<(shl I32:$Rs, (i32 16)), (A2_aslh I32:$Rs)>;
1013 def: Pat<(sra I32:$Rs, (i32 16)), (A2_asrh I32:$Rs)>;
1015 def: OpR_RI_pat<S2_asr_i_r, Sra, i32, I32, u5_0ImmPred>;
1016 def: OpR_RI_pat<S2_lsr_i_r, Srl, i32, I32, u5_0ImmPred>;
1017 def: OpR_RI_pat<S2_asl_i_r, Shl, i32, I32, u5_0ImmPred>;
1018 def: OpR_RI_pat<S2_asr_i_p, Sra, i64, I64, u6_0ImmPred>;
1019 def: OpR_RI_pat<S2_lsr_i_p, Srl, i64, I64, u6_0ImmPred>;
1020 def: OpR_RI_pat<S2_asl_i_p, Shl, i64, I64, u6_0ImmPred>;
1021 def: OpR_RI_pat<S2_asr_i_vh, Sra, v4i16, V4I16, u4_0ImmPred>;
1022 def: OpR_RI_pat<S2_lsr_i_vh, Srl, v4i16, V4I16, u4_0ImmPred>;
1023 def: OpR_RI_pat<S2_asl_i_vh, Shl, v4i16, V4I16, u4_0ImmPred>;
1024 def: OpR_RI_pat<S2_asr_i_vh, Sra, v2i32, V2I32, u5_0ImmPred>;
1025 def: OpR_RI_pat<S2_lsr_i_vh, Srl, v2i32, V2I32, u5_0ImmPred>;
1026 def: OpR_RI_pat<S2_asl_i_vh, Shl, v2i32, V2I32, u5_0ImmPred>;
1028 def: OpR_RR_pat<S2_asr_r_r, Sra, i32, I32, I32>;
1029 def: OpR_RR_pat<S2_lsr_r_r, Srl, i32, I32, I32>;
1030 def: OpR_RR_pat<S2_asl_r_r, Shl, i32, I32, I32>;
1031 def: OpR_RR_pat<S2_asr_r_p, Sra, i64, I64, I32>;
1032 def: OpR_RR_pat<S2_lsr_r_p, Srl, i64, I64, I32>;
1033 def: OpR_RR_pat<S2_asl_r_p, Shl, i64, I64, I32>;
1036 def IsMul8_U3: PatLeaf<(i32 imm), [{
1037 uint64_t V = N->getZExtValue();
1038 return V % 8 == 0 && isUInt<3>(V / 8);
1041 def Divu8: SDNodeXForm<imm, [{
1042 return CurDAG->getTargetConstant(N->getZExtValue() / 8, SDLoc(N), MVT::i32);
1045 // Funnel shift-left.
1046 def FShl32i: OutPatFrag<(ops node:$Rs, node:$Rt, node:$S),
1047 (HiReg (S2_asl_i_p (Combinew $Rs, $Rt), $S))>;
1048 def FShl32r: OutPatFrag<(ops node:$Rs, node:$Rt, node:$Ru),
1049 (HiReg (S2_asl_r_p (Combinew $Rs, $Rt), $Ru))>;
1051 def FShl64i: OutPatFrag<(ops node:$Rs, node:$Rt, node:$S),
1052 (S2_lsr_i_p_or (S2_asl_i_p $Rt, $S), $Rs, (Subi<64> $S))>;
1053 def FShl64r: OutPatFrag<(ops node:$Rs, node:$Rt, node:$Ru),
1054 (S2_lsr_r_p_or (S2_asl_r_p $Rt, $Ru), $Rs, (A2_subri 64, $Ru))>;
1056 // Combined SDNodeXForm: (Divu8 (Subi<64> $S))
1057 def Divu64_8: SDNodeXForm<imm, [{
1058 return CurDAG->getTargetConstant((64 - N->getSExtValue()) / 8,
1059 SDLoc(N), MVT::i32);
1063 let AddedComplexity = 100 in {
1064 def: Pat<(fshl I32:$Rs, I32:$Rt, (i32 16)),
1065 (A2_combine_hl I32:$Rs, I32:$Rt)>;
1066 def: Pat<(fshl I64:$Rs, I64:$Rt, IsMul8_U3:$S),
1067 (S2_valignib I64:$Rs, I64:$Rt, (Divu64_8 $S))>;
1070 let Predicates = [HasV60], AddedComplexity = 50 in {
1071 def: OpR_RI_pat<S6_rol_i_r, Rol, i32, I32, u5_0ImmPred>;
1072 def: OpR_RI_pat<S6_rol_i_p, Rol, i64, I64, u6_0ImmPred>;
1074 let AddedComplexity = 30 in {
1075 def: Pat<(rotl I32:$Rs, u5_0ImmPred:$S), (FShl32i $Rs, $Rs, imm:$S)>;
1076 def: Pat<(rotl I64:$Rs, u6_0ImmPred:$S), (FShl64i $Rs, $Rs, imm:$S)>;
1077 def: Pat<(fshl I32:$Rs, I32:$Rt, u5_0ImmPred:$S), (FShl32i $Rs, $Rt, imm:$S)>;
1078 def: Pat<(fshl I64:$Rs, I64:$Rt, u6_0ImmPred:$S), (FShl64i $Rs, $Rt, imm:$S)>;
1080 def: Pat<(rotl I32:$Rs, I32:$Rt), (FShl32r $Rs, $Rs, $Rt)>;
1081 def: Pat<(rotl I64:$Rs, I32:$Rt), (FShl64r $Rs, $Rs, $Rt)>;
1082 def: Pat<(fshl I32:$Rs, I32:$Rt, I32:$Ru), (FShl32r $Rs, $Rt, $Ru)>;
1083 def: Pat<(fshl I64:$Rs, I64:$Rt, I32:$Ru), (FShl64r $Rs, $Rt, $Ru)>;
1085 // Funnel shift-right.
1086 def FShr32i: OutPatFrag<(ops node:$Rs, node:$Rt, node:$S),
1087 (LoReg (S2_lsr_i_p (Combinew $Rs, $Rt), $S))>;
1088 def FShr32r: OutPatFrag<(ops node:$Rs, node:$Rt, node:$Ru),
1089 (LoReg (S2_lsr_r_p (Combinew $Rs, $Rt), $Ru))>;
1091 def FShr64i: OutPatFrag<(ops node:$Rs, node:$Rt, node:$S),
1092 (S2_asl_i_p_or (S2_lsr_i_p $Rt, $S), $Rs, (Subi<64> $S))>;
1093 def FShr64r: OutPatFrag<(ops node:$Rs, node:$Rt, node:$Ru),
1094 (S2_asl_r_p_or (S2_lsr_r_p $Rt, $Ru), $Rs, (A2_subri 64, $Ru))>;
1097 let AddedComplexity = 100 in {
1098 def: Pat<(fshr I32:$Rs, I32:$Rt, (i32 16)),
1099 (A2_combine_hl I32:$Rs, I32:$Rt)>;
1100 def: Pat<(fshr I64:$Rs, I64:$Rt, IsMul8_U3:$S),
1101 (S2_valignib I64:$Rs, I64:$Rt, (Divu8 $S))>;
1104 let Predicates = [HasV60], AddedComplexity = 50 in {
1105 def: Pat<(rotr I32:$Rs, u5_0ImmPred:$S), (S6_rol_i_r I32:$Rs, (Subi<32> $S))>;
1106 def: Pat<(rotr I64:$Rs, u6_0ImmPred:$S), (S6_rol_i_p I64:$Rs, (Subi<64> $S))>;
1108 let AddedComplexity = 30 in {
1109 def: Pat<(rotr I32:$Rs, u5_0ImmPred:$S), (FShr32i $Rs, $Rs, imm:$S)>;
1110 def: Pat<(rotr I64:$Rs, u6_0ImmPred:$S), (FShr64i $Rs, $Rs, imm:$S)>;
1111 def: Pat<(fshr I32:$Rs, I32:$Rt, u5_0ImmPred:$S), (FShr32i $Rs, $Rt, imm:$S)>;
1112 def: Pat<(fshr I64:$Rs, I64:$Rt, u6_0ImmPred:$S), (FShr64i $Rs, $Rt, imm:$S)>;
1114 def: Pat<(rotr I32:$Rs, I32:$Rt), (FShr32r $Rs, $Rs, $Rt)>;
1115 def: Pat<(rotr I64:$Rs, I32:$Rt), (FShr64r $Rs, $Rs, $Rt)>;
1116 def: Pat<(fshr I32:$Rs, I32:$Rt, I32:$Ru), (FShr32r $Rs, $Rt, $Ru)>;
1117 def: Pat<(fshr I64:$Rs, I64:$Rt, I32:$Ru), (FShr64r $Rs, $Rt, $Ru)>;
1120 def: Pat<(sra (add (sra I32:$Rs, u5_0ImmPred:$u5), 1), (i32 1)),
1121 (S2_asr_i_r_rnd I32:$Rs, imm:$u5)>;
1122 def: Pat<(sra (add (sra I64:$Rs, u6_0ImmPred:$u6), 1), (i32 1)),
1123 (S2_asr_i_p_rnd I64:$Rs, imm:$u6)>;
1125 // Prefer S2_addasl_rrri over S2_asl_i_r_acc.
1126 let AddedComplexity = 120 in
1127 def: Pat<(add I32:$Rt, (shl I32:$Rs, u3_0ImmPred:$u3)),
1128 (S2_addasl_rrri IntRegs:$Rt, IntRegs:$Rs, imm:$u3)>;
1130 let AddedComplexity = 100 in {
1131 def: AccRRI_pat<S2_asr_i_r_acc, Add, Su<Sra>, I32, u5_0ImmPred>;
1132 def: AccRRI_pat<S2_asr_i_r_nac, Sub, Su<Sra>, I32, u5_0ImmPred>;
1133 def: AccRRI_pat<S2_asr_i_r_and, And, Su<Sra>, I32, u5_0ImmPred>;
1134 def: AccRRI_pat<S2_asr_i_r_or, Or, Su<Sra>, I32, u5_0ImmPred>;
1136 def: AccRRI_pat<S2_asr_i_p_acc, Add, Su<Sra>, I64, u6_0ImmPred>;
1137 def: AccRRI_pat<S2_asr_i_p_nac, Sub, Su<Sra>, I64, u6_0ImmPred>;
1138 def: AccRRI_pat<S2_asr_i_p_and, And, Su<Sra>, I64, u6_0ImmPred>;
1139 def: AccRRI_pat<S2_asr_i_p_or, Or, Su<Sra>, I64, u6_0ImmPred>;
1141 def: AccRRI_pat<S2_lsr_i_r_acc, Add, Su<Srl>, I32, u5_0ImmPred>;
1142 def: AccRRI_pat<S2_lsr_i_r_nac, Sub, Su<Srl>, I32, u5_0ImmPred>;
1143 def: AccRRI_pat<S2_lsr_i_r_and, And, Su<Srl>, I32, u5_0ImmPred>;
1144 def: AccRRI_pat<S2_lsr_i_r_or, Or, Su<Srl>, I32, u5_0ImmPred>;
1145 def: AccRRI_pat<S2_lsr_i_r_xacc, Xor, Su<Srl>, I32, u5_0ImmPred>;
1147 def: AccRRI_pat<S2_lsr_i_p_acc, Add, Su<Srl>, I64, u6_0ImmPred>;
1148 def: AccRRI_pat<S2_lsr_i_p_nac, Sub, Su<Srl>, I64, u6_0ImmPred>;
1149 def: AccRRI_pat<S2_lsr_i_p_and, And, Su<Srl>, I64, u6_0ImmPred>;
1150 def: AccRRI_pat<S2_lsr_i_p_or, Or, Su<Srl>, I64, u6_0ImmPred>;
1151 def: AccRRI_pat<S2_lsr_i_p_xacc, Xor, Su<Srl>, I64, u6_0ImmPred>;
1153 def: AccRRI_pat<S2_asl_i_r_acc, Add, Su<Shl>, I32, u5_0ImmPred>;
1154 def: AccRRI_pat<S2_asl_i_r_nac, Sub, Su<Shl>, I32, u5_0ImmPred>;
1155 def: AccRRI_pat<S2_asl_i_r_and, And, Su<Shl>, I32, u5_0ImmPred>;
1156 def: AccRRI_pat<S2_asl_i_r_or, Or, Su<Shl>, I32, u5_0ImmPred>;
1157 def: AccRRI_pat<S2_asl_i_r_xacc, Xor, Su<Shl>, I32, u5_0ImmPred>;
1159 def: AccRRI_pat<S2_asl_i_p_acc, Add, Su<Shl>, I64, u6_0ImmPred>;
1160 def: AccRRI_pat<S2_asl_i_p_nac, Sub, Su<Shl>, I64, u6_0ImmPred>;
1161 def: AccRRI_pat<S2_asl_i_p_and, And, Su<Shl>, I64, u6_0ImmPred>;
1162 def: AccRRI_pat<S2_asl_i_p_or, Or, Su<Shl>, I64, u6_0ImmPred>;
1163 def: AccRRI_pat<S2_asl_i_p_xacc, Xor, Su<Shl>, I64, u6_0ImmPred>;
1165 let Predicates = [HasV60] in {
1166 def: AccRRI_pat<S6_rol_i_r_acc, Add, Su<Rol>, I32, u5_0ImmPred>;
1167 def: AccRRI_pat<S6_rol_i_r_nac, Sub, Su<Rol>, I32, u5_0ImmPred>;
1168 def: AccRRI_pat<S6_rol_i_r_and, And, Su<Rol>, I32, u5_0ImmPred>;
1169 def: AccRRI_pat<S6_rol_i_r_or, Or, Su<Rol>, I32, u5_0ImmPred>;
1170 def: AccRRI_pat<S6_rol_i_r_xacc, Xor, Su<Rol>, I32, u5_0ImmPred>;
1172 def: AccRRI_pat<S6_rol_i_p_acc, Add, Su<Rol>, I64, u6_0ImmPred>;
1173 def: AccRRI_pat<S6_rol_i_p_nac, Sub, Su<Rol>, I64, u6_0ImmPred>;
1174 def: AccRRI_pat<S6_rol_i_p_and, And, Su<Rol>, I64, u6_0ImmPred>;
1175 def: AccRRI_pat<S6_rol_i_p_or, Or, Su<Rol>, I64, u6_0ImmPred>;
1176 def: AccRRI_pat<S6_rol_i_p_xacc, Xor, Su<Rol>, I64, u6_0ImmPred>;
1180 let AddedComplexity = 100 in {
1181 def: AccRRR_pat<S2_asr_r_r_acc, Add, Su<Sra>, I32, I32, I32>;
1182 def: AccRRR_pat<S2_asr_r_r_nac, Sub, Su<Sra>, I32, I32, I32>;
1183 def: AccRRR_pat<S2_asr_r_r_and, And, Su<Sra>, I32, I32, I32>;
1184 def: AccRRR_pat<S2_asr_r_r_or, Or, Su<Sra>, I32, I32, I32>;
1186 def: AccRRR_pat<S2_asr_r_p_acc, Add, Su<Sra>, I64, I64, I32>;
1187 def: AccRRR_pat<S2_asr_r_p_nac, Sub, Su<Sra>, I64, I64, I32>;
1188 def: AccRRR_pat<S2_asr_r_p_and, And, Su<Sra>, I64, I64, I32>;
1189 def: AccRRR_pat<S2_asr_r_p_or, Or, Su<Sra>, I64, I64, I32>;
1190 def: AccRRR_pat<S2_asr_r_p_xor, Xor, Su<Sra>, I64, I64, I32>;
1192 def: AccRRR_pat<S2_lsr_r_r_acc, Add, Su<Srl>, I32, I32, I32>;
1193 def: AccRRR_pat<S2_lsr_r_r_nac, Sub, Su<Srl>, I32, I32, I32>;
1194 def: AccRRR_pat<S2_lsr_r_r_and, And, Su<Srl>, I32, I32, I32>;
1195 def: AccRRR_pat<S2_lsr_r_r_or, Or, Su<Srl>, I32, I32, I32>;
1197 def: AccRRR_pat<S2_lsr_r_p_acc, Add, Su<Srl>, I64, I64, I32>;
1198 def: AccRRR_pat<S2_lsr_r_p_nac, Sub, Su<Srl>, I64, I64, I32>;
1199 def: AccRRR_pat<S2_lsr_r_p_and, And, Su<Srl>, I64, I64, I32>;
1200 def: AccRRR_pat<S2_lsr_r_p_or, Or, Su<Srl>, I64, I64, I32>;
1201 def: AccRRR_pat<S2_lsr_r_p_xor, Xor, Su<Srl>, I64, I64, I32>;
1203 def: AccRRR_pat<S2_asl_r_r_acc, Add, Su<Shl>, I32, I32, I32>;
1204 def: AccRRR_pat<S2_asl_r_r_nac, Sub, Su<Shl>, I32, I32, I32>;
1205 def: AccRRR_pat<S2_asl_r_r_and, And, Su<Shl>, I32, I32, I32>;
1206 def: AccRRR_pat<S2_asl_r_r_or, Or, Su<Shl>, I32, I32, I32>;
1208 def: AccRRR_pat<S2_asl_r_p_acc, Add, Su<Shl>, I64, I64, I32>;
1209 def: AccRRR_pat<S2_asl_r_p_nac, Sub, Su<Shl>, I64, I64, I32>;
1210 def: AccRRR_pat<S2_asl_r_p_and, And, Su<Shl>, I64, I64, I32>;
1211 def: AccRRR_pat<S2_asl_r_p_or, Or, Su<Shl>, I64, I64, I32>;
1212 def: AccRRR_pat<S2_asl_r_p_xor, Xor, Su<Shl>, I64, I64, I32>;
1216 class OpshIRI_pat<InstHexagon MI, PatFrag Op, PatFrag ShOp,
1217 PatFrag RegPred, PatFrag ImmPred>
1218 : Pat<(Op anyimm:$u8, (ShOp RegPred:$Rs, ImmPred:$U5)),
1219 (MI anyimm:$u8, RegPred:$Rs, imm:$U5)>;
1221 let AddedComplexity = 200 in {
1222 def: OpshIRI_pat<S4_addi_asl_ri, Add, Su<Shl>, I32, u5_0ImmPred>;
1223 def: OpshIRI_pat<S4_addi_lsr_ri, Add, Su<Srl>, I32, u5_0ImmPred>;
1224 def: OpshIRI_pat<S4_subi_asl_ri, Sub, Su<Shl>, I32, u5_0ImmPred>;
1225 def: OpshIRI_pat<S4_subi_lsr_ri, Sub, Su<Srl>, I32, u5_0ImmPred>;
1226 def: OpshIRI_pat<S4_andi_asl_ri, And, Su<Shl>, I32, u5_0ImmPred>;
1227 def: OpshIRI_pat<S4_andi_lsr_ri, And, Su<Srl>, I32, u5_0ImmPred>;
1228 def: OpshIRI_pat<S4_ori_asl_ri, Or, Su<Shl>, I32, u5_0ImmPred>;
1229 def: OpshIRI_pat<S4_ori_lsr_ri, Or, Su<Srl>, I32, u5_0ImmPred>;
1232 // Prefer this pattern to S2_asl_i_p_or for the special case of joining
1233 // two 32-bit words into a 64-bit word.
1234 let AddedComplexity = 200 in
1235 def: Pat<(or (shl (Aext64 I32:$a), (i32 32)), (Zext64 I32:$b)),
1236 (Combinew I32:$a, I32:$b)>;
1238 def: Pat<(or (or (or (shl (Zext64 (and I32:$b, (i32 65535))), (i32 16)),
1239 (Zext64 (and I32:$a, (i32 65535)))),
1240 (shl (Aext64 (and I32:$c, (i32 65535))), (i32 32))),
1241 (shl (Aext64 I32:$d), (i32 48))),
1242 (Combinew (A2_combine_ll I32:$d, I32:$c),
1243 (A2_combine_ll I32:$b, I32:$a))>;
1245 let AddedComplexity = 200 in {
1246 def: Pat<(or (shl I32:$Rt, (i32 16)), (and I32:$Rs, (i32 65535))),
1247 (A2_combine_ll I32:$Rt, I32:$Rs)>;
1248 def: Pat<(or (shl I32:$Rt, (i32 16)), (srl I32:$Rs, (i32 16))),
1249 (A2_combine_lh I32:$Rt, I32:$Rs)>;
1250 def: Pat<(or (and I32:$Rt, (i32 268431360)), (and I32:$Rs, (i32 65535))),
1251 (A2_combine_hl I32:$Rt, I32:$Rs)>;
1252 def: Pat<(or (and I32:$Rt, (i32 268431360)), (srl I32:$Rs, (i32 16))),
1253 (A2_combine_hh I32:$Rt, I32:$Rs)>;
1256 def SDTHexagonVShift
1257 : SDTypeProfile<1, 2, [SDTCisSameAs<0, 1>, SDTCisVec<0>, SDTCisVT<2, i32>]>;
1259 def HexagonVASL: SDNode<"HexagonISD::VASL", SDTHexagonVShift>;
1260 def HexagonVASR: SDNode<"HexagonISD::VASR", SDTHexagonVShift>;
1261 def HexagonVLSR: SDNode<"HexagonISD::VLSR", SDTHexagonVShift>;
1263 def: OpR_RI_pat<S2_asl_i_vw, pf2<HexagonVASL>, v2i32, V2I32, u5_0ImmPred>;
1264 def: OpR_RI_pat<S2_asl_i_vh, pf2<HexagonVASL>, v4i16, V4I16, u4_0ImmPred>;
1265 def: OpR_RI_pat<S2_asr_i_vw, pf2<HexagonVASR>, v2i32, V2I32, u5_0ImmPred>;
1266 def: OpR_RI_pat<S2_asr_i_vh, pf2<HexagonVASR>, v4i16, V4I16, u4_0ImmPred>;
1267 def: OpR_RI_pat<S2_lsr_i_vw, pf2<HexagonVLSR>, v2i32, V2I32, u5_0ImmPred>;
1268 def: OpR_RI_pat<S2_lsr_i_vh, pf2<HexagonVLSR>, v4i16, V4I16, u4_0ImmPred>;
1270 def: OpR_RR_pat<S2_asl_r_vw, pf2<HexagonVASL>, v2i32, V2I32, I32>;
1271 def: OpR_RR_pat<S2_asl_r_vh, pf2<HexagonVASL>, v4i16, V4I16, I32>;
1272 def: OpR_RR_pat<S2_asr_r_vw, pf2<HexagonVASR>, v2i32, V2I32, I32>;
1273 def: OpR_RR_pat<S2_asr_r_vh, pf2<HexagonVASR>, v4i16, V4I16, I32>;
1274 def: OpR_RR_pat<S2_lsr_r_vw, pf2<HexagonVLSR>, v2i32, V2I32, I32>;
1275 def: OpR_RR_pat<S2_lsr_r_vh, pf2<HexagonVLSR>, v4i16, V4I16, I32>;
1277 def: Pat<(sra V2I32:$b, (v2i32 (HexagonVSPLAT u5_0ImmPred:$c))),
1278 (S2_asr_i_vw V2I32:$b, imm:$c)>;
1279 def: Pat<(srl V2I32:$b, (v2i32 (HexagonVSPLAT u5_0ImmPred:$c))),
1280 (S2_lsr_i_vw V2I32:$b, imm:$c)>;
1281 def: Pat<(shl V2I32:$b, (v2i32 (HexagonVSPLAT u5_0ImmPred:$c))),
1282 (S2_asl_i_vw V2I32:$b, imm:$c)>;
1283 def: Pat<(sra V4I16:$b, (v4i16 (HexagonVSPLAT u4_0ImmPred:$c))),
1284 (S2_asr_i_vh V4I16:$b, imm:$c)>;
1285 def: Pat<(srl V4I16:$b, (v4i16 (HexagonVSPLAT u4_0ImmPred:$c))),
1286 (S2_lsr_i_vh V4I16:$b, imm:$c)>;
1287 def: Pat<(shl V4I16:$b, (v4i16 (HexagonVSPLAT u4_0ImmPred:$c))),
1288 (S2_asl_i_vh V4I16:$b, imm:$c)>;
1290 def: Pat<(HexagonVASR V2I16:$Rs, u4_0ImmPred:$S),
1291 (LoReg (S2_asr_i_vh (ToAext64 $Rs), imm:$S))>;
1292 def: Pat<(HexagonVASL V2I16:$Rs, u4_0ImmPred:$S),
1293 (LoReg (S2_asl_i_vh (ToAext64 $Rs), imm:$S))>;
1294 def: Pat<(HexagonVLSR V2I16:$Rs, u4_0ImmPred:$S),
1295 (LoReg (S2_lsr_i_vh (ToAext64 $Rs), imm:$S))>;
1296 def: Pat<(HexagonVASR V2I16:$Rs, I32:$Rt),
1297 (LoReg (S2_asr_i_vh (ToAext64 $Rs), I32:$Rt))>;
1298 def: Pat<(HexagonVASL V2I16:$Rs, I32:$Rt),
1299 (LoReg (S2_asl_i_vh (ToAext64 $Rs), I32:$Rt))>;
1300 def: Pat<(HexagonVLSR V2I16:$Rs, I32:$Rt),
1301 (LoReg (S2_lsr_i_vh (ToAext64 $Rs), I32:$Rt))>;
1304 // --(9) Arithmetic/bitwise ----------------------------------------------
1307 def: Pat<(abs I32:$Rs), (A2_abs I32:$Rs)>;
1308 def: Pat<(abs I64:$Rs), (A2_absp I64:$Rs)>;
1309 def: Pat<(not I32:$Rs), (A2_subri -1, I32:$Rs)>;
1310 def: Pat<(not I64:$Rs), (A2_notp I64:$Rs)>;
1311 def: Pat<(ineg I64:$Rs), (A2_negp I64:$Rs)>;
1313 def: Pat<(fabs F32:$Rs), (S2_clrbit_i F32:$Rs, 31)>;
1314 def: Pat<(fneg F32:$Rs), (S2_togglebit_i F32:$Rs, 31)>;
1316 def: Pat<(fabs F64:$Rs),
1317 (Combinew (S2_clrbit_i (HiReg $Rs), 31),
1318 (i32 (LoReg $Rs)))>;
1319 def: Pat<(fneg F64:$Rs),
1320 (Combinew (S2_togglebit_i (HiReg $Rs), 31),
1321 (i32 (LoReg $Rs)))>;
1323 def: Pat<(add I32:$Rs, anyimm:$s16), (A2_addi I32:$Rs, imm:$s16)>;
1324 def: Pat<(or I32:$Rs, anyimm:$s10), (A2_orir I32:$Rs, imm:$s10)>;
1325 def: Pat<(and I32:$Rs, anyimm:$s10), (A2_andir I32:$Rs, imm:$s10)>;
1326 def: Pat<(sub anyimm:$s10, I32:$Rs), (A2_subri imm:$s10, I32:$Rs)>;
1328 def: OpR_RR_pat<A2_add, Add, i32, I32>;
1329 def: OpR_RR_pat<A2_sub, Sub, i32, I32>;
1330 def: OpR_RR_pat<A2_and, And, i32, I32>;
1331 def: OpR_RR_pat<A2_or, Or, i32, I32>;
1332 def: OpR_RR_pat<A2_xor, Xor, i32, I32>;
1333 def: OpR_RR_pat<A2_addp, Add, i64, I64>;
1334 def: OpR_RR_pat<A2_subp, Sub, i64, I64>;
1335 def: OpR_RR_pat<A2_andp, And, i64, I64>;
1336 def: OpR_RR_pat<A2_orp, Or, i64, I64>;
1337 def: OpR_RR_pat<A2_xorp, Xor, i64, I64>;
1338 def: OpR_RR_pat<A4_andnp, Not2<And>, i64, I64>;
1339 def: OpR_RR_pat<A4_ornp, Not2<Or>, i64, I64>;
1341 def: OpR_RR_pat<A2_svaddh, Add, v2i16, V2I16>;
1342 def: OpR_RR_pat<A2_svsubh, Sub, v2i16, V2I16>;
1344 def: OpR_RR_pat<A2_vaddub, Add, v8i8, V8I8>;
1345 def: OpR_RR_pat<A2_vaddh, Add, v4i16, V4I16>;
1346 def: OpR_RR_pat<A2_vaddw, Add, v2i32, V2I32>;
1347 def: OpR_RR_pat<A2_vsubub, Sub, v8i8, V8I8>;
1348 def: OpR_RR_pat<A2_vsubh, Sub, v4i16, V4I16>;
1349 def: OpR_RR_pat<A2_vsubw, Sub, v2i32, V2I32>;
1351 def: OpR_RR_pat<A2_and, And, v4i8, V4I8>;
1352 def: OpR_RR_pat<A2_xor, Xor, v4i8, V4I8>;
1353 def: OpR_RR_pat<A2_or, Or, v4i8, V4I8>;
1354 def: OpR_RR_pat<A2_and, And, v2i16, V2I16>;
1355 def: OpR_RR_pat<A2_xor, Xor, v2i16, V2I16>;
1356 def: OpR_RR_pat<A2_or, Or, v2i16, V2I16>;
1357 def: OpR_RR_pat<A2_andp, And, v8i8, V8I8>;
1358 def: OpR_RR_pat<A2_orp, Or, v8i8, V8I8>;
1359 def: OpR_RR_pat<A2_xorp, Xor, v8i8, V8I8>;
1360 def: OpR_RR_pat<A2_andp, And, v4i16, V4I16>;
1361 def: OpR_RR_pat<A2_orp, Or, v4i16, V4I16>;
1362 def: OpR_RR_pat<A2_xorp, Xor, v4i16, V4I16>;
1363 def: OpR_RR_pat<A2_andp, And, v2i32, V2I32>;
1364 def: OpR_RR_pat<A2_orp, Or, v2i32, V2I32>;
1365 def: OpR_RR_pat<A2_xorp, Xor, v2i32, V2I32>;
1367 def: OpR_RR_pat<M2_mpyi, Mul, i32, I32>;
1368 def: OpR_RR_pat<M2_mpy_up, pf2<mulhs>, i32, I32>;
1369 def: OpR_RR_pat<M2_mpyu_up, pf2<mulhu>, i32, I32>;
1370 def: OpR_RI_pat<M2_mpysip, Mul, i32, I32, u32_0ImmPred>;
1371 def: OpR_RI_pat<M2_mpysmi, Mul, i32, I32, s32_0ImmPred>;
1373 // Arithmetic on predicates.
1374 def: OpR_RR_pat<C2_xor, Add, i1, I1>;
1375 def: OpR_RR_pat<C2_xor, Add, v2i1, V2I1>;
1376 def: OpR_RR_pat<C2_xor, Add, v4i1, V4I1>;
1377 def: OpR_RR_pat<C2_xor, Add, v8i1, V8I1>;
1378 def: OpR_RR_pat<C2_xor, Sub, i1, I1>;
1379 def: OpR_RR_pat<C2_xor, Sub, v2i1, V2I1>;
1380 def: OpR_RR_pat<C2_xor, Sub, v4i1, V4I1>;
1381 def: OpR_RR_pat<C2_xor, Sub, v8i1, V8I1>;
1382 def: OpR_RR_pat<C2_and, Mul, i1, I1>;
1383 def: OpR_RR_pat<C2_and, Mul, v2i1, V2I1>;
1384 def: OpR_RR_pat<C2_and, Mul, v4i1, V4I1>;
1385 def: OpR_RR_pat<C2_and, Mul, v8i1, V8I1>;
1387 def: OpR_RR_pat<F2_sfadd, pf2<fadd>, f32, F32>;
1388 def: OpR_RR_pat<F2_sfsub, pf2<fsub>, f32, F32>;
1389 def: OpR_RR_pat<F2_sfmpy, pf2<fmul>, f32, F32>;
1390 def: OpR_RR_pat<F2_sfmin, pf2<fminnum>, f32, F32>;
1391 def: OpR_RR_pat<F2_sfmax, pf2<fmaxnum>, f32, F32>;
1393 let Predicates = [HasV66] in {
1394 def: OpR_RR_pat<F2_dfadd, pf2<fadd>, f64, F64>;
1395 def: OpR_RR_pat<F2_dfsub, pf2<fsub>, f64, F64>;
1398 // In expressions like a0*b0 + a1*b1 + ..., prefer to generate multiply-add,
1399 // over add-add with individual multiplies as inputs.
1400 let AddedComplexity = 10 in {
1401 def: AccRRI_pat<M2_macsip, Add, Su<Mul>, I32, u32_0ImmPred>;
1402 def: AccRRI_pat<M2_macsin, Sub, Su<Mul>, I32, u32_0ImmPred>;
1403 def: AccRRR_pat<M2_maci, Add, Su<Mul>, I32, I32, I32>;
1404 let Predicates = [HasV66] in
1405 def: AccRRR_pat<M2_mnaci, Sub, Su<Mul>, I32, I32, I32>;
1408 def: AccRRI_pat<M2_naccii, Sub, Su<Add>, I32, s32_0ImmPred>;
1409 def: AccRRI_pat<M2_accii, Add, Su<Add>, I32, s32_0ImmPred>;
1410 def: AccRRR_pat<M2_acci, Add, Su<Add>, I32, I32, I32>;
1414 def: Pat<(v2i32 (mulhu V2I32:$Rss, V2I32:$Rtt)),
1415 (Combinew (M2_mpyu_up (HiReg $Rss), (HiReg $Rtt)),
1416 (M2_mpyu_up (LoReg $Rss), (LoReg $Rtt)))>;
1418 def: Pat<(v2i32 (mulhs V2I32:$Rs, V2I32:$Rt)),
1419 (Combinew (M2_mpy_up (HiReg $Rs), (HiReg $Rt)),
1420 (M2_mpy_up (LoReg $Rt), (LoReg $Rt)))>;
1423 OutPatFrag<(ops node:$Rss, node:$Rtt),
1424 (Combinew (S2_vtrunohb (M5_vmpybuu (HiReg $Rss), (HiReg $Rtt))),
1425 (S2_vtrunohb (M5_vmpybuu (LoReg $Rss), (LoReg $Rtt))))>;
1427 // Equivalent of byte-wise arithmetic shift right by 7 in v8i8.
1429 OutPatFrag<(ops node:$Rss), (C2_mask (C2_not (A4_vcmpbgti $Rss, 0)))>;
1431 def: Pat<(v8i8 (mulhu V8I8:$Rss, V8I8:$Rtt)),
1432 (Mulhub $Rss, $Rtt)>;
1434 def: Pat<(v8i8 (mulhs V8I8:$Rss, V8I8:$Rtt)),
1436 (Mulhub $Rss, $Rtt),
1437 (A2_vaddub (A2_andp V8I8:$Rss, (Asr7 $Rtt)),
1438 (A2_andp V8I8:$Rtt, (Asr7 $Rss))))>;
1441 OutPatFrag<(ops node:$Rs, node:$Rt), (M2_vmpy2s_s0 $Rs, $Rt)>;
1443 OutPatFrag<(ops node:$Rss, node:$Rtt), (Mpysh (HiReg $Rss), (HiReg $Rtt))>;
1445 OutPatFrag<(ops node:$Rss, node:$Rtt), (Mpysh (LoReg $Rss), (LoReg $Rtt))>;
1448 OutPatFrag<(ops node:$Rss, node:$Rtt),
1449 (Combinew (A2_combine_hh (HiReg (Mpyshh $Rss, $Rtt)),
1450 (LoReg (Mpyshh $Rss, $Rtt))),
1451 (A2_combine_hh (HiReg (Mpyshl $Rss, $Rtt)),
1452 (LoReg (Mpyshl $Rss, $Rtt))))>;
1454 def: Pat<(v4i16 (mulhs V4I16:$Rss, V4I16:$Rtt)), (Mulhsh $Rss, $Rtt)>;
1456 def: Pat<(v4i16 (mulhu V4I16:$Rss, V4I16:$Rtt)),
1458 (Mulhsh $Rss, $Rtt),
1459 (A2_vaddh (A2_andp V4I16:$Rss, (S2_asr_i_vh $Rtt, 15)),
1460 (A2_andp V4I16:$Rtt, (S2_asr_i_vh $Rss, 15))))>;
1463 def: Pat<(ineg (mul I32:$Rs, u8_0ImmPred:$u8)),
1464 (M2_mpysin IntRegs:$Rs, imm:$u8)>;
1466 def n8_0ImmPred: PatLeaf<(i32 imm), [{
1467 int64_t V = N->getSExtValue();
1468 return -255 <= V && V <= 0;
1471 // Change the sign of the immediate for Rd=-mpyi(Rs,#u8)
1472 def: Pat<(mul I32:$Rs, n8_0ImmPred:$n8),
1473 (M2_mpysin I32:$Rs, (NegImm8 imm:$n8))>;
1475 def: Pat<(add Sext64:$Rs, I64:$Rt),
1476 (A2_addsp (LoReg Sext64:$Rs), I64:$Rt)>;
1478 def: AccRRR_pat<M4_and_and, And, Su_ni1<And>, I32, I32, I32>;
1479 def: AccRRR_pat<M4_and_or, And, Su_ni1<Or>, I32, I32, I32>;
1480 def: AccRRR_pat<M4_and_xor, And, Su<Xor>, I32, I32, I32>;
1481 def: AccRRR_pat<M4_or_and, Or, Su_ni1<And>, I32, I32, I32>;
1482 def: AccRRR_pat<M4_or_or, Or, Su_ni1<Or>, I32, I32, I32>;
1483 def: AccRRR_pat<M4_or_xor, Or, Su<Xor>, I32, I32, I32>;
1484 def: AccRRR_pat<M4_xor_and, Xor, Su_ni1<And>, I32, I32, I32>;
1485 def: AccRRR_pat<M4_xor_or, Xor, Su_ni1<Or>, I32, I32, I32>;
1486 def: AccRRR_pat<M2_xor_xacc, Xor, Su<Xor>, I32, I32, I32>;
1487 def: AccRRR_pat<M4_xor_xacc, Xor, Su<Xor>, I64, I64, I64>;
1489 // For dags like (or (and (not _), _), (shl _, _)) where the "or" with
1490 // one argument matches the patterns below, and with the other argument
1491 // matches S2_asl_r_r_or, etc, prefer the patterns below.
1492 let AddedComplexity = 110 in { // greater than S2_asl_r_r_and/or/xor.
1493 def: AccRRR_pat<M4_and_andn, And, Su<Not2<And>>, I32, I32, I32>;
1494 def: AccRRR_pat<M4_or_andn, Or, Su<Not2<And>>, I32, I32, I32>;
1495 def: AccRRR_pat<M4_xor_andn, Xor, Su<Not2<And>>, I32, I32, I32>;
1498 // S4_addaddi and S4_subaddi don't have tied operands, so give them
1499 // a bit of preference.
1500 let AddedComplexity = 30 in {
1501 def: Pat<(add I32:$Rs, (Su<Add> I32:$Ru, anyimm:$s6)),
1502 (S4_addaddi IntRegs:$Rs, IntRegs:$Ru, imm:$s6)>;
1503 def: Pat<(add anyimm:$s6, (Su<Add> I32:$Rs, I32:$Ru)),
1504 (S4_addaddi IntRegs:$Rs, IntRegs:$Ru, imm:$s6)>;
1505 def: Pat<(add I32:$Rs, (Su<Sub> anyimm:$s6, I32:$Ru)),
1506 (S4_subaddi IntRegs:$Rs, imm:$s6, IntRegs:$Ru)>;
1507 def: Pat<(sub (Su<Add> I32:$Rs, anyimm:$s6), I32:$Ru),
1508 (S4_subaddi IntRegs:$Rs, imm:$s6, IntRegs:$Ru)>;
1509 def: Pat<(add (Su<Sub> I32:$Rs, I32:$Ru), anyimm:$s6),
1510 (S4_subaddi IntRegs:$Rs, imm:$s6, IntRegs:$Ru)>;
1513 def: Pat<(or I32:$Ru, (Su<And> I32:$Rx, anyimm:$s10)),
1514 (S4_or_andix IntRegs:$Ru, IntRegs:$Rx, imm:$s10)>;
1515 def: Pat<(or I32:$Rx, (Su<And> I32:$Rs, anyimm:$s10)),
1516 (S4_or_andi IntRegs:$Rx, IntRegs:$Rs, imm:$s10)>;
1517 def: Pat<(or I32:$Rx, (Su<Or> I32:$Rs, anyimm:$s10)),
1518 (S4_or_ori IntRegs:$Rx, IntRegs:$Rs, imm:$s10)>;
1521 def: Pat<(i32 (trunc (sra (Su<Mul> Sext64:$Rs, Sext64:$Rt), (i32 32)))),
1522 (M2_mpy_up (LoReg Sext64:$Rs), (LoReg Sext64:$Rt))>;
1523 def: Pat<(i32 (trunc (srl (Su<Mul> Sext64:$Rs, Sext64:$Rt), (i32 32)))),
1524 (M2_mpy_up (LoReg Sext64:$Rs), (LoReg Sext64:$Rt))>;
1526 def: Pat<(mul (Zext64 I32:$Rs), (Zext64 I32:$Rt)),
1527 (M2_dpmpyuu_s0 I32:$Rs, I32:$Rt)>;
1528 def: Pat<(mul (Aext64 I32:$Rs), (Aext64 I32:$Rt)),
1529 (M2_dpmpyuu_s0 I32:$Rs, I32:$Rt)>;
1530 def: Pat<(mul Sext64:$Rs, Sext64:$Rt),
1531 (M2_dpmpyss_s0 (LoReg Sext64:$Rs), (LoReg Sext64:$Rt))>;
1533 def: Pat<(add I64:$Rx, (Su<Mul> Sext64:$Rs, Sext64:$Rt)),
1534 (M2_dpmpyss_acc_s0 I64:$Rx, (LoReg Sext64:$Rs), (LoReg Sext64:$Rt))>;
1535 def: Pat<(sub I64:$Rx, (Su<Mul> Sext64:$Rs, Sext64:$Rt)),
1536 (M2_dpmpyss_nac_s0 I64:$Rx, (LoReg Sext64:$Rs), (LoReg Sext64:$Rt))>;
1537 def: Pat<(add I64:$Rx, (Su<Mul> (Aext64 I32:$Rs), (Aext64 I32:$Rt))),
1538 (M2_dpmpyuu_acc_s0 I64:$Rx, I32:$Rs, I32:$Rt)>;
1539 def: Pat<(add I64:$Rx, (Su<Mul> (Zext64 I32:$Rs), (Zext64 I32:$Rt))),
1540 (M2_dpmpyuu_acc_s0 I64:$Rx, I32:$Rs, I32:$Rt)>;
1541 def: Pat<(sub I64:$Rx, (Su<Mul> (Aext64 I32:$Rs), (Aext64 I32:$Rt))),
1542 (M2_dpmpyuu_nac_s0 I64:$Rx, I32:$Rs, I32:$Rt)>;
1543 def: Pat<(sub I64:$Rx, (Su<Mul> (Zext64 I32:$Rs), (Zext64 I32:$Rt))),
1544 (M2_dpmpyuu_nac_s0 I64:$Rx, I32:$Rs, I32:$Rt)>;
1547 def: Pat<(sext_inreg (add I32:$Rt, I32:$Rs), i16),
1548 (A2_addh_l16_ll I32:$Rt, I32:$Rs)>;
1549 def: Pat<(sra (add (shl I32:$Rt, (i32 16)), I32:$Rs), (i32 16)),
1550 (A2_addh_l16_hl I32:$Rt, I32:$Rs)>;
1551 def: Pat<(shl (add I32:$Rt, I32:$Rs), (i32 16)),
1552 (A2_addh_h16_ll I32:$Rt, I32:$Rs)>;
1554 // Subtract halfword.
1555 def: Pat<(sext_inreg (sub I32:$Rt, I32:$Rs), i16),
1556 (A2_subh_l16_ll I32:$Rt, I32:$Rs)>;
1557 def: Pat<(sra (add (shl I32:$Rt, (i32 16)), I32:$Rs), (i32 16)),
1558 (A2_addh_l16_hl I32:$Rt, I32:$Rs)>;
1559 def: Pat<(shl (sub I32:$Rt, I32:$Rs), (i32 16)),
1560 (A2_subh_h16_ll I32:$Rt, I32:$Rs)>;
1562 def: Pat<(mul I64:$Rss, I64:$Rtt),
1564 (M2_maci (M2_maci (HiReg (M2_dpmpyuu_s0 (LoReg $Rss), (LoReg $Rtt))),
1569 (i32 (LoReg (M2_dpmpyuu_s0 (LoReg $Rss), (LoReg $Rtt)))))>;
1571 def MulHU : OutPatFrag<(ops node:$Rss, node:$Rtt),
1577 (S2_lsr_i_p (M2_dpmpyuu_s0 (LoReg $Rss), (LoReg $Rtt)), 32),
1580 (A4_combineir 0, (LoReg (M2_dpmpyuu_s0 (LoReg $Rss), (HiReg $Rtt))))),
1584 (S2_lsr_i_p (M2_dpmpyuu_s0 (LoReg $Rss), (HiReg $Rtt)), 32))>;
1586 // Multiply 64-bit unsigned and use upper result.
1587 def : Pat <(mulhu I64:$Rss, I64:$Rtt), (MulHU $Rss, $Rtt)>;
1589 // Multiply 64-bit signed and use upper result.
1591 // For two signed 64-bit integers A and B, let A' and B' denote A and B
1592 // with the sign bit cleared. Then A = -2^63*s(A) + A', where s(A) is the
1593 // sign bit of A (and identically for B). With this notation, the signed
1594 // product A*B can be written as:
1595 // AB = (-2^63 s(A) + A') * (-2^63 s(B) + B')
1596 // = 2^126 s(A)s(B) - 2^63 [s(A)B'+s(B)A'] + A'B'
1597 // = 2^126 s(A)s(B) + 2^63 [s(A)B'+s(B)A'] + A'B' - 2*2^63 [s(A)B'+s(B)A']
1598 // = (unsigned product AB) - 2^64 [s(A)B'+s(B)A']
1600 // Clear the sign bit in a 64-bit register.
1601 def ClearSign : OutPatFrag<(ops node:$Rss),
1602 (Combinew (S2_clrbit_i (HiReg $Rss), 31), (i32 (LoReg $Rss)))>;
1604 def : Pat <(mulhs I64:$Rss, I64:$Rtt),
1608 (A2_andp (S2_asr_i_p $Rss, 63), (ClearSign $Rtt)),
1609 (A2_andp (S2_asr_i_p $Rtt, 63), (ClearSign $Rss))))>;
1611 // Prefer these instructions over M2_macsip/M2_macsin: the macsi* instructions
1612 // will put the immediate addend into a register, while these instructions will
1613 // use it directly. Such a construct does not appear in the middle of a gep,
1614 // where M2_macsip would be preferable.
1615 let AddedComplexity = 20 in {
1616 def: Pat<(add (Su<Mul> I32:$Rs, u6_0ImmPred:$U6), anyimm:$u6),
1617 (M4_mpyri_addi imm:$u6, IntRegs:$Rs, imm:$U6)>;
1618 def: Pat<(add (Su<Mul> I32:$Rs, I32:$Rt), anyimm:$u6),
1619 (M4_mpyrr_addi imm:$u6, IntRegs:$Rs, IntRegs:$Rt)>;
1622 // Keep these instructions less preferable to M2_macsip/M2_macsin.
1623 def: Pat<(add I32:$Ru, (Su<Mul> I32:$Rs, u6_2ImmPred:$u6_2)),
1624 (M4_mpyri_addr_u2 IntRegs:$Ru, imm:$u6_2, IntRegs:$Rs)>;
1625 def: Pat<(add I32:$Ru, (Su<Mul> I32:$Rs, anyimm:$u6)),
1626 (M4_mpyri_addr IntRegs:$Ru, IntRegs:$Rs, imm:$u6)>;
1627 def: Pat<(add I32:$Ru, (Su<Mul> I32:$Ry, I32:$Rs)),
1628 (M4_mpyrr_addr IntRegs:$Ru, IntRegs:$Ry, IntRegs:$Rs)>;
1631 def: Pat<(fma F32:$Rs, F32:$Rt, F32:$Rx),
1632 (F2_sffma F32:$Rx, F32:$Rs, F32:$Rt)>;
1633 def: Pat<(fma (fneg F32:$Rs), F32:$Rt, F32:$Rx),
1634 (F2_sffms F32:$Rx, F32:$Rs, F32:$Rt)>;
1635 def: Pat<(fma F32:$Rs, (fneg F32:$Rt), F32:$Rx),
1636 (F2_sffms F32:$Rx, F32:$Rs, F32:$Rt)>;
1639 def: Pat<(mul V2I32:$Rs, V2I32:$Rt),
1640 (PS_vmulw V2I32:$Rs, V2I32:$Rt)>;
1641 def: Pat<(add V2I32:$Rx, (mul V2I32:$Rs, V2I32:$Rt)),
1642 (PS_vmulw_acc V2I32:$Rx, V2I32:$Rs, V2I32:$Rt)>;
1644 // Add/subtract two v4i8: Hexagon does not have an insn for this one, so
1645 // we use the double add v8i8, and use only the low part of the result.
1646 def: Pat<(add V4I8:$Rs, V4I8:$Rt),
1647 (LoReg (A2_vaddub (ToAext64 $Rs), (ToAext64 $Rt)))>;
1648 def: Pat<(sub V4I8:$Rs, V4I8:$Rt),
1649 (LoReg (A2_vsubub (ToAext64 $Rs), (ToAext64 $Rt)))>;
1651 // Use M2_vmpy2s_s0 for half-word vector multiply. It multiplies two
1652 // half-words, and saturates the result to a 32-bit value, except the
1653 // saturation never happens (it can only occur with scaling).
1654 def: Pat<(v2i16 (mul V2I16:$Rs, V2I16:$Rt)),
1655 (LoReg (S2_vtrunewh (A2_combineii 0, 0),
1656 (M2_vmpy2s_s0 V2I16:$Rs, V2I16:$Rt)))>;
1657 def: Pat<(v4i16 (mul V4I16:$Rs, V4I16:$Rt)),
1658 (S2_vtrunewh (M2_vmpy2s_s0 (HiReg $Rs), (HiReg $Rt)),
1659 (M2_vmpy2s_s0 (LoReg $Rs), (LoReg $Rt)))>;
1661 // Multiplies two v4i8 vectors.
1662 def: Pat<(v4i8 (mul V4I8:$Rs, V4I8:$Rt)),
1663 (S2_vtrunehb (M5_vmpybuu V4I8:$Rs, V4I8:$Rt))>;
1665 // Multiplies two v8i8 vectors.
1666 def: Pat<(v8i8 (mul V8I8:$Rs, V8I8:$Rt)),
1667 (Combinew (S2_vtrunehb (M5_vmpybuu (HiReg $Rs), (HiReg $Rt))),
1668 (S2_vtrunehb (M5_vmpybuu (LoReg $Rs), (LoReg $Rt))))>;
1671 // --(10) Bit ------------------------------------------------------------
1674 // Count leading zeros.
1675 def: Pat<(ctlz I32:$Rs), (S2_cl0 I32:$Rs)>;
1676 def: Pat<(i32 (trunc (ctlz I64:$Rss))), (S2_cl0p I64:$Rss)>;
1678 // Count trailing zeros.
1679 def: Pat<(cttz I32:$Rs), (S2_ct0 I32:$Rs)>;
1680 def: Pat<(i32 (trunc (cttz I64:$Rss))), (S2_ct0p I64:$Rss)>;
1682 // Count leading ones.
1683 def: Pat<(ctlz (not I32:$Rs)), (S2_cl1 I32:$Rs)>;
1684 def: Pat<(i32 (trunc (ctlz (not I64:$Rss)))), (S2_cl1p I64:$Rss)>;
1686 // Count trailing ones.
1687 def: Pat<(cttz (not I32:$Rs)), (S2_ct1 I32:$Rs)>;
1688 def: Pat<(i32 (trunc (cttz (not I64:$Rss)))), (S2_ct1p I64:$Rss)>;
1690 // Define leading/trailing patterns that require zero-extensions to 64 bits.
1691 def: Pat<(i64 (ctlz I64:$Rss)), (ToZext64 (S2_cl0p I64:$Rss))>;
1692 def: Pat<(i64 (cttz I64:$Rss)), (ToZext64 (S2_ct0p I64:$Rss))>;
1693 def: Pat<(i64 (ctlz (not I64:$Rss))), (ToZext64 (S2_cl1p I64:$Rss))>;
1694 def: Pat<(i64 (cttz (not I64:$Rss))), (ToZext64 (S2_ct1p I64:$Rss))>;
1696 def: Pat<(i64 (ctpop I64:$Rss)), (ToZext64 (S5_popcountp I64:$Rss))>;
1697 def: Pat<(i32 (ctpop I32:$Rs)), (S5_popcountp (A4_combineir 0, I32:$Rs))>;
1699 def: Pat<(bitreverse I32:$Rs), (S2_brev I32:$Rs)>;
1700 def: Pat<(bitreverse I64:$Rss), (S2_brevp I64:$Rss)>;
1702 let AddedComplexity = 20 in { // Complexity greater than and/or/xor
1703 def: Pat<(and I32:$Rs, IsNPow2_32:$V),
1704 (S2_clrbit_i IntRegs:$Rs, (LogN2_32 $V))>;
1705 def: Pat<(or I32:$Rs, IsPow2_32:$V),
1706 (S2_setbit_i IntRegs:$Rs, (Log2_32 $V))>;
1707 def: Pat<(xor I32:$Rs, IsPow2_32:$V),
1708 (S2_togglebit_i IntRegs:$Rs, (Log2_32 $V))>;
1710 def: Pat<(and I32:$Rs, (not (shl 1, I32:$Rt))),
1711 (S2_clrbit_r IntRegs:$Rs, IntRegs:$Rt)>;
1712 def: Pat<(or I32:$Rs, (shl 1, I32:$Rt)),
1713 (S2_setbit_r IntRegs:$Rs, IntRegs:$Rt)>;
1714 def: Pat<(xor I32:$Rs, (shl 1, I32:$Rt)),
1715 (S2_togglebit_r IntRegs:$Rs, IntRegs:$Rt)>;
1718 // Clr/set/toggle bit for 64-bit values with immediate bit index.
1719 let AddedComplexity = 20 in { // Complexity greater than and/or/xor
1720 def: Pat<(and I64:$Rss, IsNPow2_64L:$V),
1721 (Combinew (i32 (HiReg $Rss)),
1722 (S2_clrbit_i (LoReg $Rss), (LogN2_64 $V)))>;
1723 def: Pat<(and I64:$Rss, IsNPow2_64H:$V),
1724 (Combinew (S2_clrbit_i (HiReg $Rss), (UDEC32 (i32 (LogN2_64 $V)))),
1725 (i32 (LoReg $Rss)))>;
1727 def: Pat<(or I64:$Rss, IsPow2_64L:$V),
1728 (Combinew (i32 (HiReg $Rss)),
1729 (S2_setbit_i (LoReg $Rss), (Log2_64 $V)))>;
1730 def: Pat<(or I64:$Rss, IsPow2_64H:$V),
1731 (Combinew (S2_setbit_i (HiReg $Rss), (UDEC32 (i32 (Log2_64 $V)))),
1732 (i32 (LoReg $Rss)))>;
1734 def: Pat<(xor I64:$Rss, IsPow2_64L:$V),
1735 (Combinew (i32 (HiReg $Rss)),
1736 (S2_togglebit_i (LoReg $Rss), (Log2_64 $V)))>;
1737 def: Pat<(xor I64:$Rss, IsPow2_64H:$V),
1738 (Combinew (S2_togglebit_i (HiReg $Rss), (UDEC32 (i32 (Log2_64 $V)))),
1739 (i32 (LoReg $Rss)))>;
1742 let AddedComplexity = 20 in { // Complexity greater than cmp reg-imm.
1743 def: Pat<(i1 (setne (and (shl 1, u5_0ImmPred:$u5), I32:$Rs), 0)),
1744 (S2_tstbit_i IntRegs:$Rs, imm:$u5)>;
1745 def: Pat<(i1 (setne (and (shl 1, I32:$Rt), I32:$Rs), 0)),
1746 (S2_tstbit_r IntRegs:$Rs, IntRegs:$Rt)>;
1747 def: Pat<(i1 (trunc I32:$Rs)),
1748 (S2_tstbit_i IntRegs:$Rs, 0)>;
1749 def: Pat<(i1 (trunc I64:$Rs)),
1750 (S2_tstbit_i (LoReg DoubleRegs:$Rs), 0)>;
1753 let AddedComplexity = 20 in { // Complexity greater than compare reg-imm.
1754 def: Pat<(i1 (seteq (and I32:$Rs, u6_0ImmPred:$u6), 0)),
1755 (C2_bitsclri IntRegs:$Rs, imm:$u6)>;
1756 def: Pat<(i1 (seteq (and I32:$Rs, I32:$Rt), 0)),
1757 (C2_bitsclr IntRegs:$Rs, IntRegs:$Rt)>;
1760 let AddedComplexity = 10 in // Complexity greater than compare reg-reg.
1761 def: Pat<(i1 (seteq (and I32:$Rs, I32:$Rt), IntRegs:$Rt)),
1762 (C2_bitsset IntRegs:$Rs, IntRegs:$Rt)>;
1765 SDTypeProfile<1, 2, [SDTCisVT<0, i1>, SDTCisVT<1, i32>, SDTCisVT<2, i32>]>;
1766 def HexagonTSTBIT: SDNode<"HexagonISD::TSTBIT", SDTTestBit>;
1768 def: Pat<(HexagonTSTBIT I32:$Rs, u5_0ImmPred:$u5),
1769 (S2_tstbit_i I32:$Rs, imm:$u5)>;
1770 def: Pat<(HexagonTSTBIT I32:$Rs, I32:$Rt),
1771 (S2_tstbit_r I32:$Rs, I32:$Rt)>;
1773 let AddedComplexity = 20 in { // Complexity greater than cmp reg-imm.
1774 def: Pat<(i1 (seteq (and (shl 1, u5_0ImmPred:$u5), I32:$Rs), 0)),
1775 (S4_ntstbit_i I32:$Rs, imm:$u5)>;
1776 def: Pat<(i1 (seteq (and (shl 1, I32:$Rt), I32:$Rs), 0)),
1777 (S4_ntstbit_r I32:$Rs, I32:$Rt)>;
1780 // Add extra complexity to prefer these instructions over bitsset/bitsclr.
1781 // The reason is that tstbit/ntstbit can be folded into a compound instruction:
1782 // if ([!]tstbit(...)) jump ...
1783 let AddedComplexity = 100 in
1784 def: Pat<(i1 (setne (and I32:$Rs, (i32 IsPow2_32:$u5)), (i32 0))),
1785 (S2_tstbit_i I32:$Rs, (Log2_32 imm:$u5))>;
1787 let AddedComplexity = 100 in
1788 def: Pat<(i1 (seteq (and I32:$Rs, (i32 IsPow2_32:$u5)), (i32 0))),
1789 (S4_ntstbit_i I32:$Rs, (Log2_32 imm:$u5))>;
1791 // Do not increase complexity of these patterns. In the DAG, "cmp i8" may be
1792 // represented as a compare against "value & 0xFF", which is an exact match
1793 // for cmpb (same for cmph). The patterns below do not contain any additional
1794 // complexity that would make them preferable, and if they were actually used
1795 // instead of cmpb/cmph, they would result in a compare against register that
1796 // is loaded with the byte/half mask (i.e. 0xFF or 0xFFFF).
1797 def: Pat<(i1 (setne (and I32:$Rs, u6_0ImmPred:$u6), 0)),
1798 (C4_nbitsclri I32:$Rs, imm:$u6)>;
1799 def: Pat<(i1 (setne (and I32:$Rs, I32:$Rt), 0)),
1800 (C4_nbitsclr I32:$Rs, I32:$Rt)>;
1801 def: Pat<(i1 (setne (and I32:$Rs, I32:$Rt), I32:$Rt)),
1802 (C4_nbitsset I32:$Rs, I32:$Rt)>;
1804 // Special patterns to address certain cases where the "top-down" matching
1805 // algorithm would cause suboptimal selection.
1807 let AddedComplexity = 100 in {
1808 // Avoid A4_rcmp[n]eqi in these cases:
1809 def: Pat<(i32 (zext (i1 (setne (and (shl 1, I32:$Rt), I32:$Rs), 0)))),
1810 (I1toI32 (S2_tstbit_r IntRegs:$Rs, IntRegs:$Rt))>;
1811 def: Pat<(i32 (zext (i1 (seteq (and (shl 1, I32:$Rt), I32:$Rs), 0)))),
1812 (I1toI32 (S4_ntstbit_r IntRegs:$Rs, IntRegs:$Rt))>;
1815 // --(11) PIC ------------------------------------------------------------
1818 def SDT_HexagonAtGot
1819 : SDTypeProfile<1, 3, [SDTCisVT<0, i32>, SDTCisVT<1, i32>, SDTCisVT<2, i32>]>;
1820 def SDT_HexagonAtPcrel
1821 : SDTypeProfile<1, 1, [SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
1823 // AT_GOT address-of-GOT, address-of-global, offset-in-global
1824 def HexagonAtGot : SDNode<"HexagonISD::AT_GOT", SDT_HexagonAtGot>;
1825 // AT_PCREL address-of-global
1826 def HexagonAtPcrel : SDNode<"HexagonISD::AT_PCREL", SDT_HexagonAtPcrel>;
1828 def: Pat<(HexagonAtGot I32:$got, I32:$addr, (i32 0)),
1829 (L2_loadri_io I32:$got, imm:$addr)>;
1830 def: Pat<(HexagonAtGot I32:$got, I32:$addr, s30_2ImmPred:$off),
1831 (A2_addi (L2_loadri_io I32:$got, imm:$addr), imm:$off)>;
1832 def: Pat<(HexagonAtPcrel I32:$addr),
1833 (C4_addipc imm:$addr)>;
1835 // The HVX load patterns also match AT_PCREL directly. Make sure that
1836 // if the selection of this opcode changes, it's updated in all places.
1839 // --(12) Load -----------------------------------------------------------
1842 def extloadv2i8: PatFrag<(ops node:$ptr), (extload node:$ptr), [{
1843 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::v2i8;
1845 def extloadv4i8: PatFrag<(ops node:$ptr), (extload node:$ptr), [{
1846 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::v4i8;
1849 def zextloadv2i8: PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
1850 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::v2i8;
1852 def zextloadv4i8: PatFrag<(ops node:$ptr), (zextload node:$ptr), [{
1853 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::v4i8;
1856 def sextloadv2i8: PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
1857 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::v2i8;
1859 def sextloadv4i8: PatFrag<(ops node:$ptr), (sextload node:$ptr), [{
1860 return cast<LoadSDNode>(N)->getMemoryVT() == MVT::v4i8;
1863 // Patterns to select load-indexed: Rs + Off.
1864 // - frameindex [+ imm],
1865 multiclass Loadxfi_pat<PatFrag Load, ValueType VT, PatLeaf ImmPred,
1867 def: Pat<(VT (Load (add (i32 AddrFI:$fi), ImmPred:$Off))),
1868 (VT (MI AddrFI:$fi, imm:$Off))>;
1869 def: Pat<(VT (Load (IsOrAdd (i32 AddrFI:$fi), ImmPred:$Off))),
1870 (VT (MI AddrFI:$fi, imm:$Off))>;
1871 def: Pat<(VT (Load AddrFI:$fi)), (VT (MI AddrFI:$fi, 0))>;
1874 // Patterns to select load-indexed: Rs + Off.
1875 // - base reg [+ imm]
1876 multiclass Loadxgi_pat<PatFrag Load, ValueType VT, PatLeaf ImmPred,
1878 def: Pat<(VT (Load (add I32:$Rs, ImmPred:$Off))),
1879 (VT (MI IntRegs:$Rs, imm:$Off))>;
1880 def: Pat<(VT (Load (IsOrAdd I32:$Rs, ImmPred:$Off))),
1881 (VT (MI IntRegs:$Rs, imm:$Off))>;
1882 def: Pat<(VT (Load I32:$Rs)), (VT (MI IntRegs:$Rs, 0))>;
1885 // Patterns to select load-indexed: Rs + Off. Combines Loadxfi + Loadxgi.
1886 multiclass Loadxi_pat<PatFrag Load, ValueType VT, PatLeaf ImmPred,
1888 defm: Loadxfi_pat<Load, VT, ImmPred, MI>;
1889 defm: Loadxgi_pat<Load, VT, ImmPred, MI>;
1892 // Patterns to select load reg indexed: Rs + Off with a value modifier.
1893 // - frameindex [+ imm]
1894 multiclass Loadxfim_pat<PatFrag Load, ValueType VT, PatFrag ValueMod,
1895 PatLeaf ImmPred, InstHexagon MI> {
1896 def: Pat<(VT (Load (add (i32 AddrFI:$fi), ImmPred:$Off))),
1897 (VT (ValueMod (MI AddrFI:$fi, imm:$Off)))>;
1898 def: Pat<(VT (Load (IsOrAdd (i32 AddrFI:$fi), ImmPred:$Off))),
1899 (VT (ValueMod (MI AddrFI:$fi, imm:$Off)))>;
1900 def: Pat<(VT (Load AddrFI:$fi)), (VT (ValueMod (MI AddrFI:$fi, 0)))>;
1903 // Patterns to select load reg indexed: Rs + Off with a value modifier.
1904 // - base reg [+ imm]
1905 multiclass Loadxgim_pat<PatFrag Load, ValueType VT, PatFrag ValueMod,
1906 PatLeaf ImmPred, InstHexagon MI> {
1907 def: Pat<(VT (Load (add I32:$Rs, ImmPred:$Off))),
1908 (VT (ValueMod (MI IntRegs:$Rs, imm:$Off)))>;
1909 def: Pat<(VT (Load (IsOrAdd I32:$Rs, ImmPred:$Off))),
1910 (VT (ValueMod (MI IntRegs:$Rs, imm:$Off)))>;
1911 def: Pat<(VT (Load I32:$Rs)), (VT (ValueMod (MI IntRegs:$Rs, 0)))>;
1914 // Patterns to select load reg indexed: Rs + Off with a value modifier.
1915 // Combines Loadxfim + Loadxgim.
1916 multiclass Loadxim_pat<PatFrag Load, ValueType VT, PatFrag ValueMod,
1917 PatLeaf ImmPred, InstHexagon MI> {
1918 defm: Loadxfim_pat<Load, VT, ValueMod, ImmPred, MI>;
1919 defm: Loadxgim_pat<Load, VT, ValueMod, ImmPred, MI>;
1922 // Pattern to select load reg reg-indexed: Rs + Rt<<u2.
1923 class Loadxr_shl_pat<PatFrag Load, ValueType VT, InstHexagon MI>
1924 : Pat<(VT (Load (add I32:$Rs, (i32 (shl I32:$Rt, u2_0ImmPred:$u2))))),
1925 (VT (MI IntRegs:$Rs, IntRegs:$Rt, imm:$u2))>;
1927 // Pattern to select load reg reg-indexed: Rs + Rt<<0.
1928 class Loadxr_add_pat<PatFrag Load, ValueType VT, InstHexagon MI>
1929 : Pat<(VT (Load (add I32:$Rs, I32:$Rt))),
1930 (VT (MI IntRegs:$Rs, IntRegs:$Rt, 0))>;
1932 // Pattern to select load reg reg-indexed: Rs + Rt<<u2 with value modifier.
1933 class Loadxrm_shl_pat<PatFrag Load, ValueType VT, PatFrag ValueMod,
1935 : Pat<(VT (Load (add I32:$Rs, (i32 (shl I32:$Rt, u2_0ImmPred:$u2))))),
1936 (VT (ValueMod (MI IntRegs:$Rs, IntRegs:$Rt, imm:$u2)))>;
1938 // Pattern to select load reg reg-indexed: Rs + Rt<<0 with value modifier.
1939 class Loadxrm_add_pat<PatFrag Load, ValueType VT, PatFrag ValueMod,
1941 : Pat<(VT (Load (add I32:$Rs, I32:$Rt))),
1942 (VT (ValueMod (MI IntRegs:$Rs, IntRegs:$Rt, 0)))>;
1944 // Pattern to select load long-offset reg-indexed: Addr + Rt<<u2.
1945 // Don't match for u2==0, instead use reg+imm for those cases.
1946 class Loadxu_pat<PatFrag Load, ValueType VT, PatFrag ImmPred, InstHexagon MI>
1947 : Pat<(VT (Load (add (shl IntRegs:$Rt, u2_0ImmPred:$u2), ImmPred:$Addr))),
1948 (VT (MI IntRegs:$Rt, imm:$u2, ImmPred:$Addr))>;
1950 class Loadxum_pat<PatFrag Load, ValueType VT, PatFrag ImmPred, PatFrag ValueMod,
1952 : Pat<(VT (Load (add (shl IntRegs:$Rt, u2_0ImmPred:$u2), ImmPred:$Addr))),
1953 (VT (ValueMod (MI IntRegs:$Rt, imm:$u2, ImmPred:$Addr)))>;
1955 // Pattern to select load absolute.
1956 class Loada_pat<PatFrag Load, ValueType VT, PatFrag Addr, InstHexagon MI>
1957 : Pat<(VT (Load Addr:$addr)), (MI Addr:$addr)>;
1959 // Pattern to select load absolute with value modifier.
1960 class Loadam_pat<PatFrag Load, ValueType VT, PatFrag Addr, PatFrag ValueMod,
1962 : Pat<(VT (Load Addr:$addr)), (ValueMod (MI Addr:$addr))>;
1965 let AddedComplexity = 20 in {
1966 defm: Loadxi_pat<extloadi1, i32, anyimm0, L2_loadrub_io>;
1967 defm: Loadxi_pat<extloadi8, i32, anyimm0, L2_loadrub_io>;
1968 defm: Loadxi_pat<extloadi16, i32, anyimm1, L2_loadruh_io>;
1969 defm: Loadxi_pat<extloadv2i8, v2i16, anyimm1, L2_loadbzw2_io>;
1970 defm: Loadxi_pat<extloadv4i8, v4i16, anyimm2, L2_loadbzw4_io>;
1971 defm: Loadxi_pat<sextloadi8, i32, anyimm0, L2_loadrb_io>;
1972 defm: Loadxi_pat<sextloadi16, i32, anyimm1, L2_loadrh_io>;
1973 defm: Loadxi_pat<sextloadv2i8, v2i16, anyimm1, L2_loadbsw2_io>;
1974 defm: Loadxi_pat<sextloadv4i8, v4i16, anyimm2, L2_loadbzw4_io>;
1975 defm: Loadxi_pat<zextloadi1, i32, anyimm0, L2_loadrub_io>;
1976 defm: Loadxi_pat<zextloadi8, i32, anyimm0, L2_loadrub_io>;
1977 defm: Loadxi_pat<zextloadi16, i32, anyimm1, L2_loadruh_io>;
1978 defm: Loadxi_pat<zextloadv2i8, v2i16, anyimm1, L2_loadbzw2_io>;
1979 defm: Loadxi_pat<zextloadv4i8, v4i16, anyimm2, L2_loadbzw4_io>;
1980 defm: Loadxi_pat<load, i32, anyimm2, L2_loadri_io>;
1981 defm: Loadxi_pat<load, v2i16, anyimm2, L2_loadri_io>;
1982 defm: Loadxi_pat<load, v4i8, anyimm2, L2_loadri_io>;
1983 defm: Loadxi_pat<load, i64, anyimm3, L2_loadrd_io>;
1984 defm: Loadxi_pat<load, v2i32, anyimm3, L2_loadrd_io>;
1985 defm: Loadxi_pat<load, v4i16, anyimm3, L2_loadrd_io>;
1986 defm: Loadxi_pat<load, v8i8, anyimm3, L2_loadrd_io>;
1987 defm: Loadxi_pat<load, f32, anyimm2, L2_loadri_io>;
1988 defm: Loadxi_pat<load, f64, anyimm3, L2_loadrd_io>;
1991 defm: Loadxi_pat<atomic_load_8 , i32, anyimm0, L2_loadrub_io>;
1992 defm: Loadxi_pat<atomic_load_16, i32, anyimm1, L2_loadruh_io>;
1993 defm: Loadxi_pat<atomic_load_32, i32, anyimm2, L2_loadri_io>;
1994 defm: Loadxi_pat<atomic_load_64, i64, anyimm3, L2_loadrd_io>;
1997 let AddedComplexity = 30 in {
1998 defm: Loadxim_pat<extloadi1, i64, ToAext64, anyimm0, L2_loadrub_io>;
1999 defm: Loadxim_pat<extloadi8, i64, ToAext64, anyimm0, L2_loadrub_io>;
2000 defm: Loadxim_pat<extloadi16, i64, ToAext64, anyimm1, L2_loadruh_io>;
2001 defm: Loadxim_pat<extloadi32, i64, ToAext64, anyimm2, L2_loadri_io>;
2002 defm: Loadxim_pat<zextloadi1, i64, ToZext64, anyimm0, L2_loadrub_io>;
2003 defm: Loadxim_pat<zextloadi8, i64, ToZext64, anyimm0, L2_loadrub_io>;
2004 defm: Loadxim_pat<zextloadi16, i64, ToZext64, anyimm1, L2_loadruh_io>;
2005 defm: Loadxim_pat<zextloadi32, i64, ToZext64, anyimm2, L2_loadri_io>;
2006 defm: Loadxim_pat<sextloadi8, i64, ToSext64, anyimm0, L2_loadrb_io>;
2007 defm: Loadxim_pat<sextloadi16, i64, ToSext64, anyimm1, L2_loadrh_io>;
2008 defm: Loadxim_pat<sextloadi32, i64, ToSext64, anyimm2, L2_loadri_io>;
2011 let AddedComplexity = 60 in {
2012 def: Loadxu_pat<extloadi8, i32, anyimm0, L4_loadrub_ur>;
2013 def: Loadxu_pat<extloadi16, i32, anyimm1, L4_loadruh_ur>;
2014 def: Loadxu_pat<extloadv2i8, v2i16, anyimm1, L4_loadbzw2_ur>;
2015 def: Loadxu_pat<extloadv4i8, v4i16, anyimm2, L4_loadbzw4_ur>;
2016 def: Loadxu_pat<sextloadi8, i32, anyimm0, L4_loadrb_ur>;
2017 def: Loadxu_pat<sextloadi16, i32, anyimm1, L4_loadrh_ur>;
2018 def: Loadxu_pat<sextloadv2i8, v2i16, anyimm1, L4_loadbsw2_ur>;
2019 def: Loadxu_pat<sextloadv4i8, v4i16, anyimm2, L4_loadbzw4_ur>;
2020 def: Loadxu_pat<zextloadi8, i32, anyimm0, L4_loadrub_ur>;
2021 def: Loadxu_pat<zextloadi16, i32, anyimm1, L4_loadruh_ur>;
2022 def: Loadxu_pat<zextloadv2i8, v2i16, anyimm1, L4_loadbzw2_ur>;
2023 def: Loadxu_pat<zextloadv4i8, v4i16, anyimm2, L4_loadbzw4_ur>;
2024 def: Loadxu_pat<load, i32, anyimm2, L4_loadri_ur>;
2025 def: Loadxu_pat<load, v2i16, anyimm2, L4_loadri_ur>;
2026 def: Loadxu_pat<load, v4i8, anyimm2, L4_loadri_ur>;
2027 def: Loadxu_pat<load, i64, anyimm3, L4_loadrd_ur>;
2028 def: Loadxu_pat<load, v2i32, anyimm3, L4_loadrd_ur>;
2029 def: Loadxu_pat<load, v4i16, anyimm3, L4_loadrd_ur>;
2030 def: Loadxu_pat<load, v8i8, anyimm3, L4_loadrd_ur>;
2031 def: Loadxu_pat<load, f32, anyimm2, L4_loadri_ur>;
2032 def: Loadxu_pat<load, f64, anyimm3, L4_loadrd_ur>;
2034 def: Loadxum_pat<sextloadi8, i64, anyimm0, ToSext64, L4_loadrb_ur>;
2035 def: Loadxum_pat<zextloadi8, i64, anyimm0, ToZext64, L4_loadrub_ur>;
2036 def: Loadxum_pat<extloadi8, i64, anyimm0, ToAext64, L4_loadrub_ur>;
2037 def: Loadxum_pat<sextloadi16, i64, anyimm1, ToSext64, L4_loadrh_ur>;
2038 def: Loadxum_pat<zextloadi16, i64, anyimm1, ToZext64, L4_loadruh_ur>;
2039 def: Loadxum_pat<extloadi16, i64, anyimm1, ToAext64, L4_loadruh_ur>;
2040 def: Loadxum_pat<sextloadi32, i64, anyimm2, ToSext64, L4_loadri_ur>;
2041 def: Loadxum_pat<zextloadi32, i64, anyimm2, ToZext64, L4_loadri_ur>;
2042 def: Loadxum_pat<extloadi32, i64, anyimm2, ToAext64, L4_loadri_ur>;
2045 let AddedComplexity = 40 in {
2046 def: Loadxr_shl_pat<extloadi8, i32, L4_loadrub_rr>;
2047 def: Loadxr_shl_pat<zextloadi8, i32, L4_loadrub_rr>;
2048 def: Loadxr_shl_pat<sextloadi8, i32, L4_loadrb_rr>;
2049 def: Loadxr_shl_pat<extloadi16, i32, L4_loadruh_rr>;
2050 def: Loadxr_shl_pat<zextloadi16, i32, L4_loadruh_rr>;
2051 def: Loadxr_shl_pat<sextloadi16, i32, L4_loadrh_rr>;
2052 def: Loadxr_shl_pat<load, i32, L4_loadri_rr>;
2053 def: Loadxr_shl_pat<load, v2i16, L4_loadri_rr>;
2054 def: Loadxr_shl_pat<load, v4i8, L4_loadri_rr>;
2055 def: Loadxr_shl_pat<load, i64, L4_loadrd_rr>;
2056 def: Loadxr_shl_pat<load, v2i32, L4_loadrd_rr>;
2057 def: Loadxr_shl_pat<load, v4i16, L4_loadrd_rr>;
2058 def: Loadxr_shl_pat<load, v8i8, L4_loadrd_rr>;
2059 def: Loadxr_shl_pat<load, f32, L4_loadri_rr>;
2060 def: Loadxr_shl_pat<load, f64, L4_loadrd_rr>;
2063 let AddedComplexity = 20 in {
2064 def: Loadxr_add_pat<extloadi8, i32, L4_loadrub_rr>;
2065 def: Loadxr_add_pat<zextloadi8, i32, L4_loadrub_rr>;
2066 def: Loadxr_add_pat<sextloadi8, i32, L4_loadrb_rr>;
2067 def: Loadxr_add_pat<extloadi16, i32, L4_loadruh_rr>;
2068 def: Loadxr_add_pat<zextloadi16, i32, L4_loadruh_rr>;
2069 def: Loadxr_add_pat<sextloadi16, i32, L4_loadrh_rr>;
2070 def: Loadxr_add_pat<load, i32, L4_loadri_rr>;
2071 def: Loadxr_add_pat<load, v2i16, L4_loadri_rr>;
2072 def: Loadxr_add_pat<load, v4i8, L4_loadri_rr>;
2073 def: Loadxr_add_pat<load, i64, L4_loadrd_rr>;
2074 def: Loadxr_add_pat<load, v2i32, L4_loadrd_rr>;
2075 def: Loadxr_add_pat<load, v4i16, L4_loadrd_rr>;
2076 def: Loadxr_add_pat<load, v8i8, L4_loadrd_rr>;
2077 def: Loadxr_add_pat<load, f32, L4_loadri_rr>;
2078 def: Loadxr_add_pat<load, f64, L4_loadrd_rr>;
2081 let AddedComplexity = 40 in {
2082 def: Loadxrm_shl_pat<extloadi8, i64, ToAext64, L4_loadrub_rr>;
2083 def: Loadxrm_shl_pat<zextloadi8, i64, ToZext64, L4_loadrub_rr>;
2084 def: Loadxrm_shl_pat<sextloadi8, i64, ToSext64, L4_loadrb_rr>;
2085 def: Loadxrm_shl_pat<extloadi16, i64, ToAext64, L4_loadruh_rr>;
2086 def: Loadxrm_shl_pat<zextloadi16, i64, ToZext64, L4_loadruh_rr>;
2087 def: Loadxrm_shl_pat<sextloadi16, i64, ToSext64, L4_loadrh_rr>;
2088 def: Loadxrm_shl_pat<extloadi32, i64, ToAext64, L4_loadri_rr>;
2089 def: Loadxrm_shl_pat<zextloadi32, i64, ToZext64, L4_loadri_rr>;
2090 def: Loadxrm_shl_pat<sextloadi32, i64, ToSext64, L4_loadri_rr>;
2093 let AddedComplexity = 20 in {
2094 def: Loadxrm_add_pat<extloadi8, i64, ToAext64, L4_loadrub_rr>;
2095 def: Loadxrm_add_pat<zextloadi8, i64, ToZext64, L4_loadrub_rr>;
2096 def: Loadxrm_add_pat<sextloadi8, i64, ToSext64, L4_loadrb_rr>;
2097 def: Loadxrm_add_pat<extloadi16, i64, ToAext64, L4_loadruh_rr>;
2098 def: Loadxrm_add_pat<zextloadi16, i64, ToZext64, L4_loadruh_rr>;
2099 def: Loadxrm_add_pat<sextloadi16, i64, ToSext64, L4_loadrh_rr>;
2100 def: Loadxrm_add_pat<extloadi32, i64, ToAext64, L4_loadri_rr>;
2101 def: Loadxrm_add_pat<zextloadi32, i64, ToZext64, L4_loadri_rr>;
2102 def: Loadxrm_add_pat<sextloadi32, i64, ToSext64, L4_loadri_rr>;
2107 let AddedComplexity = 60 in {
2108 def: Loada_pat<zextloadi1, i32, anyimm0, PS_loadrubabs>;
2109 def: Loada_pat<sextloadi8, i32, anyimm0, PS_loadrbabs>;
2110 def: Loada_pat<extloadi8, i32, anyimm0, PS_loadrubabs>;
2111 def: Loada_pat<zextloadi8, i32, anyimm0, PS_loadrubabs>;
2112 def: Loada_pat<sextloadi16, i32, anyimm1, PS_loadrhabs>;
2113 def: Loada_pat<extloadi16, i32, anyimm1, PS_loadruhabs>;
2114 def: Loada_pat<zextloadi16, i32, anyimm1, PS_loadruhabs>;
2115 def: Loada_pat<load, i32, anyimm2, PS_loadriabs>;
2116 def: Loada_pat<load, v2i16, anyimm2, PS_loadriabs>;
2117 def: Loada_pat<load, v4i8, anyimm2, PS_loadriabs>;
2118 def: Loada_pat<load, i64, anyimm3, PS_loadrdabs>;
2119 def: Loada_pat<load, v2i32, anyimm3, PS_loadrdabs>;
2120 def: Loada_pat<load, v4i16, anyimm3, PS_loadrdabs>;
2121 def: Loada_pat<load, v8i8, anyimm3, PS_loadrdabs>;
2122 def: Loada_pat<load, f32, anyimm2, PS_loadriabs>;
2123 def: Loada_pat<load, f64, anyimm3, PS_loadrdabs>;
2125 def: Loada_pat<atomic_load_8, i32, anyimm0, PS_loadrubabs>;
2126 def: Loada_pat<atomic_load_16, i32, anyimm1, PS_loadruhabs>;
2127 def: Loada_pat<atomic_load_32, i32, anyimm2, PS_loadriabs>;
2128 def: Loada_pat<atomic_load_64, i64, anyimm3, PS_loadrdabs>;
2131 let AddedComplexity = 30 in {
2132 def: Loadam_pat<extloadi8, i64, anyimm0, ToAext64, PS_loadrubabs>;
2133 def: Loadam_pat<sextloadi8, i64, anyimm0, ToSext64, PS_loadrbabs>;
2134 def: Loadam_pat<zextloadi8, i64, anyimm0, ToZext64, PS_loadrubabs>;
2135 def: Loadam_pat<extloadi16, i64, anyimm1, ToAext64, PS_loadruhabs>;
2136 def: Loadam_pat<sextloadi16, i64, anyimm1, ToSext64, PS_loadrhabs>;
2137 def: Loadam_pat<zextloadi16, i64, anyimm1, ToZext64, PS_loadruhabs>;
2138 def: Loadam_pat<extloadi32, i64, anyimm2, ToAext64, PS_loadriabs>;
2139 def: Loadam_pat<sextloadi32, i64, anyimm2, ToSext64, PS_loadriabs>;
2140 def: Loadam_pat<zextloadi32, i64, anyimm2, ToZext64, PS_loadriabs>;
2142 def: Loadam_pat<load, i1, anyimm0, I32toI1, PS_loadrubabs>;
2143 def: Loadam_pat<zextloadi1, i64, anyimm0, ToZext64, PS_loadrubabs>;
2146 // GP-relative address
2148 let AddedComplexity = 100 in {
2149 def: Loada_pat<extloadi1, i32, addrgp, L2_loadrubgp>;
2150 def: Loada_pat<zextloadi1, i32, addrgp, L2_loadrubgp>;
2151 def: Loada_pat<extloadi8, i32, addrgp, L2_loadrubgp>;
2152 def: Loada_pat<sextloadi8, i32, addrgp, L2_loadrbgp>;
2153 def: Loada_pat<zextloadi8, i32, addrgp, L2_loadrubgp>;
2154 def: Loada_pat<extloadi16, i32, addrgp, L2_loadruhgp>;
2155 def: Loada_pat<sextloadi16, i32, addrgp, L2_loadrhgp>;
2156 def: Loada_pat<zextloadi16, i32, addrgp, L2_loadruhgp>;
2157 def: Loada_pat<load, i32, addrgp, L2_loadrigp>;
2158 def: Loada_pat<load, v2i16, addrgp, L2_loadrigp>;
2159 def: Loada_pat<load, v4i8, addrgp, L2_loadrigp>;
2160 def: Loada_pat<load, i64, addrgp, L2_loadrdgp>;
2161 def: Loada_pat<load, v2i32, addrgp, L2_loadrdgp>;
2162 def: Loada_pat<load, v4i16, addrgp, L2_loadrdgp>;
2163 def: Loada_pat<load, v8i8, addrgp, L2_loadrdgp>;
2164 def: Loada_pat<load, f32, addrgp, L2_loadrigp>;
2165 def: Loada_pat<load, f64, addrgp, L2_loadrdgp>;
2167 def: Loada_pat<atomic_load_8, i32, addrgp, L2_loadrubgp>;
2168 def: Loada_pat<atomic_load_16, i32, addrgp, L2_loadruhgp>;
2169 def: Loada_pat<atomic_load_32, i32, addrgp, L2_loadrigp>;
2170 def: Loada_pat<atomic_load_64, i64, addrgp, L2_loadrdgp>;
2173 let AddedComplexity = 70 in {
2174 def: Loadam_pat<extloadi8, i64, addrgp, ToAext64, L2_loadrubgp>;
2175 def: Loadam_pat<sextloadi8, i64, addrgp, ToSext64, L2_loadrbgp>;
2176 def: Loadam_pat<zextloadi8, i64, addrgp, ToZext64, L2_loadrubgp>;
2177 def: Loadam_pat<extloadi16, i64, addrgp, ToAext64, L2_loadruhgp>;
2178 def: Loadam_pat<sextloadi16, i64, addrgp, ToSext64, L2_loadrhgp>;
2179 def: Loadam_pat<zextloadi16, i64, addrgp, ToZext64, L2_loadruhgp>;
2180 def: Loadam_pat<extloadi32, i64, addrgp, ToAext64, L2_loadrigp>;
2181 def: Loadam_pat<sextloadi32, i64, addrgp, ToSext64, L2_loadrigp>;
2182 def: Loadam_pat<zextloadi32, i64, addrgp, ToZext64, L2_loadrigp>;
2184 def: Loadam_pat<load, i1, addrgp, I32toI1, L2_loadrubgp>;
2185 def: Loadam_pat<zextloadi1, i64, addrgp, ToZext64, L2_loadrubgp>;
2189 // Sign-extending loads of i1 need to replicate the lowest bit throughout
2190 // the 32-bit value. Since the loaded value can only be 0 or 1, 0-v should
2192 let AddedComplexity = 20 in
2193 def: Pat<(i32 (sextloadi1 I32:$Rs)),
2194 (A2_subri 0, (L2_loadrub_io IntRegs:$Rs, 0))>;
2196 // Patterns for loads of i1:
2197 def: Pat<(i1 (load AddrFI:$fi)),
2198 (C2_tfrrp (L2_loadrub_io AddrFI:$fi, 0))>;
2199 def: Pat<(i1 (load (add I32:$Rs, anyimm0:$Off))),
2200 (C2_tfrrp (L2_loadrub_io IntRegs:$Rs, imm:$Off))>;
2201 def: Pat<(i1 (load I32:$Rs)),
2202 (C2_tfrrp (L2_loadrub_io IntRegs:$Rs, 0))>;
2205 // --(13) Store ----------------------------------------------------------
2208 class Storepi_pat<PatFrag Store, PatFrag Value, PatFrag Offset, InstHexagon MI>
2209 : Pat<(Store Value:$Rt, I32:$Rx, Offset:$s4),
2210 (MI I32:$Rx, imm:$s4, Value:$Rt)>;
2212 def: Storepi_pat<post_truncsti8, I32, s4_0ImmPred, S2_storerb_pi>;
2213 def: Storepi_pat<post_truncsti16, I32, s4_1ImmPred, S2_storerh_pi>;
2214 def: Storepi_pat<post_store, I32, s4_2ImmPred, S2_storeri_pi>;
2215 def: Storepi_pat<post_store, I64, s4_3ImmPred, S2_storerd_pi>;
2217 // Patterns for generating stores, where the address takes different forms:
2219 // - frameindex + offset,
2221 // - simple (base address without offset).
2222 // These would usually be used together (via Storexi_pat defined below), but
2223 // in some cases one may want to apply different properties (such as
2224 // AddedComplexity) to the individual patterns.
2225 class Storexi_fi_pat<PatFrag Store, PatFrag Value, InstHexagon MI>
2226 : Pat<(Store Value:$Rs, AddrFI:$fi), (MI AddrFI:$fi, 0, Value:$Rs)>;
2228 multiclass Storexi_fi_add_pat<PatFrag Store, PatFrag Value, PatFrag ImmPred,
2230 def: Pat<(Store Value:$Rs, (add (i32 AddrFI:$fi), ImmPred:$Off)),
2231 (MI AddrFI:$fi, imm:$Off, Value:$Rs)>;
2232 def: Pat<(Store Value:$Rs, (IsOrAdd (i32 AddrFI:$fi), ImmPred:$Off)),
2233 (MI AddrFI:$fi, imm:$Off, Value:$Rs)>;
2236 multiclass Storexi_add_pat<PatFrag Store, PatFrag Value, PatFrag ImmPred,
2238 def: Pat<(Store Value:$Rt, (add I32:$Rs, ImmPred:$Off)),
2239 (MI IntRegs:$Rs, imm:$Off, Value:$Rt)>;
2240 def: Pat<(Store Value:$Rt, (IsOrAdd I32:$Rs, ImmPred:$Off)),
2241 (MI IntRegs:$Rs, imm:$Off, Value:$Rt)>;
2244 class Storexi_base_pat<PatFrag Store, PatFrag Value, InstHexagon MI>
2245 : Pat<(Store Value:$Rt, I32:$Rs),
2246 (MI IntRegs:$Rs, 0, Value:$Rt)>;
2248 // Patterns for generating stores, where the address takes different forms,
2249 // and where the value being stored is transformed through the value modifier
2250 // ValueMod. The address forms are same as above.
2251 class Storexim_fi_pat<PatFrag Store, PatFrag Value, PatFrag ValueMod,
2253 : Pat<(Store Value:$Rs, AddrFI:$fi),
2254 (MI AddrFI:$fi, 0, (ValueMod Value:$Rs))>;
2256 multiclass Storexim_fi_add_pat<PatFrag Store, PatFrag Value, PatFrag ImmPred,
2257 PatFrag ValueMod, InstHexagon MI> {
2258 def: Pat<(Store Value:$Rs, (add (i32 AddrFI:$fi), ImmPred:$Off)),
2259 (MI AddrFI:$fi, imm:$Off, (ValueMod Value:$Rs))>;
2260 def: Pat<(Store Value:$Rs, (IsOrAdd (i32 AddrFI:$fi), ImmPred:$Off)),
2261 (MI AddrFI:$fi, imm:$Off, (ValueMod Value:$Rs))>;
2264 multiclass Storexim_add_pat<PatFrag Store, PatFrag Value, PatFrag ImmPred,
2265 PatFrag ValueMod, InstHexagon MI> {
2266 def: Pat<(Store Value:$Rt, (add I32:$Rs, ImmPred:$Off)),
2267 (MI IntRegs:$Rs, imm:$Off, (ValueMod Value:$Rt))>;
2268 def: Pat<(Store Value:$Rt, (IsOrAdd I32:$Rs, ImmPred:$Off)),
2269 (MI IntRegs:$Rs, imm:$Off, (ValueMod Value:$Rt))>;
2272 class Storexim_base_pat<PatFrag Store, PatFrag Value, PatFrag ValueMod,
2274 : Pat<(Store Value:$Rt, I32:$Rs),
2275 (MI IntRegs:$Rs, 0, (ValueMod Value:$Rt))>;
2277 multiclass Storexi_pat<PatFrag Store, PatFrag Value, PatLeaf ImmPred,
2279 defm: Storexi_fi_add_pat <Store, Value, ImmPred, MI>;
2280 def: Storexi_fi_pat <Store, Value, MI>;
2281 defm: Storexi_add_pat <Store, Value, ImmPred, MI>;
2284 multiclass Storexim_pat<PatFrag Store, PatFrag Value, PatLeaf ImmPred,
2285 PatFrag ValueMod, InstHexagon MI> {
2286 defm: Storexim_fi_add_pat <Store, Value, ImmPred, ValueMod, MI>;
2287 def: Storexim_fi_pat <Store, Value, ValueMod, MI>;
2288 defm: Storexim_add_pat <Store, Value, ImmPred, ValueMod, MI>;
2292 class Storexu_shl_pat<PatFrag Store, PatFrag Value, PatFrag ImmPred, InstHexagon MI>
2293 : Pat<(Store Value:$Rt, (add (shl I32:$Ru, u2_0ImmPred:$u2), ImmPred:$A)),
2294 (MI IntRegs:$Ru, imm:$u2, ImmPred:$A, Value:$Rt)>;
2297 class Storexr_shl_pat<PatFrag Store, PatFrag Value, InstHexagon MI>
2298 : Pat<(Store Value:$Ru, (add I32:$Rs, (shl I32:$Rt, u2_0ImmPred:$u2))),
2299 (MI IntRegs:$Rs, IntRegs:$Rt, imm:$u2, Value:$Ru)>;
2302 class Storexr_add_pat<PatFrag Store, PatFrag Value, InstHexagon MI>
2303 : Pat<(Store Value:$Ru, (add I32:$Rs, I32:$Rt)),
2304 (MI IntRegs:$Rs, IntRegs:$Rt, 0, Value:$Ru)>;
2306 class Storea_pat<PatFrag Store, PatFrag Value, PatFrag Addr, InstHexagon MI>
2307 : Pat<(Store Value:$val, Addr:$addr), (MI Addr:$addr, Value:$val)>;
2309 class Stoream_pat<PatFrag Store, PatFrag Value, PatFrag Addr, PatFrag ValueMod,
2311 : Pat<(Store Value:$val, Addr:$addr),
2312 (MI Addr:$addr, (ValueMod Value:$val))>;
2314 // Regular stores in the DAG have two operands: value and address.
2315 // Atomic stores also have two, but they are reversed: address, value.
2316 // To use atomic stores with the patterns, they need to have their operands
2317 // swapped. This relies on the knowledge that the F.Fragment uses names
2319 class AtomSt<PatFrag F>
2320 : PatFrag<(ops node:$val, node:$ptr), !head(F.Fragments), F.PredicateCode,
2321 F.OperandTransform> {
2322 let IsAtomic = F.IsAtomic;
2323 let MemoryVT = F.MemoryVT;
2327 def IMM_BYTE : SDNodeXForm<imm, [{
2328 // -1 can be represented as 255, etc.
2329 // assigning to a byte restores our desired signed value.
2330 int8_t imm = N->getSExtValue();
2331 return CurDAG->getTargetConstant(imm, SDLoc(N), MVT::i32);
2334 def IMM_HALF : SDNodeXForm<imm, [{
2335 // -1 can be represented as 65535, etc.
2336 // assigning to a short restores our desired signed value.
2337 int16_t imm = N->getSExtValue();
2338 return CurDAG->getTargetConstant(imm, SDLoc(N), MVT::i32);
2341 def IMM_WORD : SDNodeXForm<imm, [{
2342 // -1 can be represented as 4294967295, etc.
2343 // Currently, it's not doing this. But some optimization
2344 // might convert -1 to a large +ve number.
2345 // assigning to a word restores our desired signed value.
2346 int32_t imm = N->getSExtValue();
2347 return CurDAG->getTargetConstant(imm, SDLoc(N), MVT::i32);
2350 def ToImmByte : OutPatFrag<(ops node:$R), (IMM_BYTE $R)>;
2351 def ToImmHalf : OutPatFrag<(ops node:$R), (IMM_HALF $R)>;
2352 def ToImmWord : OutPatFrag<(ops node:$R), (IMM_WORD $R)>;
2354 // Even though the offset is not extendable in the store-immediate, we
2355 // can still generate the fi# in the base address. If the final offset
2356 // is not valid for the instruction, we will replace it with a scratch
2358 class SmallStackStore<PatFrag Store>
2359 : PatFrag<(ops node:$Val, node:$Addr), (Store node:$Val, node:$Addr), [{
2360 return isSmallStackStore(cast<StoreSDNode>(N));
2363 // This is the complement of SmallStackStore.
2364 class LargeStackStore<PatFrag Store>
2365 : PatFrag<(ops node:$Val, node:$Addr), (Store node:$Val, node:$Addr), [{
2366 return !isSmallStackStore(cast<StoreSDNode>(N));
2369 // Preferred addressing modes for various combinations of stored value
2370 // and address computation.
2371 // For stores where the address and value are both immediates, prefer
2372 // store-immediate. The reason is that the constant-extender optimization
2373 // can replace store-immediate with a store-register, but there is nothing
2374 // to generate a store-immediate out of a store-register.
2376 // C R F F+C R+C R+R R<<S+C R<<S+R
2377 // --+-------+-----+-----+------+-----+-----+--------+--------
2378 // C | imm | imm | imm | imm | imm | rr | ur | rr
2379 // R | abs* | io | io | io | io | rr | ur | rr
2381 // (*) Absolute or GP-relative.
2383 // Note that any expression can be matched by Reg. In particular, an immediate
2384 // can always be placed in a register, so patterns checking for Imm should
2385 // have a higher priority than the ones involving Reg that could also match.
2386 // For example, *(p+4) could become r1=#4; memw(r0+r1<<#0) instead of the
2387 // preferred memw(r0+#4). Similarly Reg+Imm or Reg+Reg should be tried before
2390 // The order in which the different combinations are tried:
2392 // C F R F+C R+C R+R R<<S+C R<<S+R
2393 // --+-------+-----+-----+------+-----+-----+--------+--------
2394 // C | 1 | 6 | - | 5 | 9 | - | - | -
2395 // R | 2 | 8 | 12 | 7 | 10 | 11 | 3 | 4
2398 // First, match the unusual case of doubleword store into Reg+Imm4, i.e.
2399 // a store where the offset Imm4 is a multiple of 4, but not of 8. This
2400 // implies that Reg is also a proper multiple of 4. To still generate a
2401 // doubleword store, add 4 to Reg, and subtract 4 from the offset.
2403 def s30_2ProperPred : PatLeaf<(i32 imm), [{
2404 int64_t v = (int64_t)N->getSExtValue();
2405 return isShiftedInt<30,2>(v) && !isShiftedInt<29,3>(v);
2407 def RoundTo8 : SDNodeXForm<imm, [{
2408 int32_t Imm = N->getSExtValue();
2409 return CurDAG->getTargetConstant(Imm & -8, SDLoc(N), MVT::i32);
2412 let AddedComplexity = 150 in
2413 def: Pat<(store I64:$Ru, (add I32:$Rs, s30_2ProperPred:$Off)),
2414 (S2_storerd_io (A2_addi I32:$Rs, 4), (RoundTo8 $Off), I64:$Ru)>;
2416 class Storexi_abs_pat<PatFrag Store, PatFrag Value, InstHexagon MI>
2417 : Pat<(Store Value:$val, anyimm:$addr),
2418 (MI (ToI32 $addr), 0, Value:$val)>;
2419 class Storexim_abs_pat<PatFrag Store, PatFrag Value, PatFrag ValueMod,
2421 : Pat<(Store Value:$val, anyimm:$addr),
2422 (MI (ToI32 $addr), 0, (ValueMod Value:$val))>;
2424 let AddedComplexity = 140 in {
2425 def: Storexim_abs_pat<truncstorei8, anyint, ToImmByte, S4_storeirb_io>;
2426 def: Storexim_abs_pat<truncstorei16, anyint, ToImmHalf, S4_storeirh_io>;
2427 def: Storexim_abs_pat<store, anyint, ToImmWord, S4_storeiri_io>;
2429 def: Storexi_abs_pat<truncstorei8, anyimm, S4_storeirb_io>;
2430 def: Storexi_abs_pat<truncstorei16, anyimm, S4_storeirh_io>;
2431 def: Storexi_abs_pat<store, anyimm, S4_storeiri_io>;
2434 // GP-relative address
2435 let AddedComplexity = 120 in {
2436 def: Storea_pat<truncstorei8, I32, addrgp, S2_storerbgp>;
2437 def: Storea_pat<truncstorei16, I32, addrgp, S2_storerhgp>;
2438 def: Storea_pat<store, I32, addrgp, S2_storerigp>;
2439 def: Storea_pat<store, V4I8, addrgp, S2_storerigp>;
2440 def: Storea_pat<store, V2I16, addrgp, S2_storerigp>;
2441 def: Storea_pat<store, I64, addrgp, S2_storerdgp>;
2442 def: Storea_pat<store, V8I8, addrgp, S2_storerdgp>;
2443 def: Storea_pat<store, V4I16, addrgp, S2_storerdgp>;
2444 def: Storea_pat<store, V2I32, addrgp, S2_storerdgp>;
2445 def: Storea_pat<store, F32, addrgp, S2_storerigp>;
2446 def: Storea_pat<store, F64, addrgp, S2_storerdgp>;
2447 def: Storea_pat<AtomSt<atomic_store_8>, I32, addrgp, S2_storerbgp>;
2448 def: Storea_pat<AtomSt<atomic_store_16>, I32, addrgp, S2_storerhgp>;
2449 def: Storea_pat<AtomSt<atomic_store_32>, I32, addrgp, S2_storerigp>;
2450 def: Storea_pat<AtomSt<atomic_store_32>, V4I8, addrgp, S2_storerigp>;
2451 def: Storea_pat<AtomSt<atomic_store_32>, V2I16, addrgp, S2_storerigp>;
2452 def: Storea_pat<AtomSt<atomic_store_64>, I64, addrgp, S2_storerdgp>;
2453 def: Storea_pat<AtomSt<atomic_store_64>, V8I8, addrgp, S2_storerdgp>;
2454 def: Storea_pat<AtomSt<atomic_store_64>, V4I16, addrgp, S2_storerdgp>;
2455 def: Storea_pat<AtomSt<atomic_store_64>, V2I32, addrgp, S2_storerdgp>;
2457 def: Stoream_pat<truncstorei8, I64, addrgp, LoReg, S2_storerbgp>;
2458 def: Stoream_pat<truncstorei16, I64, addrgp, LoReg, S2_storerhgp>;
2459 def: Stoream_pat<truncstorei32, I64, addrgp, LoReg, S2_storerigp>;
2460 def: Stoream_pat<store, I1, addrgp, I1toI32, S2_storerbgp>;
2464 let AddedComplexity = 110 in {
2465 def: Storea_pat<truncstorei8, I32, anyimm0, PS_storerbabs>;
2466 def: Storea_pat<truncstorei16, I32, anyimm1, PS_storerhabs>;
2467 def: Storea_pat<store, I32, anyimm2, PS_storeriabs>;
2468 def: Storea_pat<store, V4I8, anyimm2, PS_storeriabs>;
2469 def: Storea_pat<store, V2I16, anyimm2, PS_storeriabs>;
2470 def: Storea_pat<store, I64, anyimm3, PS_storerdabs>;
2471 def: Storea_pat<store, V8I8, anyimm3, PS_storerdabs>;
2472 def: Storea_pat<store, V4I16, anyimm3, PS_storerdabs>;
2473 def: Storea_pat<store, V2I32, anyimm3, PS_storerdabs>;
2474 def: Storea_pat<store, F32, anyimm2, PS_storeriabs>;
2475 def: Storea_pat<store, F64, anyimm3, PS_storerdabs>;
2476 def: Storea_pat<AtomSt<atomic_store_8>, I32, anyimm0, PS_storerbabs>;
2477 def: Storea_pat<AtomSt<atomic_store_16>, I32, anyimm1, PS_storerhabs>;
2478 def: Storea_pat<AtomSt<atomic_store_32>, I32, anyimm2, PS_storeriabs>;
2479 def: Storea_pat<AtomSt<atomic_store_32>, V4I8, anyimm2, PS_storeriabs>;
2480 def: Storea_pat<AtomSt<atomic_store_32>, V2I16, anyimm2, PS_storeriabs>;
2481 def: Storea_pat<AtomSt<atomic_store_64>, I64, anyimm3, PS_storerdabs>;
2482 def: Storea_pat<AtomSt<atomic_store_64>, V8I8, anyimm3, PS_storerdabs>;
2483 def: Storea_pat<AtomSt<atomic_store_64>, V4I16, anyimm3, PS_storerdabs>;
2484 def: Storea_pat<AtomSt<atomic_store_64>, V2I32, anyimm3, PS_storerdabs>;
2486 def: Stoream_pat<truncstorei8, I64, anyimm0, LoReg, PS_storerbabs>;
2487 def: Stoream_pat<truncstorei16, I64, anyimm1, LoReg, PS_storerhabs>;
2488 def: Stoream_pat<truncstorei32, I64, anyimm2, LoReg, PS_storeriabs>;
2489 def: Stoream_pat<store, I1, anyimm0, I1toI32, PS_storerbabs>;
2493 let AddedComplexity = 100 in {
2494 def: Storexu_shl_pat<truncstorei8, I32, anyimm0, S4_storerb_ur>;
2495 def: Storexu_shl_pat<truncstorei16, I32, anyimm1, S4_storerh_ur>;
2496 def: Storexu_shl_pat<store, I32, anyimm2, S4_storeri_ur>;
2497 def: Storexu_shl_pat<store, V4I8, anyimm2, S4_storeri_ur>;
2498 def: Storexu_shl_pat<store, V2I16, anyimm2, S4_storeri_ur>;
2499 def: Storexu_shl_pat<store, I64, anyimm3, S4_storerd_ur>;
2500 def: Storexu_shl_pat<store, V8I8, anyimm3, S4_storerd_ur>;
2501 def: Storexu_shl_pat<store, V4I16, anyimm3, S4_storerd_ur>;
2502 def: Storexu_shl_pat<store, V2I32, anyimm3, S4_storerd_ur>;
2503 def: Storexu_shl_pat<store, F32, anyimm2, S4_storeri_ur>;
2504 def: Storexu_shl_pat<store, F64, anyimm3, S4_storerd_ur>;
2506 def: Pat<(store I1:$Pu, (add (shl I32:$Rs, u2_0ImmPred:$u2), anyimm:$A)),
2507 (S4_storerb_ur IntRegs:$Rs, imm:$u2, imm:$A, (I1toI32 I1:$Pu))>;
2511 let AddedComplexity = 90 in {
2512 def: Storexr_shl_pat<truncstorei8, I32, S4_storerb_rr>;
2513 def: Storexr_shl_pat<truncstorei16, I32, S4_storerh_rr>;
2514 def: Storexr_shl_pat<store, I32, S4_storeri_rr>;
2515 def: Storexr_shl_pat<store, V4I8, S4_storeri_rr>;
2516 def: Storexr_shl_pat<store, V2I16, S4_storeri_rr>;
2517 def: Storexr_shl_pat<store, I64, S4_storerd_rr>;
2518 def: Storexr_shl_pat<store, V8I8, S4_storerd_rr>;
2519 def: Storexr_shl_pat<store, V4I16, S4_storerd_rr>;
2520 def: Storexr_shl_pat<store, V2I32, S4_storerd_rr>;
2521 def: Storexr_shl_pat<store, F32, S4_storeri_rr>;
2522 def: Storexr_shl_pat<store, F64, S4_storerd_rr>;
2524 def: Pat<(store I1:$Pu, (add (shl I32:$Rs, u2_0ImmPred:$u2), I32:$Rt)),
2525 (S4_storerb_ur IntRegs:$Rt, IntRegs:$Rs, imm:$u2, (I1toI32 I1:$Pu))>;
2528 class SS_<PatFrag F> : SmallStackStore<F>;
2529 class LS_<PatFrag F> : LargeStackStore<F>;
2531 multiclass IMFA_<PatFrag S, PatFrag V, PatFrag O, PatFrag M, InstHexagon I> {
2532 defm: Storexim_fi_add_pat<S, V, O, M, I>;
2534 multiclass IFA_<PatFrag S, PatFrag V, PatFrag O, InstHexagon I> {
2535 defm: Storexi_fi_add_pat<S, V, O, I>;
2538 // Fi+Imm, store-immediate
2539 let AddedComplexity = 80 in {
2540 defm: IMFA_<SS_<truncstorei8>, anyint, u6_0ImmPred, ToImmByte, S4_storeirb_io>;
2541 defm: IMFA_<SS_<truncstorei16>, anyint, u6_1ImmPred, ToImmHalf, S4_storeirh_io>;
2542 defm: IMFA_<SS_<store>, anyint, u6_2ImmPred, ToImmWord, S4_storeiri_io>;
2544 defm: IFA_<SS_<truncstorei8>, anyimm, u6_0ImmPred, S4_storeirb_io>;
2545 defm: IFA_<SS_<truncstorei16>, anyimm, u6_1ImmPred, S4_storeirh_io>;
2546 defm: IFA_<SS_<store>, anyimm, u6_2ImmPred, S4_storeiri_io>;
2548 // For large-stack stores, generate store-register (prefer explicit Fi
2550 defm: IMFA_<LS_<truncstorei8>, anyimm, u6_0ImmPred, ToI32, S2_storerb_io>;
2551 defm: IMFA_<LS_<truncstorei16>, anyimm, u6_1ImmPred, ToI32, S2_storerh_io>;
2552 defm: IMFA_<LS_<store>, anyimm, u6_2ImmPred, ToI32, S2_storeri_io>;
2555 // Fi, store-immediate
2556 let AddedComplexity = 70 in {
2557 def: Storexim_fi_pat<SS_<truncstorei8>, anyint, ToImmByte, S4_storeirb_io>;
2558 def: Storexim_fi_pat<SS_<truncstorei16>, anyint, ToImmHalf, S4_storeirh_io>;
2559 def: Storexim_fi_pat<SS_<store>, anyint, ToImmWord, S4_storeiri_io>;
2561 def: Storexi_fi_pat<SS_<truncstorei8>, anyimm, S4_storeirb_io>;
2562 def: Storexi_fi_pat<SS_<truncstorei16>, anyimm, S4_storeirh_io>;
2563 def: Storexi_fi_pat<SS_<store>, anyimm, S4_storeiri_io>;
2565 // For large-stack stores, generate store-register (prefer explicit Fi
2567 def: Storexim_fi_pat<LS_<truncstorei8>, anyimm, ToI32, S2_storerb_io>;
2568 def: Storexim_fi_pat<LS_<truncstorei16>, anyimm, ToI32, S2_storerh_io>;
2569 def: Storexim_fi_pat<LS_<store>, anyimm, ToI32, S2_storeri_io>;
2572 // Fi+Imm, Fi, store-register
2573 let AddedComplexity = 60 in {
2574 defm: Storexi_fi_add_pat<truncstorei8, I32, anyimm, S2_storerb_io>;
2575 defm: Storexi_fi_add_pat<truncstorei16, I32, anyimm, S2_storerh_io>;
2576 defm: Storexi_fi_add_pat<store, I32, anyimm, S2_storeri_io>;
2577 defm: Storexi_fi_add_pat<store, V4I8, anyimm, S2_storeri_io>;
2578 defm: Storexi_fi_add_pat<store, V2I16, anyimm, S2_storeri_io>;
2579 defm: Storexi_fi_add_pat<store, I64, anyimm, S2_storerd_io>;
2580 defm: Storexi_fi_add_pat<store, V8I8, anyimm, S2_storerd_io>;
2581 defm: Storexi_fi_add_pat<store, V4I16, anyimm, S2_storerd_io>;
2582 defm: Storexi_fi_add_pat<store, V2I32, anyimm, S2_storerd_io>;
2583 defm: Storexi_fi_add_pat<store, F32, anyimm, S2_storeri_io>;
2584 defm: Storexi_fi_add_pat<store, F64, anyimm, S2_storerd_io>;
2585 defm: Storexim_fi_add_pat<store, I1, anyimm, I1toI32, S2_storerb_io>;
2587 def: Storexi_fi_pat<truncstorei8, I32, S2_storerb_io>;
2588 def: Storexi_fi_pat<truncstorei16, I32, S2_storerh_io>;
2589 def: Storexi_fi_pat<store, I32, S2_storeri_io>;
2590 def: Storexi_fi_pat<store, V4I8, S2_storeri_io>;
2591 def: Storexi_fi_pat<store, V2I16, S2_storeri_io>;
2592 def: Storexi_fi_pat<store, I64, S2_storerd_io>;
2593 def: Storexi_fi_pat<store, V8I8, S2_storerd_io>;
2594 def: Storexi_fi_pat<store, V4I16, S2_storerd_io>;
2595 def: Storexi_fi_pat<store, V2I32, S2_storerd_io>;
2596 def: Storexi_fi_pat<store, F32, S2_storeri_io>;
2597 def: Storexi_fi_pat<store, F64, S2_storerd_io>;
2598 def: Storexim_fi_pat<store, I1, I1toI32, S2_storerb_io>;
2602 multiclass IMRA_<PatFrag S, PatFrag V, PatFrag O, PatFrag M, InstHexagon I> {
2603 defm: Storexim_add_pat<S, V, O, M, I>;
2605 multiclass IRA_<PatFrag S, PatFrag V, PatFrag O, InstHexagon I> {
2606 defm: Storexi_add_pat<S, V, O, I>;
2609 // Reg+Imm, store-immediate
2610 let AddedComplexity = 50 in {
2611 defm: IMRA_<truncstorei8, anyint, u6_0ImmPred, ToImmByte, S4_storeirb_io>;
2612 defm: IMRA_<truncstorei16, anyint, u6_1ImmPred, ToImmHalf, S4_storeirh_io>;
2613 defm: IMRA_<store, anyint, u6_2ImmPred, ToImmWord, S4_storeiri_io>;
2615 defm: IRA_<truncstorei8, anyimm, u6_0ImmPred, S4_storeirb_io>;
2616 defm: IRA_<truncstorei16, anyimm, u6_1ImmPred, S4_storeirh_io>;
2617 defm: IRA_<store, anyimm, u6_2ImmPred, S4_storeiri_io>;
2620 // Reg+Imm, store-register
2621 let AddedComplexity = 40 in {
2622 defm: Storexi_pat<truncstorei8, I32, anyimm0, S2_storerb_io>;
2623 defm: Storexi_pat<truncstorei16, I32, anyimm1, S2_storerh_io>;
2624 defm: Storexi_pat<store, I32, anyimm2, S2_storeri_io>;
2625 defm: Storexi_pat<store, V4I8, anyimm2, S2_storeri_io>;
2626 defm: Storexi_pat<store, V2I16, anyimm2, S2_storeri_io>;
2627 defm: Storexi_pat<store, I64, anyimm3, S2_storerd_io>;
2628 defm: Storexi_pat<store, V8I8, anyimm3, S2_storerd_io>;
2629 defm: Storexi_pat<store, V4I16, anyimm3, S2_storerd_io>;
2630 defm: Storexi_pat<store, V2I32, anyimm3, S2_storerd_io>;
2631 defm: Storexi_pat<store, F32, anyimm2, S2_storeri_io>;
2632 defm: Storexi_pat<store, F64, anyimm3, S2_storerd_io>;
2634 defm: Storexim_pat<truncstorei8, I64, anyimm0, LoReg, S2_storerb_io>;
2635 defm: Storexim_pat<truncstorei16, I64, anyimm1, LoReg, S2_storerh_io>;
2636 defm: Storexim_pat<truncstorei32, I64, anyimm2, LoReg, S2_storeri_io>;
2637 defm: Storexim_pat<store, I1, anyimm0, I1toI32, S2_storerb_io>;
2639 defm: Storexi_pat<AtomSt<atomic_store_8>, I32, anyimm0, S2_storerb_io>;
2640 defm: Storexi_pat<AtomSt<atomic_store_16>, I32, anyimm1, S2_storerh_io>;
2641 defm: Storexi_pat<AtomSt<atomic_store_32>, I32, anyimm2, S2_storeri_io>;
2642 defm: Storexi_pat<AtomSt<atomic_store_32>, V4I8, anyimm2, S2_storeri_io>;
2643 defm: Storexi_pat<AtomSt<atomic_store_32>, V2I16, anyimm2, S2_storeri_io>;
2644 defm: Storexi_pat<AtomSt<atomic_store_64>, I64, anyimm3, S2_storerd_io>;
2645 defm: Storexi_pat<AtomSt<atomic_store_64>, V8I8, anyimm3, S2_storerd_io>;
2646 defm: Storexi_pat<AtomSt<atomic_store_64>, V4I16, anyimm3, S2_storerd_io>;
2647 defm: Storexi_pat<AtomSt<atomic_store_64>, V2I32, anyimm3, S2_storerd_io>;
2651 let AddedComplexity = 30 in {
2652 def: Storexr_add_pat<truncstorei8, I32, S4_storerb_rr>;
2653 def: Storexr_add_pat<truncstorei16, I32, S4_storerh_rr>;
2654 def: Storexr_add_pat<store, I32, S4_storeri_rr>;
2655 def: Storexr_add_pat<store, V4I8, S4_storeri_rr>;
2656 def: Storexr_add_pat<store, V2I16, S4_storeri_rr>;
2657 def: Storexr_add_pat<store, I64, S4_storerd_rr>;
2658 def: Storexr_add_pat<store, V8I8, S4_storerd_rr>;
2659 def: Storexr_add_pat<store, V4I16, S4_storerd_rr>;
2660 def: Storexr_add_pat<store, V2I32, S4_storerd_rr>;
2661 def: Storexr_add_pat<store, F32, S4_storeri_rr>;
2662 def: Storexr_add_pat<store, F64, S4_storerd_rr>;
2664 def: Pat<(store I1:$Pu, (add I32:$Rs, I32:$Rt)),
2665 (S4_storerb_rr IntRegs:$Rs, IntRegs:$Rt, 0, (I1toI32 I1:$Pu))>;
2668 // Reg, store-immediate
2669 let AddedComplexity = 20 in {
2670 def: Storexim_base_pat<truncstorei8, anyint, ToImmByte, S4_storeirb_io>;
2671 def: Storexim_base_pat<truncstorei16, anyint, ToImmHalf, S4_storeirh_io>;
2672 def: Storexim_base_pat<store, anyint, ToImmWord, S4_storeiri_io>;
2674 def: Storexi_base_pat<truncstorei8, anyimm, S4_storeirb_io>;
2675 def: Storexi_base_pat<truncstorei16, anyimm, S4_storeirh_io>;
2676 def: Storexi_base_pat<store, anyimm, S4_storeiri_io>;
2679 // Reg, store-register
2680 let AddedComplexity = 10 in {
2681 def: Storexi_base_pat<truncstorei8, I32, S2_storerb_io>;
2682 def: Storexi_base_pat<truncstorei16, I32, S2_storerh_io>;
2683 def: Storexi_base_pat<store, I32, S2_storeri_io>;
2684 def: Storexi_base_pat<store, V4I8, S2_storeri_io>;
2685 def: Storexi_base_pat<store, V2I16, S2_storeri_io>;
2686 def: Storexi_base_pat<store, I64, S2_storerd_io>;
2687 def: Storexi_base_pat<store, V8I8, S2_storerd_io>;
2688 def: Storexi_base_pat<store, V4I16, S2_storerd_io>;
2689 def: Storexi_base_pat<store, V2I32, S2_storerd_io>;
2690 def: Storexi_base_pat<store, F32, S2_storeri_io>;
2691 def: Storexi_base_pat<store, F64, S2_storerd_io>;
2693 def: Storexim_base_pat<truncstorei8, I64, LoReg, S2_storerb_io>;
2694 def: Storexim_base_pat<truncstorei16, I64, LoReg, S2_storerh_io>;
2695 def: Storexim_base_pat<truncstorei32, I64, LoReg, S2_storeri_io>;
2696 def: Storexim_base_pat<store, I1, I1toI32, S2_storerb_io>;
2698 def: Storexi_base_pat<AtomSt<atomic_store_8>, I32, S2_storerb_io>;
2699 def: Storexi_base_pat<AtomSt<atomic_store_16>, I32, S2_storerh_io>;
2700 def: Storexi_base_pat<AtomSt<atomic_store_32>, I32, S2_storeri_io>;
2701 def: Storexi_base_pat<AtomSt<atomic_store_32>, V4I8, S2_storeri_io>;
2702 def: Storexi_base_pat<AtomSt<atomic_store_32>, V2I16, S2_storeri_io>;
2703 def: Storexi_base_pat<AtomSt<atomic_store_64>, I64, S2_storerd_io>;
2704 def: Storexi_base_pat<AtomSt<atomic_store_64>, V8I8, S2_storerd_io>;
2705 def: Storexi_base_pat<AtomSt<atomic_store_64>, V4I16, S2_storerd_io>;
2706 def: Storexi_base_pat<AtomSt<atomic_store_64>, V2I32, S2_storerd_io>;
2710 // --(14) Memop ----------------------------------------------------------
2713 def m5_0Imm8Pred : PatLeaf<(i32 imm), [{
2714 int8_t V = N->getSExtValue();
2715 return -32 < V && V <= -1;
2718 def m5_0Imm16Pred : PatLeaf<(i32 imm), [{
2719 int16_t V = N->getSExtValue();
2720 return -32 < V && V <= -1;
2723 def m5_0ImmPred : PatLeaf<(i32 imm), [{
2724 int64_t V = N->getSExtValue();
2725 return -31 <= V && V <= -1;
2728 def IsNPow2_8 : PatLeaf<(i32 imm), [{
2729 uint8_t NV = ~N->getZExtValue();
2730 return isPowerOf2_32(NV);
2733 def IsNPow2_16 : PatLeaf<(i32 imm), [{
2734 uint16_t NV = ~N->getZExtValue();
2735 return isPowerOf2_32(NV);
2738 def Log2_8 : SDNodeXForm<imm, [{
2739 uint8_t V = N->getZExtValue();
2740 return CurDAG->getTargetConstant(Log2_32(V), SDLoc(N), MVT::i32);
2743 def Log2_16 : SDNodeXForm<imm, [{
2744 uint16_t V = N->getZExtValue();
2745 return CurDAG->getTargetConstant(Log2_32(V), SDLoc(N), MVT::i32);
2748 def LogN2_8 : SDNodeXForm<imm, [{
2749 uint8_t NV = ~N->getZExtValue();
2750 return CurDAG->getTargetConstant(Log2_32(NV), SDLoc(N), MVT::i32);
2753 def LogN2_16 : SDNodeXForm<imm, [{
2754 uint16_t NV = ~N->getZExtValue();
2755 return CurDAG->getTargetConstant(Log2_32(NV), SDLoc(N), MVT::i32);
2758 def IdImm : SDNodeXForm<imm, [{ return SDValue(N, 0); }]>;
2760 multiclass Memopxr_base_pat<PatFrag Load, PatFrag Store, SDNode Oper,
2763 def: Pat<(Store (Oper (Load I32:$Rs), I32:$A), I32:$Rs),
2764 (MI I32:$Rs, 0, I32:$A)>;
2766 def: Pat<(Store (Oper (Load AddrFI:$Rs), I32:$A), AddrFI:$Rs),
2767 (MI AddrFI:$Rs, 0, I32:$A)>;
2770 multiclass Memopxr_add_pat<PatFrag Load, PatFrag Store, PatFrag ImmPred,
2771 SDNode Oper, InstHexagon MI> {
2773 def: Pat<(Store (Oper (Load (add I32:$Rs, ImmPred:$Off)), I32:$A),
2774 (add I32:$Rs, ImmPred:$Off)),
2775 (MI I32:$Rs, imm:$Off, I32:$A)>;
2776 def: Pat<(Store (Oper (Load (IsOrAdd I32:$Rs, ImmPred:$Off)), I32:$A),
2777 (IsOrAdd I32:$Rs, ImmPred:$Off)),
2778 (MI I32:$Rs, imm:$Off, I32:$A)>;
2780 def: Pat<(Store (Oper (Load (add AddrFI:$Rs, ImmPred:$Off)), I32:$A),
2781 (add AddrFI:$Rs, ImmPred:$Off)),
2782 (MI AddrFI:$Rs, imm:$Off, I32:$A)>;
2783 def: Pat<(Store (Oper (Load (IsOrAdd AddrFI:$Rs, ImmPred:$Off)), I32:$A),
2784 (IsOrAdd AddrFI:$Rs, ImmPred:$Off)),
2785 (MI AddrFI:$Rs, imm:$Off, I32:$A)>;
2788 multiclass Memopxr_pat<PatFrag Load, PatFrag Store, PatFrag ImmPred,
2789 SDNode Oper, InstHexagon MI> {
2790 let Predicates = [UseMEMOPS] in {
2791 defm: Memopxr_base_pat <Load, Store, Oper, MI>;
2792 defm: Memopxr_add_pat <Load, Store, ImmPred, Oper, MI>;
2796 let AddedComplexity = 200 in {
2798 defm: Memopxr_pat<extloadi8, truncstorei8, u6_0ImmPred, add,
2799 /*anyext*/ L4_add_memopb_io>;
2800 defm: Memopxr_pat<sextloadi8, truncstorei8, u6_0ImmPred, add,
2801 /*sext*/ L4_add_memopb_io>;
2802 defm: Memopxr_pat<zextloadi8, truncstorei8, u6_0ImmPred, add,
2803 /*zext*/ L4_add_memopb_io>;
2804 defm: Memopxr_pat<extloadi16, truncstorei16, u6_1ImmPred, add,
2805 /*anyext*/ L4_add_memoph_io>;
2806 defm: Memopxr_pat<sextloadi16, truncstorei16, u6_1ImmPred, add,
2807 /*sext*/ L4_add_memoph_io>;
2808 defm: Memopxr_pat<zextloadi16, truncstorei16, u6_1ImmPred, add,
2809 /*zext*/ L4_add_memoph_io>;
2810 defm: Memopxr_pat<load, store, u6_2ImmPred, add, L4_add_memopw_io>;
2813 defm: Memopxr_pat<extloadi8, truncstorei8, u6_0ImmPred, sub,
2814 /*anyext*/ L4_sub_memopb_io>;
2815 defm: Memopxr_pat<sextloadi8, truncstorei8, u6_0ImmPred, sub,
2816 /*sext*/ L4_sub_memopb_io>;
2817 defm: Memopxr_pat<zextloadi8, truncstorei8, u6_0ImmPred, sub,
2818 /*zext*/ L4_sub_memopb_io>;
2819 defm: Memopxr_pat<extloadi16, truncstorei16, u6_1ImmPred, sub,
2820 /*anyext*/ L4_sub_memoph_io>;
2821 defm: Memopxr_pat<sextloadi16, truncstorei16, u6_1ImmPred, sub,
2822 /*sext*/ L4_sub_memoph_io>;
2823 defm: Memopxr_pat<zextloadi16, truncstorei16, u6_1ImmPred, sub,
2824 /*zext*/ L4_sub_memoph_io>;
2825 defm: Memopxr_pat<load, store, u6_2ImmPred, sub, L4_sub_memopw_io>;
2828 defm: Memopxr_pat<extloadi8, truncstorei8, u6_0ImmPred, and,
2829 /*anyext*/ L4_and_memopb_io>;
2830 defm: Memopxr_pat<sextloadi8, truncstorei8, u6_0ImmPred, and,
2831 /*sext*/ L4_and_memopb_io>;
2832 defm: Memopxr_pat<zextloadi8, truncstorei8, u6_0ImmPred, and,
2833 /*zext*/ L4_and_memopb_io>;
2834 defm: Memopxr_pat<extloadi16, truncstorei16, u6_1ImmPred, and,
2835 /*anyext*/ L4_and_memoph_io>;
2836 defm: Memopxr_pat<sextloadi16, truncstorei16, u6_1ImmPred, and,
2837 /*sext*/ L4_and_memoph_io>;
2838 defm: Memopxr_pat<zextloadi16, truncstorei16, u6_1ImmPred, and,
2839 /*zext*/ L4_and_memoph_io>;
2840 defm: Memopxr_pat<load, store, u6_2ImmPred, and, L4_and_memopw_io>;
2843 defm: Memopxr_pat<extloadi8, truncstorei8, u6_0ImmPred, or,
2844 /*anyext*/ L4_or_memopb_io>;
2845 defm: Memopxr_pat<sextloadi8, truncstorei8, u6_0ImmPred, or,
2846 /*sext*/ L4_or_memopb_io>;
2847 defm: Memopxr_pat<zextloadi8, truncstorei8, u6_0ImmPred, or,
2848 /*zext*/ L4_or_memopb_io>;
2849 defm: Memopxr_pat<extloadi16, truncstorei16, u6_1ImmPred, or,
2850 /*anyext*/ L4_or_memoph_io>;
2851 defm: Memopxr_pat<sextloadi16, truncstorei16, u6_1ImmPred, or,
2852 /*sext*/ L4_or_memoph_io>;
2853 defm: Memopxr_pat<zextloadi16, truncstorei16, u6_1ImmPred, or,
2854 /*zext*/ L4_or_memoph_io>;
2855 defm: Memopxr_pat<load, store, u6_2ImmPred, or, L4_or_memopw_io>;
2859 multiclass Memopxi_base_pat<PatFrag Load, PatFrag Store, SDNode Oper,
2860 PatFrag Arg, SDNodeXForm ArgMod, InstHexagon MI> {
2862 def: Pat<(Store (Oper (Load I32:$Rs), Arg:$A), I32:$Rs),
2863 (MI I32:$Rs, 0, (ArgMod Arg:$A))>;
2865 def: Pat<(Store (Oper (Load AddrFI:$Rs), Arg:$A), AddrFI:$Rs),
2866 (MI AddrFI:$Rs, 0, (ArgMod Arg:$A))>;
2869 multiclass Memopxi_add_pat<PatFrag Load, PatFrag Store, PatFrag ImmPred,
2870 SDNode Oper, PatFrag Arg, SDNodeXForm ArgMod,
2873 def: Pat<(Store (Oper (Load (add I32:$Rs, ImmPred:$Off)), Arg:$A),
2874 (add I32:$Rs, ImmPred:$Off)),
2875 (MI I32:$Rs, imm:$Off, (ArgMod Arg:$A))>;
2876 def: Pat<(Store (Oper (Load (IsOrAdd I32:$Rs, ImmPred:$Off)), Arg:$A),
2877 (IsOrAdd I32:$Rs, ImmPred:$Off)),
2878 (MI I32:$Rs, imm:$Off, (ArgMod Arg:$A))>;
2880 def: Pat<(Store (Oper (Load (add AddrFI:$Rs, ImmPred:$Off)), Arg:$A),
2881 (add AddrFI:$Rs, ImmPred:$Off)),
2882 (MI AddrFI:$Rs, imm:$Off, (ArgMod Arg:$A))>;
2883 def: Pat<(Store (Oper (Load (IsOrAdd AddrFI:$Rs, ImmPred:$Off)), Arg:$A),
2884 (IsOrAdd AddrFI:$Rs, ImmPred:$Off)),
2885 (MI AddrFI:$Rs, imm:$Off, (ArgMod Arg:$A))>;
2888 multiclass Memopxi_pat<PatFrag Load, PatFrag Store, PatFrag ImmPred,
2889 SDNode Oper, PatFrag Arg, SDNodeXForm ArgMod,
2891 let Predicates = [UseMEMOPS] in {
2892 defm: Memopxi_base_pat <Load, Store, Oper, Arg, ArgMod, MI>;
2893 defm: Memopxi_add_pat <Load, Store, ImmPred, Oper, Arg, ArgMod, MI>;
2897 let AddedComplexity = 220 in {
2899 defm: Memopxi_pat<extloadi8, truncstorei8, u6_0ImmPred, add, u5_0ImmPred,
2900 /*anyext*/ IdImm, L4_iadd_memopb_io>;
2901 defm: Memopxi_pat<sextloadi8, truncstorei8, u6_0ImmPred, add, u5_0ImmPred,
2902 /*sext*/ IdImm, L4_iadd_memopb_io>;
2903 defm: Memopxi_pat<zextloadi8, truncstorei8, u6_0ImmPred, add, u5_0ImmPred,
2904 /*zext*/ IdImm, L4_iadd_memopb_io>;
2905 defm: Memopxi_pat<extloadi16, truncstorei16, u6_1ImmPred, add, u5_0ImmPred,
2906 /*anyext*/ IdImm, L4_iadd_memoph_io>;
2907 defm: Memopxi_pat<extloadi16, truncstorei16, u6_1ImmPred, add, u5_0ImmPred,
2908 /*sext*/ IdImm, L4_iadd_memoph_io>;
2909 defm: Memopxi_pat<extloadi16, truncstorei16, u6_1ImmPred, add, u5_0ImmPred,
2910 /*zext*/ IdImm, L4_iadd_memoph_io>;
2911 defm: Memopxi_pat<load, store, u6_2ImmPred, add, u5_0ImmPred, IdImm,
2913 defm: Memopxi_pat<extloadi8, truncstorei8, u6_0ImmPred, sub, m5_0Imm8Pred,
2914 /*anyext*/ NegImm8, L4_iadd_memopb_io>;
2915 defm: Memopxi_pat<sextloadi8, truncstorei8, u6_0ImmPred, sub, m5_0Imm8Pred,
2916 /*sext*/ NegImm8, L4_iadd_memopb_io>;
2917 defm: Memopxi_pat<zextloadi8, truncstorei8, u6_0ImmPred, sub, m5_0Imm8Pred,
2918 /*zext*/ NegImm8, L4_iadd_memopb_io>;
2919 defm: Memopxi_pat<extloadi16, truncstorei16, u6_1ImmPred, sub, m5_0Imm16Pred,
2920 /*anyext*/ NegImm16, L4_iadd_memoph_io>;
2921 defm: Memopxi_pat<sextloadi16, truncstorei16, u6_1ImmPred, sub, m5_0Imm16Pred,
2922 /*sext*/ NegImm16, L4_iadd_memoph_io>;
2923 defm: Memopxi_pat<zextloadi16, truncstorei16, u6_1ImmPred, sub, m5_0Imm16Pred,
2924 /*zext*/ NegImm16, L4_iadd_memoph_io>;
2925 defm: Memopxi_pat<load, store, u6_2ImmPred, sub, m5_0ImmPred, NegImm32,
2929 defm: Memopxi_pat<extloadi8, truncstorei8, u6_0ImmPred, sub, u5_0ImmPred,
2930 /*anyext*/ IdImm, L4_isub_memopb_io>;
2931 defm: Memopxi_pat<sextloadi8, truncstorei8, u6_0ImmPred, sub, u5_0ImmPred,
2932 /*sext*/ IdImm, L4_isub_memopb_io>;
2933 defm: Memopxi_pat<zextloadi8, truncstorei8, u6_0ImmPred, sub, u5_0ImmPred,
2934 /*zext*/ IdImm, L4_isub_memopb_io>;
2935 defm: Memopxi_pat<extloadi16, truncstorei16, u6_1ImmPred, sub, u5_0ImmPred,
2936 /*anyext*/ IdImm, L4_isub_memoph_io>;
2937 defm: Memopxi_pat<sextloadi16, truncstorei16, u6_1ImmPred, sub, u5_0ImmPred,
2938 /*sext*/ IdImm, L4_isub_memoph_io>;
2939 defm: Memopxi_pat<zextloadi16, truncstorei16, u6_1ImmPred, sub, u5_0ImmPred,
2940 /*zext*/ IdImm, L4_isub_memoph_io>;
2941 defm: Memopxi_pat<load, store, u6_2ImmPred, sub, u5_0ImmPred, IdImm,
2943 defm: Memopxi_pat<extloadi8, truncstorei8, u6_0ImmPred, add, m5_0Imm8Pred,
2944 /*anyext*/ NegImm8, L4_isub_memopb_io>;
2945 defm: Memopxi_pat<sextloadi8, truncstorei8, u6_0ImmPred, add, m5_0Imm8Pred,
2946 /*sext*/ NegImm8, L4_isub_memopb_io>;
2947 defm: Memopxi_pat<zextloadi8, truncstorei8, u6_0ImmPred, add, m5_0Imm8Pred,
2948 /*zext*/ NegImm8, L4_isub_memopb_io>;
2949 defm: Memopxi_pat<extloadi16, truncstorei16, u6_1ImmPred, add, m5_0Imm16Pred,
2950 /*anyext*/ NegImm16, L4_isub_memoph_io>;
2951 defm: Memopxi_pat<sextloadi16, truncstorei16, u6_1ImmPred, add, m5_0Imm16Pred,
2952 /*sext*/ NegImm16, L4_isub_memoph_io>;
2953 defm: Memopxi_pat<zextloadi16, truncstorei16, u6_1ImmPred, add, m5_0Imm16Pred,
2954 /*zext*/ NegImm16, L4_isub_memoph_io>;
2955 defm: Memopxi_pat<load, store, u6_2ImmPred, add, m5_0ImmPred, NegImm32,
2959 defm: Memopxi_pat<extloadi8, truncstorei8, u6_0ImmPred, and, IsNPow2_8,
2960 /*anyext*/ LogN2_8, L4_iand_memopb_io>;
2961 defm: Memopxi_pat<sextloadi8, truncstorei8, u6_0ImmPred, and, IsNPow2_8,
2962 /*sext*/ LogN2_8, L4_iand_memopb_io>;
2963 defm: Memopxi_pat<zextloadi8, truncstorei8, u6_0ImmPred, and, IsNPow2_8,
2964 /*zext*/ LogN2_8, L4_iand_memopb_io>;
2965 defm: Memopxi_pat<extloadi16, truncstorei16, u6_1ImmPred, and, IsNPow2_16,
2966 /*anyext*/ LogN2_16, L4_iand_memoph_io>;
2967 defm: Memopxi_pat<sextloadi16, truncstorei16, u6_1ImmPred, and, IsNPow2_16,
2968 /*sext*/ LogN2_16, L4_iand_memoph_io>;
2969 defm: Memopxi_pat<zextloadi16, truncstorei16, u6_1ImmPred, and, IsNPow2_16,
2970 /*zext*/ LogN2_16, L4_iand_memoph_io>;
2971 defm: Memopxi_pat<load, store, u6_2ImmPred, and, IsNPow2_32,
2972 LogN2_32, L4_iand_memopw_io>;
2975 defm: Memopxi_pat<extloadi8, truncstorei8, u6_0ImmPred, or, IsPow2_32,
2976 /*anyext*/ Log2_8, L4_ior_memopb_io>;
2977 defm: Memopxi_pat<sextloadi8, truncstorei8, u6_0ImmPred, or, IsPow2_32,
2978 /*sext*/ Log2_8, L4_ior_memopb_io>;
2979 defm: Memopxi_pat<zextloadi8, truncstorei8, u6_0ImmPred, or, IsPow2_32,
2980 /*zext*/ Log2_8, L4_ior_memopb_io>;
2981 defm: Memopxi_pat<extloadi16, truncstorei16, u6_1ImmPred, or, IsPow2_32,
2982 /*anyext*/ Log2_16, L4_ior_memoph_io>;
2983 defm: Memopxi_pat<sextloadi16, truncstorei16, u6_1ImmPred, or, IsPow2_32,
2984 /*sext*/ Log2_16, L4_ior_memoph_io>;
2985 defm: Memopxi_pat<zextloadi16, truncstorei16, u6_1ImmPred, or, IsPow2_32,
2986 /*zext*/ Log2_16, L4_ior_memoph_io>;
2987 defm: Memopxi_pat<load, store, u6_2ImmPred, or, IsPow2_32,
2988 Log2_32, L4_ior_memopw_io>;
2992 // --(15) Call -----------------------------------------------------------
2995 // Pseudo instructions.
2996 def SDT_SPCallSeqStart
2997 : SDCallSeqStart<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
2998 def SDT_SPCallSeqEnd
2999 : SDCallSeqEnd<[SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
3001 def callseq_start: SDNode<"ISD::CALLSEQ_START", SDT_SPCallSeqStart,
3002 [SDNPHasChain, SDNPOutGlue]>;
3003 def callseq_end: SDNode<"ISD::CALLSEQ_END", SDT_SPCallSeqEnd,
3004 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
3006 def SDT_SPCall: SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
3008 def HexagonTCRet: SDNode<"HexagonISD::TC_RETURN", SDT_SPCall,
3009 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
3010 def callv3: SDNode<"HexagonISD::CALL", SDT_SPCall,
3011 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue, SDNPVariadic]>;
3012 def callv3nr: SDNode<"HexagonISD::CALLnr", SDT_SPCall,
3013 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue, SDNPVariadic]>;
3015 def: Pat<(callseq_start timm:$amt, timm:$amt2),
3016 (ADJCALLSTACKDOWN imm:$amt, imm:$amt2)>;
3017 def: Pat<(callseq_end timm:$amt1, timm:$amt2),
3018 (ADJCALLSTACKUP imm:$amt1, imm:$amt2)>;
3020 def: Pat<(HexagonTCRet tglobaladdr:$dst), (PS_tailcall_i tglobaladdr:$dst)>;
3021 def: Pat<(HexagonTCRet texternalsym:$dst), (PS_tailcall_i texternalsym:$dst)>;
3022 def: Pat<(HexagonTCRet I32:$dst), (PS_tailcall_r I32:$dst)>;
3024 def: Pat<(callv3 I32:$dst), (J2_callr I32:$dst)>;
3025 def: Pat<(callv3 tglobaladdr:$dst), (J2_call tglobaladdr:$dst)>;
3026 def: Pat<(callv3 texternalsym:$dst), (J2_call texternalsym:$dst)>;
3027 def: Pat<(callv3 tglobaltlsaddr:$dst), (J2_call tglobaltlsaddr:$dst)>;
3029 def: Pat<(callv3nr I32:$dst), (PS_callr_nr I32:$dst)>;
3030 def: Pat<(callv3nr tglobaladdr:$dst), (PS_call_nr tglobaladdr:$dst)>;
3031 def: Pat<(callv3nr texternalsym:$dst), (PS_call_nr texternalsym:$dst)>;
3033 def retflag : SDNode<"HexagonISD::RET_FLAG", SDTNone,
3034 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
3035 def eh_return: SDNode<"HexagonISD::EH_RETURN", SDTNone, [SDNPHasChain]>;
3037 def: Pat<(retflag), (PS_jmpret (i32 R31))>;
3038 def: Pat<(eh_return), (EH_RETURN_JMPR (i32 R31))>;
3041 // --(16) Branch ---------------------------------------------------------
3044 def: Pat<(br bb:$dst), (J2_jump b30_2Imm:$dst)>;
3045 def: Pat<(brind I32:$dst), (J2_jumpr I32:$dst)>;
3047 def: Pat<(brcond I1:$Pu, bb:$dst),
3048 (J2_jumpt I1:$Pu, bb:$dst)>;
3049 def: Pat<(brcond (not I1:$Pu), bb:$dst),
3050 (J2_jumpf I1:$Pu, bb:$dst)>;
3051 def: Pat<(brcond (i1 (setne I1:$Pu, -1)), bb:$dst),
3052 (J2_jumpf I1:$Pu, bb:$dst)>;
3053 def: Pat<(brcond (i1 (seteq I1:$Pu, 0)), bb:$dst),
3054 (J2_jumpf I1:$Pu, bb:$dst)>;
3055 def: Pat<(brcond (i1 (setne I1:$Pu, 0)), bb:$dst),
3056 (J2_jumpt I1:$Pu, bb:$dst)>;
3059 // --(17) Misc -----------------------------------------------------------
3062 // Generate code of the form 'C2_muxii(cmpbgtui(Rdd, C-1),0,1)'
3063 // for C code of the form r = (c>='0' && c<='9') ? 1 : 0.
3064 // The isdigit transformation relies on two 'clever' aspects:
3065 // 1) The data type is unsigned which allows us to eliminate a zero test after
3066 // biasing the expression by 48. We are depending on the representation of
3067 // the unsigned types, and semantics.
3068 // 2) The front end has converted <= 9 into < 10 on entry to LLVM.
3071 // retval = (c >= '0' && c <= '9') ? 1 : 0;
3072 // The code is transformed upstream of llvm into
3073 // retval = (c-48) < 10 ? 1 : 0;
3075 def u7_0PosImmPred : ImmLeaf<i32, [{
3076 // True if the immediate fits in an 7-bit unsigned field and is positive.
3077 return Imm > 0 && isUInt<7>(Imm);
3080 let AddedComplexity = 139 in
3081 def: Pat<(i32 (zext (i1 (setult (and I32:$Rs, 255), u7_0PosImmPred:$u7)))),
3082 (C2_muxii (A4_cmpbgtui IntRegs:$Rs, (UDEC1 imm:$u7)), 0, 1)>;
3084 let AddedComplexity = 100 in
3085 def: Pat<(or (or (shl (HexagonINSERT (i32 (zextloadi8 (add I32:$b, 2))),
3086 (i32 (extloadi8 (add I32:$b, 3))),
3089 (shl (i32 (zextloadi8 (add I32:$b, 1))), (i32 8))),
3090 (zextloadi8 I32:$b)),
3091 (A2_swiz (L2_loadri_io I32:$b, 0))>;
3094 // We need custom lowering of ISD::PREFETCH into HexagonISD::DCFETCH
3095 // because the SDNode ISD::PREFETCH has properties MayLoad and MayStore.
3096 // We don't really want either one here.
3097 def SDTHexagonDCFETCH: SDTypeProfile<0, 2, [SDTCisPtrTy<0>,SDTCisInt<1>]>;
3098 def HexagonDCFETCH: SDNode<"HexagonISD::DCFETCH", SDTHexagonDCFETCH,
3101 def: Pat<(HexagonDCFETCH IntRegs:$Rs, u11_3ImmPred:$u11_3),
3102 (Y2_dcfetchbo IntRegs:$Rs, imm:$u11_3)>;
3103 def: Pat<(HexagonDCFETCH (i32 (add IntRegs:$Rs, u11_3ImmPred:$u11_3)), (i32 0)),
3104 (Y2_dcfetchbo IntRegs:$Rs, imm:$u11_3)>;
3106 def SDTHexagonALLOCA
3107 : SDTypeProfile<1, 2, [SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
3109 : SDNode<"HexagonISD::ALLOCA", SDTHexagonALLOCA, [SDNPHasChain]>;
3111 def: Pat<(HexagonALLOCA I32:$Rs, (i32 imm:$A)),
3112 (PS_alloca IntRegs:$Rs, imm:$A)>;
3114 def HexagonBARRIER: SDNode<"HexagonISD::BARRIER", SDTNone, [SDNPHasChain]>;
3115 def: Pat<(HexagonBARRIER), (Y2_barrier)>;
3117 def: Pat<(trap), (PS_crash)>;
3119 // Read cycle counter.
3120 def SDTInt64Leaf: SDTypeProfile<1, 0, [SDTCisVT<0, i64>]>;
3121 def HexagonREADCYCLE: SDNode<"HexagonISD::READCYCLE", SDTInt64Leaf,
3124 def: Pat<(HexagonREADCYCLE), (A4_tfrcpp UPCYCLE)>;
3126 // The declared return value of the store-locked intrinsics is i32, but
3127 // the instructions actually define i1. To avoid register copies from
3128 // IntRegs to PredRegs and back, fold the entire pattern checking the
3129 // result against true/false.
3130 let AddedComplexity = 100 in {
3131 def: Pat<(i1 (setne (int_hexagon_S2_storew_locked I32:$Rs, I32:$Rt), 0)),
3132 (S2_storew_locked I32:$Rs, I32:$Rt)>;
3133 def: Pat<(i1 (seteq (int_hexagon_S2_storew_locked I32:$Rs, I32:$Rt), 0)),
3134 (C2_not (S2_storew_locked I32:$Rs, I32:$Rt))>;
3135 def: Pat<(i1 (setne (int_hexagon_S4_stored_locked I32:$Rs, I64:$Rt), 0)),
3136 (S4_stored_locked I32:$Rs, I64:$Rt)>;
3137 def: Pat<(i1 (seteq (int_hexagon_S4_stored_locked I32:$Rs, I64:$Rt), 0)),
3138 (C2_not (S4_stored_locked I32:$Rs, I64:$Rt))>;