1 //==- HexagonInstrInfo.td - Target Description for Hexagon -*- tablegen -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file describes the Hexagon instructions in TableGen format.
12 //===----------------------------------------------------------------------===//
14 include "HexagonInstrFormats.td"
15 include "HexagonOperands.td"
17 // Pattern fragment that combines the value type and the register class
18 // into a single parameter.
19 // The pat frags in the definitions below need to have a named register,
20 // otherwise i32 will be assumed regardless of the register class. The
21 // name of the register does not matter.
22 def I1 : PatLeaf<(i1 PredRegs:$R)>;
23 def I32 : PatLeaf<(i32 IntRegs:$R)>;
24 def I64 : PatLeaf<(i64 DoubleRegs:$R)>;
25 def F32 : PatLeaf<(f32 IntRegs:$R)>;
26 def F64 : PatLeaf<(f64 DoubleRegs:$R)>;
28 // Pattern fragments to extract the low and high subregisters from a
30 def LoReg: OutPatFrag<(ops node:$Rs),
31 (EXTRACT_SUBREG (i64 $Rs), subreg_loreg)>;
33 // SDNode for converting immediate C to C-1.
34 def DEC_CONST_SIGNED : SDNodeXForm<imm, [{
35 // Return the byte immediate const-1 as an SDNode.
36 int32_t imm = N->getSExtValue();
37 return XformSToSM1Imm(imm);
40 // SDNode for converting immediate C to C-1.
41 def DEC_CONST_UNSIGNED : SDNodeXForm<imm, [{
42 // Return the byte immediate const-1 as an SDNode.
43 uint32_t imm = N->getZExtValue();
44 return XformUToUM1Imm(imm);
47 //===----------------------------------------------------------------------===//
49 //===----------------------------------------------------------------------===//
51 //===----------------------------------------------------------------------===//
52 let hasSideEffects = 0, isCompare = 1, InputType = "imm", isExtendable = 1,
54 class T_CMP <string mnemonic, bits<2> MajOp, bit isNot, Operand ImmOp>
55 : ALU32Inst <(outs PredRegs:$dst),
56 (ins IntRegs:$src1, ImmOp:$src2),
57 "$dst = "#!if(isNot, "!","")#mnemonic#"($src1, #$src2)",
58 [], "",ALU32_2op_tc_2early_SLOT0123 >, ImmRegRel {
62 let CextOpcode = mnemonic;
63 let opExtentBits = !if(!eq(mnemonic, "cmp.gtu"), 9, 10);
64 let isExtentSigned = !if(!eq(mnemonic, "cmp.gtu"), 0, 1);
68 let Inst{27-24} = 0b0101;
69 let Inst{23-22} = MajOp;
70 let Inst{21} = !if(!eq(mnemonic, "cmp.gtu"), 0, src2{9});
71 let Inst{20-16} = src1;
72 let Inst{13-5} = src2{8-0};
78 def C2_cmpeqi : T_CMP <"cmp.eq", 0b00, 0, s10Ext>;
79 def C2_cmpgti : T_CMP <"cmp.gt", 0b01, 0, s10Ext>;
80 def C2_cmpgtui : T_CMP <"cmp.gtu", 0b10, 0, u9Ext>;
82 class T_CMP_pat <InstHexagon MI, PatFrag OpNode, PatLeaf ImmPred>
83 : Pat<(i1 (OpNode (i32 IntRegs:$src1), ImmPred:$src2)),
84 (MI IntRegs:$src1, ImmPred:$src2)>;
86 def : T_CMP_pat <C2_cmpeqi, seteq, s10ImmPred>;
87 def : T_CMP_pat <C2_cmpgti, setgt, s10ImmPred>;
88 def : T_CMP_pat <C2_cmpgtui, setugt, u9ImmPred>;
90 //===----------------------------------------------------------------------===//
92 //===----------------------------------------------------------------------===//
93 def SDTHexagonI64I32I32 : SDTypeProfile<1, 2,
94 [SDTCisVT<0, i64>, SDTCisVT<1, i32>, SDTCisSameAs<1, 2>]>;
96 def HexagonCOMBINE : SDNode<"HexagonISD::COMBINE", SDTHexagonI64I32I32>;
98 let hasSideEffects = 0, hasNewValue = 1, InputType = "reg" in
99 class T_ALU32_3op<string mnemonic, bits<3> MajOp, bits<3> MinOp, bit OpsRev,
101 : ALU32_rr<(outs IntRegs:$Rd), (ins IntRegs:$Rs, IntRegs:$Rt),
102 "$Rd = "#mnemonic#"($Rs, $Rt)",
103 [], "", ALU32_3op_tc_1_SLOT0123>, ImmRegRel, PredRel {
104 let isCommutable = IsComm;
105 let BaseOpcode = mnemonic#_rr;
106 let CextOpcode = mnemonic;
114 let Inst{26-24} = MajOp;
115 let Inst{23-21} = MinOp;
116 let Inst{20-16} = !if(OpsRev,Rt,Rs);
117 let Inst{12-8} = !if(OpsRev,Rs,Rt);
121 let hasSideEffects = 0, hasNewValue = 1 in
122 class T_ALU32_3op_pred<string mnemonic, bits<3> MajOp, bits<3> MinOp,
123 bit OpsRev, bit PredNot, bit PredNew>
124 : ALU32_rr<(outs IntRegs:$Rd), (ins PredRegs:$Pu, IntRegs:$Rs, IntRegs:$Rt),
125 "if ("#!if(PredNot,"!","")#"$Pu"#!if(PredNew,".new","")#") "#
126 "$Rd = "#mnemonic#"($Rs, $Rt)",
127 [], "", ALU32_3op_tc_1_SLOT0123>, ImmRegRel, PredNewRel {
128 let isPredicated = 1;
129 let isPredicatedFalse = PredNot;
130 let isPredicatedNew = PredNew;
131 let BaseOpcode = mnemonic#_rr;
132 let CextOpcode = mnemonic;
141 let Inst{26-24} = MajOp;
142 let Inst{23-21} = MinOp;
143 let Inst{20-16} = !if(OpsRev,Rt,Rs);
144 let Inst{13} = PredNew;
145 let Inst{12-8} = !if(OpsRev,Rs,Rt);
146 let Inst{7} = PredNot;
151 class T_ALU32_combineh<string Op1, string Op2, bits<3> MajOp, bits<3> MinOp,
153 : T_ALU32_3op<"", MajOp, MinOp, OpsRev, 0> {
154 let AsmString = "$Rd = combine($Rs"#Op1#", $Rt"#Op2#")";
157 let isCodeGenOnly = 0 in {
158 def A2_combine_hh : T_ALU32_combineh<".h", ".h", 0b011, 0b100, 1>;
159 def A2_combine_hl : T_ALU32_combineh<".h", ".l", 0b011, 0b101, 1>;
160 def A2_combine_lh : T_ALU32_combineh<".l", ".h", 0b011, 0b110, 1>;
161 def A2_combine_ll : T_ALU32_combineh<".l", ".l", 0b011, 0b111, 1>;
164 class T_ALU32_3op_sfx<string mnemonic, string suffix, bits<3> MajOp,
165 bits<3> MinOp, bit OpsRev, bit IsComm>
166 : T_ALU32_3op<"", MajOp, MinOp, OpsRev, IsComm> {
167 let AsmString = "$Rd = "#mnemonic#"($Rs, $Rt)"#suffix;
170 let Defs = [USR_OVF], Itinerary = ALU32_3op_tc_2_SLOT0123,
171 isCodeGenOnly = 0 in {
172 def A2_addsat : T_ALU32_3op_sfx<"add", ":sat", 0b110, 0b010, 0, 1>;
173 def A2_subsat : T_ALU32_3op_sfx<"sub", ":sat", 0b110, 0b110, 1, 0>;
176 multiclass T_ALU32_3op_p<string mnemonic, bits<3> MajOp, bits<3> MinOp,
178 def t : T_ALU32_3op_pred<mnemonic, MajOp, MinOp, OpsRev, 0, 0>;
179 def f : T_ALU32_3op_pred<mnemonic, MajOp, MinOp, OpsRev, 1, 0>;
180 def tnew : T_ALU32_3op_pred<mnemonic, MajOp, MinOp, OpsRev, 0, 1>;
181 def fnew : T_ALU32_3op_pred<mnemonic, MajOp, MinOp, OpsRev, 1, 1>;
184 multiclass T_ALU32_3op_A2<string mnemonic, bits<3> MajOp, bits<3> MinOp,
185 bit OpsRev, bit IsComm> {
186 let isPredicable = 1 in
187 def A2_#NAME : T_ALU32_3op <mnemonic, MajOp, MinOp, OpsRev, IsComm>;
188 defm A2_p#NAME : T_ALU32_3op_p<mnemonic, MajOp, MinOp, OpsRev>;
191 let isCodeGenOnly = 0 in {
192 defm add : T_ALU32_3op_A2<"add", 0b011, 0b000, 0, 1>;
193 defm and : T_ALU32_3op_A2<"and", 0b001, 0b000, 0, 1>;
194 defm or : T_ALU32_3op_A2<"or", 0b001, 0b001, 0, 1>;
195 defm sub : T_ALU32_3op_A2<"sub", 0b011, 0b001, 1, 0>;
196 defm xor : T_ALU32_3op_A2<"xor", 0b001, 0b011, 0, 1>;
199 // Pats for instruction selection.
200 class BinOp32_pat<SDNode Op, InstHexagon MI, ValueType ResT>
201 : Pat<(ResT (Op (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))),
202 (ResT (MI IntRegs:$Rs, IntRegs:$Rt))>;
204 def: BinOp32_pat<add, A2_add, i32>;
205 def: BinOp32_pat<and, A2_and, i32>;
206 def: BinOp32_pat<or, A2_or, i32>;
207 def: BinOp32_pat<sub, A2_sub, i32>;
208 def: BinOp32_pat<xor, A2_xor, i32>;
210 // A few special cases producing register pairs:
211 let OutOperandList = (outs DoubleRegs:$Rd), hasNewValue = 0,
212 isCodeGenOnly = 0 in {
213 def S2_packhl : T_ALU32_3op <"packhl", 0b101, 0b100, 0, 0>;
215 let isPredicable = 1 in
216 def A2_combinew : T_ALU32_3op <"combine", 0b101, 0b000, 0, 0>;
218 // Conditional combinew uses "newt/f" instead of "t/fnew".
219 def C2_ccombinewt : T_ALU32_3op_pred<"combine", 0b101, 0b000, 0, 0, 0>;
220 def C2_ccombinewf : T_ALU32_3op_pred<"combine", 0b101, 0b000, 0, 1, 0>;
221 def C2_ccombinewnewt : T_ALU32_3op_pred<"combine", 0b101, 0b000, 0, 0, 1>;
222 def C2_ccombinewnewf : T_ALU32_3op_pred<"combine", 0b101, 0b000, 0, 1, 1>;
225 let hasSideEffects = 0, hasNewValue = 1, isCompare = 1, InputType = "reg" in
226 class T_ALU32_3op_cmp<string mnemonic, bits<2> MinOp, bit IsNeg, bit IsComm>
227 : ALU32_rr<(outs PredRegs:$Pd), (ins IntRegs:$Rs, IntRegs:$Rt),
228 "$Pd = "#mnemonic#"($Rs, $Rt)",
229 [], "", ALU32_3op_tc_1_SLOT0123>, ImmRegRel {
230 let CextOpcode = mnemonic;
231 let isCommutable = IsComm;
237 let Inst{27-24} = 0b0010;
238 let Inst{22-21} = MinOp;
239 let Inst{20-16} = Rs;
242 let Inst{3-2} = 0b00;
246 let Itinerary = ALU32_3op_tc_2early_SLOT0123, isCodeGenOnly = 0 in {
247 def C2_cmpeq : T_ALU32_3op_cmp< "cmp.eq", 0b00, 0, 1>;
248 def C2_cmpgt : T_ALU32_3op_cmp< "cmp.gt", 0b10, 0, 0>;
249 def C2_cmpgtu : T_ALU32_3op_cmp< "cmp.gtu", 0b11, 0, 0>;
252 // Patfrag to convert the usual comparison patfrags (e.g. setlt) to ones
253 // that reverse the order of the operands.
254 class RevCmp<PatFrag F> : PatFrag<(ops node:$rhs, node:$lhs), F.Fragment>;
256 // Pats for compares. They use PatFrags as operands, not SDNodes,
257 // since seteq/setgt/etc. are defined as ParFrags.
258 class T_cmp32_rr_pat<InstHexagon MI, PatFrag Op, ValueType VT>
259 : Pat<(VT (Op (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))),
260 (VT (MI IntRegs:$Rs, IntRegs:$Rt))>;
262 def: T_cmp32_rr_pat<C2_cmpeq, seteq, i1>;
263 def: T_cmp32_rr_pat<C2_cmpgt, setgt, i1>;
264 def: T_cmp32_rr_pat<C2_cmpgtu, setugt, i1>;
266 def: T_cmp32_rr_pat<C2_cmpgt, RevCmp<setlt>, i1>;
267 def: T_cmp32_rr_pat<C2_cmpgtu, RevCmp<setult>, i1>;
269 let CextOpcode = "MUX", InputType = "reg", hasNewValue = 1,
271 def C2_mux: ALU32_rr<(outs IntRegs:$Rd),
272 (ins PredRegs:$Pu, IntRegs:$Rs, IntRegs:$Rt),
273 "$Rd = mux($Pu, $Rs, $Rt)", [], "", ALU32_3op_tc_1_SLOT0123>, ImmRegRel {
279 let CextOpcode = "mux";
280 let InputType = "reg";
281 let hasSideEffects = 0;
284 let Inst{27-24} = 0b0100;
285 let Inst{20-16} = Rs;
291 def: Pat<(i32 (select (i1 PredRegs:$Pu), (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))),
292 (C2_mux PredRegs:$Pu, IntRegs:$Rs, IntRegs:$Rt)>;
294 // Combines the two immediates into a double register.
295 // Increase complexity to make it greater than any complexity of a combine
296 // that involves a register.
298 let isReMaterializable = 1, isMoveImm = 1, isAsCheapAsAMove = 1,
299 isExtentSigned = 1, isExtendable = 1, opExtentBits = 8, opExtendable = 1,
300 AddedComplexity = 75, isCodeGenOnly = 0 in
301 def A2_combineii: ALU32Inst <(outs DoubleRegs:$Rdd), (ins s8Ext:$s8, s8Imm:$S8),
302 "$Rdd = combine(#$s8, #$S8)",
303 [(set (i64 DoubleRegs:$Rdd),
304 (i64 (HexagonCOMBINE(i32 s8ExtPred:$s8), (i32 s8ImmPred:$S8))))]> {
310 let Inst{27-23} = 0b11000;
311 let Inst{22-16} = S8{7-1};
312 let Inst{13} = S8{0};
317 //===----------------------------------------------------------------------===//
318 // Template class for predicated ADD of a reg and an Immediate value.
319 //===----------------------------------------------------------------------===//
320 let hasNewValue = 1 in
321 class T_Addri_Pred <bit PredNot, bit PredNew>
322 : ALU32_ri <(outs IntRegs:$Rd),
323 (ins PredRegs:$Pu, IntRegs:$Rs, s8Ext:$s8),
324 !if(PredNot, "if (!$Pu", "if ($Pu")#!if(PredNew,".new) $Rd = ",
325 ") $Rd = ")#"add($Rs, #$s8)"> {
331 let isPredicatedNew = PredNew;
334 let Inst{27-24} = 0b0100;
335 let Inst{23} = PredNot;
336 let Inst{22-21} = Pu;
337 let Inst{20-16} = Rs;
338 let Inst{13} = PredNew;
343 //===----------------------------------------------------------------------===//
344 // A2_addi: Add a signed immediate to a register.
345 //===----------------------------------------------------------------------===//
346 let hasNewValue = 1 in
347 class T_Addri <Operand immOp, list<dag> pattern = [] >
348 : ALU32_ri <(outs IntRegs:$Rd),
349 (ins IntRegs:$Rs, immOp:$s16),
350 "$Rd = add($Rs, #$s16)", pattern,
351 //[(set (i32 IntRegs:$Rd), (add (i32 IntRegs:$Rs), (s16ExtPred:$s16)))],
352 "", ALU32_ADDI_tc_1_SLOT0123> {
359 let Inst{27-21} = s16{15-9};
360 let Inst{20-16} = Rs;
361 let Inst{13-5} = s16{8-0};
365 //===----------------------------------------------------------------------===//
366 // Multiclass for ADD of a register and an immediate value.
367 //===----------------------------------------------------------------------===//
368 multiclass Addri_Pred<string mnemonic, bit PredNot> {
369 let isPredicatedFalse = PredNot in {
370 def _c#NAME : T_Addri_Pred<PredNot, 0>;
372 def _cdn#NAME : T_Addri_Pred<PredNot, 1>;
376 let isExtendable = 1, InputType = "imm" in
377 multiclass Addri_base<string mnemonic, SDNode OpNode> {
378 let CextOpcode = mnemonic, BaseOpcode = mnemonic#_ri in {
379 let opExtendable = 2, isExtentSigned = 1, opExtentBits = 16,
381 def NAME : T_Addri< s16Ext, // Rd=add(Rs,#s16)
382 [(set (i32 IntRegs:$Rd),
383 (add IntRegs:$Rs, s16ExtPred:$s16))]>;
385 let opExtendable = 3, isExtentSigned = 1, opExtentBits = 8,
386 hasSideEffects = 0, isPredicated = 1 in {
387 defm Pt : Addri_Pred<mnemonic, 0>;
388 defm NotPt : Addri_Pred<mnemonic, 1>;
393 let isCodeGenOnly = 0 in
394 defm ADD_ri : Addri_base<"add", add>, ImmRegRel, PredNewRel;
396 //===----------------------------------------------------------------------===//
397 // Template class used for the following ALU32 instructions.
400 //===----------------------------------------------------------------------===//
401 let isExtendable = 1, opExtendable = 2, isExtentSigned = 1, opExtentBits = 10,
402 InputType = "imm", hasNewValue = 1 in
403 class T_ALU32ri_logical <string mnemonic, SDNode OpNode, bits<2> MinOp>
404 : ALU32_ri <(outs IntRegs:$Rd),
405 (ins IntRegs:$Rs, s10Ext:$s10),
406 "$Rd = "#mnemonic#"($Rs, #$s10)" ,
407 [(set (i32 IntRegs:$Rd), (OpNode (i32 IntRegs:$Rs), s10ExtPred:$s10))]> {
411 let CextOpcode = mnemonic;
415 let Inst{27-24} = 0b0110;
416 let Inst{23-22} = MinOp;
417 let Inst{21} = s10{9};
418 let Inst{20-16} = Rs;
419 let Inst{13-5} = s10{8-0};
423 let isCodeGenOnly = 0 in {
424 def OR_ri : T_ALU32ri_logical<"or", or, 0b10>, ImmRegRel;
425 def AND_ri : T_ALU32ri_logical<"and", and, 0b00>, ImmRegRel;
428 // Subtract register from immediate
429 // Rd32=sub(#s10,Rs32)
430 let isExtendable = 1, opExtendable = 1, isExtentSigned = 1, opExtentBits = 10,
431 CextOpcode = "sub", InputType = "imm", hasNewValue = 1, isCodeGenOnly = 0 in
432 def SUB_ri: ALU32_ri <(outs IntRegs:$Rd), (ins s10Ext:$s10, IntRegs:$Rs),
433 "$Rd = sub(#$s10, $Rs)" ,
434 [(set IntRegs:$Rd, (sub s10ExtPred:$s10, IntRegs:$Rs))] > ,
442 let Inst{27-22} = 0b011001;
443 let Inst{21} = s10{9};
444 let Inst{20-16} = Rs;
445 let Inst{13-5} = s10{8-0};
450 let hasSideEffects = 0, isCodeGenOnly = 0 in
451 def A2_nop: ALU32Inst <(outs), (ins), "nop" > {
453 let Inst{27-24} = 0b1111;
455 // Rd = not(Rs) gets mapped to Rd=sub(#-1, Rs).
456 def : Pat<(not (i32 IntRegs:$src1)),
457 (SUB_ri -1, (i32 IntRegs:$src1))>;
459 let hasSideEffects = 0, hasNewValue = 1 in
460 class T_tfr16<bit isHi>
461 : ALU32Inst <(outs IntRegs:$Rx), (ins IntRegs:$src1, u16Imm:$u16),
462 "$Rx"#!if(isHi, ".h", ".l")#" = #$u16",
463 [], "$src1 = $Rx" > {
468 let Inst{27-26} = 0b00;
469 let Inst{25-24} = !if(isHi, 0b10, 0b01);
470 let Inst{23-22} = u16{15-14};
472 let Inst{20-16} = Rx;
473 let Inst{13-0} = u16{13-0};
476 let isCodeGenOnly = 0 in {
477 def A2_tfril: T_tfr16<0>;
478 def A2_tfrih: T_tfr16<1>;
481 // Conditional transfer is an alias to conditional "Rd = add(Rs, #0)".
482 let isPredicated = 1, hasNewValue = 1, opNewValue = 0 in
483 class T_tfr_pred<bit isPredNot, bit isPredNew>
484 : ALU32Inst<(outs IntRegs:$dst),
485 (ins PredRegs:$src1, IntRegs:$src2),
486 "if ("#!if(isPredNot, "!", "")#
487 "$src1"#!if(isPredNew, ".new", "")#
493 let isPredicatedFalse = isPredNot;
494 let isPredicatedNew = isPredNew;
497 let Inst{27-24} = 0b0100;
498 let Inst{23} = isPredNot;
499 let Inst{13} = isPredNew;
502 let Inst{22-21} = src1;
503 let Inst{20-16} = src2;
506 let isPredicable = 1 in
507 class T_tfr : ALU32Inst<(outs IntRegs:$dst), (ins IntRegs:$src),
514 let Inst{27-21} = 0b0000011;
515 let Inst{20-16} = src;
520 let InputType = "reg", hasNewValue = 1, hasSideEffects = 0 in
521 multiclass tfr_base<string CextOp> {
522 let CextOpcode = CextOp, BaseOpcode = CextOp in {
526 def t : T_tfr_pred<0, 0>;
527 def f : T_tfr_pred<1, 0>;
529 def tnew : T_tfr_pred<0, 1>;
530 def fnew : T_tfr_pred<1, 1>;
534 // Assembler mapped to C2_ccombinew[t|f|newt|newf].
535 // Please don't add bits to this instruction as it'll be converted into
536 // 'combine' before object code emission.
537 let isPredicated = 1 in
538 class T_tfrp_pred<bit PredNot, bit PredNew>
539 : ALU32_rr <(outs DoubleRegs:$dst),
540 (ins PredRegs:$src1, DoubleRegs:$src2),
541 "if ("#!if(PredNot, "!", "")#"$src1"
542 #!if(PredNew, ".new", "")#") $dst = $src2" > {
543 let isPredicatedFalse = PredNot;
544 let isPredicatedNew = PredNew;
547 // Assembler mapped to A2_combinew.
548 // Please don't add bits to this instruction as it'll be converted into
549 // 'combine' before object code emission.
550 class T_tfrp : ALU32Inst <(outs DoubleRegs:$dst),
551 (ins DoubleRegs:$src),
554 let hasSideEffects = 0 in
555 multiclass TFR64_base<string BaseName> {
556 let BaseOpcode = BaseName in {
557 let isPredicable = 1 in
560 def t : T_tfrp_pred <0, 0>;
561 def f : T_tfrp_pred <1, 0>;
563 def tnew : T_tfrp_pred <0, 1>;
564 def fnew : T_tfrp_pred <1, 1>;
568 let InputType = "imm", isExtendable = 1, isExtentSigned = 1, opExtentBits = 12,
569 isMoveImm = 1, opExtendable = 2, BaseOpcode = "TFRI", CextOpcode = "TFR",
570 hasSideEffects = 0, isPredicated = 1, hasNewValue = 1 in
571 class T_TFRI_Pred<bit PredNot, bit PredNew>
572 : ALU32_ri<(outs IntRegs:$Rd), (ins PredRegs:$Pu, s12Ext:$s12),
573 "if ("#!if(PredNot,"!","")#"$Pu"#!if(PredNew,".new","")#") $Rd = #$s12",
574 [], "", ALU32_2op_tc_1_SLOT0123>, ImmRegRel, PredNewRel {
575 let isPredicatedFalse = PredNot;
576 let isPredicatedNew = PredNew;
583 let Inst{27-24} = 0b1110;
584 let Inst{23} = PredNot;
585 let Inst{22-21} = Pu;
587 let Inst{19-16,12-5} = s12;
588 let Inst{13} = PredNew;
592 let isCodeGenOnly = 0 in {
593 def C2_cmoveit : T_TFRI_Pred<0, 0>;
594 def C2_cmoveif : T_TFRI_Pred<1, 0>;
595 def C2_cmovenewit : T_TFRI_Pred<0, 1>;
596 def C2_cmovenewif : T_TFRI_Pred<1, 1>;
599 let InputType = "imm", isExtendable = 1, isExtentSigned = 1,
600 CextOpcode = "TFR", BaseOpcode = "TFRI", hasNewValue = 1, opNewValue = 0,
601 isAsCheapAsAMove = 1 , opExtendable = 1, opExtentBits = 16, isMoveImm = 1,
602 isPredicated = 0, isPredicable = 1, isReMaterializable = 1,
604 def A2_tfrsi : ALU32Inst<(outs IntRegs:$Rd), (ins s16Ext:$s16), "$Rd = #$s16",
605 [(set (i32 IntRegs:$Rd), s16ExtPred:$s16)], "", ALU32_2op_tc_1_SLOT0123>,
611 let Inst{27-24} = 0b1000;
612 let Inst{23-22,20-16,13-5} = s16;
616 let isCodeGenOnly = 0 in
617 defm A2_tfr : tfr_base<"TFR">, ImmRegRel, PredNewRel;
618 defm A2_tfrp : TFR64_base<"TFR64">, PredNewRel;
621 let isReMaterializable = 1, isMoveImm = 1, isAsCheapAsAMove = 1 in
622 def A2_tfrpi : ALU64_rr<(outs DoubleRegs:$dst), (ins s8Imm64:$src1),
624 [(set (i64 DoubleRegs:$dst), s8Imm64Pred:$src1)]>;
626 // TODO: see if this instruction can be deleted..
627 let isExtendable = 1, opExtendable = 1, opExtentBits = 6 in
628 def TFRI64_V4 : ALU64_rr<(outs DoubleRegs:$dst), (ins u6Ext:$src1),
631 //===----------------------------------------------------------------------===//
633 //===----------------------------------------------------------------------===//
636 //===----------------------------------------------------------------------===//
638 //===----------------------------------------------------------------------===//
639 // Scalar mux register immediate.
640 let hasSideEffects = 0, isExtentSigned = 1, CextOpcode = "MUX",
641 InputType = "imm", hasNewValue = 1, isExtendable = 1, opExtentBits = 8 in
642 class T_MUX1 <bit MajOp, dag ins, string AsmStr>
643 : ALU32Inst <(outs IntRegs:$Rd), ins, AsmStr>, ImmRegRel {
650 let Inst{27-24} = 0b0011;
651 let Inst{23} = MajOp;
652 let Inst{22-21} = Pu;
653 let Inst{20-16} = Rs;
659 let opExtendable = 2, isCodeGenOnly = 0 in
660 def C2_muxri : T_MUX1<0b1, (ins PredRegs:$Pu, s8Ext:$s8, IntRegs:$Rs),
661 "$Rd = mux($Pu, #$s8, $Rs)">;
663 let opExtendable = 3, isCodeGenOnly = 0 in
664 def C2_muxir : T_MUX1<0b0, (ins PredRegs:$Pu, IntRegs:$Rs, s8Ext:$s8),
665 "$Rd = mux($Pu, $Rs, #$s8)">;
667 def : Pat<(i32 (select I1:$Pu, s8ExtPred:$s8, I32:$Rs)),
668 (C2_muxri I1:$Pu, s8ExtPred:$s8, I32:$Rs)>;
670 def : Pat<(i32 (select I1:$Pu, I32:$Rs, s8ExtPred:$s8)),
671 (C2_muxir I1:$Pu, I32:$Rs, s8ExtPred:$s8)>;
673 // C2_muxii: Scalar mux immediates.
674 let isExtentSigned = 1, hasNewValue = 1, isExtendable = 1,
675 opExtentBits = 8, opExtendable = 2, isCodeGenOnly = 0 in
676 def C2_muxii: ALU32Inst <(outs IntRegs:$Rd),
677 (ins PredRegs:$Pu, s8Ext:$s8, s8Imm:$S8),
678 "$Rd = mux($Pu, #$s8, #$S8)" ,
679 [(set (i32 IntRegs:$Rd),
680 (i32 (select I1:$Pu, s8ExtPred:$s8, s8ImmPred:$S8)))] > {
688 let Inst{27-25} = 0b101;
689 let Inst{24-23} = Pu;
690 let Inst{22-16} = S8{7-1};
691 let Inst{13} = S8{0};
696 //===----------------------------------------------------------------------===//
697 // template class for non-predicated alu32_2op instructions
698 // - aslh, asrh, sxtb, sxth, zxth
699 //===----------------------------------------------------------------------===//
700 let hasNewValue = 1, opNewValue = 0 in
701 class T_ALU32_2op <string mnemonic, bits<3> minOp> :
702 ALU32Inst < (outs IntRegs:$Rd), (ins IntRegs:$Rs),
703 "$Rd = "#mnemonic#"($Rs)", [] > {
709 let Inst{27-24} = 0b0000;
710 let Inst{23-21} = minOp;
713 let Inst{20-16} = Rs;
716 //===----------------------------------------------------------------------===//
717 // template class for predicated alu32_2op instructions
718 // - aslh, asrh, sxtb, sxth, zxtb, zxth
719 //===----------------------------------------------------------------------===//
720 let hasSideEffects = 0, validSubTargets = HasV4SubT,
721 hasNewValue = 1, opNewValue = 0 in
722 class T_ALU32_2op_Pred <string mnemonic, bits<3> minOp, bit isPredNot,
724 ALU32Inst <(outs IntRegs:$Rd), (ins PredRegs:$Pu, IntRegs:$Rs),
725 !if(isPredNot, "if (!$Pu", "if ($Pu")
726 #!if(isPredNew, ".new) ",") ")#"$Rd = "#mnemonic#"($Rs)"> {
733 let Inst{27-24} = 0b0000;
734 let Inst{23-21} = minOp;
736 let Inst{11} = isPredNot;
737 let Inst{10} = isPredNew;
740 let Inst{20-16} = Rs;
743 multiclass ALU32_2op_Pred<string mnemonic, bits<3> minOp, bit PredNot> {
744 let isPredicatedFalse = PredNot in {
745 def NAME : T_ALU32_2op_Pred<mnemonic, minOp, PredNot, 0>;
748 let isPredicatedNew = 1 in
749 def NAME#new : T_ALU32_2op_Pred<mnemonic, minOp, PredNot, 1>;
753 multiclass ALU32_2op_base<string mnemonic, bits<3> minOp> {
754 let BaseOpcode = mnemonic in {
755 let isPredicable = 1, hasSideEffects = 0 in
756 def A2_#NAME : T_ALU32_2op<mnemonic, minOp>;
758 let validSubTargets = HasV4SubT, isPredicated = 1, hasSideEffects = 0 in {
759 defm A4_p#NAME#t : ALU32_2op_Pred<mnemonic, minOp, 0>;
760 defm A4_p#NAME#f : ALU32_2op_Pred<mnemonic, minOp, 1>;
765 let isCodeGenOnly = 0 in {
766 defm aslh : ALU32_2op_base<"aslh", 0b000>, PredNewRel;
767 defm asrh : ALU32_2op_base<"asrh", 0b001>, PredNewRel;
768 defm sxtb : ALU32_2op_base<"sxtb", 0b101>, PredNewRel;
769 defm sxth : ALU32_2op_base<"sxth", 0b111>, PredNewRel;
770 defm zxth : ALU32_2op_base<"zxth", 0b110>, PredNewRel;
773 // Rd=zxtb(Rs): assembler mapped to Rd=and(Rs,#255).
774 // Compiler would want to generate 'zxtb' instead of 'and' becuase 'zxtb' has
775 // predicated forms while 'and' doesn't. Since integrated assembler can't
776 // handle 'mapped' instructions, we need to encode 'zxtb' same as 'and' where
777 // immediate operand is set to '255'.
779 let hasNewValue = 1, opNewValue = 0 in
780 class T_ZXTB: ALU32Inst < (outs IntRegs:$Rd), (ins IntRegs:$Rs),
781 "$Rd = zxtb($Rs)", [] > { // Rd = and(Rs,255)
788 let Inst{27-22} = 0b011000;
790 let Inst{20-16} = Rs;
791 let Inst{21} = s10{9};
792 let Inst{13-5} = s10{8-0};
795 //Rd=zxtb(Rs): assembler mapped to "Rd=and(Rs,#255)
796 multiclass ZXTB_base <string mnemonic, bits<3> minOp> {
797 let BaseOpcode = mnemonic in {
798 let isPredicable = 1, hasSideEffects = 0 in
799 def A2_#NAME : T_ZXTB;
801 let validSubTargets = HasV4SubT, isPredicated = 1, hasSideEffects = 0 in {
802 defm A4_p#NAME#t : ALU32_2op_Pred<mnemonic, minOp, 0>;
803 defm A4_p#NAME#f : ALU32_2op_Pred<mnemonic, minOp, 1>;
808 let isCodeGenOnly=0 in
809 defm zxtb : ZXTB_base<"zxtb",0b100>, PredNewRel;
811 def: Pat<(shl I32:$src1, (i32 16)), (A2_aslh I32:$src1)>;
812 def: Pat<(sra I32:$src1, (i32 16)), (A2_asrh I32:$src1)>;
813 def: Pat<(sext_inreg I32:$src1, i8), (A2_sxtb I32:$src1)>;
814 def: Pat<(sext_inreg I32:$src1, i16), (A2_sxth I32:$src1)>;
816 //===----------------------------------------------------------------------===//
818 //===----------------------------------------------------------------------===//
821 //===----------------------------------------------------------------------===//
823 //===----------------------------------------------------------------------===//
825 //===----------------------------------------------------------------------===//
827 //===----------------------------------------------------------------------===//
830 //===----------------------------------------------------------------------===//
832 //===----------------------------------------------------------------------===//// Add.
833 //===----------------------------------------------------------------------===//
835 // Add/Subtract halfword
836 // Rd=add(Rt.L,Rs.[HL])[:sat]
837 // Rd=sub(Rt.L,Rs.[HL])[:sat]
838 // Rd=add(Rt.[LH],Rs.[HL])[:sat][:<16]
839 // Rd=sub(Rt.[LH],Rs.[HL])[:sat][:<16]
840 //===----------------------------------------------------------------------===//
842 let hasNewValue = 1, opNewValue = 0 in
843 class T_XTYPE_ADD_SUB <bits<2> LHbits, bit isSat, bit hasShift, bit isSub>
844 : ALU64Inst <(outs IntRegs:$Rd), (ins IntRegs:$Rt, IntRegs:$Rs),
845 "$Rd = "#!if(isSub,"sub","add")#"($Rt."
846 #!if(hasShift, !if(LHbits{1},"h","l"),"l") #", $Rs."
847 #!if(hasShift, !if(LHbits{0},"h)","l)"), !if(LHbits{1},"h)","l)"))
848 #!if(isSat,":sat","")
849 #!if(hasShift,":<<16",""), [], "", ALU64_tc_1_SLOT23> {
855 let Inst{27-23} = 0b01010;
856 let Inst{22} = hasShift;
857 let Inst{21} = isSub;
859 let Inst{6-5} = LHbits;
862 let Inst{20-16} = Rs;
865 //Rd=sub(Rt.L,Rs.[LH])
866 let isCodeGenOnly = 0 in {
867 def A2_subh_l16_ll : T_XTYPE_ADD_SUB <0b00, 0, 0, 1>;
868 def A2_subh_l16_hl : T_XTYPE_ADD_SUB <0b10, 0, 0, 1>;
871 let isCodeGenOnly = 0 in {
872 //Rd=add(Rt.L,Rs.[LH])
873 def A2_addh_l16_ll : T_XTYPE_ADD_SUB <0b00, 0, 0, 0>;
874 def A2_addh_l16_hl : T_XTYPE_ADD_SUB <0b10, 0, 0, 0>;
877 let Itinerary = ALU64_tc_2_SLOT23, Defs = [USR_OVF], isCodeGenOnly = 0 in {
878 //Rd=sub(Rt.L,Rs.[LH]):sat
879 def A2_subh_l16_sat_ll : T_XTYPE_ADD_SUB <0b00, 1, 0, 1>;
880 def A2_subh_l16_sat_hl : T_XTYPE_ADD_SUB <0b10, 1, 0, 1>;
882 //Rd=add(Rt.L,Rs.[LH]):sat
883 def A2_addh_l16_sat_ll : T_XTYPE_ADD_SUB <0b00, 1, 0, 0>;
884 def A2_addh_l16_sat_hl : T_XTYPE_ADD_SUB <0b10, 1, 0, 0>;
887 //Rd=sub(Rt.[LH],Rs.[LH]):<<16
888 let isCodeGenOnly = 0 in {
889 def A2_subh_h16_ll : T_XTYPE_ADD_SUB <0b00, 0, 1, 1>;
890 def A2_subh_h16_lh : T_XTYPE_ADD_SUB <0b01, 0, 1, 1>;
891 def A2_subh_h16_hl : T_XTYPE_ADD_SUB <0b10, 0, 1, 1>;
892 def A2_subh_h16_hh : T_XTYPE_ADD_SUB <0b11, 0, 1, 1>;
895 //Rd=add(Rt.[LH],Rs.[LH]):<<16
896 let isCodeGenOnly = 0 in {
897 def A2_addh_h16_ll : T_XTYPE_ADD_SUB <0b00, 0, 1, 0>;
898 def A2_addh_h16_lh : T_XTYPE_ADD_SUB <0b01, 0, 1, 0>;
899 def A2_addh_h16_hl : T_XTYPE_ADD_SUB <0b10, 0, 1, 0>;
900 def A2_addh_h16_hh : T_XTYPE_ADD_SUB <0b11, 0, 1, 0>;
903 let Itinerary = ALU64_tc_2_SLOT23, Defs = [USR_OVF], isCodeGenOnly = 0 in {
904 //Rd=sub(Rt.[LH],Rs.[LH]):sat:<<16
905 def A2_subh_h16_sat_ll : T_XTYPE_ADD_SUB <0b00, 1, 1, 1>;
906 def A2_subh_h16_sat_lh : T_XTYPE_ADD_SUB <0b01, 1, 1, 1>;
907 def A2_subh_h16_sat_hl : T_XTYPE_ADD_SUB <0b10, 1, 1, 1>;
908 def A2_subh_h16_sat_hh : T_XTYPE_ADD_SUB <0b11, 1, 1, 1>;
910 //Rd=add(Rt.[LH],Rs.[LH]):sat:<<16
911 def A2_addh_h16_sat_ll : T_XTYPE_ADD_SUB <0b00, 1, 1, 0>;
912 def A2_addh_h16_sat_lh : T_XTYPE_ADD_SUB <0b01, 1, 1, 0>;
913 def A2_addh_h16_sat_hl : T_XTYPE_ADD_SUB <0b10, 1, 1, 0>;
914 def A2_addh_h16_sat_hh : T_XTYPE_ADD_SUB <0b11, 1, 1, 0>;
918 def: Pat<(sext_inreg (add I32:$src1, I32:$src2), i16),
919 (A2_addh_l16_ll I32:$src1, I32:$src2)>;
921 def: Pat<(sra (add (shl I32:$src1, (i32 16)), I32:$src2), (i32 16)),
922 (A2_addh_l16_hl I32:$src1, I32:$src2)>;
924 def: Pat<(shl (add I32:$src1, I32:$src2), (i32 16)),
925 (A2_addh_h16_ll I32:$src1, I32:$src2)>;
927 // Subtract halfword.
928 def: Pat<(sext_inreg (sub I32:$src1, I32:$src2), i16),
929 (A2_subh_l16_ll I32:$src1, I32:$src2)>;
931 def: Pat<(shl (sub I32:$src1, I32:$src2), (i32 16)),
932 (A2_subh_h16_ll I32:$src1, I32:$src2)>;
934 let hasSideEffects = 0, hasNewValue = 1, isCodeGenOnly = 0 in
935 def S2_parityp: ALU64Inst<(outs IntRegs:$Rd),
936 (ins DoubleRegs:$Rs, DoubleRegs:$Rt),
937 "$Rd = parity($Rs, $Rt)", [], "", ALU64_tc_2_SLOT23> {
943 let Inst{27-24} = 0b0000;
944 let Inst{20-16} = Rs;
949 let hasNewValue = 1, opNewValue = 0, hasSideEffects = 0 in
950 class T_XTYPE_MIN_MAX < bit isMax, bit isUnsigned >
951 : ALU64Inst < (outs IntRegs:$Rd), (ins IntRegs:$Rt, IntRegs:$Rs),
952 "$Rd = "#!if(isMax,"max","min")#!if(isUnsigned,"u","")
953 #"($Rt, $Rs)", [], "", ALU64_tc_2_SLOT23> {
960 let Inst{27-23} = 0b01011;
961 let Inst{22-21} = !if(isMax, 0b10, 0b01);
962 let Inst{7} = isUnsigned;
964 let Inst{12-8} = !if(isMax, Rs, Rt);
965 let Inst{20-16} = !if(isMax, Rt, Rs);
968 let isCodeGenOnly = 0 in {
969 def A2_min : T_XTYPE_MIN_MAX < 0, 0 >;
970 def A2_minu : T_XTYPE_MIN_MAX < 0, 1 >;
971 def A2_max : T_XTYPE_MIN_MAX < 1, 0 >;
972 def A2_maxu : T_XTYPE_MIN_MAX < 1, 1 >;
975 // Here, depending on the operand being selected, we'll either generate a
976 // min or max instruction.
978 // (a>b)?a:b --> max(a,b) => Here check performed is '>' and the value selected
979 // is the larger of two. So, the corresponding HexagonInst is passed in 'Inst'.
980 // (a>b)?b:a --> min(a,b) => Here check performed is '>' but the smaller value
981 // is selected and the corresponding HexagonInst is passed in 'SwapInst'.
983 multiclass T_MinMax_pats <PatFrag Op, RegisterClass RC, ValueType VT,
984 InstHexagon Inst, InstHexagon SwapInst> {
985 def: Pat<(select (i1 (Op (VT RC:$src1), (VT RC:$src2))),
986 (VT RC:$src1), (VT RC:$src2)),
987 (Inst RC:$src1, RC:$src2)>;
988 def: Pat<(select (i1 (Op (VT RC:$src1), (VT RC:$src2))),
989 (VT RC:$src2), (VT RC:$src1)),
990 (SwapInst RC:$src1, RC:$src2)>;
994 multiclass MinMax_pats <PatFrag Op, InstHexagon Inst, InstHexagon SwapInst> {
995 defm: T_MinMax_pats<Op, IntRegs, i32, Inst, SwapInst>;
997 def: Pat<(sext_inreg (i32 (select (i1 (Op (i32 PositiveHalfWord:$src1),
998 (i32 PositiveHalfWord:$src2))),
999 (i32 PositiveHalfWord:$src1),
1000 (i32 PositiveHalfWord:$src2))), i16),
1001 (Inst IntRegs:$src1, IntRegs:$src2)>;
1003 def: Pat<(sext_inreg (i32 (select (i1 (Op (i32 PositiveHalfWord:$src1),
1004 (i32 PositiveHalfWord:$src2))),
1005 (i32 PositiveHalfWord:$src2),
1006 (i32 PositiveHalfWord:$src1))), i16),
1007 (SwapInst IntRegs:$src1, IntRegs:$src2)>;
1010 let AddedComplexity = 200 in {
1011 defm: MinMax_pats<setge, A2_max, A2_min>;
1012 defm: MinMax_pats<setgt, A2_max, A2_min>;
1013 defm: MinMax_pats<setle, A2_min, A2_max>;
1014 defm: MinMax_pats<setlt, A2_min, A2_max>;
1015 defm: MinMax_pats<setuge, A2_maxu, A2_minu>;
1016 defm: MinMax_pats<setugt, A2_maxu, A2_minu>;
1017 defm: MinMax_pats<setule, A2_minu, A2_maxu>;
1018 defm: MinMax_pats<setult, A2_minu, A2_maxu>;
1021 class T_cmp64_rr<string mnemonic, bits<3> MinOp, bit IsComm>
1022 : ALU64_rr<(outs PredRegs:$Pd), (ins DoubleRegs:$Rs, DoubleRegs:$Rt),
1023 "$Pd = "#mnemonic#"($Rs, $Rt)", [], "", ALU64_tc_2early_SLOT23> {
1025 let isCommutable = IsComm;
1026 let hasSideEffects = 0;
1032 let IClass = 0b1101;
1033 let Inst{27-21} = 0b0010100;
1034 let Inst{20-16} = Rs;
1035 let Inst{12-8} = Rt;
1036 let Inst{7-5} = MinOp;
1040 let isCodeGenOnly = 0 in {
1041 def C2_cmpeqp : T_cmp64_rr<"cmp.eq", 0b000, 1>;
1042 def C2_cmpgtp : T_cmp64_rr<"cmp.gt", 0b010, 0>;
1043 def C2_cmpgtup : T_cmp64_rr<"cmp.gtu", 0b100, 0>;
1046 class T_cmp64_rr_pat<InstHexagon MI, PatFrag CmpOp>
1047 : Pat<(i1 (CmpOp (i64 DoubleRegs:$Rs), (i64 DoubleRegs:$Rt))),
1048 (i1 (MI DoubleRegs:$Rs, DoubleRegs:$Rt))>;
1050 def: T_cmp64_rr_pat<C2_cmpeqp, seteq>;
1051 def: T_cmp64_rr_pat<C2_cmpgtp, setgt>;
1052 def: T_cmp64_rr_pat<C2_cmpgtup, setugt>;
1053 def: T_cmp64_rr_pat<C2_cmpgtp, RevCmp<setlt>>;
1054 def: T_cmp64_rr_pat<C2_cmpgtup, RevCmp<setult>>;
1056 let isCodeGenOnly = 0 in
1057 def C2_vmux : ALU64_rr<(outs DoubleRegs:$Rd),
1058 (ins PredRegs:$Pu, DoubleRegs:$Rs, DoubleRegs:$Rt),
1059 "$Rd = vmux($Pu, $Rs, $Rt)", [], "", ALU64_tc_1_SLOT23> {
1060 let hasSideEffects = 0;
1067 let IClass = 0b1101;
1068 let Inst{27-24} = 0b0001;
1069 let Inst{20-16} = Rs;
1070 let Inst{12-8} = Rt;
1075 class T_ALU64_rr<string mnemonic, string suffix, bits<4> RegType,
1076 bits<3> MajOp, bits<3> MinOp, bit OpsRev, bit IsComm,
1078 : ALU64_rr<(outs DoubleRegs:$Rd), (ins DoubleRegs:$Rs, DoubleRegs:$Rt),
1079 "$Rd = " #mnemonic# "($Rs, " #Op2Pfx# "$Rt)" #suffix, [],
1080 "", ALU64_tc_1_SLOT23> {
1081 let hasSideEffects = 0;
1082 let isCommutable = IsComm;
1088 let IClass = 0b1101;
1089 let Inst{27-24} = RegType;
1090 let Inst{23-21} = MajOp;
1091 let Inst{20-16} = !if (OpsRev,Rt,Rs);
1092 let Inst{12-8} = !if (OpsRev,Rs,Rt);
1093 let Inst{7-5} = MinOp;
1097 class T_ALU64_arith<string mnemonic, bits<3> MajOp, bits<3> MinOp, bit IsSat,
1098 bit OpsRev, bit IsComm>
1099 : T_ALU64_rr<mnemonic, !if(IsSat,":sat",""), 0b0011, MajOp, MinOp, OpsRev,
1102 let isCodeGenOnly = 0 in {
1103 def A2_addp : T_ALU64_arith<"add", 0b000, 0b111, 0, 0, 1>;
1104 def A2_subp : T_ALU64_arith<"sub", 0b001, 0b111, 0, 1, 0>;
1107 def: Pat<(i64 (add I64:$Rs, I64:$Rt)), (A2_addp I64:$Rs, I64:$Rt)>;
1108 def: Pat<(i64 (sub I64:$Rs, I64:$Rt)), (A2_subp I64:$Rs, I64:$Rt)>;
1110 class T_ALU64_logical<string mnemonic, bits<3> MinOp, bit OpsRev, bit IsComm,
1112 : T_ALU64_rr<mnemonic, "", 0b0011, 0b111, MinOp, OpsRev, IsComm,
1115 let isCodeGenOnly = 0 in {
1116 def A2_andp : T_ALU64_logical<"and", 0b000, 0, 1, 0>;
1117 def A2_orp : T_ALU64_logical<"or", 0b010, 0, 1, 0>;
1118 def A2_xorp : T_ALU64_logical<"xor", 0b100, 0, 1, 0>;
1121 def: Pat<(i64 (and I64:$Rs, I64:$Rt)), (A2_andp I64:$Rs, I64:$Rt)>;
1122 def: Pat<(i64 (or I64:$Rs, I64:$Rt)), (A2_orp I64:$Rs, I64:$Rt)>;
1123 def: Pat<(i64 (xor I64:$Rs, I64:$Rt)), (A2_xorp I64:$Rs, I64:$Rt)>;
1125 //===----------------------------------------------------------------------===//
1127 //===----------------------------------------------------------------------===//
1129 //===----------------------------------------------------------------------===//
1131 //===----------------------------------------------------------------------===//
1133 //===----------------------------------------------------------------------===//
1135 //===----------------------------------------------------------------------===//
1137 //===----------------------------------------------------------------------===//
1139 //===----------------------------------------------------------------------===//
1141 //===----------------------------------------------------------------------===//
1143 //===----------------------------------------------------------------------===//
1145 //===----------------------------------------------------------------------===//
1147 //===----------------------------------------------------------------------===//
1148 // Logical reductions on predicates.
1150 // Looping instructions.
1152 // Pipelined looping instructions.
1154 // Logical operations on predicates.
1155 let hasSideEffects = 0 in
1156 class T_LOGICAL_1OP<string MnOp, bits<2> OpBits>
1157 : CRInst<(outs PredRegs:$Pd), (ins PredRegs:$Ps),
1158 "$Pd = " # MnOp # "($Ps)", [], "", CR_tc_2early_SLOT23> {
1162 let IClass = 0b0110;
1163 let Inst{27-23} = 0b10111;
1164 let Inst{22-21} = OpBits;
1166 let Inst{17-16} = Ps;
1171 let isCodeGenOnly = 0 in {
1172 def C2_any8 : T_LOGICAL_1OP<"any8", 0b00>;
1173 def C2_all8 : T_LOGICAL_1OP<"all8", 0b01>;
1174 def C2_not : T_LOGICAL_1OP<"not", 0b10>;
1177 def: Pat<(i1 (not (i1 PredRegs:$Ps))),
1178 (C2_not PredRegs:$Ps)>;
1180 let hasSideEffects = 0 in
1181 class T_LOGICAL_2OP<string MnOp, bits<3> OpBits, bit IsNeg, bit Rev>
1182 : CRInst<(outs PredRegs:$Pd), (ins PredRegs:$Ps, PredRegs:$Pt),
1183 "$Pd = " # MnOp # "($Ps, " # !if (IsNeg,"!","") # "$Pt)",
1184 [], "", CR_tc_2early_SLOT23> {
1189 let IClass = 0b0110;
1190 let Inst{27-24} = 0b1011;
1191 let Inst{23-21} = OpBits;
1193 let Inst{17-16} = !if(Rev,Pt,Ps); // Rs and Rt are reversed for some
1194 let Inst{13} = 0b0; // instructions.
1195 let Inst{9-8} = !if(Rev,Ps,Pt);
1199 let isCodeGenOnly = 0 in {
1200 def C2_and : T_LOGICAL_2OP<"and", 0b000, 0, 1>;
1201 def C2_or : T_LOGICAL_2OP<"or", 0b001, 0, 1>;
1202 def C2_xor : T_LOGICAL_2OP<"xor", 0b010, 0, 0>;
1203 def C2_andn : T_LOGICAL_2OP<"and", 0b011, 1, 1>;
1204 def C2_orn : T_LOGICAL_2OP<"or", 0b111, 1, 1>;
1207 def: Pat<(i1 (and I1:$Ps, I1:$Pt)), (C2_and I1:$Ps, I1:$Pt)>;
1208 def: Pat<(i1 (or I1:$Ps, I1:$Pt)), (C2_or I1:$Ps, I1:$Pt)>;
1209 def: Pat<(i1 (xor I1:$Ps, I1:$Pt)), (C2_xor I1:$Ps, I1:$Pt)>;
1210 def: Pat<(i1 (and I1:$Ps, (not I1:$Pt))), (C2_andn I1:$Ps, I1:$Pt)>;
1211 def: Pat<(i1 (or I1:$Ps, (not I1:$Pt))), (C2_orn I1:$Ps, I1:$Pt)>;
1213 let hasSideEffects = 0, hasNewValue = 1, isCodeGenOnly = 0 in
1214 def C2_vitpack : SInst<(outs IntRegs:$Rd), (ins PredRegs:$Ps, PredRegs:$Pt),
1215 "$Rd = vitpack($Ps, $Pt)", [], "", S_2op_tc_1_SLOT23> {
1220 let IClass = 0b1000;
1221 let Inst{27-24} = 0b1001;
1222 let Inst{22-21} = 0b00;
1223 let Inst{17-16} = Ps;
1228 let hasSideEffects = 0, isCodeGenOnly = 0 in
1229 def C2_mask : SInst<(outs DoubleRegs:$Rd), (ins PredRegs:$Pt),
1230 "$Rd = mask($Pt)", [], "", S_2op_tc_1_SLOT23> {
1234 let IClass = 0b1000;
1235 let Inst{27-24} = 0b0110;
1240 // User control register transfer.
1241 //===----------------------------------------------------------------------===//
1243 //===----------------------------------------------------------------------===//
1245 //===----------------------------------------------------------------------===//
1247 //===----------------------------------------------------------------------===//
1249 def retflag : SDNode<"HexagonISD::RET_FLAG", SDTNone,
1250 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
1251 def eh_return: SDNode<"HexagonISD::EH_RETURN", SDTNone, [SDNPHasChain]>;
1253 def SDHexagonBR_JT: SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
1254 def HexagonBR_JT: SDNode<"HexagonISD::BR_JT", SDHexagonBR_JT, [SDNPHasChain]>;
1256 class CondStr<string CReg, bit True, bit New> {
1257 string S = "if (" # !if(True,"","!") # CReg # !if(New,".new","") # ") ";
1259 class JumpOpcStr<string Mnemonic, bit New, bit Taken> {
1260 string S = Mnemonic # !if(New, !if(Taken,":t",":nt"), "");
1263 let isBranch = 1, isBarrier = 1, Defs = [PC], hasSideEffects = 0,
1265 isExtendable = 1, opExtendable = 0, isExtentSigned = 1,
1266 opExtentBits = 24, opExtentAlign = 2, InputType = "imm" in
1267 class T_JMP<string ExtStr>
1268 : JInst<(outs), (ins brtarget:$dst),
1269 "jump " # ExtStr # "$dst",
1270 [], "", J_tc_2early_SLOT23> {
1272 let IClass = 0b0101;
1274 let Inst{27-25} = 0b100;
1275 let Inst{24-16} = dst{23-15};
1276 let Inst{13-1} = dst{14-2};
1279 let isBranch = 1, Defs = [PC], hasSideEffects = 0, isPredicated = 1,
1280 isExtendable = 1, opExtendable = 1, isExtentSigned = 1,
1281 opExtentBits = 17, opExtentAlign = 2, InputType = "imm" in
1282 class T_JMP_c<bit PredNot, bit isPredNew, bit isTak, string ExtStr>
1283 : JInst<(outs), (ins PredRegs:$src, brtarget:$dst),
1284 CondStr<"$src", !if(PredNot,0,1), isPredNew>.S #
1285 JumpOpcStr<"jump", isPredNew, isTak>.S # " " #
1287 [], "", J_tc_2early_SLOT23>, ImmRegRel {
1288 let isTaken = isTak;
1289 let isPredicatedFalse = PredNot;
1290 let isPredicatedNew = isPredNew;
1294 let IClass = 0b0101;
1296 let Inst{27-24} = 0b1100;
1297 let Inst{21} = PredNot;
1298 let Inst{12} = !if(isPredNew, isTak, zero);
1299 let Inst{11} = isPredNew;
1300 let Inst{9-8} = src;
1301 let Inst{23-22} = dst{16-15};
1302 let Inst{20-16} = dst{14-10};
1303 let Inst{13} = dst{9};
1304 let Inst{7-1} = dst{8-2};
1307 multiclass JMP_Pred<bit PredNot, string ExtStr> {
1308 def NAME : T_JMP_c<PredNot, 0, 0, ExtStr>;
1310 def NAME#newpt : T_JMP_c<PredNot, 1, 1, ExtStr>; // taken
1311 def NAME#new : T_JMP_c<PredNot, 1, 0, ExtStr>; // not taken
1314 multiclass JMP_base<string BaseOp, string ExtStr> {
1315 let BaseOpcode = BaseOp in {
1316 def NAME : T_JMP<ExtStr>;
1317 defm t : JMP_Pred<0, ExtStr>;
1318 defm f : JMP_Pred<1, ExtStr>;
1322 // Jumps to address stored in a register, JUMPR_MISC
1323 // if ([[!]P[.new]]) jumpr[:t/nt] Rs
1324 let isBranch = 1, isIndirectBranch = 1, isBarrier = 1, Defs = [PC],
1325 isPredicable = 1, hasSideEffects = 0, InputType = "reg" in
1327 : JRInst<(outs), (ins IntRegs:$dst),
1328 "jumpr $dst", [], "", J_tc_2early_SLOT2> {
1331 let IClass = 0b0101;
1332 let Inst{27-21} = 0b0010100;
1333 let Inst{20-16} = dst;
1336 let isBranch = 1, isIndirectBranch = 1, Defs = [PC], isPredicated = 1,
1337 hasSideEffects = 0, InputType = "reg" in
1338 class T_JMPr_c <bit PredNot, bit isPredNew, bit isTak>
1339 : JRInst <(outs), (ins PredRegs:$src, IntRegs:$dst),
1340 CondStr<"$src", !if(PredNot,0,1), isPredNew>.S #
1341 JumpOpcStr<"jumpr", isPredNew, isTak>.S # " $dst", [],
1342 "", J_tc_2early_SLOT2> {
1344 let isTaken = isTak;
1345 let isPredicatedFalse = PredNot;
1346 let isPredicatedNew = isPredNew;
1350 let IClass = 0b0101;
1352 let Inst{27-22} = 0b001101;
1353 let Inst{21} = PredNot;
1354 let Inst{20-16} = dst;
1355 let Inst{12} = !if(isPredNew, isTak, zero);
1356 let Inst{11} = isPredNew;
1357 let Inst{9-8} = src;
1360 multiclass JMPR_Pred<bit PredNot> {
1361 def NAME: T_JMPr_c<PredNot, 0, 0>;
1363 def NAME#newpt : T_JMPr_c<PredNot, 1, 1>; // taken
1364 def NAME#new : T_JMPr_c<PredNot, 1, 0>; // not taken
1367 multiclass JMPR_base<string BaseOp> {
1368 let BaseOpcode = BaseOp in {
1370 defm t : JMPR_Pred<0>;
1371 defm f : JMPR_Pred<1>;
1375 let isCall = 1, hasSideEffects = 1 in
1376 class JUMPR_MISC_CALLR<bit isPred, bit isPredNot,
1377 dag InputDag = (ins IntRegs:$Rs)>
1378 : JRInst<(outs), InputDag,
1379 !if(isPred, !if(isPredNot, "if (!$Pu) callr $Rs",
1380 "if ($Pu) callr $Rs"),
1382 [], "", J_tc_2early_SLOT2> {
1385 let isPredicated = isPred;
1386 let isPredicatedFalse = isPredNot;
1388 let IClass = 0b0101;
1389 let Inst{27-25} = 0b000;
1390 let Inst{24-23} = !if (isPred, 0b10, 0b01);
1392 let Inst{21} = isPredNot;
1393 let Inst{9-8} = !if (isPred, Pu, 0b00);
1394 let Inst{20-16} = Rs;
1398 let Defs = VolatileV3.Regs, isCodeGenOnly = 0 in {
1399 def J2_callrt : JUMPR_MISC_CALLR<1, 0, (ins PredRegs:$Pu, IntRegs:$Rs)>;
1400 def J2_callrf : JUMPR_MISC_CALLR<1, 1, (ins PredRegs:$Pu, IntRegs:$Rs)>;
1403 let isTerminator = 1, hasSideEffects = 0, isCodeGenOnly = 0 in {
1404 defm J2_jump : JMP_base<"JMP", "">, PredNewRel;
1406 // Deal with explicit assembly
1407 // - never extened a jump #, always extend a jump ##
1408 let isAsmParserOnly = 1 in {
1409 defm J2_jump_ext : JMP_base<"JMP", "##">;
1410 defm J2_jump_noext : JMP_base<"JMP", "#">;
1413 defm J2_jumpr : JMPR_base<"JMPr">, PredNewRel;
1415 let isReturn = 1, isCodeGenOnly = 1 in
1416 defm JMPret : JMPR_base<"JMPret">, PredNewRel;
1419 def: Pat<(br bb:$dst),
1420 (J2_jump brtarget:$dst)>;
1422 (JMPret (i32 R31))>;
1423 def: Pat<(brcond (i1 PredRegs:$src1), bb:$offset),
1424 (J2_jumpt PredRegs:$src1, bb:$offset)>;
1426 // A return through builtin_eh_return.
1427 let isReturn = 1, isTerminator = 1, isBarrier = 1, hasSideEffects = 0,
1428 isCodeGenOnly = 1, Defs = [PC], Uses = [R28], isPredicable = 0 in
1429 def EH_RETURN_JMPR : T_JMPr;
1431 def: Pat<(eh_return),
1432 (EH_RETURN_JMPR (i32 R31))>;
1433 def: Pat<(HexagonBR_JT (i32 IntRegs:$dst)),
1434 (J2_jumpr IntRegs:$dst)>;
1435 def: Pat<(brind (i32 IntRegs:$dst)),
1436 (J2_jumpr IntRegs:$dst)>;
1438 //===----------------------------------------------------------------------===//
1440 //===----------------------------------------------------------------------===//
1442 //===----------------------------------------------------------------------===//
1444 //===----------------------------------------------------------------------===//
1445 let isExtendable = 1, opExtendable = 2, isExtentSigned = 1, AddedComplexity = 20 in
1446 class T_load_io <string mnemonic, RegisterClass RC, bits<4> MajOp,
1448 : LDInst<(outs RC:$dst), (ins IntRegs:$src1, ImmOp:$offset),
1449 "$dst = "#mnemonic#"($src1 + #$offset)", []>, AddrModeRel {
1454 bits<11> offsetBits;
1456 string ImmOpStr = !cast<string>(ImmOp);
1457 let offsetBits = !if (!eq(ImmOpStr, "s11_3Ext"), offset{13-3},
1458 !if (!eq(ImmOpStr, "s11_2Ext"), offset{12-2},
1459 !if (!eq(ImmOpStr, "s11_1Ext"), offset{11-1},
1460 /* s11_0Ext */ offset{10-0})));
1461 let opExtentBits = !if (!eq(ImmOpStr, "s11_3Ext"), 14,
1462 !if (!eq(ImmOpStr, "s11_2Ext"), 13,
1463 !if (!eq(ImmOpStr, "s11_1Ext"), 12,
1464 /* s11_0Ext */ 11)));
1465 let hasNewValue = !if (!eq(ImmOpStr, "s11_3Ext"), 0, 1);
1467 let IClass = 0b1001;
1470 let Inst{26-25} = offsetBits{10-9};
1471 let Inst{24-21} = MajOp;
1472 let Inst{20-16} = src1;
1473 let Inst{13-5} = offsetBits{8-0};
1474 let Inst{4-0} = dst;
1477 let opExtendable = 3, isExtentSigned = 0, isPredicated = 1 in
1478 class T_pload_io <string mnemonic, RegisterClass RC, bits<4>MajOp,
1479 Operand ImmOp, bit isNot, bit isPredNew>
1480 : LDInst<(outs RC:$dst),
1481 (ins PredRegs:$src1, IntRegs:$src2, ImmOp:$offset),
1482 "if ("#!if(isNot, "!$src1", "$src1")
1483 #!if(isPredNew, ".new", "")
1484 #") $dst = "#mnemonic#"($src2 + #$offset)",
1485 [],"", V2LDST_tc_ld_SLOT01> , AddrModeRel {
1491 string ImmOpStr = !cast<string>(ImmOp);
1493 let offsetBits = !if (!eq(ImmOpStr, "u6_3Ext"), offset{8-3},
1494 !if (!eq(ImmOpStr, "u6_2Ext"), offset{7-2},
1495 !if (!eq(ImmOpStr, "u6_1Ext"), offset{6-1},
1496 /* u6_0Ext */ offset{5-0})));
1497 let opExtentBits = !if (!eq(ImmOpStr, "u6_3Ext"), 9,
1498 !if (!eq(ImmOpStr, "u6_2Ext"), 8,
1499 !if (!eq(ImmOpStr, "u6_1Ext"), 7,
1501 let hasNewValue = !if (!eq(ImmOpStr, "u6_3Ext"), 0, 1);
1502 let isPredicatedNew = isPredNew;
1503 let isPredicatedFalse = isNot;
1505 let IClass = 0b0100;
1509 let Inst{26} = isNot;
1510 let Inst{25} = isPredNew;
1511 let Inst{24-21} = MajOp;
1512 let Inst{20-16} = src2;
1514 let Inst{12-11} = src1;
1515 let Inst{10-5} = offsetBits;
1516 let Inst{4-0} = dst;
1519 let isExtendable = 1, hasSideEffects = 0, addrMode = BaseImmOffset in
1520 multiclass LD_Idxd<string mnemonic, string CextOp, RegisterClass RC,
1521 Operand ImmOp, Operand predImmOp, bits<4>MajOp> {
1522 let CextOpcode = CextOp, BaseOpcode = CextOp#_indexed in {
1523 let isPredicable = 1 in
1524 def L2_#NAME#_io : T_load_io <mnemonic, RC, MajOp, ImmOp>;
1527 def L2_p#NAME#t_io : T_pload_io <mnemonic, RC, MajOp, predImmOp, 0, 0>;
1528 def L2_p#NAME#f_io : T_pload_io <mnemonic, RC, MajOp, predImmOp, 1, 0>;
1531 def L2_p#NAME#tnew_io : T_pload_io <mnemonic, RC, MajOp, predImmOp, 0, 1>;
1532 def L2_p#NAME#fnew_io : T_pload_io <mnemonic, RC, MajOp, predImmOp, 1, 1>;
1536 let accessSize = ByteAccess, isCodeGenOnly = 0 in {
1537 defm loadrb: LD_Idxd <"memb", "LDrib", IntRegs, s11_0Ext, u6_0Ext, 0b1000>;
1538 defm loadrub: LD_Idxd <"memub", "LDriub", IntRegs, s11_0Ext, u6_0Ext, 0b1001>;
1541 let accessSize = HalfWordAccess, opExtentAlign = 1, isCodeGenOnly = 0 in {
1542 defm loadrh: LD_Idxd <"memh", "LDrih", IntRegs, s11_1Ext, u6_1Ext, 0b1010>;
1543 defm loadruh: LD_Idxd <"memuh", "LDriuh", IntRegs, s11_1Ext, u6_1Ext, 0b1011>;
1546 let accessSize = WordAccess, opExtentAlign = 2, isCodeGenOnly = 0 in
1547 defm loadri: LD_Idxd <"memw", "LDriw", IntRegs, s11_2Ext, u6_2Ext, 0b1100>;
1549 let accessSize = DoubleWordAccess, opExtentAlign = 3, isCodeGenOnly = 0 in
1550 defm loadrd: LD_Idxd <"memd", "LDrid", DoubleRegs, s11_3Ext, u6_3Ext, 0b1110>;
1552 // Patterns to select load-indexed (i.e. load from base+offset).
1553 multiclass Loadx_pat<PatFrag Load, ValueType VT, PatLeaf ImmPred,
1555 def: Pat<(VT (Load AddrFI:$fi)), (VT (MI AddrFI:$fi, 0))>;
1556 def: Pat<(VT (Load (add (i32 IntRegs:$Rs), ImmPred:$Off))),
1557 (VT (MI IntRegs:$Rs, imm:$Off))>;
1558 def: Pat<(VT (Load (i32 IntRegs:$Rs))), (VT (MI IntRegs:$Rs, 0))>;
1561 let AddedComplexity = 20 in {
1562 defm: Loadx_pat<load, i32, s11_2ExtPred, L2_loadri_io>;
1563 defm: Loadx_pat<load, i64, s11_3ExtPred, L2_loadrd_io>;
1564 defm: Loadx_pat<atomic_load_8 , i32, s11_0ExtPred, L2_loadrub_io>;
1565 defm: Loadx_pat<atomic_load_16, i32, s11_1ExtPred, L2_loadruh_io>;
1566 defm: Loadx_pat<atomic_load_32, i32, s11_2ExtPred, L2_loadri_io>;
1567 defm: Loadx_pat<atomic_load_64, i64, s11_3ExtPred, L2_loadrd_io>;
1569 defm: Loadx_pat<extloadi1, i32, s11_0ExtPred, L2_loadrub_io>;
1570 //defm: Loadx_pat<extloadi8, i32, s11_0ExtPred, L2_loadrub_io>;
1571 defm: Loadx_pat<extloadi16, i32, s11_1ExtPred, L2_loadruh_io>;
1572 //defm: Loadx_pat<sextloadi8, i32, s11_0ExtPred, L2_loadrb_io>;
1573 defm: Loadx_pat<sextloadi16, i32, s11_1ExtPred, L2_loadrh_io>;
1574 defm: Loadx_pat<zextloadi1, i32, s11_0ExtPred, L2_loadrub_io>;
1575 defm: Loadx_pat<zextloadi8, i32, s11_0ExtPred, L2_loadrub_io>;
1576 defm: Loadx_pat<zextloadi16, i32, s11_1ExtPred, L2_loadruh_io>;
1580 // Sign-extending loads of i1 need to replicate the lowest bit throughout
1581 // the 32-bit value. Since the loaded value can only be 0 or 1, 0-v should
1583 let AddedComplexity = 20 in
1584 def: Pat<(i32 (sextloadi1 (i32 IntRegs:$Rs))),
1585 (SUB_ri 0, (L2_loadrub_io IntRegs:$Rs, 0))>;
1587 //===----------------------------------------------------------------------===//
1588 // Post increment load
1589 //===----------------------------------------------------------------------===//
1590 //===----------------------------------------------------------------------===//
1591 // Template class for non-predicated post increment loads with immediate offset.
1592 //===----------------------------------------------------------------------===//
1593 let hasSideEffects = 0, addrMode = PostInc in
1594 class T_load_pi <string mnemonic, RegisterClass RC, Operand ImmOp,
1596 : LDInstPI <(outs RC:$dst, IntRegs:$dst2),
1597 (ins IntRegs:$src1, ImmOp:$offset),
1598 "$dst = "#mnemonic#"($src1++#$offset)" ,
1607 string ImmOpStr = !cast<string>(ImmOp);
1608 let offsetBits = !if (!eq(ImmOpStr, "s4_3Imm"), offset{6-3},
1609 !if (!eq(ImmOpStr, "s4_2Imm"), offset{5-2},
1610 !if (!eq(ImmOpStr, "s4_1Imm"), offset{4-1},
1611 /* s4_0Imm */ offset{3-0})));
1612 let hasNewValue = !if (!eq(ImmOpStr, "s4_3Imm"), 0, 1);
1614 let IClass = 0b1001;
1616 let Inst{27-25} = 0b101;
1617 let Inst{24-21} = MajOp;
1618 let Inst{20-16} = src1;
1619 let Inst{13-12} = 0b00;
1620 let Inst{8-5} = offsetBits;
1621 let Inst{4-0} = dst;
1624 //===----------------------------------------------------------------------===//
1625 // Template class for predicated post increment loads with immediate offset.
1626 //===----------------------------------------------------------------------===//
1627 let isPredicated = 1, hasSideEffects = 0, addrMode = PostInc in
1628 class T_pload_pi <string mnemonic, RegisterClass RC, Operand ImmOp,
1629 bits<4> MajOp, bit isPredNot, bit isPredNew >
1630 : LDInst <(outs RC:$dst, IntRegs:$dst2),
1631 (ins PredRegs:$src1, IntRegs:$src2, ImmOp:$offset),
1632 !if(isPredNot, "if (!$src1", "if ($src1")#!if(isPredNew, ".new) ",
1633 ") ")#"$dst = "#mnemonic#"($src2++#$offset)",
1643 let isPredicatedNew = isPredNew;
1644 let isPredicatedFalse = isPredNot;
1646 string ImmOpStr = !cast<string>(ImmOp);
1647 let offsetBits = !if (!eq(ImmOpStr, "s4_3Imm"), offset{6-3},
1648 !if (!eq(ImmOpStr, "s4_2Imm"), offset{5-2},
1649 !if (!eq(ImmOpStr, "s4_1Imm"), offset{4-1},
1650 /* s4_0Imm */ offset{3-0})));
1651 let hasNewValue = !if (!eq(ImmOpStr, "s4_3Imm"), 0, 1);
1653 let IClass = 0b1001;
1655 let Inst{27-25} = 0b101;
1656 let Inst{24-21} = MajOp;
1657 let Inst{20-16} = src2;
1659 let Inst{12} = isPredNew;
1660 let Inst{11} = isPredNot;
1661 let Inst{10-9} = src1;
1662 let Inst{8-5} = offsetBits;
1663 let Inst{4-0} = dst;
1666 //===----------------------------------------------------------------------===//
1667 // Multiclass for post increment loads with immediate offset.
1668 //===----------------------------------------------------------------------===//
1670 multiclass LD_PostInc <string mnemonic, string BaseOp, RegisterClass RC,
1671 Operand ImmOp, bits<4> MajOp> {
1672 let BaseOpcode = "POST_"#BaseOp in {
1673 let isPredicable = 1 in
1674 def L2_#NAME#_pi : T_load_pi < mnemonic, RC, ImmOp, MajOp>;
1677 def L2_p#NAME#t_pi : T_pload_pi < mnemonic, RC, ImmOp, MajOp, 0, 0>;
1678 def L2_p#NAME#f_pi : T_pload_pi < mnemonic, RC, ImmOp, MajOp, 1, 0>;
1681 def L2_p#NAME#tnew_pi : T_pload_pi < mnemonic, RC, ImmOp, MajOp, 0, 1>;
1682 def L2_p#NAME#fnew_pi : T_pload_pi < mnemonic, RC, ImmOp, MajOp, 1, 1>;
1686 // post increment byte loads with immediate offset
1687 let accessSize = ByteAccess, isCodeGenOnly = 0 in {
1688 defm loadrb : LD_PostInc <"memb", "LDrib", IntRegs, s4_0Imm, 0b1000>;
1689 defm loadrub : LD_PostInc <"memub", "LDriub", IntRegs, s4_0Imm, 0b1001>;
1692 // post increment halfword loads with immediate offset
1693 let accessSize = HalfWordAccess, opExtentAlign = 1, isCodeGenOnly = 0 in {
1694 defm loadrh : LD_PostInc <"memh", "LDrih", IntRegs, s4_1Imm, 0b1010>;
1695 defm loadruh : LD_PostInc <"memuh", "LDriuh", IntRegs, s4_1Imm, 0b1011>;
1698 // post increment word loads with immediate offset
1699 let accessSize = WordAccess, opExtentAlign = 2, isCodeGenOnly = 0 in
1700 defm loadri : LD_PostInc <"memw", "LDriw", IntRegs, s4_2Imm, 0b1100>;
1702 // post increment doubleword loads with immediate offset
1703 let accessSize = DoubleWordAccess, opExtentAlign = 3, isCodeGenOnly = 0 in
1704 defm loadrd : LD_PostInc <"memd", "LDrid", DoubleRegs, s4_3Imm, 0b1110>;
1706 def : Pat< (i32 (extloadi1 ADDRriS11_0:$addr)),
1707 (i32 (L2_loadrb_io AddrFI:$addr, 0)) >;
1709 // Load byte any-extend.
1710 def : Pat < (i32 (extloadi8 ADDRriS11_0:$addr)),
1711 (i32 (L2_loadrb_io AddrFI:$addr, 0)) >;
1713 // Indexed load byte any-extend.
1714 let AddedComplexity = 20 in
1715 def : Pat < (i32 (extloadi8 (add IntRegs:$src1, s11_0ImmPred:$offset))),
1716 (i32 (L2_loadrb_io IntRegs:$src1, s11_0ImmPred:$offset)) >;
1718 def : Pat < (i32 (extloadi16 ADDRriS11_1:$addr)),
1719 (i32 (L2_loadrh_io AddrFI:$addr, 0))>;
1721 let AddedComplexity = 20 in
1722 def : Pat < (i32 (extloadi16 (add IntRegs:$src1, s11_1ImmPred:$offset))),
1723 (i32 (L2_loadrh_io IntRegs:$src1, s11_1ImmPred:$offset)) >;
1725 let AddedComplexity = 10 in
1726 def : Pat < (i32 (zextloadi1 ADDRriS11_0:$addr)),
1727 (i32 (L2_loadrub_io AddrFI:$addr, 0))>;
1729 let AddedComplexity = 20 in
1730 def : Pat < (i32 (zextloadi1 (add IntRegs:$src1, s11_0ImmPred:$offset))),
1731 (i32 (L2_loadrub_io IntRegs:$src1, s11_0ImmPred:$offset))>;
1733 //===----------------------------------------------------------------------===//
1734 // Template class for post increment loads with register offset.
1735 //===----------------------------------------------------------------------===//
1736 let hasSideEffects = 0, addrMode = PostInc in
1737 class T_load_pr <string mnemonic, RegisterClass RC, bits<4> MajOp,
1738 MemAccessSize AccessSz>
1739 : LDInstPI <(outs RC:$dst, IntRegs:$_dst_),
1740 (ins IntRegs:$src1, ModRegs:$src2),
1741 "$dst = "#mnemonic#"($src1++$src2)" ,
1742 [], "$src1 = $_dst_" > {
1747 let accessSize = AccessSz;
1748 let IClass = 0b1001;
1750 let Inst{27-25} = 0b110;
1751 let Inst{24-21} = MajOp;
1752 let Inst{20-16} = src1;
1753 let Inst{13} = src2;
1756 let Inst{4-0} = dst;
1759 let hasNewValue = 1, isCodeGenOnly = 0 in {
1760 def L2_loadrb_pr : T_load_pr <"memb", IntRegs, 0b1000, ByteAccess>;
1761 def L2_loadrub_pr : T_load_pr <"memub", IntRegs, 0b1001, ByteAccess>;
1762 def L2_loadrh_pr : T_load_pr <"memh", IntRegs, 0b1010, HalfWordAccess>;
1763 def L2_loadruh_pr : T_load_pr <"memuh", IntRegs, 0b1011, HalfWordAccess>;
1764 def L2_loadri_pr : T_load_pr <"memw", IntRegs, 0b1100, WordAccess>;
1767 let isCodeGenOnly = 0 in
1768 def L2_loadrd_pr : T_load_pr <"memd", DoubleRegs, 0b1110, DoubleWordAccess>;
1771 let isExtendable = 1, opExtendable = 2, isExtentSigned = 1, opExtentBits = 13,
1772 isPseudo = 1, Defs = [R10,R11,D5], hasSideEffects = 0 in
1773 def LDriw_pred : LDInst2<(outs PredRegs:$dst),
1775 "Error; should not emit",
1778 let Defs = [R29, R30, R31], Uses = [R30], hasSideEffects = 0, isCodeGenOnly = 0 in
1779 def L2_deallocframe : LDInst<(outs), (ins),
1782 let IClass = 0b1001;
1784 let Inst{27-16} = 0b000000011110;
1786 let Inst{4-0} = 0b11110;
1789 // Load / Post increment circular addressing mode.
1790 let Uses = [CS], hasSideEffects = 0, hasNewValue = 1, opNewValue = 0 in
1791 class T_load_pcr<string mnemonic, RegisterClass RC, bits<4> MajOp>
1792 : LDInst <(outs RC:$dst, IntRegs:$_dst_),
1793 (ins IntRegs:$Rz, ModRegs:$Mu),
1794 "$dst = "#mnemonic#"($Rz ++ I:circ($Mu))", [],
1800 let IClass = 0b1001;
1802 let Inst{27-25} = 0b100;
1803 let Inst{24-21} = MajOp;
1804 let Inst{20-16} = Rz;
1809 let Inst{4-0} = dst;
1812 let accessSize = ByteAccess, isCodeGenOnly = 0 in {
1813 def L2_loadrb_pcr : T_load_pcr <"memb", IntRegs, 0b1000>;
1814 def L2_loadrub_pcr : T_load_pcr <"memub", IntRegs, 0b1001>;
1817 let accessSize = HalfWordAccess, isCodeGenOnly = 0 in {
1818 def L2_loadrh_pcr : T_load_pcr <"memh", IntRegs, 0b1010>;
1819 def L2_loadruh_pcr : T_load_pcr <"memuh", IntRegs, 0b1011>;
1822 let accessSize = WordAccess, isCodeGenOnly = 0 in {
1823 def L2_loadri_pcr : T_load_pcr <"memw", IntRegs, 0b1100>;
1826 let accessSize = DoubleWordAccess, isCodeGenOnly = 0 in
1827 def L2_loadrd_pcr : T_load_pcr <"memd", DoubleRegs, 0b1110>;
1829 //===----------------------------------------------------------------------===//
1830 // Circular loads with immediate offset.
1831 //===----------------------------------------------------------------------===//
1832 let Uses = [CS], mayLoad = 1, hasSideEffects = 0, hasNewValue = 1 in
1833 class T_load_pci <string mnemonic, RegisterClass RC,
1834 Operand ImmOp, bits<4> MajOp>
1835 : LDInstPI<(outs RC:$dst, IntRegs:$_dst_),
1836 (ins IntRegs:$Rz, ImmOp:$offset, ModRegs:$Mu),
1837 "$dst = "#mnemonic#"($Rz ++ #$offset:circ($Mu))", [],
1845 string ImmOpStr = !cast<string>(ImmOp);
1846 let offsetBits = !if (!eq(ImmOpStr, "s4_3Imm"), offset{6-3},
1847 !if (!eq(ImmOpStr, "s4_2Imm"), offset{5-2},
1848 !if (!eq(ImmOpStr, "s4_1Imm"), offset{4-1},
1849 /* s4_0Imm */ offset{3-0})));
1850 let IClass = 0b1001;
1851 let Inst{27-25} = 0b100;
1852 let Inst{24-21} = MajOp;
1853 let Inst{20-16} = Rz;
1857 let Inst{8-5} = offsetBits;
1858 let Inst{4-0} = dst;
1861 // Byte variants of circ load
1862 let accessSize = ByteAccess, isCodeGenOnly = 0 in {
1863 def L2_loadrb_pci : T_load_pci <"memb", IntRegs, s4_0Imm, 0b1000>;
1864 def L2_loadrub_pci : T_load_pci <"memub", IntRegs, s4_0Imm, 0b1001>;
1867 // Half word variants of circ load
1868 let accessSize = HalfWordAccess, isCodeGenOnly = 0 in {
1869 def L2_loadrh_pci : T_load_pci <"memh", IntRegs, s4_1Imm, 0b1010>;
1870 def L2_loadruh_pci : T_load_pci <"memuh", IntRegs, s4_1Imm, 0b1011>;
1873 // Word variants of circ load
1874 let accessSize = WordAccess, isCodeGenOnly = 0 in
1875 def L2_loadri_pci : T_load_pci <"memw", IntRegs, s4_2Imm, 0b1100>;
1877 let accessSize = DoubleWordAccess, hasNewValue = 0, isCodeGenOnly = 0 in
1878 def L2_loadrd_pci : T_load_pci <"memd", DoubleRegs, s4_3Imm, 0b1110>;
1880 // L[24]_load[wd]_locked: Load word/double with lock.
1882 class T_load_locked <string mnemonic, RegisterClass RC>
1883 : LD0Inst <(outs RC:$dst),
1885 "$dst = "#mnemonic#"($src)"> {
1888 let IClass = 0b1001;
1889 let Inst{27-21} = 0b0010000;
1890 let Inst{20-16} = src;
1891 let Inst{13-12} = !if (!eq(mnemonic, "memd_locked"), 0b01, 0b00);
1892 let Inst{4-0} = dst;
1894 let hasNewValue = 1, accessSize = WordAccess, opNewValue = 0, isCodeGenOnly = 0 in
1895 def L2_loadw_locked : T_load_locked <"memw_locked", IntRegs>;
1896 let accessSize = DoubleWordAccess, isCodeGenOnly = 0 in
1897 def L4_loadd_locked : T_load_locked <"memd_locked", DoubleRegs>;
1898 //===----------------------------------------------------------------------===//
1899 // Bit-reversed loads with auto-increment register
1900 //===----------------------------------------------------------------------===//
1901 let hasSideEffects = 0 in
1902 class T_load_pbr<string mnemonic, RegisterClass RC,
1903 MemAccessSize addrSize, bits<4> majOp>
1905 <(outs RC:$dst, IntRegs:$_dst_),
1906 (ins IntRegs:$Rz, ModRegs:$Mu),
1907 "$dst = "#mnemonic#"($Rz ++ $Mu:brev)" ,
1908 [] , "$Rz = $_dst_" > {
1910 let accessSize = addrSize;
1916 let IClass = 0b1001;
1918 let Inst{27-25} = 0b111;
1919 let Inst{24-21} = majOp;
1920 let Inst{20-16} = Rz;
1924 let Inst{4-0} = dst;
1927 let hasNewValue =1, opNewValue = 0, isCodeGenOnly = 0 in {
1928 def L2_loadrb_pbr : T_load_pbr <"memb", IntRegs, ByteAccess, 0b1000>;
1929 def L2_loadrub_pbr : T_load_pbr <"memub", IntRegs, ByteAccess, 0b1001>;
1930 def L2_loadrh_pbr : T_load_pbr <"memh", IntRegs, HalfWordAccess, 0b1010>;
1931 def L2_loadruh_pbr : T_load_pbr <"memuh", IntRegs, HalfWordAccess, 0b1011>;
1932 def L2_loadri_pbr : T_load_pbr <"memw", IntRegs, WordAccess, 0b1100>;
1935 let isCodeGenOnly = 0 in
1936 def L2_loadrd_pbr : T_load_pbr <"memd", DoubleRegs, DoubleWordAccess, 0b1110>;
1938 //===----------------------------------------------------------------------===//
1940 //===----------------------------------------------------------------------===//
1942 //===----------------------------------------------------------------------===//
1944 //===----------------------------------------------------------------------===//
1945 //===----------------------------------------------------------------------===//
1947 //===----------------------------------------------------------------------===//
1949 //===----------------------------------------------------------------------===//
1951 //===----------------------------------------------------------------------===//
1952 //===----------------------------------------------------------------------===//
1954 //===----------------------------------------------------------------------===//
1956 //===----------------------------------------------------------------------===//
1958 //===----------------------------------------------------------------------===//
1960 //===----------------------------------------------------------------------===//
1962 // MPYS / Multipy signed/unsigned halfwords
1963 //Rd=mpy[u](Rs.[H|L],Rt.[H|L])[:<<1][:rnd][:sat]
1964 //===----------------------------------------------------------------------===//
1966 let hasNewValue = 1, opNewValue = 0 in
1967 class T_M2_mpy < bits<2> LHbits, bit isSat, bit isRnd,
1968 bit hasShift, bit isUnsigned>
1969 : MInst < (outs IntRegs:$Rd), (ins IntRegs:$Rs, IntRegs:$Rt),
1970 "$Rd = "#!if(isUnsigned,"mpyu","mpy")#"($Rs."#!if(LHbits{1},"h","l")
1971 #", $Rt."#!if(LHbits{0},"h)","l)")
1972 #!if(hasShift,":<<1","")
1973 #!if(isRnd,":rnd","")
1974 #!if(isSat,":sat",""),
1975 [], "", M_tc_3x_SLOT23 > {
1980 let IClass = 0b1110;
1982 let Inst{27-24} = 0b1100;
1983 let Inst{23} = hasShift;
1984 let Inst{22} = isUnsigned;
1985 let Inst{21} = isRnd;
1986 let Inst{7} = isSat;
1987 let Inst{6-5} = LHbits;
1989 let Inst{20-16} = Rs;
1990 let Inst{12-8} = Rt;
1993 //Rd=mpy(Rs.[H|L],Rt.[H|L])[:<<1]
1994 let isCodeGenOnly = 0 in {
1995 def M2_mpy_ll_s1: T_M2_mpy<0b00, 0, 0, 1, 0>;
1996 def M2_mpy_ll_s0: T_M2_mpy<0b00, 0, 0, 0, 0>;
1997 def M2_mpy_lh_s1: T_M2_mpy<0b01, 0, 0, 1, 0>;
1998 def M2_mpy_lh_s0: T_M2_mpy<0b01, 0, 0, 0, 0>;
1999 def M2_mpy_hl_s1: T_M2_mpy<0b10, 0, 0, 1, 0>;
2000 def M2_mpy_hl_s0: T_M2_mpy<0b10, 0, 0, 0, 0>;
2001 def M2_mpy_hh_s1: T_M2_mpy<0b11, 0, 0, 1, 0>;
2002 def M2_mpy_hh_s0: T_M2_mpy<0b11, 0, 0, 0, 0>;
2005 //Rd=mpyu(Rs.[H|L],Rt.[H|L])[:<<1]
2006 let isCodeGenOnly = 0 in {
2007 def M2_mpyu_ll_s1: T_M2_mpy<0b00, 0, 0, 1, 1>;
2008 def M2_mpyu_ll_s0: T_M2_mpy<0b00, 0, 0, 0, 1>;
2009 def M2_mpyu_lh_s1: T_M2_mpy<0b01, 0, 0, 1, 1>;
2010 def M2_mpyu_lh_s0: T_M2_mpy<0b01, 0, 0, 0, 1>;
2011 def M2_mpyu_hl_s1: T_M2_mpy<0b10, 0, 0, 1, 1>;
2012 def M2_mpyu_hl_s0: T_M2_mpy<0b10, 0, 0, 0, 1>;
2013 def M2_mpyu_hh_s1: T_M2_mpy<0b11, 0, 0, 1, 1>;
2014 def M2_mpyu_hh_s0: T_M2_mpy<0b11, 0, 0, 0, 1>;
2017 //Rd=mpy(Rs.[H|L],Rt.[H|L])[:<<1]:rnd
2018 let isCodeGenOnly = 0 in {
2019 def M2_mpy_rnd_ll_s1: T_M2_mpy <0b00, 0, 1, 1, 0>;
2020 def M2_mpy_rnd_ll_s0: T_M2_mpy <0b00, 0, 1, 0, 0>;
2021 def M2_mpy_rnd_lh_s1: T_M2_mpy <0b01, 0, 1, 1, 0>;
2022 def M2_mpy_rnd_lh_s0: T_M2_mpy <0b01, 0, 1, 0, 0>;
2023 def M2_mpy_rnd_hl_s1: T_M2_mpy <0b10, 0, 1, 1, 0>;
2024 def M2_mpy_rnd_hl_s0: T_M2_mpy <0b10, 0, 1, 0, 0>;
2025 def M2_mpy_rnd_hh_s1: T_M2_mpy <0b11, 0, 1, 1, 0>;
2026 def M2_mpy_rnd_hh_s0: T_M2_mpy <0b11, 0, 1, 0, 0>;
2029 //Rd=mpy(Rs.[H|L],Rt.[H|L])[:<<1][:sat]
2030 //Rd=mpy(Rs.[H|L],Rt.[H|L])[:<<1][:rnd][:sat]
2031 let Defs = [USR_OVF], isCodeGenOnly = 0 in {
2032 def M2_mpy_sat_ll_s1: T_M2_mpy <0b00, 1, 0, 1, 0>;
2033 def M2_mpy_sat_ll_s0: T_M2_mpy <0b00, 1, 0, 0, 0>;
2034 def M2_mpy_sat_lh_s1: T_M2_mpy <0b01, 1, 0, 1, 0>;
2035 def M2_mpy_sat_lh_s0: T_M2_mpy <0b01, 1, 0, 0, 0>;
2036 def M2_mpy_sat_hl_s1: T_M2_mpy <0b10, 1, 0, 1, 0>;
2037 def M2_mpy_sat_hl_s0: T_M2_mpy <0b10, 1, 0, 0, 0>;
2038 def M2_mpy_sat_hh_s1: T_M2_mpy <0b11, 1, 0, 1, 0>;
2039 def M2_mpy_sat_hh_s0: T_M2_mpy <0b11, 1, 0, 0, 0>;
2041 def M2_mpy_sat_rnd_ll_s1: T_M2_mpy <0b00, 1, 1, 1, 0>;
2042 def M2_mpy_sat_rnd_ll_s0: T_M2_mpy <0b00, 1, 1, 0, 0>;
2043 def M2_mpy_sat_rnd_lh_s1: T_M2_mpy <0b01, 1, 1, 1, 0>;
2044 def M2_mpy_sat_rnd_lh_s0: T_M2_mpy <0b01, 1, 1, 0, 0>;
2045 def M2_mpy_sat_rnd_hl_s1: T_M2_mpy <0b10, 1, 1, 1, 0>;
2046 def M2_mpy_sat_rnd_hl_s0: T_M2_mpy <0b10, 1, 1, 0, 0>;
2047 def M2_mpy_sat_rnd_hh_s1: T_M2_mpy <0b11, 1, 1, 1, 0>;
2048 def M2_mpy_sat_rnd_hh_s0: T_M2_mpy <0b11, 1, 1, 0, 0>;
2051 //===----------------------------------------------------------------------===//
2053 // MPYS / Multipy signed/unsigned halfwords and add/subtract the
2054 // result from the accumulator.
2055 //Rx [-+]= mpy[u](Rs.[H|L],Rt.[H|L])[:<<1][:sat]
2056 //===----------------------------------------------------------------------===//
2058 let hasNewValue = 1, opNewValue = 0 in
2059 class T_M2_mpy_acc < bits<2> LHbits, bit isSat, bit isNac,
2060 bit hasShift, bit isUnsigned >
2061 : MInst_acc<(outs IntRegs:$Rx), (ins IntRegs:$dst2, IntRegs:$Rs, IntRegs:$Rt),
2062 "$Rx "#!if(isNac,"-= ","+= ")#!if(isUnsigned,"mpyu","mpy")
2063 #"($Rs."#!if(LHbits{1},"h","l")
2064 #", $Rt."#!if(LHbits{0},"h)","l)")
2065 #!if(hasShift,":<<1","")
2066 #!if(isSat,":sat",""),
2067 [], "$dst2 = $Rx", M_tc_3x_SLOT23 > {
2072 let IClass = 0b1110;
2073 let Inst{27-24} = 0b1110;
2074 let Inst{23} = hasShift;
2075 let Inst{22} = isUnsigned;
2076 let Inst{21} = isNac;
2077 let Inst{7} = isSat;
2078 let Inst{6-5} = LHbits;
2080 let Inst{20-16} = Rs;
2081 let Inst{12-8} = Rt;
2084 //Rx += mpy(Rs.[H|L],Rt.[H|L])[:<<1]
2085 let isCodeGenOnly = 0 in {
2086 def M2_mpy_acc_ll_s1: T_M2_mpy_acc <0b00, 0, 0, 1, 0>;
2087 def M2_mpy_acc_ll_s0: T_M2_mpy_acc <0b00, 0, 0, 0, 0>;
2088 def M2_mpy_acc_lh_s1: T_M2_mpy_acc <0b01, 0, 0, 1, 0>;
2089 def M2_mpy_acc_lh_s0: T_M2_mpy_acc <0b01, 0, 0, 0, 0>;
2090 def M2_mpy_acc_hl_s1: T_M2_mpy_acc <0b10, 0, 0, 1, 0>;
2091 def M2_mpy_acc_hl_s0: T_M2_mpy_acc <0b10, 0, 0, 0, 0>;
2092 def M2_mpy_acc_hh_s1: T_M2_mpy_acc <0b11, 0, 0, 1, 0>;
2093 def M2_mpy_acc_hh_s0: T_M2_mpy_acc <0b11, 0, 0, 0, 0>;
2096 //Rx += mpyu(Rs.[H|L],Rt.[H|L])[:<<1]
2097 let isCodeGenOnly = 0 in {
2098 def M2_mpyu_acc_ll_s1: T_M2_mpy_acc <0b00, 0, 0, 1, 1>;
2099 def M2_mpyu_acc_ll_s0: T_M2_mpy_acc <0b00, 0, 0, 0, 1>;
2100 def M2_mpyu_acc_lh_s1: T_M2_mpy_acc <0b01, 0, 0, 1, 1>;
2101 def M2_mpyu_acc_lh_s0: T_M2_mpy_acc <0b01, 0, 0, 0, 1>;
2102 def M2_mpyu_acc_hl_s1: T_M2_mpy_acc <0b10, 0, 0, 1, 1>;
2103 def M2_mpyu_acc_hl_s0: T_M2_mpy_acc <0b10, 0, 0, 0, 1>;
2104 def M2_mpyu_acc_hh_s1: T_M2_mpy_acc <0b11, 0, 0, 1, 1>;
2105 def M2_mpyu_acc_hh_s0: T_M2_mpy_acc <0b11, 0, 0, 0, 1>;
2108 //Rx -= mpy(Rs.[H|L],Rt.[H|L])[:<<1]
2109 let isCodeGenOnly = 0 in {
2110 def M2_mpy_nac_ll_s1: T_M2_mpy_acc <0b00, 0, 1, 1, 0>;
2111 def M2_mpy_nac_ll_s0: T_M2_mpy_acc <0b00, 0, 1, 0, 0>;
2112 def M2_mpy_nac_lh_s1: T_M2_mpy_acc <0b01, 0, 1, 1, 0>;
2113 def M2_mpy_nac_lh_s0: T_M2_mpy_acc <0b01, 0, 1, 0, 0>;
2114 def M2_mpy_nac_hl_s1: T_M2_mpy_acc <0b10, 0, 1, 1, 0>;
2115 def M2_mpy_nac_hl_s0: T_M2_mpy_acc <0b10, 0, 1, 0, 0>;
2116 def M2_mpy_nac_hh_s1: T_M2_mpy_acc <0b11, 0, 1, 1, 0>;
2117 def M2_mpy_nac_hh_s0: T_M2_mpy_acc <0b11, 0, 1, 0, 0>;
2120 //Rx -= mpyu(Rs.[H|L],Rt.[H|L])[:<<1]
2121 let isCodeGenOnly = 0 in {
2122 def M2_mpyu_nac_ll_s1: T_M2_mpy_acc <0b00, 0, 1, 1, 1>;
2123 def M2_mpyu_nac_ll_s0: T_M2_mpy_acc <0b00, 0, 1, 0, 1>;
2124 def M2_mpyu_nac_lh_s1: T_M2_mpy_acc <0b01, 0, 1, 1, 1>;
2125 def M2_mpyu_nac_lh_s0: T_M2_mpy_acc <0b01, 0, 1, 0, 1>;
2126 def M2_mpyu_nac_hl_s1: T_M2_mpy_acc <0b10, 0, 1, 1, 1>;
2127 def M2_mpyu_nac_hl_s0: T_M2_mpy_acc <0b10, 0, 1, 0, 1>;
2128 def M2_mpyu_nac_hh_s1: T_M2_mpy_acc <0b11, 0, 1, 1, 1>;
2129 def M2_mpyu_nac_hh_s0: T_M2_mpy_acc <0b11, 0, 1, 0, 1>;
2132 //Rx += mpy(Rs.[H|L],Rt.[H|L])[:<<1]:sat
2133 let isCodeGenOnly = 0 in {
2134 def M2_mpy_acc_sat_ll_s1: T_M2_mpy_acc <0b00, 1, 0, 1, 0>;
2135 def M2_mpy_acc_sat_ll_s0: T_M2_mpy_acc <0b00, 1, 0, 0, 0>;
2136 def M2_mpy_acc_sat_lh_s1: T_M2_mpy_acc <0b01, 1, 0, 1, 0>;
2137 def M2_mpy_acc_sat_lh_s0: T_M2_mpy_acc <0b01, 1, 0, 0, 0>;
2138 def M2_mpy_acc_sat_hl_s1: T_M2_mpy_acc <0b10, 1, 0, 1, 0>;
2139 def M2_mpy_acc_sat_hl_s0: T_M2_mpy_acc <0b10, 1, 0, 0, 0>;
2140 def M2_mpy_acc_sat_hh_s1: T_M2_mpy_acc <0b11, 1, 0, 1, 0>;
2141 def M2_mpy_acc_sat_hh_s0: T_M2_mpy_acc <0b11, 1, 0, 0, 0>;
2144 //Rx -= mpy(Rs.[H|L],Rt.[H|L])[:<<1]:sat
2145 let isCodeGenOnly = 0 in {
2146 def M2_mpy_nac_sat_ll_s1: T_M2_mpy_acc <0b00, 1, 1, 1, 0>;
2147 def M2_mpy_nac_sat_ll_s0: T_M2_mpy_acc <0b00, 1, 1, 0, 0>;
2148 def M2_mpy_nac_sat_lh_s1: T_M2_mpy_acc <0b01, 1, 1, 1, 0>;
2149 def M2_mpy_nac_sat_lh_s0: T_M2_mpy_acc <0b01, 1, 1, 0, 0>;
2150 def M2_mpy_nac_sat_hl_s1: T_M2_mpy_acc <0b10, 1, 1, 1, 0>;
2151 def M2_mpy_nac_sat_hl_s0: T_M2_mpy_acc <0b10, 1, 1, 0, 0>;
2152 def M2_mpy_nac_sat_hh_s1: T_M2_mpy_acc <0b11, 1, 1, 1, 0>;
2153 def M2_mpy_nac_sat_hh_s0: T_M2_mpy_acc <0b11, 1, 1, 0, 0>;
2156 //===----------------------------------------------------------------------===//
2158 // MPYS / Multipy signed/unsigned halfwords and add/subtract the
2159 // result from the 64-bit destination register.
2160 //Rxx [-+]= mpy[u](Rs.[H|L],Rt.[H|L])[:<<1][:sat]
2161 //===----------------------------------------------------------------------===//
2163 class T_M2_mpyd_acc < bits<2> LHbits, bit isNac, bit hasShift, bit isUnsigned>
2164 : MInst_acc<(outs DoubleRegs:$Rxx),
2165 (ins DoubleRegs:$dst2, IntRegs:$Rs, IntRegs:$Rt),
2166 "$Rxx "#!if(isNac,"-= ","+= ")#!if(isUnsigned,"mpyu","mpy")
2167 #"($Rs."#!if(LHbits{1},"h","l")
2168 #", $Rt."#!if(LHbits{0},"h)","l)")
2169 #!if(hasShift,":<<1",""),
2170 [], "$dst2 = $Rxx", M_tc_3x_SLOT23 > {
2175 let IClass = 0b1110;
2177 let Inst{27-24} = 0b0110;
2178 let Inst{23} = hasShift;
2179 let Inst{22} = isUnsigned;
2180 let Inst{21} = isNac;
2182 let Inst{6-5} = LHbits;
2183 let Inst{4-0} = Rxx;
2184 let Inst{20-16} = Rs;
2185 let Inst{12-8} = Rt;
2188 let isCodeGenOnly = 0 in {
2189 def M2_mpyd_acc_hh_s0: T_M2_mpyd_acc <0b11, 0, 0, 0>;
2190 def M2_mpyd_acc_hl_s0: T_M2_mpyd_acc <0b10, 0, 0, 0>;
2191 def M2_mpyd_acc_lh_s0: T_M2_mpyd_acc <0b01, 0, 0, 0>;
2192 def M2_mpyd_acc_ll_s0: T_M2_mpyd_acc <0b00, 0, 0, 0>;
2194 def M2_mpyd_acc_hh_s1: T_M2_mpyd_acc <0b11, 0, 1, 0>;
2195 def M2_mpyd_acc_hl_s1: T_M2_mpyd_acc <0b10, 0, 1, 0>;
2196 def M2_mpyd_acc_lh_s1: T_M2_mpyd_acc <0b01, 0, 1, 0>;
2197 def M2_mpyd_acc_ll_s1: T_M2_mpyd_acc <0b00, 0, 1, 0>;
2199 def M2_mpyd_nac_hh_s0: T_M2_mpyd_acc <0b11, 1, 0, 0>;
2200 def M2_mpyd_nac_hl_s0: T_M2_mpyd_acc <0b10, 1, 0, 0>;
2201 def M2_mpyd_nac_lh_s0: T_M2_mpyd_acc <0b01, 1, 0, 0>;
2202 def M2_mpyd_nac_ll_s0: T_M2_mpyd_acc <0b00, 1, 0, 0>;
2204 def M2_mpyd_nac_hh_s1: T_M2_mpyd_acc <0b11, 1, 1, 0>;
2205 def M2_mpyd_nac_hl_s1: T_M2_mpyd_acc <0b10, 1, 1, 0>;
2206 def M2_mpyd_nac_lh_s1: T_M2_mpyd_acc <0b01, 1, 1, 0>;
2207 def M2_mpyd_nac_ll_s1: T_M2_mpyd_acc <0b00, 1, 1, 0>;
2209 def M2_mpyud_acc_hh_s0: T_M2_mpyd_acc <0b11, 0, 0, 1>;
2210 def M2_mpyud_acc_hl_s0: T_M2_mpyd_acc <0b10, 0, 0, 1>;
2211 def M2_mpyud_acc_lh_s0: T_M2_mpyd_acc <0b01, 0, 0, 1>;
2212 def M2_mpyud_acc_ll_s0: T_M2_mpyd_acc <0b00, 0, 0, 1>;
2214 def M2_mpyud_acc_hh_s1: T_M2_mpyd_acc <0b11, 0, 1, 1>;
2215 def M2_mpyud_acc_hl_s1: T_M2_mpyd_acc <0b10, 0, 1, 1>;
2216 def M2_mpyud_acc_lh_s1: T_M2_mpyd_acc <0b01, 0, 1, 1>;
2217 def M2_mpyud_acc_ll_s1: T_M2_mpyd_acc <0b00, 0, 1, 1>;
2219 def M2_mpyud_nac_hh_s0: T_M2_mpyd_acc <0b11, 1, 0, 1>;
2220 def M2_mpyud_nac_hl_s0: T_M2_mpyd_acc <0b10, 1, 0, 1>;
2221 def M2_mpyud_nac_lh_s0: T_M2_mpyd_acc <0b01, 1, 0, 1>;
2222 def M2_mpyud_nac_ll_s0: T_M2_mpyd_acc <0b00, 1, 0, 1>;
2224 def M2_mpyud_nac_hh_s1: T_M2_mpyd_acc <0b11, 1, 1, 1>;
2225 def M2_mpyud_nac_hl_s1: T_M2_mpyd_acc <0b10, 1, 1, 1>;
2226 def M2_mpyud_nac_lh_s1: T_M2_mpyd_acc <0b01, 1, 1, 1>;
2227 def M2_mpyud_nac_ll_s1: T_M2_mpyd_acc <0b00, 1, 1, 1>;
2230 let hasNewValue = 1, opNewValue = 0 in
2231 class T_MType_mpy <string mnemonic, bits<4> RegTyBits, RegisterClass RC,
2232 bits<3> MajOp, bits<3> MinOp, bit isSat = 0, bit isRnd = 0,
2233 string op2Suffix = "", bit isRaw = 0, bit isHi = 0 >
2234 : MInst <(outs IntRegs:$dst), (ins RC:$src1, RC:$src2),
2236 #"($src1, $src2"#op2Suffix#")"
2237 #!if(MajOp{2}, ":<<1", "")
2238 #!if(isRnd, ":rnd", "")
2239 #!if(isSat, ":sat", "")
2240 #!if(isRaw, !if(isHi, ":raw:hi", ":raw:lo"), ""), [] > {
2245 let IClass = 0b1110;
2247 let Inst{27-24} = RegTyBits;
2248 let Inst{23-21} = MajOp;
2249 let Inst{20-16} = src1;
2251 let Inst{12-8} = src2;
2252 let Inst{7-5} = MinOp;
2253 let Inst{4-0} = dst;
2256 class T_MType_dd <string mnemonic, bits<3> MajOp, bits<3> MinOp,
2257 bit isSat = 0, bit isRnd = 0 >
2258 : T_MType_mpy <mnemonic, 0b1001, DoubleRegs, MajOp, MinOp, isSat, isRnd>;
2260 class T_MType_rr1 <string mnemonic, bits<3> MajOp, bits<3> MinOp,
2261 bit isSat = 0, bit isRnd = 0 >
2262 : T_MType_mpy<mnemonic, 0b1101, IntRegs, MajOp, MinOp, isSat, isRnd>;
2264 class T_MType_rr2 <string mnemonic, bits<3> MajOp, bits<3> MinOp,
2265 bit isSat = 0, bit isRnd = 0, string op2str = "" >
2266 : T_MType_mpy<mnemonic, 0b1101, IntRegs, MajOp, MinOp, isSat, isRnd, op2str>;
2268 let CextOpcode = "mpyi", InputType = "reg", isCodeGenOnly = 0 in
2269 def M2_mpyi : T_MType_rr1 <"mpyi", 0b000, 0b000>, ImmRegRel;
2271 let isCodeGenOnly = 0 in {
2272 def M2_mpy_up : T_MType_rr1 <"mpy", 0b000, 0b001>;
2273 def M2_mpyu_up : T_MType_rr1 <"mpyu", 0b010, 0b001>;
2276 let isCodeGenOnly = 0 in
2277 def M2_dpmpyss_rnd_s0 : T_MType_rr1 <"mpy", 0b001, 0b001, 0, 1>;
2279 let isCodeGenOnly = 0 in {
2280 def M2_hmmpyh_rs1 : T_MType_rr2 <"mpy", 0b101, 0b100, 1, 1, ".h">;
2281 def M2_hmmpyl_rs1 : T_MType_rr2 <"mpy", 0b111, 0b100, 1, 1, ".l">;
2285 let isCodeGenOnly = 0 in {
2286 def M2_mpysu_up : T_MType_rr1 <"mpysu", 0b011, 0b001, 0>;
2287 def M2_mpy_up_s1_sat : T_MType_rr1 <"mpy", 0b111, 0b000, 1>;
2289 def M2_hmmpyh_s1 : T_MType_rr2 <"mpy", 0b101, 0b000, 1, 0, ".h">;
2290 def M2_hmmpyl_s1 : T_MType_rr2 <"mpy", 0b101, 0b001, 1, 0, ".l">;
2293 def: Pat<(i32 (mul I32:$src1, I32:$src2)), (M2_mpyi I32:$src1, I32:$src2)>;
2294 def: Pat<(i32 (mulhs I32:$src1, I32:$src2)), (M2_mpy_up I32:$src1, I32:$src2)>;
2295 def: Pat<(i32 (mulhu I32:$src1, I32:$src2)), (M2_mpyu_up I32:$src1, I32:$src2)>;
2297 let hasNewValue = 1, opNewValue = 0 in
2298 class T_MType_mpy_ri <bit isNeg, Operand ImmOp, list<dag> pattern>
2299 : MInst < (outs IntRegs:$Rd), (ins IntRegs:$Rs, ImmOp:$u8),
2300 "$Rd ="#!if(isNeg, "- ", "+ ")#"mpyi($Rs, #$u8)" ,
2301 pattern, "", M_tc_3x_SLOT23> {
2306 let IClass = 0b1110;
2308 let Inst{27-24} = 0b0000;
2309 let Inst{23} = isNeg;
2312 let Inst{20-16} = Rs;
2313 let Inst{12-5} = u8;
2316 let isExtendable = 1, opExtentBits = 8, opExtendable = 2, isCodeGenOnly = 0 in
2317 def M2_mpysip : T_MType_mpy_ri <0, u8Ext,
2318 [(set (i32 IntRegs:$Rd), (mul IntRegs:$Rs, u8ExtPred:$u8))]>;
2320 let isCodeGenOnly = 0 in
2321 def M2_mpysin : T_MType_mpy_ri <1, u8Imm,
2322 [(set (i32 IntRegs:$Rd), (ineg (mul IntRegs:$Rs,
2325 // Assember mapped to M2_mpyi
2326 let isAsmParserOnly = 1 in
2327 def M2_mpyui : MInst<(outs IntRegs:$dst),
2328 (ins IntRegs:$src1, IntRegs:$src2),
2329 "$dst = mpyui($src1, $src2)">;
2332 // s9 is NOT the same as m9 - but it works.. so far.
2333 // Assembler maps to either Rd=+mpyi(Rs,#u8) or Rd=-mpyi(Rs,#u8)
2334 // depending on the value of m9. See Arch Spec.
2335 let isExtendable = 1, opExtendable = 2, isExtentSigned = 1, opExtentBits = 9,
2336 CextOpcode = "mpyi", InputType = "imm", hasNewValue = 1 in
2337 def M2_mpysmi : MInst<(outs IntRegs:$dst), (ins IntRegs:$src1, s9Ext:$src2),
2338 "$dst = mpyi($src1, #$src2)",
2339 [(set (i32 IntRegs:$dst), (mul (i32 IntRegs:$src1),
2340 s9ExtPred:$src2))]>, ImmRegRel;
2342 let hasNewValue = 1, isExtendable = 1, opExtentBits = 8, opExtendable = 3,
2343 InputType = "imm" in
2344 class T_MType_acc_ri <string mnemonic, bits<3> MajOp, Operand ImmOp,
2345 list<dag> pattern = []>
2346 : MInst < (outs IntRegs:$dst), (ins IntRegs:$src1, IntRegs:$src2, ImmOp:$src3),
2347 "$dst "#mnemonic#"($src2, #$src3)",
2348 pattern, "$src1 = $dst", M_tc_2_SLOT23> {
2353 let IClass = 0b1110;
2355 let Inst{27-26} = 0b00;
2356 let Inst{25-23} = MajOp;
2357 let Inst{20-16} = src2;
2359 let Inst{12-5} = src3;
2360 let Inst{4-0} = dst;
2363 let InputType = "reg", hasNewValue = 1 in
2364 class T_MType_acc_rr <string mnemonic, bits<3> MajOp, bits<3> MinOp,
2365 bit isSwap = 0, list<dag> pattern = [], bit hasNot = 0,
2366 bit isSat = 0, bit isShift = 0>
2367 : MInst < (outs IntRegs:$dst),
2368 (ins IntRegs:$src1, IntRegs:$src2, IntRegs:$src3),
2369 "$dst "#mnemonic#"($src2, "#!if(hasNot, "~$src3)","$src3)")
2370 #!if(isShift, ":<<1", "")
2371 #!if(isSat, ":sat", ""),
2372 pattern, "$src1 = $dst", M_tc_2_SLOT23 > {
2377 let IClass = 0b1110;
2379 let Inst{27-24} = 0b1111;
2380 let Inst{23-21} = MajOp;
2381 let Inst{20-16} = !if(isSwap, src3, src2);
2383 let Inst{12-8} = !if(isSwap, src2, src3);
2384 let Inst{7-5} = MinOp;
2385 let Inst{4-0} = dst;
2388 let CextOpcode = "MPYI_acc", Itinerary = M_tc_3x_SLOT23, isCodeGenOnly = 0 in {
2389 def M2_macsip : T_MType_acc_ri <"+= mpyi", 0b010, u8Ext,
2390 [(set (i32 IntRegs:$dst),
2391 (add (mul IntRegs:$src2, u8ExtPred:$src3),
2392 IntRegs:$src1))]>, ImmRegRel;
2394 def M2_maci : T_MType_acc_rr <"+= mpyi", 0b000, 0b000, 0,
2395 [(set (i32 IntRegs:$dst),
2396 (add (mul IntRegs:$src2, IntRegs:$src3),
2397 IntRegs:$src1))]>, ImmRegRel;
2400 let CextOpcode = "ADD_acc", isCodeGenOnly = 0 in {
2401 let isExtentSigned = 1 in
2402 def M2_accii : T_MType_acc_ri <"+= add", 0b100, s8Ext,
2403 [(set (i32 IntRegs:$dst),
2404 (add (add (i32 IntRegs:$src2), s8_16ExtPred:$src3),
2405 (i32 IntRegs:$src1)))]>, ImmRegRel;
2407 def M2_acci : T_MType_acc_rr <"+= add", 0b000, 0b001, 0,
2408 [(set (i32 IntRegs:$dst),
2409 (add (add (i32 IntRegs:$src2), (i32 IntRegs:$src3)),
2410 (i32 IntRegs:$src1)))]>, ImmRegRel;
2413 let CextOpcode = "SUB_acc", isCodeGenOnly = 0 in {
2414 let isExtentSigned = 1 in
2415 def M2_naccii : T_MType_acc_ri <"-= add", 0b101, s8Ext>, ImmRegRel;
2417 def M2_nacci : T_MType_acc_rr <"-= add", 0b100, 0b001, 0>, ImmRegRel;
2420 let Itinerary = M_tc_3x_SLOT23, isCodeGenOnly = 0 in
2421 def M2_macsin : T_MType_acc_ri <"-= mpyi", 0b011, u8Ext>;
2423 let isCodeGenOnly = 0 in {
2424 def M2_xor_xacc : T_MType_acc_rr < "^= xor", 0b100, 0b011, 0>;
2425 def M2_subacc : T_MType_acc_rr <"+= sub", 0b000, 0b011, 1>;
2428 class T_MType_acc_pat1 <InstHexagon MI, SDNode firstOp, SDNode secOp,
2430 : Pat <(secOp IntRegs:$src1, (firstOp IntRegs:$src2, ImmPred:$src3)),
2431 (MI IntRegs:$src1, IntRegs:$src2, ImmPred:$src3)>;
2433 class T_MType_acc_pat2 <InstHexagon MI, SDNode firstOp, SDNode secOp>
2434 : Pat <(i32 (secOp IntRegs:$src1, (firstOp IntRegs:$src2, IntRegs:$src3))),
2435 (MI IntRegs:$src1, IntRegs:$src2, IntRegs:$src3)>;
2437 def : T_MType_acc_pat2 <M2_xor_xacc, xor, xor>;
2438 def : T_MType_acc_pat1 <M2_macsin, mul, sub, u8ExtPred>;
2440 def : T_MType_acc_pat1 <M2_naccii, add, sub, s8_16ExtPred>;
2441 def : T_MType_acc_pat2 <M2_nacci, add, sub>;
2442 //===----------------------------------------------------------------------===//
2443 // Template Class -- Multiply signed/unsigned halfwords with and without
2444 // saturation and rounding
2445 //===----------------------------------------------------------------------===//
2446 class T_M2_mpyd < bits<2> LHbits, bit isRnd, bit hasShift, bit isUnsigned >
2447 : MInst < (outs DoubleRegs:$Rdd), (ins IntRegs:$Rs, IntRegs:$Rt),
2448 "$Rdd = "#!if(isUnsigned,"mpyu","mpy")#"($Rs."#!if(LHbits{1},"h","l")
2449 #", $Rt."#!if(LHbits{0},"h)","l)")
2450 #!if(hasShift,":<<1","")
2451 #!if(isRnd,":rnd",""),
2457 let IClass = 0b1110;
2459 let Inst{27-24} = 0b0100;
2460 let Inst{23} = hasShift;
2461 let Inst{22} = isUnsigned;
2462 let Inst{21} = isRnd;
2463 let Inst{6-5} = LHbits;
2464 let Inst{4-0} = Rdd;
2465 let Inst{20-16} = Rs;
2466 let Inst{12-8} = Rt;
2469 let isCodeGenOnly = 0 in {
2470 def M2_mpyd_hh_s0: T_M2_mpyd<0b11, 0, 0, 0>;
2471 def M2_mpyd_hl_s0: T_M2_mpyd<0b10, 0, 0, 0>;
2472 def M2_mpyd_lh_s0: T_M2_mpyd<0b01, 0, 0, 0>;
2473 def M2_mpyd_ll_s0: T_M2_mpyd<0b00, 0, 0, 0>;
2475 def M2_mpyd_hh_s1: T_M2_mpyd<0b11, 0, 1, 0>;
2476 def M2_mpyd_hl_s1: T_M2_mpyd<0b10, 0, 1, 0>;
2477 def M2_mpyd_lh_s1: T_M2_mpyd<0b01, 0, 1, 0>;
2478 def M2_mpyd_ll_s1: T_M2_mpyd<0b00, 0, 1, 0>;
2480 def M2_mpyd_rnd_hh_s0: T_M2_mpyd<0b11, 1, 0, 0>;
2481 def M2_mpyd_rnd_hl_s0: T_M2_mpyd<0b10, 1, 0, 0>;
2482 def M2_mpyd_rnd_lh_s0: T_M2_mpyd<0b01, 1, 0, 0>;
2483 def M2_mpyd_rnd_ll_s0: T_M2_mpyd<0b00, 1, 0, 0>;
2485 def M2_mpyd_rnd_hh_s1: T_M2_mpyd<0b11, 1, 1, 0>;
2486 def M2_mpyd_rnd_hl_s1: T_M2_mpyd<0b10, 1, 1, 0>;
2487 def M2_mpyd_rnd_lh_s1: T_M2_mpyd<0b01, 1, 1, 0>;
2488 def M2_mpyd_rnd_ll_s1: T_M2_mpyd<0b00, 1, 1, 0>;
2490 //Rdd=mpyu(Rs.[HL],Rt.[HL])[:<<1]
2491 def M2_mpyud_hh_s0: T_M2_mpyd<0b11, 0, 0, 1>;
2492 def M2_mpyud_hl_s0: T_M2_mpyd<0b10, 0, 0, 1>;
2493 def M2_mpyud_lh_s0: T_M2_mpyd<0b01, 0, 0, 1>;
2494 def M2_mpyud_ll_s0: T_M2_mpyd<0b00, 0, 0, 1>;
2496 def M2_mpyud_hh_s1: T_M2_mpyd<0b11, 0, 1, 1>;
2497 def M2_mpyud_hl_s1: T_M2_mpyd<0b10, 0, 1, 1>;
2498 def M2_mpyud_lh_s1: T_M2_mpyd<0b01, 0, 1, 1>;
2499 def M2_mpyud_ll_s1: T_M2_mpyd<0b00, 0, 1, 1>;
2501 //===----------------------------------------------------------------------===//
2502 // Template Class for xtype mpy:
2505 // multiply 32X32 and use full result
2506 //===----------------------------------------------------------------------===//
2507 let hasSideEffects = 0 in
2508 class T_XTYPE_mpy64 <string mnemonic, bits<3> MajOp, bits<3> MinOp,
2509 bit isSat, bit hasShift, bit isConj>
2510 : MInst <(outs DoubleRegs:$Rdd),
2511 (ins IntRegs:$Rs, IntRegs:$Rt),
2512 "$Rdd = "#mnemonic#"($Rs, $Rt"#!if(isConj,"*)",")")
2513 #!if(hasShift,":<<1","")
2514 #!if(isSat,":sat",""),
2520 let IClass = 0b1110;
2522 let Inst{27-24} = 0b0101;
2523 let Inst{23-21} = MajOp;
2524 let Inst{20-16} = Rs;
2525 let Inst{12-8} = Rt;
2526 let Inst{7-5} = MinOp;
2527 let Inst{4-0} = Rdd;
2530 //===----------------------------------------------------------------------===//
2531 // Template Class for xtype mpy with accumulation into 64-bit:
2534 // multiply 32X32 and use full result
2535 //===----------------------------------------------------------------------===//
2536 class T_XTYPE_mpy64_acc <string op1, string op2, bits<3> MajOp, bits<3> MinOp,
2537 bit isSat, bit hasShift, bit isConj>
2538 : MInst <(outs DoubleRegs:$Rxx),
2539 (ins DoubleRegs:$dst2, IntRegs:$Rs, IntRegs:$Rt),
2540 "$Rxx "#op2#"= "#op1#"($Rs, $Rt"#!if(isConj,"*)",")")
2541 #!if(hasShift,":<<1","")
2542 #!if(isSat,":sat",""),
2544 [] , "$dst2 = $Rxx" > {
2549 let IClass = 0b1110;
2551 let Inst{27-24} = 0b0111;
2552 let Inst{23-21} = MajOp;
2553 let Inst{20-16} = Rs;
2554 let Inst{12-8} = Rt;
2555 let Inst{7-5} = MinOp;
2556 let Inst{4-0} = Rxx;
2559 // MPY - Multiply and use full result
2560 // Rdd = mpy[u](Rs,Rt)
2561 let isCodeGenOnly = 0 in {
2562 def M2_dpmpyss_s0 : T_XTYPE_mpy64 < "mpy", 0b000, 0b000, 0, 0, 0>;
2563 def M2_dpmpyuu_s0 : T_XTYPE_mpy64 < "mpyu", 0b010, 0b000, 0, 0, 0>;
2565 // Rxx[+-]= mpy[u](Rs,Rt)
2566 def M2_dpmpyss_acc_s0 : T_XTYPE_mpy64_acc < "mpy", "+", 0b000, 0b000, 0, 0, 0>;
2567 def M2_dpmpyss_nac_s0 : T_XTYPE_mpy64_acc < "mpy", "-", 0b001, 0b000, 0, 0, 0>;
2568 def M2_dpmpyuu_acc_s0 : T_XTYPE_mpy64_acc < "mpyu", "+", 0b010, 0b000, 0, 0, 0>;
2569 def M2_dpmpyuu_nac_s0 : T_XTYPE_mpy64_acc < "mpyu", "-", 0b011, 0b000, 0, 0, 0>;
2572 def: Pat<(i64 (mul (i64 (anyext (i32 IntRegs:$src1))),
2573 (i64 (anyext (i32 IntRegs:$src2))))),
2574 (M2_dpmpyuu_s0 IntRegs:$src1, IntRegs:$src2)>;
2576 def: Pat<(i64 (mul (i64 (sext (i32 IntRegs:$src1))),
2577 (i64 (sext (i32 IntRegs:$src2))))),
2578 (M2_dpmpyss_s0 IntRegs:$src1, IntRegs:$src2)>;
2580 def: Pat<(i64 (mul (is_sext_i32:$src1),
2581 (is_sext_i32:$src2))),
2582 (M2_dpmpyss_s0 (LoReg DoubleRegs:$src1), (LoReg DoubleRegs:$src2))>;
2584 // Multiply and accumulate, use full result.
2585 // Rxx[+-]=mpy(Rs,Rt)
2587 def: Pat<(i64 (add (i64 DoubleRegs:$src1),
2588 (mul (i64 (sext (i32 IntRegs:$src2))),
2589 (i64 (sext (i32 IntRegs:$src3)))))),
2590 (M2_dpmpyss_acc_s0 DoubleRegs:$src1, IntRegs:$src2, IntRegs:$src3)>;
2592 def: Pat<(i64 (sub (i64 DoubleRegs:$src1),
2593 (mul (i64 (sext (i32 IntRegs:$src2))),
2594 (i64 (sext (i32 IntRegs:$src3)))))),
2595 (M2_dpmpyss_nac_s0 DoubleRegs:$src1, IntRegs:$src2, IntRegs:$src3)>;
2597 def: Pat<(i64 (add (i64 DoubleRegs:$src1),
2598 (mul (i64 (anyext (i32 IntRegs:$src2))),
2599 (i64 (anyext (i32 IntRegs:$src3)))))),
2600 (M2_dpmpyuu_acc_s0 DoubleRegs:$src1, IntRegs:$src2, IntRegs:$src3)>;
2602 def: Pat<(i64 (add (i64 DoubleRegs:$src1),
2603 (mul (i64 (zext (i32 IntRegs:$src2))),
2604 (i64 (zext (i32 IntRegs:$src3)))))),
2605 (M2_dpmpyuu_acc_s0 DoubleRegs:$src1, IntRegs:$src2, IntRegs:$src3)>;
2607 def: Pat<(i64 (sub (i64 DoubleRegs:$src1),
2608 (mul (i64 (anyext (i32 IntRegs:$src2))),
2609 (i64 (anyext (i32 IntRegs:$src3)))))),
2610 (M2_dpmpyuu_nac_s0 DoubleRegs:$src1, IntRegs:$src2, IntRegs:$src3)>;
2612 def: Pat<(i64 (sub (i64 DoubleRegs:$src1),
2613 (mul (i64 (zext (i32 IntRegs:$src2))),
2614 (i64 (zext (i32 IntRegs:$src3)))))),
2615 (M2_dpmpyuu_nac_s0 DoubleRegs:$src1, IntRegs:$src2, IntRegs:$src3)>;
2617 //===----------------------------------------------------------------------===//
2619 //===----------------------------------------------------------------------===//
2621 //===----------------------------------------------------------------------===//
2623 //===----------------------------------------------------------------------===//
2624 //===----------------------------------------------------------------------===//
2626 //===----------------------------------------------------------------------===//
2628 //===----------------------------------------------------------------------===//
2630 //===----------------------------------------------------------------------===//
2631 //===----------------------------------------------------------------------===//
2633 //===----------------------------------------------------------------------===//
2635 //===----------------------------------------------------------------------===//
2637 //===----------------------------------------------------------------------===//
2638 //===----------------------------------------------------------------------===//
2640 //===----------------------------------------------------------------------===//
2642 //===----------------------------------------------------------------------===//
2644 //===----------------------------------------------------------------------===//
2646 // Store doubleword.
2647 //===----------------------------------------------------------------------===//
2648 // Template class for non-predicated post increment stores with immediate offset
2649 //===----------------------------------------------------------------------===//
2650 let isPredicable = 1, hasSideEffects = 0, addrMode = PostInc in
2651 class T_store_pi <string mnemonic, RegisterClass RC, Operand ImmOp,
2652 bits<4> MajOp, bit isHalf >
2653 : STInst <(outs IntRegs:$_dst_),
2654 (ins IntRegs:$src1, ImmOp:$offset, RC:$src2),
2655 mnemonic#"($src1++#$offset) = $src2"#!if(isHalf, ".h", ""),
2656 [], "$src1 = $_dst_" >,
2663 string ImmOpStr = !cast<string>(ImmOp);
2664 let offsetBits = !if (!eq(ImmOpStr, "s4_3Imm"), offset{6-3},
2665 !if (!eq(ImmOpStr, "s4_2Imm"), offset{5-2},
2666 !if (!eq(ImmOpStr, "s4_1Imm"), offset{4-1},
2667 /* s4_0Imm */ offset{3-0})));
2668 let isNVStorable = !if (!eq(ImmOpStr, "s4_3Imm"), 0, 1);
2670 let IClass = 0b1010;
2672 let Inst{27-25} = 0b101;
2673 let Inst{24-21} = MajOp;
2674 let Inst{20-16} = src1;
2676 let Inst{12-8} = src2;
2678 let Inst{6-3} = offsetBits;
2682 //===----------------------------------------------------------------------===//
2683 // Template class for predicated post increment stores with immediate offset
2684 //===----------------------------------------------------------------------===//
2685 let isPredicated = 1, hasSideEffects = 0, addrMode = PostInc in
2686 class T_pstore_pi <string mnemonic, RegisterClass RC, Operand ImmOp,
2687 bits<4> MajOp, bit isHalf, bit isPredNot, bit isPredNew >
2688 : STInst <(outs IntRegs:$_dst_),
2689 (ins PredRegs:$src1, IntRegs:$src2, ImmOp:$offset, RC:$src3),
2690 !if(isPredNot, "if (!$src1", "if ($src1")#!if(isPredNew, ".new) ",
2691 ") ")#mnemonic#"($src2++#$offset) = $src3"#!if(isHalf, ".h", ""),
2692 [], "$src2 = $_dst_" >,
2700 string ImmOpStr = !cast<string>(ImmOp);
2701 let offsetBits = !if (!eq(ImmOpStr, "s4_3Imm"), offset{6-3},
2702 !if (!eq(ImmOpStr, "s4_2Imm"), offset{5-2},
2703 !if (!eq(ImmOpStr, "s4_1Imm"), offset{4-1},
2704 /* s4_0Imm */ offset{3-0})));
2706 let isNVStorable = !if (!eq(ImmOpStr, "s4_3Imm"), 0, 1);
2707 let isPredicatedNew = isPredNew;
2708 let isPredicatedFalse = isPredNot;
2710 let IClass = 0b1010;
2712 let Inst{27-25} = 0b101;
2713 let Inst{24-21} = MajOp;
2714 let Inst{20-16} = src2;
2716 let Inst{12-8} = src3;
2717 let Inst{7} = isPredNew;
2718 let Inst{6-3} = offsetBits;
2719 let Inst{2} = isPredNot;
2720 let Inst{1-0} = src1;
2723 multiclass ST_PostInc<string mnemonic, string BaseOp, RegisterClass RC,
2724 Operand ImmOp, bits<4> MajOp, bit isHalf = 0 > {
2726 let BaseOpcode = "POST_"#BaseOp in {
2727 def S2_#NAME#_pi : T_store_pi <mnemonic, RC, ImmOp, MajOp, isHalf>;
2730 def S2_p#NAME#t_pi : T_pstore_pi <mnemonic, RC, ImmOp, MajOp, isHalf, 0, 0>;
2731 def S2_p#NAME#f_pi : T_pstore_pi <mnemonic, RC, ImmOp, MajOp, isHalf, 1, 0>;
2734 def S2_p#NAME#tnew_pi : T_pstore_pi <mnemonic, RC, ImmOp, MajOp,
2736 def S2_p#NAME#fnew_pi : T_pstore_pi <mnemonic, RC, ImmOp, MajOp,
2741 let accessSize = ByteAccess, isCodeGenOnly = 0 in
2742 defm storerb: ST_PostInc <"memb", "STrib", IntRegs, s4_0Imm, 0b1000>;
2744 let accessSize = HalfWordAccess, isCodeGenOnly = 0 in
2745 defm storerh: ST_PostInc <"memh", "STrih", IntRegs, s4_1Imm, 0b1010>;
2747 let accessSize = WordAccess, isCodeGenOnly = 0 in
2748 defm storeri: ST_PostInc <"memw", "STriw", IntRegs, s4_2Imm, 0b1100>;
2750 let accessSize = DoubleWordAccess, isCodeGenOnly = 0 in
2751 defm storerd: ST_PostInc <"memd", "STrid", DoubleRegs, s4_3Imm, 0b1110>;
2753 let accessSize = HalfWordAccess, isNVStorable = 0, isCodeGenOnly = 0 in
2754 defm storerf: ST_PostInc <"memh", "STrih_H", IntRegs, s4_1Imm, 0b1011, 1>;
2756 // Patterns for generating stores, where the address takes different forms:
2759 // - simple (base address without offset).
2760 // These would usually be used together (via Storex_pat defined below), but
2761 // in some cases one may want to apply different properties (such as
2762 // AddedComplexity) to the individual patterns.
2763 class Storex_fi_pat<PatFrag Store, PatFrag Value, InstHexagon MI>
2764 : Pat<(Store Value:$Rs, AddrFI:$fi), (MI AddrFI:$fi, 0, Value:$Rs)>;
2765 class Storex_add_pat<PatFrag Store, PatFrag Value, PatFrag ImmPred,
2767 : Pat<(Store Value:$Rt, (add (i32 IntRegs:$Rs), ImmPred:$Off)),
2768 (MI IntRegs:$Rs, imm:$Off, Value:$Rt)>;
2770 multiclass Storex_pat<PatFrag Store, PatFrag Value, PatLeaf ImmPred,
2772 def: Storex_fi_pat <Store, Value, MI>;
2773 def: Storex_add_pat <Store, Value, ImmPred, MI>;
2776 def : Pat<(post_truncsti8 (i32 IntRegs:$src1), IntRegs:$src2,
2777 s4_3ImmPred:$offset),
2778 (S2_storerb_pi IntRegs:$src2, s4_0ImmPred:$offset, IntRegs:$src1)>;
2780 def : Pat<(post_truncsti16 (i32 IntRegs:$src1), IntRegs:$src2,
2781 s4_3ImmPred:$offset),
2782 (S2_storerh_pi IntRegs:$src2, s4_1ImmPred:$offset, IntRegs:$src1)>;
2784 def : Pat<(post_store (i32 IntRegs:$src1), IntRegs:$src2, s4_2ImmPred:$offset),
2785 (S2_storeri_pi IntRegs:$src2, s4_1ImmPred:$offset, IntRegs:$src1)>;
2787 def : Pat<(post_store (i64 DoubleRegs:$src1), IntRegs:$src2,
2788 s4_3ImmPred:$offset),
2789 (S2_storerd_pi IntRegs:$src2, s4_3ImmPred:$offset, DoubleRegs:$src1)>;
2791 //===----------------------------------------------------------------------===//
2792 // Template class for post increment stores with register offset.
2793 //===----------------------------------------------------------------------===//
2794 let isNVStorable = 1 in
2795 class T_store_pr <string mnemonic, RegisterClass RC, bits<3> MajOp,
2796 MemAccessSize AccessSz, bit isHalf = 0>
2797 : STInst <(outs IntRegs:$_dst_),
2798 (ins IntRegs:$src1, ModRegs:$src2, RC:$src3),
2799 mnemonic#"($src1++$src2) = $src3"#!if(isHalf, ".h", ""),
2800 [], "$src1 = $_dst_" > {
2804 let accessSize = AccessSz;
2806 let IClass = 0b1010;
2808 let Inst{27-24} = 0b1101;
2809 let Inst{23-21} = MajOp;
2810 let Inst{20-16} = src1;
2811 let Inst{13} = src2;
2812 let Inst{12-8} = src3;
2816 let isCodeGenOnly = 0 in {
2817 def S2_storerb_pr : T_store_pr<"memb", IntRegs, 0b000, ByteAccess>;
2818 def S2_storerh_pr : T_store_pr<"memh", IntRegs, 0b010, HalfWordAccess>;
2819 def S2_storeri_pr : T_store_pr<"memw", IntRegs, 0b100, WordAccess>;
2820 def S2_storerd_pr : T_store_pr<"memd", DoubleRegs, 0b110, DoubleWordAccess>;
2822 def S2_storerf_pr : T_store_pr<"memh", IntRegs, 0b011, HalfWordAccess, 1>;
2824 let opExtendable = 1, isExtentSigned = 1, isPredicable = 1 in
2825 class T_store_io <string mnemonic, RegisterClass RC, Operand ImmOp,
2826 bits<3>MajOp, bit isH = 0>
2828 (ins IntRegs:$src1, ImmOp:$src2, RC:$src3),
2829 mnemonic#"($src1+#$src2) = $src3"#!if(isH,".h","")>,
2830 AddrModeRel, ImmRegRel {
2832 bits<14> src2; // Actual address offset
2834 bits<11> offsetBits; // Represents offset encoding
2836 string ImmOpStr = !cast<string>(ImmOp);
2838 let opExtentBits = !if (!eq(ImmOpStr, "s11_3Ext"), 14,
2839 !if (!eq(ImmOpStr, "s11_2Ext"), 13,
2840 !if (!eq(ImmOpStr, "s11_1Ext"), 12,
2841 /* s11_0Ext */ 11)));
2842 let offsetBits = !if (!eq(ImmOpStr, "s11_3Ext"), src2{13-3},
2843 !if (!eq(ImmOpStr, "s11_2Ext"), src2{12-2},
2844 !if (!eq(ImmOpStr, "s11_1Ext"), src2{11-1},
2845 /* s11_0Ext */ src2{10-0})));
2846 let IClass = 0b1010;
2849 let Inst{26-25} = offsetBits{10-9};
2851 let Inst{23-21} = MajOp;
2852 let Inst{20-16} = src1;
2853 let Inst{13} = offsetBits{8};
2854 let Inst{12-8} = src3;
2855 let Inst{7-0} = offsetBits{7-0};
2858 let opExtendable = 2, isPredicated = 1 in
2859 class T_pstore_io <string mnemonic, RegisterClass RC, Operand ImmOp,
2860 bits<3>MajOp, bit PredNot, bit isPredNew, bit isH = 0>
2862 (ins PredRegs:$src1, IntRegs:$src2, ImmOp:$src3, RC:$src4),
2863 !if(PredNot, "if (!$src1", "if ($src1")#!if(isPredNew, ".new) ",
2864 ") ")#mnemonic#"($src2+#$src3) = $src4"#!if(isH,".h",""),
2865 [],"",V2LDST_tc_st_SLOT01 >,
2866 AddrModeRel, ImmRegRel {
2869 bits<9> src3; // Actual address offset
2871 bits<6> offsetBits; // Represents offset encoding
2873 let isPredicatedNew = isPredNew;
2874 let isPredicatedFalse = PredNot;
2876 string ImmOpStr = !cast<string>(ImmOp);
2877 let opExtentBits = !if (!eq(ImmOpStr, "u6_3Ext"), 9,
2878 !if (!eq(ImmOpStr, "u6_2Ext"), 8,
2879 !if (!eq(ImmOpStr, "u6_1Ext"), 7,
2881 let offsetBits = !if (!eq(ImmOpStr, "u6_3Ext"), src3{8-3},
2882 !if (!eq(ImmOpStr, "u6_2Ext"), src3{7-2},
2883 !if (!eq(ImmOpStr, "u6_1Ext"), src3{6-1},
2884 /* u6_0Ext */ src3{5-0})));
2885 let IClass = 0b0100;
2888 let Inst{26} = PredNot;
2889 let Inst{25} = isPredNew;
2891 let Inst{23-21} = MajOp;
2892 let Inst{20-16} = src2;
2893 let Inst{13} = offsetBits{5};
2894 let Inst{12-8} = src4;
2895 let Inst{7-3} = offsetBits{4-0};
2896 let Inst{1-0} = src1;
2899 let isExtendable = 1, isNVStorable = 1, hasSideEffects = 0 in
2900 multiclass ST_Idxd<string mnemonic, string CextOp, RegisterClass RC,
2901 Operand ImmOp, Operand predImmOp, bits<3> MajOp, bit isH = 0> {
2902 let CextOpcode = CextOp, BaseOpcode = CextOp#_indexed in {
2903 def S2_#NAME#_io : T_store_io <mnemonic, RC, ImmOp, MajOp, isH>;
2906 def S2_p#NAME#t_io : T_pstore_io<mnemonic, RC, predImmOp, MajOp, 0, 0, isH>;
2907 def S2_p#NAME#f_io : T_pstore_io<mnemonic, RC, predImmOp, MajOp, 1, 0, isH>;
2910 def S4_p#NAME#tnew_io : T_pstore_io <mnemonic, RC, predImmOp,
2912 def S4_p#NAME#fnew_io : T_pstore_io <mnemonic, RC, predImmOp,
2917 let addrMode = BaseImmOffset, InputType = "imm", isCodeGenOnly = 0 in {
2918 let accessSize = ByteAccess in
2919 defm storerb: ST_Idxd < "memb", "STrib", IntRegs, s11_0Ext, u6_0Ext, 0b000>;
2921 let accessSize = HalfWordAccess, opExtentAlign = 1 in
2922 defm storerh: ST_Idxd < "memh", "STrih", IntRegs, s11_1Ext, u6_1Ext, 0b010>;
2924 let accessSize = WordAccess, opExtentAlign = 2 in
2925 defm storeri: ST_Idxd < "memw", "STriw", IntRegs, s11_2Ext, u6_2Ext, 0b100>;
2927 let accessSize = DoubleWordAccess, isNVStorable = 0, opExtentAlign = 3 in
2928 defm storerd: ST_Idxd < "memd", "STrid", DoubleRegs, s11_3Ext,
2931 let accessSize = HalfWordAccess, opExtentAlign = 1 in
2932 defm storerf: ST_Idxd < "memh", "STrif", IntRegs, s11_1Ext,
2936 def : Pat<(truncstorei8 (i32 IntRegs:$src1), ADDRriS11_0:$addr),
2937 (S2_storerb_io AddrFI:$addr, 0, (i32 IntRegs:$src1))>;
2939 def : Pat<(truncstorei16 (i32 IntRegs:$src1), ADDRriS11_1:$addr),
2940 (S2_storerh_io AddrFI:$addr, 0, (i32 IntRegs:$src1))>;
2942 def : Pat<(store (i32 IntRegs:$src1), ADDRriS11_2:$addr),
2943 (S2_storeri_io AddrFI:$addr, 0, (i32 IntRegs:$src1))>;
2945 def : Pat<(store (i64 DoubleRegs:$src1), ADDRriS11_3:$addr),
2946 (S2_storerd_io AddrFI:$addr, 0, (i64 DoubleRegs:$src1))>;
2949 let AddedComplexity = 10 in {
2950 def : Pat<(truncstorei8 (i32 IntRegs:$src1), (add IntRegs:$src2,
2951 s11_0ExtPred:$offset)),
2952 (S2_storerb_io IntRegs:$src2, s11_0ImmPred:$offset,
2953 (i32 IntRegs:$src1))>;
2955 def : Pat<(truncstorei16 (i32 IntRegs:$src1), (add IntRegs:$src2,
2956 s11_1ExtPred:$offset)),
2957 (S2_storerh_io IntRegs:$src2, s11_1ImmPred:$offset,
2958 (i32 IntRegs:$src1))>;
2960 def : Pat<(store (i32 IntRegs:$src1), (add IntRegs:$src2,
2961 s11_2ExtPred:$offset)),
2962 (S2_storeri_io IntRegs:$src2, s11_2ImmPred:$offset,
2963 (i32 IntRegs:$src1))>;
2965 def : Pat<(store (i64 DoubleRegs:$src1), (add IntRegs:$src2,
2966 s11_3ExtPred:$offset)),
2967 (S2_storerd_io IntRegs:$src2, s11_3ImmPred:$offset,
2968 (i64 DoubleRegs:$src1))>;
2971 // memh(Rx++#s4:1)=Rt.H
2974 let isExtendable = 1, opExtendable = 1, isExtentSigned = 1, opExtentBits = 13,
2975 isCodeGenOnly = 1, isPseudo = 1, hasSideEffects = 0 in
2976 def STriw_pred : STInst<(outs),
2977 (ins IntRegs:$addr, s11_2Ext:$off, PredRegs:$src1),
2978 ".error \"should not emit\"", []>;
2980 // S2_allocframe: Allocate stack frame.
2981 let Defs = [R29, R30], Uses = [R29, R31, R30],
2982 hasSideEffects = 0, accessSize = DoubleWordAccess, isCodeGenOnly = 0 in
2983 def S2_allocframe: ST0Inst <
2984 (outs), (ins u11_3Imm:$u11_3),
2985 "allocframe(#$u11_3)" > {
2988 let IClass = 0b1010;
2989 let Inst{27-16} = 0b000010011101;
2990 let Inst{13-11} = 0b000;
2991 let Inst{10-0} = u11_3{13-3};
2994 // S2_storer[bhwdf]_pci: Store byte/half/word/double.
2995 // S2_storer[bhwdf]_pci -> S2_storerbnew_pci
2996 let Uses = [CS], isNVStorable = 1 in
2997 class T_store_pci <string mnemonic, RegisterClass RC,
2998 Operand Imm, bits<4>MajOp,
2999 MemAccessSize AlignSize, string RegSrc = "Rt">
3000 : STInst <(outs IntRegs:$_dst_),
3001 (ins IntRegs:$Rz, Imm:$offset, ModRegs:$Mu, RC:$Rt),
3002 #mnemonic#"($Rz ++ #$offset:circ($Mu)) = $"#RegSrc#"",
3009 let accessSize = AlignSize;
3011 let IClass = 0b1010;
3012 let Inst{27-25} = 0b100;
3013 let Inst{24-21} = MajOp;
3014 let Inst{20-16} = Rz;
3016 let Inst{12-8} = Rt;
3019 !if (!eq(!cast<string>(AlignSize), "DoubleWordAccess"), offset{6-3},
3020 !if (!eq(!cast<string>(AlignSize), "WordAccess"), offset{5-2},
3021 !if (!eq(!cast<string>(AlignSize), "HalfWordAccess"), offset{4-1},
3022 /* ByteAccess */ offset{3-0})));
3026 let isCodeGenOnly = 0 in {
3027 def S2_storerb_pci : T_store_pci<"memb", IntRegs, s4_0Imm, 0b1000,
3029 def S2_storerh_pci : T_store_pci<"memh", IntRegs, s4_1Imm, 0b1010,
3031 def S2_storerf_pci : T_store_pci<"memh", IntRegs, s4_1Imm, 0b1011,
3032 HalfWordAccess, "Rt.h">;
3033 def S2_storeri_pci : T_store_pci<"memw", IntRegs, s4_2Imm, 0b1100,
3035 def S2_storerd_pci : T_store_pci<"memd", DoubleRegs, s4_3Imm, 0b1110,
3039 //===----------------------------------------------------------------------===//
3040 // Circular stores with auto-increment register
3041 //===----------------------------------------------------------------------===//
3042 let Uses = [CS], isNVStorable = 1, isCodeGenOnly = 0 in
3043 class T_store_pcr <string mnemonic, RegisterClass RC, bits<4>MajOp,
3044 MemAccessSize AlignSize, string RegSrc = "Rt">
3045 : STInst <(outs IntRegs:$_dst_),
3046 (ins IntRegs:$Rz, ModRegs:$Mu, RC:$Rt),
3047 #mnemonic#"($Rz ++ I:circ($Mu)) = $"#RegSrc#"",
3054 let accessSize = AlignSize;
3056 let IClass = 0b1010;
3057 let Inst{27-25} = 0b100;
3058 let Inst{24-21} = MajOp;
3059 let Inst{20-16} = Rz;
3061 let Inst{12-8} = Rt;
3066 let isCodeGenOnly = 0 in {
3067 def S2_storerb_pcr : T_store_pcr<"memb", IntRegs, 0b1000, ByteAccess>;
3068 def S2_storerh_pcr : T_store_pcr<"memh", IntRegs, 0b1010, HalfWordAccess>;
3069 def S2_storeri_pcr : T_store_pcr<"memw", IntRegs, 0b1100, WordAccess>;
3070 def S2_storerd_pcr : T_store_pcr<"memd", DoubleRegs, 0b1110, DoubleWordAccess>;
3071 def S2_storerf_pcr : T_store_pcr<"memh", IntRegs, 0b1011,
3072 HalfWordAccess, "Rt.h">;
3075 //===----------------------------------------------------------------------===//
3076 // Bit-reversed stores with auto-increment register
3077 //===----------------------------------------------------------------------===//
3078 let hasSideEffects = 0 in
3079 class T_store_pbr<string mnemonic, RegisterClass RC,
3080 MemAccessSize addrSize, bits<3> majOp,
3083 <(outs IntRegs:$_dst_),
3084 (ins IntRegs:$Rz, ModRegs:$Mu, RC:$src),
3085 #mnemonic#"($Rz ++ $Mu:brev) = $src"#!if (!eq(isHalf, 1), ".h", ""),
3086 [], "$Rz = $_dst_" > {
3088 let accessSize = addrSize;
3094 let IClass = 0b1010;
3096 let Inst{27-24} = 0b1111;
3097 let Inst{23-21} = majOp;
3099 let Inst{20-16} = Rz;
3101 let Inst{12-8} = src;
3104 let isNVStorable = 1, isCodeGenOnly = 0 in {
3105 let BaseOpcode = "S2_storerb_pbr" in
3106 def S2_storerb_pbr : T_store_pbr<"memb", IntRegs, ByteAccess,
3107 0b000>, NewValueRel;
3108 let BaseOpcode = "S2_storerh_pbr" in
3109 def S2_storerh_pbr : T_store_pbr<"memh", IntRegs, HalfWordAccess,
3110 0b010>, NewValueRel;
3111 let BaseOpcode = "S2_storeri_pbr" in
3112 def S2_storeri_pbr : T_store_pbr<"memw", IntRegs, WordAccess,
3113 0b100>, NewValueRel;
3115 let isCodeGenOnly = 0 in {
3116 def S2_storerf_pbr : T_store_pbr<"memh", IntRegs, HalfWordAccess, 0b011, 1>;
3117 def S2_storerd_pbr : T_store_pbr<"memd", DoubleRegs, DoubleWordAccess, 0b110>;
3120 //===----------------------------------------------------------------------===//
3122 //===----------------------------------------------------------------------===//
3124 //===----------------------------------------------------------------------===//
3126 //===----------------------------------------------------------------------===//
3128 def NOT_rr64 : ALU64_rr<(outs DoubleRegs:$dst), (ins DoubleRegs:$src1),
3129 "$dst = not($src1)",
3130 [(set (i64 DoubleRegs:$dst), (not (i64 DoubleRegs:$src1)))]>;
3133 //===----------------------------------------------------------------------===//
3135 //===----------------------------------------------------------------------===//
3137 let hasSideEffects = 0 in
3138 class T_S2op_1 <string mnemonic, bits<4> RegTyBits, RegisterClass RCOut,
3139 RegisterClass RCIn, bits<2> MajOp, bits<3> MinOp, bit isSat>
3140 : SInst <(outs RCOut:$dst), (ins RCIn:$src),
3141 "$dst = "#mnemonic#"($src)"#!if(isSat, ":sat", ""),
3142 [], "", S_2op_tc_1_SLOT23 > {
3146 let IClass = 0b1000;
3148 let Inst{27-24} = RegTyBits;
3149 let Inst{23-22} = MajOp;
3151 let Inst{20-16} = src;
3152 let Inst{7-5} = MinOp;
3153 let Inst{4-0} = dst;
3156 class T_S2op_1_di <string mnemonic, bits<2> MajOp, bits<3> MinOp>
3157 : T_S2op_1 <mnemonic, 0b0100, DoubleRegs, IntRegs, MajOp, MinOp, 0>;
3159 let hasNewValue = 1 in
3160 class T_S2op_1_id <string mnemonic, bits<2> MajOp, bits<3> MinOp, bit isSat = 0>
3161 : T_S2op_1 <mnemonic, 0b1000, IntRegs, DoubleRegs, MajOp, MinOp, isSat>;
3163 let hasNewValue = 1 in
3164 class T_S2op_1_ii <string mnemonic, bits<2> MajOp, bits<3> MinOp, bit isSat = 0>
3165 : T_S2op_1 <mnemonic, 0b1100, IntRegs, IntRegs, MajOp, MinOp, isSat>;
3167 // Sign extend word to doubleword
3168 let isCodeGenOnly = 0 in
3169 def A2_sxtw : T_S2op_1_di <"sxtw", 0b01, 0b000>;
3171 def: Pat <(i64 (sext I32:$src)), (A2_sxtw I32:$src)>;
3173 // Swizzle the bytes of a word
3174 let isCodeGenOnly = 0 in
3175 def A2_swiz : T_S2op_1_ii <"swiz", 0b10, 0b111>;
3178 let Defs = [USR_OVF], isCodeGenOnly = 0 in {
3179 def A2_sat : T_S2op_1_id <"sat", 0b11, 0b000>;
3180 def A2_satb : T_S2op_1_ii <"satb", 0b11, 0b111>;
3181 def A2_satub : T_S2op_1_ii <"satub", 0b11, 0b110>;
3182 def A2_sath : T_S2op_1_ii <"sath", 0b11, 0b100>;
3183 def A2_satuh : T_S2op_1_ii <"satuh", 0b11, 0b101>;
3186 let Itinerary = S_2op_tc_2_SLOT23, isCodeGenOnly = 0 in {
3187 // Absolute value word
3188 def A2_abs : T_S2op_1_ii <"abs", 0b10, 0b100>;
3190 let Defs = [USR_OVF] in
3191 def A2_abssat : T_S2op_1_ii <"abs", 0b10, 0b101, 1>;
3193 // Negate with saturation
3194 let Defs = [USR_OVF] in
3195 def A2_negsat : T_S2op_1_ii <"neg", 0b10, 0b110, 1>;
3198 def: Pat<(i32 (select (i1 (setlt (i32 IntRegs:$src), 0)),
3199 (i32 (sub 0, (i32 IntRegs:$src))),
3200 (i32 IntRegs:$src))),
3201 (A2_abs IntRegs:$src)>;
3203 let AddedComplexity = 50 in
3204 def: Pat<(i32 (xor (add (sra (i32 IntRegs:$src), (i32 31)),
3205 (i32 IntRegs:$src)),
3206 (sra (i32 IntRegs:$src), (i32 31)))),
3207 (A2_abs IntRegs:$src)>;
3209 class T_S2op_2 <string mnemonic, bits<4> RegTyBits, RegisterClass RCOut,
3210 RegisterClass RCIn, bits<3> MajOp, bits<3> MinOp,
3211 bit isSat, bit isRnd, list<dag> pattern = []>
3212 : SInst <(outs RCOut:$dst),
3213 (ins RCIn:$src, u5Imm:$u5),
3214 "$dst = "#mnemonic#"($src, #$u5)"#!if(isSat, ":sat", "")
3215 #!if(isRnd, ":rnd", ""),
3216 pattern, "", S_2op_tc_2_SLOT23> {
3221 let IClass = 0b1000;
3223 let Inst{27-24} = RegTyBits;
3224 let Inst{23-21} = MajOp;
3225 let Inst{20-16} = src;
3227 let Inst{12-8} = u5;
3228 let Inst{7-5} = MinOp;
3229 let Inst{4-0} = dst;
3232 class T_S2op_2_di <string mnemonic, bits<3> MajOp, bits<3> MinOp>
3233 : T_S2op_2 <mnemonic, 0b1000, DoubleRegs, IntRegs, MajOp, MinOp, 0, 0>;
3235 let hasNewValue = 1 in
3236 class T_S2op_2_id <string mnemonic, bits<3> MajOp, bits<3> MinOp>
3237 : T_S2op_2 <mnemonic, 0b1000, IntRegs, DoubleRegs, MajOp, MinOp, 0, 0>;
3239 let hasNewValue = 1 in
3240 class T_S2op_2_ii <string mnemonic, bits<3> MajOp, bits<3> MinOp,
3241 bit isSat = 0, bit isRnd = 0, list<dag> pattern = []>
3242 : T_S2op_2 <mnemonic, 0b1100, IntRegs, IntRegs, MajOp, MinOp,
3243 isSat, isRnd, pattern>;
3245 class T_S2op_shift <string mnemonic, bits<3> MajOp, bits<3> MinOp, SDNode OpNd>
3246 : T_S2op_2_ii <mnemonic, MajOp, MinOp, 0, 0,
3247 [(set (i32 IntRegs:$dst), (OpNd (i32 IntRegs:$src),
3248 (u5ImmPred:$u5)))]>;
3250 // Arithmetic/logical shift right/left by immediate
3251 let Itinerary = S_2op_tc_1_SLOT23, isCodeGenOnly = 0 in {
3252 def S2_asr_i_r : T_S2op_shift <"asr", 0b000, 0b000, sra>;
3253 def S2_lsr_i_r : T_S2op_shift <"lsr", 0b000, 0b001, srl>;
3254 def S2_asl_i_r : T_S2op_shift <"asl", 0b000, 0b010, shl>;
3257 // Shift left by immediate with saturation
3258 let Defs = [USR_OVF], isCodeGenOnly = 0 in
3259 def S2_asl_i_r_sat : T_S2op_2_ii <"asl", 0b010, 0b010, 1>;
3261 // Shift right with round
3262 let isCodeGenOnly = 0 in
3263 def S2_asr_i_r_rnd : T_S2op_2_ii <"asr", 0b010, 0b000, 0, 1>;
3265 def: Pat<(i32 (sra (i32 (add (i32 (sra I32:$src1, u5ImmPred:$src2)),
3268 (S2_asr_i_r_rnd IntRegs:$src1, u5ImmPred:$src2)>;
3270 class T_S2op_3<string opc, bits<2>MajOp, bits<3>minOp, bits<1> sat = 0>
3271 : SInst<(outs DoubleRegs:$Rdd), (ins DoubleRegs:$Rss),
3272 "$Rdd = "#opc#"($Rss)"#!if(!eq(sat, 1),":sat","")> {
3275 let IClass = 0b1000;
3276 let Inst{27-24} = 0;
3277 let Inst{23-22} = MajOp;
3278 let Inst{20-16} = Rss;
3279 let Inst{7-5} = minOp;
3280 let Inst{4-0} = Rdd;
3283 let isCodeGenOnly = 0 in {
3284 def A2_absp : T_S2op_3 <"abs", 0b10, 0b110>;
3285 def A2_negp : T_S2op_3 <"neg", 0b10, 0b101>;
3286 def A2_notp : T_S2op_3 <"not", 0b10, 0b100>;
3289 // Innterleave/deinterleave
3290 let isCodeGenOnly = 0 in {
3291 def S2_interleave : T_S2op_3 <"interleave", 0b11, 0b101>;
3292 def S2_deinterleave : T_S2op_3 <"deinterleave", 0b11, 0b100>;
3295 //===----------------------------------------------------------------------===//
3297 //===----------------------------------------------------------------------===//
3300 let hasSideEffects = 0, hasNewValue = 1 in
3301 class T_COUNT_LEADING<string MnOp, bits<3> MajOp, bits<3> MinOp, bit Is32,
3303 : SInst<Out, Inp, "$Rd = "#MnOp#"($Rs)", [], "", S_2op_tc_1_SLOT23> {
3306 let IClass = 0b1000;
3308 let Inst{26} = Is32;
3309 let Inst{25-24} = 0b00;
3310 let Inst{23-21} = MajOp;
3311 let Inst{20-16} = Rs;
3312 let Inst{7-5} = MinOp;
3316 class T_COUNT_LEADING_32<string MnOp, bits<3> MajOp, bits<3> MinOp>
3317 : T_COUNT_LEADING<MnOp, MajOp, MinOp, 0b1,
3318 (outs IntRegs:$Rd), (ins IntRegs:$Rs)>;
3320 class T_COUNT_LEADING_64<string MnOp, bits<3> MajOp, bits<3> MinOp>
3321 : T_COUNT_LEADING<MnOp, MajOp, MinOp, 0b0,
3322 (outs IntRegs:$Rd), (ins DoubleRegs:$Rs)>;
3324 let isCodeGenOnly = 0 in {
3325 def S2_cl0 : T_COUNT_LEADING_32<"cl0", 0b000, 0b101>;
3326 def S2_cl1 : T_COUNT_LEADING_32<"cl1", 0b000, 0b110>;
3327 def S2_ct0 : T_COUNT_LEADING_32<"ct0", 0b010, 0b100>;
3328 def S2_ct1 : T_COUNT_LEADING_32<"ct1", 0b010, 0b101>;
3329 def S2_cl0p : T_COUNT_LEADING_64<"cl0", 0b010, 0b010>;
3330 def S2_cl1p : T_COUNT_LEADING_64<"cl1", 0b010, 0b100>;
3331 def S2_clb : T_COUNT_LEADING_32<"clb", 0b000, 0b100>;
3332 def S2_clbp : T_COUNT_LEADING_64<"clb", 0b010, 0b000>;
3333 def S2_clbnorm : T_COUNT_LEADING_32<"normamt", 0b000, 0b111>;
3336 def: Pat<(i32 (ctlz I32:$Rs)), (S2_cl0 I32:$Rs)>;
3337 def: Pat<(i32 (ctlz (not I32:$Rs))), (S2_cl1 I32:$Rs)>;
3338 def: Pat<(i32 (cttz I32:$Rs)), (S2_ct0 I32:$Rs)>;
3339 def: Pat<(i32 (cttz (not I32:$Rs))), (S2_ct1 I32:$Rs)>;
3340 def: Pat<(i32 (trunc (ctlz I64:$Rss))), (S2_cl0p I64:$Rss)>;
3341 def: Pat<(i32 (trunc (ctlz (not I64:$Rss)))), (S2_cl1p I64:$Rss)>;
3343 // Bit set/clear/toggle
3345 let hasSideEffects = 0, hasNewValue = 1 in
3346 class T_SCT_BIT_IMM<string MnOp, bits<3> MinOp>
3347 : SInst<(outs IntRegs:$Rd), (ins IntRegs:$Rs, u5Imm:$u5),
3348 "$Rd = "#MnOp#"($Rs, #$u5)", [], "", S_2op_tc_1_SLOT23> {
3352 let IClass = 0b1000;
3353 let Inst{27-21} = 0b1100110;
3354 let Inst{20-16} = Rs;
3356 let Inst{12-8} = u5;
3357 let Inst{7-5} = MinOp;
3361 let hasSideEffects = 0, hasNewValue = 1 in
3362 class T_SCT_BIT_REG<string MnOp, bits<2> MinOp>
3363 : SInst<(outs IntRegs:$Rd), (ins IntRegs:$Rs, IntRegs:$Rt),
3364 "$Rd = "#MnOp#"($Rs, $Rt)", [], "", S_3op_tc_1_SLOT23> {
3368 let IClass = 0b1100;
3369 let Inst{27-22} = 0b011010;
3370 let Inst{20-16} = Rs;
3371 let Inst{12-8} = Rt;
3372 let Inst{7-6} = MinOp;
3376 let isCodeGenOnly = 0 in {
3377 def S2_clrbit_i : T_SCT_BIT_IMM<"clrbit", 0b001>;
3378 def S2_setbit_i : T_SCT_BIT_IMM<"setbit", 0b000>;
3379 def S2_togglebit_i : T_SCT_BIT_IMM<"togglebit", 0b010>;
3380 def S2_clrbit_r : T_SCT_BIT_REG<"clrbit", 0b01>;
3381 def S2_setbit_r : T_SCT_BIT_REG<"setbit", 0b00>;
3382 def S2_togglebit_r : T_SCT_BIT_REG<"togglebit", 0b10>;
3385 def: Pat<(i32 (and (i32 IntRegs:$Rs), (not (shl 1, u5ImmPred:$u5)))),
3386 (S2_clrbit_i IntRegs:$Rs, u5ImmPred:$u5)>;
3387 def: Pat<(i32 (or (i32 IntRegs:$Rs), (shl 1, u5ImmPred:$u5))),
3388 (S2_setbit_i IntRegs:$Rs, u5ImmPred:$u5)>;
3389 def: Pat<(i32 (xor (i32 IntRegs:$Rs), (shl 1, u5ImmPred:$u5))),
3390 (S2_togglebit_i IntRegs:$Rs, u5ImmPred:$u5)>;
3391 def: Pat<(i32 (and (i32 IntRegs:$Rs), (not (shl 1, (i32 IntRegs:$Rt))))),
3392 (S2_clrbit_r IntRegs:$Rs, IntRegs:$Rt)>;
3393 def: Pat<(i32 (or (i32 IntRegs:$Rs), (shl 1, (i32 IntRegs:$Rt)))),
3394 (S2_setbit_r IntRegs:$Rs, IntRegs:$Rt)>;
3395 def: Pat<(i32 (xor (i32 IntRegs:$Rs), (shl 1, (i32 IntRegs:$Rt)))),
3396 (S2_togglebit_r IntRegs:$Rs, IntRegs:$Rt)>;
3400 let hasSideEffects = 0 in
3401 class T_TEST_BIT_IMM<string MnOp, bits<3> MajOp>
3402 : SInst<(outs PredRegs:$Pd), (ins IntRegs:$Rs, u5Imm:$u5),
3403 "$Pd = "#MnOp#"($Rs, #$u5)",
3404 [], "", S_2op_tc_2early_SLOT23> {
3408 let IClass = 0b1000;
3409 let Inst{27-24} = 0b0101;
3410 let Inst{23-21} = MajOp;
3411 let Inst{20-16} = Rs;
3413 let Inst{12-8} = u5;
3417 let hasSideEffects = 0 in
3418 class T_TEST_BIT_REG<string MnOp, bit IsNeg>
3419 : SInst<(outs PredRegs:$Pd), (ins IntRegs:$Rs, IntRegs:$Rt),
3420 "$Pd = "#MnOp#"($Rs, $Rt)",
3421 [], "", S_3op_tc_2early_SLOT23> {
3425 let IClass = 0b1100;
3426 let Inst{27-22} = 0b011100;
3427 let Inst{21} = IsNeg;
3428 let Inst{20-16} = Rs;
3429 let Inst{12-8} = Rt;
3433 let isCodeGenOnly = 0 in {
3434 def S2_tstbit_i : T_TEST_BIT_IMM<"tstbit", 0b000>;
3435 def S2_tstbit_r : T_TEST_BIT_REG<"tstbit", 0>;
3438 let AddedComplexity = 20 in { // Complexity greater than cmp reg-imm.
3439 def: Pat<(i1 (setne (and (shl 1, u5ImmPred:$u5), (i32 IntRegs:$Rs)), 0)),
3440 (S2_tstbit_i IntRegs:$Rs, u5ImmPred:$u5)>;
3441 def: Pat<(i1 (setne (and (shl 1, (i32 IntRegs:$Rt)), (i32 IntRegs:$Rs)), 0)),
3442 (S2_tstbit_r IntRegs:$Rs, IntRegs:$Rt)>;
3443 def: Pat<(i1 (trunc (i32 IntRegs:$Rs))),
3444 (S2_tstbit_i IntRegs:$Rs, 0)>;
3445 def: Pat<(i1 (trunc (i64 DoubleRegs:$Rs))),
3446 (S2_tstbit_i (LoReg DoubleRegs:$Rs), 0)>;
3448 let hasSideEffects = 0 in
3449 class T_TEST_BITS_IMM<string MnOp, bits<2> MajOp, bit IsNeg>
3450 : SInst<(outs PredRegs:$Pd), (ins IntRegs:$Rs, u6Imm:$u6),
3451 "$Pd = "#MnOp#"($Rs, #$u6)",
3452 [], "", S_2op_tc_2early_SLOT23> {
3456 let IClass = 0b1000;
3457 let Inst{27-24} = 0b0101;
3458 let Inst{23-22} = MajOp;
3459 let Inst{21} = IsNeg;
3460 let Inst{20-16} = Rs;
3461 let Inst{13-8} = u6;
3465 let hasSideEffects = 0 in
3466 class T_TEST_BITS_REG<string MnOp, bits<2> MajOp, bit IsNeg>
3467 : SInst<(outs PredRegs:$Pd), (ins IntRegs:$Rs, IntRegs:$Rt),
3468 "$Pd = "#MnOp#"($Rs, $Rt)",
3469 [], "", S_3op_tc_2early_SLOT23> {
3473 let IClass = 0b1100;
3474 let Inst{27-24} = 0b0111;
3475 let Inst{23-22} = MajOp;
3476 let Inst{21} = IsNeg;
3477 let Inst{20-16} = Rs;
3478 let Inst{12-8} = Rt;
3482 let isCodeGenOnly = 0 in {
3483 def C2_bitsclri : T_TEST_BITS_IMM<"bitsclr", 0b10, 0>;
3484 def C2_bitsclr : T_TEST_BITS_REG<"bitsclr", 0b10, 0>;
3485 def C2_bitsset : T_TEST_BITS_REG<"bitsset", 0b01, 0>;
3488 let AddedComplexity = 20 in { // Complexity greater than compare reg-imm.
3489 def: Pat<(i1 (seteq (and (i32 IntRegs:$Rs), u6ImmPred:$u6), 0)),
3490 (C2_bitsclri IntRegs:$Rs, u6ImmPred:$u6)>;
3491 def: Pat<(i1 (seteq (and (i32 IntRegs:$Rs), (i32 IntRegs:$Rt)), 0)),
3492 (C2_bitsclr IntRegs:$Rs, IntRegs:$Rt)>;
3495 let AddedComplexity = 10 in // Complexity greater than compare reg-reg.
3496 def: Pat<(i1 (seteq (and (i32 IntRegs:$Rs), (i32 IntRegs:$Rt)), IntRegs:$Rt)),
3497 (C2_bitsset IntRegs:$Rs, IntRegs:$Rt)>;
3499 //===----------------------------------------------------------------------===//
3501 //===----------------------------------------------------------------------===//
3503 //===----------------------------------------------------------------------===//
3505 //===----------------------------------------------------------------------===//
3506 //===----------------------------------------------------------------------===//
3508 //===----------------------------------------------------------------------===//
3510 //===----------------------------------------------------------------------===//
3512 //===----------------------------------------------------------------------===//
3514 //===----------------------------------------------------------------------===//
3516 //===----------------------------------------------------------------------===//
3518 //===----------------------------------------------------------------------===//
3520 //===----------------------------------------------------------------------===//
3522 // Predicate transfer.
3523 let hasSideEffects = 0, hasNewValue = 1, isCodeGenOnly = 0 in
3524 def C2_tfrpr : SInst<(outs IntRegs:$Rd), (ins PredRegs:$Ps),
3525 "$Rd = $Ps", [], "", S_2op_tc_1_SLOT23> {
3529 let IClass = 0b1000;
3530 let Inst{27-24} = 0b1001;
3532 let Inst{17-16} = Ps;
3536 // Transfer general register to predicate.
3537 let hasSideEffects = 0, isCodeGenOnly = 0 in
3538 def C2_tfrrp: SInst<(outs PredRegs:$Pd), (ins IntRegs:$Rs),
3539 "$Pd = $Rs", [], "", S_2op_tc_2early_SLOT23> {
3543 let IClass = 0b1000;
3544 let Inst{27-21} = 0b0101010;
3545 let Inst{20-16} = Rs;
3550 //===----------------------------------------------------------------------===//
3552 //===----------------------------------------------------------------------===//
3554 //===----------------------------------------------------------------------===//
3556 //===----------------------------------------------------------------------===//
3557 class S_2OpInstImm<string Mnemonic, bits<3>MajOp, bits<3>MinOp,
3558 Operand Imm, list<dag> pattern = [], bit isRnd = 0>
3559 : SInst<(outs DoubleRegs:$dst), (ins DoubleRegs:$src1, Imm:$src2),
3560 "$dst = "#Mnemonic#"($src1, #$src2)"#!if(isRnd, ":rnd", ""),
3564 let IClass = 0b1000;
3565 let Inst{27-24} = 0;
3566 let Inst{23-21} = MajOp;
3567 let Inst{20-16} = src1;
3568 let Inst{7-5} = MinOp;
3569 let Inst{4-0} = dst;
3572 class S_2OpInstImmI6<string Mnemonic, SDNode OpNode, bits<3>MinOp>
3573 : S_2OpInstImm<Mnemonic, 0b000, MinOp, u6Imm,
3574 [(set (i64 DoubleRegs:$dst), (OpNode (i64 DoubleRegs:$src1),
3575 u6ImmPred:$src2))]> {
3577 let Inst{13-8} = src2;
3580 // Shift by immediate.
3581 let isCodeGenOnly = 0 in {
3582 def S2_asr_i_p : S_2OpInstImmI6<"asr", sra, 0b000>;
3583 def S2_asl_i_p : S_2OpInstImmI6<"asl", shl, 0b010>;
3584 def S2_lsr_i_p : S_2OpInstImmI6<"lsr", srl, 0b001>;
3587 // Shift left by small amount and add.
3588 let AddedComplexity = 100, hasNewValue = 1, hasSideEffects = 0,
3589 isCodeGenOnly = 0 in
3590 def S2_addasl_rrri: SInst <(outs IntRegs:$Rd),
3591 (ins IntRegs:$Rt, IntRegs:$Rs, u3Imm:$u3),
3592 "$Rd = addasl($Rt, $Rs, #$u3)" ,
3593 [(set (i32 IntRegs:$Rd), (add (i32 IntRegs:$Rt),
3594 (shl (i32 IntRegs:$Rs), u3ImmPred:$u3)))],
3595 "", S_3op_tc_2_SLOT23> {
3601 let IClass = 0b1100;
3603 let Inst{27-21} = 0b0100000;
3604 let Inst{20-16} = Rs;
3606 let Inst{12-8} = Rt;
3611 //===----------------------------------------------------------------------===//
3613 //===----------------------------------------------------------------------===//
3615 //===----------------------------------------------------------------------===//
3617 //===----------------------------------------------------------------------===//
3618 //===----------------------------------------------------------------------===//
3620 //===----------------------------------------------------------------------===//
3622 //===----------------------------------------------------------------------===//
3624 //===----------------------------------------------------------------------===//
3625 //===----------------------------------------------------------------------===//
3627 //===----------------------------------------------------------------------===//
3629 //===----------------------------------------------------------------------===//
3631 //===----------------------------------------------------------------------===//
3633 //===----------------------------------------------------------------------===//
3635 //===----------------------------------------------------------------------===//
3636 def HexagonBARRIER: SDNode<"HexagonISD::BARRIER", SDTNone, [SDNPHasChain]>;
3638 let hasSideEffects = 1, isSoloAX = 1, isCodeGenOnly = 0 in
3639 def BARRIER : SYSInst<(outs), (ins),
3641 [(HexagonBARRIER)],"",ST_tc_st_SLOT0> {
3642 let Inst{31-28} = 0b1010;
3643 let Inst{27-21} = 0b1000000;
3646 //===----------------------------------------------------------------------===//
3648 //===----------------------------------------------------------------------===//
3649 //===----------------------------------------------------------------------===//
3651 //===----------------------------------------------------------------------===//
3653 let isExtendable = 1, isExtentSigned = 1, opExtentBits = 9, opExtentAlign = 2,
3654 opExtendable = 0, hasSideEffects = 0 in
3655 class LOOP_iBase<string mnemonic, Operand brOp, bit mustExtend = 0>
3656 : CRInst<(outs), (ins brOp:$offset, u10Imm:$src2),
3657 #mnemonic#"($offset, #$src2)",
3658 [], "" , CR_tc_3x_SLOT3> {
3662 let IClass = 0b0110;
3664 let Inst{27-22} = 0b100100;
3665 let Inst{21} = !if (!eq(mnemonic, "loop0"), 0b0, 0b1);
3666 let Inst{20-16} = src2{9-5};
3667 let Inst{12-8} = offset{8-4};
3668 let Inst{7-5} = src2{4-2};
3669 let Inst{4-3} = offset{3-2};
3670 let Inst{1-0} = src2{1-0};
3673 let isExtendable = 1, isExtentSigned = 1, opExtentBits = 9, opExtentAlign = 2,
3674 opExtendable = 0, hasSideEffects = 0 in
3675 class LOOP_rBase<string mnemonic, Operand brOp, bit mustExtend = 0>
3676 : CRInst<(outs), (ins brOp:$offset, IntRegs:$src2),
3677 #mnemonic#"($offset, $src2)",
3678 [], "" ,CR_tc_3x_SLOT3> {
3682 let IClass = 0b0110;
3684 let Inst{27-22} = 0b000000;
3685 let Inst{21} = !if (!eq(mnemonic, "loop0"), 0b0, 0b1);
3686 let Inst{20-16} = src2;
3687 let Inst{12-8} = offset{8-4};
3688 let Inst{4-3} = offset{3-2};
3691 multiclass LOOP_ri<string mnemonic> {
3692 def i : LOOP_iBase<mnemonic, brtarget>;
3693 def r : LOOP_rBase<mnemonic, brtarget>;
3697 let Defs = [SA0, LC0, USR], isCodeGenOnly = 0 in
3698 defm J2_loop0 : LOOP_ri<"loop0">;
3700 // Interestingly only loop0's appear to set usr.lpcfg
3701 let Defs = [SA1, LC1], isCodeGenOnly = 0 in
3702 defm J2_loop1 : LOOP_ri<"loop1">;
3704 let isBranch = 1, isTerminator = 1, hasSideEffects = 0,
3705 Defs = [PC, LC0], Uses = [SA0, LC0] in {
3706 def ENDLOOP0 : Endloop<(outs), (ins brtarget:$offset),
3711 let isBranch = 1, isTerminator = 1, hasSideEffects = 0,
3712 Defs = [PC, LC1], Uses = [SA1, LC1] in {
3713 def ENDLOOP1 : Endloop<(outs), (ins brtarget:$offset),
3718 // Pipelined loop instructions, sp[123]loop0
3719 let Defs = [LC0, SA0, P3, USR], hasSideEffects = 0,
3720 isExtentSigned = 1, isExtendable = 1, opExtentBits = 9, opExtentAlign = 2,
3721 opExtendable = 0, isPredicateLate = 1 in
3722 class SPLOOP_iBase<string SP, bits<2> op>
3723 : CRInst <(outs), (ins brtarget:$r7_2, u10Imm:$U10),
3724 "p3 = sp"#SP#"loop0($r7_2, #$U10)" > {
3728 let IClass = 0b0110;
3730 let Inst{22-21} = op;
3731 let Inst{27-23} = 0b10011;
3732 let Inst{20-16} = U10{9-5};
3733 let Inst{12-8} = r7_2{8-4};
3734 let Inst{7-5} = U10{4-2};
3735 let Inst{4-3} = r7_2{3-2};
3736 let Inst{1-0} = U10{1-0};
3739 let Defs = [LC0, SA0, P3, USR], hasSideEffects = 0,
3740 isExtentSigned = 1, isExtendable = 1, opExtentBits = 9, opExtentAlign = 2,
3741 opExtendable = 0, isPredicateLate = 1 in
3742 class SPLOOP_rBase<string SP, bits<2> op>
3743 : CRInst <(outs), (ins brtarget:$r7_2, IntRegs:$Rs),
3744 "p3 = sp"#SP#"loop0($r7_2, $Rs)" > {
3748 let IClass = 0b0110;
3750 let Inst{22-21} = op;
3751 let Inst{27-23} = 0b00001;
3752 let Inst{20-16} = Rs;
3753 let Inst{12-8} = r7_2{8-4};
3754 let Inst{4-3} = r7_2{3-2};
3757 multiclass SPLOOP_ri<string mnemonic, bits<2> op> {
3758 def i : SPLOOP_iBase<mnemonic, op>;
3759 def r : SPLOOP_rBase<mnemonic, op>;
3762 let isCodeGenOnly = 0 in {
3763 defm J2_ploop1s : SPLOOP_ri<"1", 0b01>;
3764 defm J2_ploop2s : SPLOOP_ri<"2", 0b10>;
3765 defm J2_ploop3s : SPLOOP_ri<"3", 0b11>;
3768 // Transfer to/from Control/GPR Guest/GPR
3769 let hasSideEffects = 0 in
3770 class TFR_CR_RS_base<RegisterClass CTRC, RegisterClass RC, bit isDouble>
3771 : CRInst <(outs CTRC:$dst), (ins RC:$src),
3772 "$dst = $src", [], "", CR_tc_3x_SLOT3> {
3776 let IClass = 0b0110;
3778 let Inst{27-25} = 0b001;
3779 let Inst{24} = isDouble;
3780 let Inst{23-21} = 0b001;
3781 let Inst{20-16} = src;
3782 let Inst{4-0} = dst;
3784 let isCodeGenOnly = 0 in
3785 def A2_tfrrcr : TFR_CR_RS_base<CtrRegs, IntRegs, 0b0>;
3786 def : InstAlias<"m0 = $Rs", (A2_tfrrcr C6, IntRegs:$Rs)>;
3787 def : InstAlias<"m1 = $Rs", (A2_tfrrcr C7, IntRegs:$Rs)>;
3789 let hasSideEffects = 0 in
3790 class TFR_RD_CR_base<RegisterClass RC, RegisterClass CTRC, bit isSingle>
3791 : CRInst <(outs RC:$dst), (ins CTRC:$src),
3792 "$dst = $src", [], "", CR_tc_3x_SLOT3> {
3796 let IClass = 0b0110;
3798 let Inst{27-26} = 0b10;
3799 let Inst{25} = isSingle;
3800 let Inst{24-21} = 0b0000;
3801 let Inst{20-16} = src;
3802 let Inst{4-0} = dst;
3805 let hasNewValue = 1, opNewValue = 0, isCodeGenOnly = 0 in
3806 def A2_tfrcrr : TFR_RD_CR_base<IntRegs, CtrRegs, 1>;
3807 def : InstAlias<"$Rd = m0", (A2_tfrcrr IntRegs:$Rd, C6)>;
3808 def : InstAlias<"$Rd = m1", (A2_tfrcrr IntRegs:$Rd, C7)>;
3810 // Y4_trace: Send value to etm trace.
3811 let isSoloAX = 1, hasSideEffects = 0, isCodeGenOnly = 0 in
3812 def Y4_trace: CRInst <(outs), (ins IntRegs:$Rs),
3816 let IClass = 0b0110;
3817 let Inst{27-21} = 0b0010010;
3818 let Inst{20-16} = Rs;
3821 let AddedComplexity = 100, isPredicated = 1 in
3822 def TFR_condset_ri : ALU32_rr<(outs IntRegs:$dst),
3823 (ins PredRegs:$src1, IntRegs:$src2, s12Imm:$src3),
3824 "Error; should not emit",
3825 [(set (i32 IntRegs:$dst),
3826 (i32 (select (i1 PredRegs:$src1), (i32 IntRegs:$src2),
3827 s12ImmPred:$src3)))]>;
3829 let AddedComplexity = 100, isPredicated = 1 in
3830 def TFR_condset_ir : ALU32_rr<(outs IntRegs:$dst),
3831 (ins PredRegs:$src1, s12Imm:$src2, IntRegs:$src3),
3832 "Error; should not emit",
3833 [(set (i32 IntRegs:$dst),
3834 (i32 (select (i1 PredRegs:$src1), s12ImmPred:$src2,
3835 (i32 IntRegs:$src3))))]>;
3837 let AddedComplexity = 100, isPredicated = 1 in
3838 def TFR_condset_ii : ALU32_rr<(outs IntRegs:$dst),
3839 (ins PredRegs:$src1, s12Imm:$src2, s12Imm:$src3),
3840 "Error; should not emit",
3841 [(set (i32 IntRegs:$dst),
3842 (i32 (select (i1 PredRegs:$src1), s12ImmPred:$src2,
3843 s12ImmPred:$src3)))]>;
3845 // Generate frameindex addresses.
3846 let isReMaterializable = 1 in
3847 def TFR_FI : ALU32_ri<(outs IntRegs:$dst), (ins FrameIndex:$src1),
3848 "$dst = add($src1)",
3849 [(set (i32 IntRegs:$dst), ADDRri:$src1)]>;
3851 // Support for generating global address.
3852 // Taken from X86InstrInfo.td.
3853 def SDTHexagonCONST32 : SDTypeProfile<1, 1, [
3857 def HexagonCONST32 : SDNode<"HexagonISD::CONST32", SDTHexagonCONST32>;
3858 def HexagonCONST32_GP : SDNode<"HexagonISD::CONST32_GP", SDTHexagonCONST32>;
3860 // HI/LO Instructions
3861 let isReMaterializable = 1, isMoveImm = 1, hasSideEffects = 0 in
3862 def LO : ALU32_ri<(outs IntRegs:$dst), (ins globaladdress:$global),
3863 "$dst.l = #LO($global)",
3866 let isReMaterializable = 1, isMoveImm = 1, hasSideEffects = 0 in
3867 def HI : ALU32_ri<(outs IntRegs:$dst), (ins globaladdress:$global),
3868 "$dst.h = #HI($global)",
3871 let isReMaterializable = 1, isMoveImm = 1, hasSideEffects = 0 in
3872 def LOi : ALU32_ri<(outs IntRegs:$dst), (ins i32imm:$imm_value),
3873 "$dst.l = #LO($imm_value)",
3877 let isReMaterializable = 1, isMoveImm = 1, hasSideEffects = 0 in
3878 def HIi : ALU32_ri<(outs IntRegs:$dst), (ins i32imm:$imm_value),
3879 "$dst.h = #HI($imm_value)",
3882 let isReMaterializable = 1, isMoveImm = 1, hasSideEffects = 0 in
3883 def LO_jt : ALU32_ri<(outs IntRegs:$dst), (ins jumptablebase:$jt),
3884 "$dst.l = #LO($jt)",
3887 let isReMaterializable = 1, isMoveImm = 1, hasSideEffects = 0 in
3888 def HI_jt : ALU32_ri<(outs IntRegs:$dst), (ins jumptablebase:$jt),
3889 "$dst.h = #HI($jt)",
3893 let isReMaterializable = 1, isMoveImm = 1, hasSideEffects = 0 in
3894 def LO_label : ALU32_ri<(outs IntRegs:$dst), (ins bblabel:$label),
3895 "$dst.l = #LO($label)",
3898 let isReMaterializable = 1, isMoveImm = 1 , hasSideEffects = 0 in
3899 def HI_label : ALU32_ri<(outs IntRegs:$dst), (ins bblabel:$label),
3900 "$dst.h = #HI($label)",
3903 // This pattern is incorrect. When we add small data, we should change
3904 // this pattern to use memw(#foo).
3905 // This is for sdata.
3906 let isMoveImm = 1 in
3907 def CONST32 : LDInst<(outs IntRegs:$dst), (ins globaladdress:$global),
3908 "$dst = CONST32(#$global)",
3909 [(set (i32 IntRegs:$dst),
3910 (load (HexagonCONST32 tglobaltlsaddr:$global)))]>;
3912 // This is for non-sdata.
3913 let isReMaterializable = 1, isMoveImm = 1 in
3914 def CONST32_set : LDInst2<(outs IntRegs:$dst), (ins globaladdress:$global),
3915 "$dst = CONST32(#$global)",
3916 [(set (i32 IntRegs:$dst),
3917 (HexagonCONST32 tglobaladdr:$global))]>;
3919 let isReMaterializable = 1, isMoveImm = 1 in
3920 def CONST32_set_jt : LDInst2<(outs IntRegs:$dst), (ins jumptablebase:$jt),
3921 "$dst = CONST32(#$jt)",
3922 [(set (i32 IntRegs:$dst),
3923 (HexagonCONST32 tjumptable:$jt))]>;
3925 let isReMaterializable = 1, isMoveImm = 1 in
3926 def CONST32GP_set : LDInst2<(outs IntRegs:$dst), (ins globaladdress:$global),
3927 "$dst = CONST32(#$global)",
3928 [(set (i32 IntRegs:$dst),
3929 (HexagonCONST32_GP tglobaladdr:$global))]>;
3931 let isReMaterializable = 1, isMoveImm = 1 in
3932 def CONST32_Int_Real : LDInst2<(outs IntRegs:$dst), (ins i32imm:$global),
3933 "$dst = CONST32(#$global)",
3934 [(set (i32 IntRegs:$dst), imm:$global) ]>;
3936 // Map BlockAddress lowering to CONST32_Int_Real
3937 def : Pat<(HexagonCONST32_GP tblockaddress:$addr),
3938 (CONST32_Int_Real tblockaddress:$addr)>;
3940 let isReMaterializable = 1, isMoveImm = 1 in
3941 def CONST32_Label : LDInst2<(outs IntRegs:$dst), (ins bblabel:$label),
3942 "$dst = CONST32($label)",
3943 [(set (i32 IntRegs:$dst), (HexagonCONST32 bbl:$label))]>;
3945 let isReMaterializable = 1, isMoveImm = 1 in
3946 def CONST64_Int_Real : LDInst2<(outs DoubleRegs:$dst), (ins i64imm:$global),
3947 "$dst = CONST64(#$global)",
3948 [(set (i64 DoubleRegs:$dst), imm:$global) ]>;
3950 def TFR_PdFalse : SInst<(outs PredRegs:$dst), (ins),
3951 "$dst = xor($dst, $dst)",
3952 [(set (i1 PredRegs:$dst), 0)]>;
3954 def MPY_trsext : MInst<(outs IntRegs:$dst), (ins IntRegs:$src1, IntRegs:$src2),
3955 "$dst = mpy($src1, $src2)",
3956 [(set (i32 IntRegs:$dst),
3957 (trunc (i64 (srl (i64 (mul (i64 (sext (i32 IntRegs:$src1))),
3958 (i64 (sext (i32 IntRegs:$src2))))),
3961 // Pseudo instructions.
3962 def SDT_SPCallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i32> ]>;
3964 def SDT_SPCallSeqEnd : SDCallSeqEnd<[ SDTCisVT<0, i32>,
3965 SDTCisVT<1, i32> ]>;
3967 def callseq_end : SDNode<"ISD::CALLSEQ_END", SDT_SPCallSeqEnd,
3968 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
3970 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_SPCallSeqStart,
3971 [SDNPHasChain, SDNPOutGlue]>;
3973 def SDT_SPCall : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
3975 def call : SDNode<"HexagonISD::CALL", SDT_SPCall,
3976 [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue, SDNPVariadic]>;
3978 // For tailcalls a HexagonTCRet SDNode has 3 SDNode Properties - a chain,
3979 // Optional Flag and Variable Arguments.
3980 // Its 1 Operand has pointer type.
3981 def HexagonTCRet : SDNode<"HexagonISD::TC_RETURN", SDT_SPCall,
3982 [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
3984 let Defs = [R29, R30], Uses = [R31, R30, R29] in {
3985 def ADJCALLSTACKDOWN : Pseudo<(outs), (ins i32imm:$amt),
3986 "Should never be emitted",
3987 [(callseq_start timm:$amt)]>;
3990 let Defs = [R29, R30, R31], Uses = [R29] in {
3991 def ADJCALLSTACKUP : Pseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2),
3992 "Should never be emitted",
3993 [(callseq_end timm:$amt1, timm:$amt2)]>;
3996 let isCall = 1, hasSideEffects = 0,
3997 Defs = [D0, D1, D2, D3, D4, D5, D6, D7, D8, D9, D10,
3998 R22, R23, R28, R31, P0, P1, P2, P3, LC0, LC1, SA0, SA1] in {
3999 def CALL : JInst<(outs), (ins calltarget:$dst),
4003 // Call subroutine indirectly.
4004 let Defs = VolatileV3.Regs, isCodeGenOnly = 0 in
4005 def J2_callr : JUMPR_MISC_CALLR<0, 1>;
4007 // Indirect tail-call.
4008 let isCodeGenOnly = 1, isCall = 1, isReturn = 1 in
4009 def TCRETURNR : T_JMPr;
4011 // Direct tail-calls.
4012 let isCall = 1, isReturn = 1, isBarrier = 1, isPredicable = 0,
4013 isTerminator = 1, isCodeGenOnly = 1 in {
4014 def TCRETURNtg : JInst<(outs), (ins calltarget:$dst), "jump $dst",
4015 [], "", J_tc_2early_SLOT23>;
4016 def TCRETURNtext : JInst<(outs), (ins calltarget:$dst), "jump $dst",
4017 [], "", J_tc_2early_SLOT23>;
4020 // Map call instruction.
4021 def : Pat<(call (i32 IntRegs:$dst)),
4022 (J2_callr (i32 IntRegs:$dst))>, Requires<[HasV2TOnly]>;
4023 def : Pat<(call tglobaladdr:$dst),
4024 (CALL tglobaladdr:$dst)>, Requires<[HasV2TOnly]>;
4025 def : Pat<(call texternalsym:$dst),
4026 (CALL texternalsym:$dst)>, Requires<[HasV2TOnly]>;
4028 def : Pat<(HexagonTCRet tglobaladdr:$dst),
4029 (TCRETURNtg tglobaladdr:$dst)>;
4030 def : Pat<(HexagonTCRet texternalsym:$dst),
4031 (TCRETURNtext texternalsym:$dst)>;
4032 def : Pat<(HexagonTCRet (i32 IntRegs:$dst)),
4033 (TCRETURNR (i32 IntRegs:$dst))>;
4035 // Atomic load and store support
4036 // 8 bit atomic load
4037 def : Pat<(atomic_load_8 ADDRriS11_0:$src1),
4038 (i32 (L2_loadrub_io AddrFI:$src1, 0))>;
4040 def : Pat<(atomic_load_8 (add (i32 IntRegs:$src1), s11_0ImmPred:$offset)),
4041 (i32 (L2_loadrub_io (i32 IntRegs:$src1), s11_0ImmPred:$offset))>;
4043 // 16 bit atomic load
4044 def : Pat<(atomic_load_16 ADDRriS11_1:$src1),
4045 (i32 (L2_loadruh_io AddrFI:$src1, 0))>;
4047 def : Pat<(atomic_load_16 (add (i32 IntRegs:$src1), s11_1ImmPred:$offset)),
4048 (i32 (L2_loadruh_io (i32 IntRegs:$src1), s11_1ImmPred:$offset))>;
4050 def : Pat<(atomic_load_32 ADDRriS11_2:$src1),
4051 (i32 (L2_loadri_io AddrFI:$src1, 0))>;
4053 def : Pat<(atomic_load_32 (add (i32 IntRegs:$src1), s11_2ImmPred:$offset)),
4054 (i32 (L2_loadri_io (i32 IntRegs:$src1), s11_2ImmPred:$offset))>;
4056 // 64 bit atomic load
4057 def : Pat<(atomic_load_64 ADDRriS11_3:$src1),
4058 (i64 (L2_loadrd_io AddrFI:$src1, 0))>;
4060 def : Pat<(atomic_load_64 (add (i32 IntRegs:$src1), s11_3ImmPred:$offset)),
4061 (i64 (L2_loadrd_io (i32 IntRegs:$src1), s11_3ImmPred:$offset))>;
4064 def : Pat<(atomic_store_8 ADDRriS11_0:$src2, (i32 IntRegs:$src1)),
4065 (S2_storerb_io AddrFI:$src2, 0, (i32 IntRegs:$src1))>;
4067 def : Pat<(atomic_store_8 (add (i32 IntRegs:$src2), s11_0ImmPred:$offset),
4068 (i32 IntRegs:$src1)),
4069 (S2_storerb_io (i32 IntRegs:$src2), s11_0ImmPred:$offset,
4070 (i32 IntRegs:$src1))>;
4073 def : Pat<(atomic_store_16 ADDRriS11_1:$src2, (i32 IntRegs:$src1)),
4074 (S2_storerh_io AddrFI:$src2, 0, (i32 IntRegs:$src1))>;
4076 def : Pat<(atomic_store_16 (i32 IntRegs:$src1),
4077 (add (i32 IntRegs:$src2), s11_1ImmPred:$offset)),
4078 (S2_storerh_io (i32 IntRegs:$src2), s11_1ImmPred:$offset,
4079 (i32 IntRegs:$src1))>;
4081 def : Pat<(atomic_store_32 ADDRriS11_2:$src2, (i32 IntRegs:$src1)),
4082 (S2_storeri_io AddrFI:$src2, 0, (i32 IntRegs:$src1))>;
4084 def : Pat<(atomic_store_32 (add (i32 IntRegs:$src2), s11_2ImmPred:$offset),
4085 (i32 IntRegs:$src1)),
4086 (S2_storeri_io (i32 IntRegs:$src2), s11_2ImmPred:$offset,
4087 (i32 IntRegs:$src1))>;
4092 def : Pat<(atomic_store_64 ADDRriS11_3:$src2, (i64 DoubleRegs:$src1)),
4093 (S2_storerd_io AddrFI:$src2, 0, (i64 DoubleRegs:$src1))>;
4095 def : Pat<(atomic_store_64 (add (i32 IntRegs:$src2), s11_3ImmPred:$offset),
4096 (i64 DoubleRegs:$src1)),
4097 (S2_storerd_io (i32 IntRegs:$src2), s11_3ImmPred:$offset,
4098 (i64 DoubleRegs:$src1))>;
4100 // Map from r0 = and(r1, 65535) to r0 = zxth(r1)
4101 def : Pat <(and (i32 IntRegs:$src1), 65535),
4102 (A2_zxth (i32 IntRegs:$src1))>;
4104 // Map from r0 = and(r1, 255) to r0 = zxtb(r1).
4105 def : Pat <(and (i32 IntRegs:$src1), 255),
4106 (A2_zxtb (i32 IntRegs:$src1))>;
4108 // Map Add(p1, true) to p1 = not(p1).
4109 // Add(p1, false) should never be produced,
4110 // if it does, it got to be mapped to NOOP.
4111 def : Pat <(add (i1 PredRegs:$src1), -1),
4112 (C2_not (i1 PredRegs:$src1))>;
4114 // Map from p0 = pnot(p0); r0 = mux(p0, #i, #j) => r0 = mux(p0, #j, #i).
4115 def : Pat <(select (not (i1 PredRegs:$src1)), s8ImmPred:$src2, s8ImmPred:$src3),
4116 (i32 (TFR_condset_ii (i1 PredRegs:$src1), s8ImmPred:$src3,
4119 // Map from p0 = pnot(p0); r0 = select(p0, #i, r1)
4120 // => r0 = TFR_condset_ri(p0, r1, #i)
4121 def : Pat <(select (not (i1 PredRegs:$src1)), s12ImmPred:$src2,
4122 (i32 IntRegs:$src3)),
4123 (i32 (TFR_condset_ri (i1 PredRegs:$src1), (i32 IntRegs:$src3),
4124 s12ImmPred:$src2))>;
4126 // Map from p0 = pnot(p0); r0 = mux(p0, r1, #i)
4127 // => r0 = TFR_condset_ir(p0, #i, r1)
4128 def : Pat <(select (not (i1 PredRegs:$src1)), IntRegs:$src2, s12ImmPred:$src3),
4129 (i32 (TFR_condset_ir (i1 PredRegs:$src1), s12ImmPred:$src3,
4130 (i32 IntRegs:$src2)))>;
4132 // Map from p0 = pnot(p0); if (p0) jump => if (!p0) jump.
4133 def : Pat <(brcond (not (i1 PredRegs:$src1)), bb:$offset),
4134 (J2_jumpf (i1 PredRegs:$src1), bb:$offset)>;
4136 // Map from p2 = pnot(p2); p1 = and(p0, p2) => p1 = and(p0, !p2).
4137 def : Pat <(and (i1 PredRegs:$src1), (not (i1 PredRegs:$src2))),
4138 (i1 (C2_andn (i1 PredRegs:$src1), (i1 PredRegs:$src2)))>;
4141 let AddedComplexity = 100 in
4142 def : Pat <(i64 (zextloadi1 (HexagonCONST32 tglobaladdr:$global))),
4143 (i64 (A2_combinew (A2_tfrsi 0),
4144 (L2_loadrub_io (CONST32_set tglobaladdr:$global), 0)))>,
4147 // Map from i1 loads to 32 bits. This assumes that the i1* is byte aligned.
4148 let AddedComplexity = 10 in
4149 def : Pat <(i32 (zextloadi1 ADDRriS11_0:$addr)),
4150 (i32 (A2_and (i32 (L2_loadrb_io AddrFI:$addr, 0)), (A2_tfrsi 0x1)))>;
4152 // Map from Rdd = sign_extend_inreg(Rss, i32) -> Rdd = A2_sxtw(Rss.lo).
4153 def : Pat <(i64 (sext_inreg (i64 DoubleRegs:$src1), i32)),
4154 (i64 (A2_sxtw (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src1), subreg_loreg))))>;
4156 // Map from Rdd = sign_extend_inreg(Rss, i16) -> Rdd = A2_sxtw(SXTH(Rss.lo)).
4157 def : Pat <(i64 (sext_inreg (i64 DoubleRegs:$src1), i16)),
4158 (i64 (A2_sxtw (i32 (A2_sxth (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src1),
4159 subreg_loreg))))))>;
4161 // Map from Rdd = sign_extend_inreg(Rss, i8) -> Rdd = A2_sxtw(SXTB(Rss.lo)).
4162 def : Pat <(i64 (sext_inreg (i64 DoubleRegs:$src1), i8)),
4163 (i64 (A2_sxtw (i32 (A2_sxtb (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src1),
4164 subreg_loreg))))))>;
4166 // We want to prevent emitting pnot's as much as possible.
4167 // Map brcond with an unsupported setcc to a J2_jumpf.
4168 def : Pat <(brcond (i1 (setne (i32 IntRegs:$src1), (i32 IntRegs:$src2))),
4170 (J2_jumpf (C2_cmpeq (i32 IntRegs:$src1), (i32 IntRegs:$src2)),
4173 def : Pat <(brcond (i1 (setne (i32 IntRegs:$src1), s10ImmPred:$src2)),
4175 (J2_jumpf (C2_cmpeqi (i32 IntRegs:$src1), s10ImmPred:$src2), bb:$offset)>;
4177 def : Pat <(brcond (i1 (setne (i1 PredRegs:$src1), (i1 -1))), bb:$offset),
4178 (J2_jumpf (i1 PredRegs:$src1), bb:$offset)>;
4180 def : Pat <(brcond (i1 (setne (i1 PredRegs:$src1), (i1 0))), bb:$offset),
4181 (J2_jumpt (i1 PredRegs:$src1), bb:$offset)>;
4183 // cmp.lt(Rs, Imm) -> !cmp.ge(Rs, Imm) -> !cmp.gt(Rs, Imm-1)
4184 def : Pat <(brcond (i1 (setlt (i32 IntRegs:$src1), s8ImmPred:$src2)),
4186 (J2_jumpf (C2_cmpgti (i32 IntRegs:$src1),
4187 (DEC_CONST_SIGNED s8ImmPred:$src2)), bb:$offset)>;
4189 // cmp.lt(r0, r1) -> cmp.gt(r1, r0)
4190 def : Pat <(brcond (i1 (setlt (i32 IntRegs:$src1), (i32 IntRegs:$src2))),
4192 (J2_jumpt (C2_cmpgt (i32 IntRegs:$src2), (i32 IntRegs:$src1)), bb:$offset)>;
4194 def : Pat <(brcond (i1 (setuge (i64 DoubleRegs:$src1), (i64 DoubleRegs:$src2))),
4196 (J2_jumpf (C2_cmpgtup (i64 DoubleRegs:$src2), (i64 DoubleRegs:$src1)),
4199 def : Pat <(brcond (i1 (setule (i32 IntRegs:$src1), (i32 IntRegs:$src2))),
4201 (J2_jumpf (C2_cmpgtu (i32 IntRegs:$src1), (i32 IntRegs:$src2)),
4204 def : Pat <(brcond (i1 (setule (i64 DoubleRegs:$src1), (i64 DoubleRegs:$src2))),
4206 (J2_jumpf (C2_cmpgtup (i64 DoubleRegs:$src1), (i64 DoubleRegs:$src2)),
4209 // Map from a 64-bit select to an emulated 64-bit mux.
4210 // Hexagon does not support 64-bit MUXes; so emulate with combines.
4211 def : Pat <(select (i1 PredRegs:$src1), (i64 DoubleRegs:$src2),
4212 (i64 DoubleRegs:$src3)),
4213 (i64 (A2_combinew (i32 (C2_mux (i1 PredRegs:$src1),
4214 (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src2),
4216 (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src3),
4218 (i32 (C2_mux (i1 PredRegs:$src1),
4219 (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src2),
4221 (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src3),
4222 subreg_loreg))))))>;
4224 // Map from a 1-bit select to logical ops.
4225 // From LegalizeDAG.cpp: (B1 ? B2 : B3) <=> (B1 & B2)|(!B1&B3).
4226 def : Pat <(select (i1 PredRegs:$src1), (i1 PredRegs:$src2),
4227 (i1 PredRegs:$src3)),
4228 (C2_or (C2_and (i1 PredRegs:$src1), (i1 PredRegs:$src2)),
4229 (C2_and (C2_not (i1 PredRegs:$src1)), (i1 PredRegs:$src3)))>;
4231 // Map Pd = load(addr) -> Rs = load(addr); Pd = Rs.
4232 def : Pat<(i1 (load ADDRriS11_2:$addr)),
4233 (i1 (C2_tfrrp (i32 (L2_loadrb_io AddrFI:$addr, 0))))>;
4235 // Map for truncating from 64 immediates to 32 bit immediates.
4236 def : Pat<(i32 (trunc (i64 DoubleRegs:$src))),
4237 (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src), subreg_loreg))>;
4239 // Map for truncating from i64 immediates to i1 bit immediates.
4240 def : Pat<(i1 (trunc (i64 DoubleRegs:$src))),
4241 (i1 (C2_tfrrp (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src),
4244 // Map memb(Rs) = Rdd -> memb(Rs) = Rt.
4245 def : Pat<(truncstorei8 (i64 DoubleRegs:$src), ADDRriS11_0:$addr),
4246 (S2_storerb_io AddrFI:$addr, 0, (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src),
4249 // Map memh(Rs) = Rdd -> memh(Rs) = Rt.
4250 def : Pat<(truncstorei16 (i64 DoubleRegs:$src), ADDRriS11_0:$addr),
4251 (S2_storerh_io AddrFI:$addr, 0, (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src),
4253 // Map memw(Rs) = Rdd -> memw(Rs) = Rt
4254 def : Pat<(truncstorei32 (i64 DoubleRegs:$src), ADDRriS11_0:$addr),
4255 (S2_storeri_io AddrFI:$addr, 0, (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src),
4258 // Map memw(Rs) = Rdd -> memw(Rs) = Rt.
4259 def : Pat<(truncstorei32 (i64 DoubleRegs:$src), ADDRriS11_0:$addr),
4260 (S2_storeri_io AddrFI:$addr, 0, (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src),
4263 // Map from i1 = constant<-1>; memw(addr) = i1 -> r0 = 1; memw(addr) = r0.
4264 def : Pat<(store (i1 -1), ADDRriS11_2:$addr),
4265 (S2_storerb_io AddrFI:$addr, 0, (A2_tfrsi 1))>;
4268 // Map from i1 = constant<-1>; store i1 -> r0 = 1; store r0.
4269 def : Pat<(store (i1 -1), ADDRriS11_2:$addr),
4270 (S2_storerb_io AddrFI:$addr, 0, (A2_tfrsi 1))>;
4272 // Map from memb(Rs) = Pd -> Rt = mux(Pd, #0, #1); store Rt.
4273 def : Pat<(store (i1 PredRegs:$src1), ADDRriS11_2:$addr),
4274 (S2_storerb_io AddrFI:$addr, 0, (i32 (C2_muxii (i1 PredRegs:$src1), 1, 0)) )>;
4276 // Map Rdd = anyext(Rs) -> Rdd = A2_sxtw(Rs).
4277 // Hexagon_TODO: We can probably use combine but that will cost 2 instructions.
4278 // Better way to do this?
4279 def : Pat<(i64 (anyext (i32 IntRegs:$src1))),
4280 (i64 (A2_sxtw (i32 IntRegs:$src1)))>;
4282 // Map cmple -> cmpgt.
4283 // rs <= rt -> !(rs > rt).
4284 def : Pat<(i1 (setle (i32 IntRegs:$src1), s10ExtPred:$src2)),
4285 (i1 (C2_not (C2_cmpgti (i32 IntRegs:$src1), s10ExtPred:$src2)))>;
4287 // rs <= rt -> !(rs > rt).
4288 def : Pat<(i1 (setle (i32 IntRegs:$src1), (i32 IntRegs:$src2))),
4289 (i1 (C2_not (C2_cmpgt (i32 IntRegs:$src1), (i32 IntRegs:$src2))))>;
4291 // Rss <= Rtt -> !(Rss > Rtt).
4292 def : Pat<(i1 (setle (i64 DoubleRegs:$src1), (i64 DoubleRegs:$src2))),
4293 (i1 (C2_not (C2_cmpgtp (i64 DoubleRegs:$src1), (i64 DoubleRegs:$src2))))>;
4295 // Map cmpne -> cmpeq.
4296 // Hexagon_TODO: We should improve on this.
4297 // rs != rt -> !(rs == rt).
4298 def : Pat <(i1 (setne (i32 IntRegs:$src1), s10ExtPred:$src2)),
4299 (i1 (C2_not(i1 (C2_cmpeqi (i32 IntRegs:$src1), s10ExtPred:$src2))))>;
4301 // Map cmpne(Rs) -> !cmpeqe(Rs).
4302 // rs != rt -> !(rs == rt).
4303 def : Pat <(i1 (setne (i32 IntRegs:$src1), (i32 IntRegs:$src2))),
4304 (i1 (C2_not (i1 (C2_cmpeq (i32 IntRegs:$src1), (i32 IntRegs:$src2)))))>;
4306 // Convert setne back to xor for hexagon since we compute w/ pred registers.
4307 def : Pat <(i1 (setne (i1 PredRegs:$src1), (i1 PredRegs:$src2))),
4308 (i1 (C2_xor (i1 PredRegs:$src1), (i1 PredRegs:$src2)))>;
4310 // Map cmpne(Rss) -> !cmpew(Rss).
4311 // rs != rt -> !(rs == rt).
4312 def : Pat <(i1 (setne (i64 DoubleRegs:$src1), (i64 DoubleRegs:$src2))),
4313 (i1 (C2_not (i1 (C2_cmpeqp (i64 DoubleRegs:$src1),
4314 (i64 DoubleRegs:$src2)))))>;
4316 // Map cmpge(Rs, Rt) -> !(cmpgt(Rs, Rt).
4317 // rs >= rt -> !(rt > rs).
4318 def : Pat <(i1 (setge (i32 IntRegs:$src1), (i32 IntRegs:$src2))),
4319 (i1 (C2_not (i1 (C2_cmpgt (i32 IntRegs:$src2), (i32 IntRegs:$src1)))))>;
4321 // cmpge(Rs, Imm) -> cmpgt(Rs, Imm-1)
4322 def : Pat <(i1 (setge (i32 IntRegs:$src1), s8ExtPred:$src2)),
4323 (i1 (C2_cmpgti (i32 IntRegs:$src1), (DEC_CONST_SIGNED s8ExtPred:$src2)))>;
4325 // Map cmpge(Rss, Rtt) -> !cmpgt(Rtt, Rss).
4326 // rss >= rtt -> !(rtt > rss).
4327 def : Pat <(i1 (setge (i64 DoubleRegs:$src1), (i64 DoubleRegs:$src2))),
4328 (i1 (C2_not (i1 (C2_cmpgtp (i64 DoubleRegs:$src2),
4329 (i64 DoubleRegs:$src1)))))>;
4331 // Map cmplt(Rs, Imm) -> !cmpge(Rs, Imm).
4332 // !cmpge(Rs, Imm) -> !cmpgt(Rs, Imm-1).
4333 // rs < rt -> !(rs >= rt).
4334 def : Pat <(i1 (setlt (i32 IntRegs:$src1), s8ExtPred:$src2)),
4335 (i1 (C2_not (C2_cmpgti (i32 IntRegs:$src1), (DEC_CONST_SIGNED s8ExtPred:$src2))))>;
4337 // Map cmplt(Rs, Rt) -> cmpgt(Rt, Rs).
4338 // rs < rt -> rt > rs.
4339 // We can let assembler map it, or we can do in the compiler itself.
4340 def : Pat <(i1 (setlt (i32 IntRegs:$src1), (i32 IntRegs:$src2))),
4341 (i1 (C2_cmpgt (i32 IntRegs:$src2), (i32 IntRegs:$src1)))>;
4343 // Map cmplt(Rss, Rtt) -> cmpgt(Rtt, Rss).
4344 // rss < rtt -> (rtt > rss).
4345 def : Pat <(i1 (setlt (i64 DoubleRegs:$src1), (i64 DoubleRegs:$src2))),
4346 (i1 (C2_cmpgtp (i64 DoubleRegs:$src2), (i64 DoubleRegs:$src1)))>;
4348 // Map from cmpltu(Rs, Rd) -> cmpgtu(Rd, Rs)
4349 // rs < rt -> rt > rs.
4350 // We can let assembler map it, or we can do in the compiler itself.
4351 def : Pat <(i1 (setult (i32 IntRegs:$src1), (i32 IntRegs:$src2))),
4352 (i1 (C2_cmpgtu (i32 IntRegs:$src2), (i32 IntRegs:$src1)))>;
4354 // Map from cmpltu(Rss, Rdd) -> cmpgtu(Rdd, Rss).
4355 // rs < rt -> rt > rs.
4356 def : Pat <(i1 (setult (i64 DoubleRegs:$src1), (i64 DoubleRegs:$src2))),
4357 (i1 (C2_cmpgtup (i64 DoubleRegs:$src2), (i64 DoubleRegs:$src1)))>;
4359 // Generate cmpgeu(Rs, #0) -> cmpeq(Rs, Rs)
4360 def : Pat <(i1 (setuge (i32 IntRegs:$src1), 0)),
4361 (i1 (C2_cmpeq (i32 IntRegs:$src1), (i32 IntRegs:$src1)))>;
4363 // Generate cmpgeu(Rs, #u8) -> cmpgtu(Rs, #u8 -1)
4364 def : Pat <(i1 (setuge (i32 IntRegs:$src1), u8ExtPred:$src2)),
4365 (i1 (C2_cmpgtui (i32 IntRegs:$src1), (DEC_CONST_UNSIGNED u8ExtPred:$src2)))>;
4367 // Generate cmpgtu(Rs, #u9)
4368 def : Pat <(i1 (setugt (i32 IntRegs:$src1), u9ExtPred:$src2)),
4369 (i1 (C2_cmpgtui (i32 IntRegs:$src1), u9ExtPred:$src2))>;
4371 // Map from Rs >= Rt -> !(Rt > Rs).
4372 // rs >= rt -> !(rt > rs).
4373 def : Pat <(i1 (setuge (i32 IntRegs:$src1), (i32 IntRegs:$src2))),
4374 (i1 (C2_not (C2_cmpgtu (i32 IntRegs:$src2), (i32 IntRegs:$src1))))>;
4376 // Map from Rs >= Rt -> !(Rt > Rs).
4377 // rs >= rt -> !(rt > rs).
4378 def : Pat <(i1 (setuge (i64 DoubleRegs:$src1), (i64 DoubleRegs:$src2))),
4379 (i1 (C2_not (C2_cmpgtup (i64 DoubleRegs:$src2), (i64 DoubleRegs:$src1))))>;
4381 // Map from cmpleu(Rs, Rt) -> !cmpgtu(Rs, Rt).
4382 // Map from (Rs <= Rt) -> !(Rs > Rt).
4383 def : Pat <(i1 (setule (i32 IntRegs:$src1), (i32 IntRegs:$src2))),
4384 (i1 (C2_not (C2_cmpgtu (i32 IntRegs:$src1), (i32 IntRegs:$src2))))>;
4386 // Map from cmpleu(Rss, Rtt) -> !cmpgtu(Rss, Rtt-1).
4387 // Map from (Rs <= Rt) -> !(Rs > Rt).
4388 def : Pat <(i1 (setule (i64 DoubleRegs:$src1), (i64 DoubleRegs:$src2))),
4389 (i1 (C2_not (C2_cmpgtup (i64 DoubleRegs:$src1), (i64 DoubleRegs:$src2))))>;
4393 def : Pat <(i32 (sext (i1 PredRegs:$src1))),
4394 (i32 (C2_muxii (i1 PredRegs:$src1), -1, 0))>;
4397 def : Pat <(i64 (sext (i1 PredRegs:$src1))),
4398 (i64 (A2_combinew (A2_tfrsi -1), (C2_muxii (i1 PredRegs:$src1), -1, 0)))>;
4400 // Convert sign-extended load back to load and sign extend.
4402 def: Pat <(i64 (sextloadi8 ADDRriS11_0:$src1)),
4403 (i64 (A2_sxtw (L2_loadrb_io AddrFI:$src1, 0)))>;
4405 // Convert any-extended load back to load and sign extend.
4407 def: Pat <(i64 (extloadi8 ADDRriS11_0:$src1)),
4408 (i64 (A2_sxtw (L2_loadrb_io AddrFI:$src1, 0)))>;
4410 // Convert sign-extended load back to load and sign extend.
4412 def: Pat <(i64 (sextloadi16 ADDRriS11_1:$src1)),
4413 (i64 (A2_sxtw (L2_loadrh_io AddrFI:$src1, 0)))>;
4415 // Convert sign-extended load back to load and sign extend.
4417 def: Pat <(i64 (sextloadi32 ADDRriS11_2:$src1)),
4418 (i64 (A2_sxtw (L2_loadri_io AddrFI:$src1, 0)))>;
4423 def : Pat <(i32 (zext (i1 PredRegs:$src1))),
4424 (i32 (C2_muxii (i1 PredRegs:$src1), 1, 0))>;
4427 def : Pat <(i64 (zext (i1 PredRegs:$src1))),
4428 (i64 (A2_combinew (A2_tfrsi 0), (C2_muxii (i1 PredRegs:$src1), 1, 0)))>,
4432 def : Pat <(i64 (zext (i32 IntRegs:$src1))),
4433 (i64 (A2_combinew (A2_tfrsi 0), (i32 IntRegs:$src1)))>,
4437 def: Pat <(i64 (zextloadi8 ADDRriS11_0:$src1)),
4438 (i64 (A2_combinew (A2_tfrsi 0), (L2_loadrub_io AddrFI:$src1, 0)))>,
4441 let AddedComplexity = 20 in
4442 def: Pat <(i64 (zextloadi8 (add (i32 IntRegs:$src1),
4443 s11_0ExtPred:$offset))),
4444 (i64 (A2_combinew (A2_tfrsi 0), (L2_loadrub_io IntRegs:$src1,
4445 s11_0ExtPred:$offset)))>,
4449 def: Pat <(i64 (zextloadi1 ADDRriS11_0:$src1)),
4450 (i64 (A2_combinew (A2_tfrsi 0), (L2_loadrub_io AddrFI:$src1, 0)))>,
4453 let AddedComplexity = 20 in
4454 def: Pat <(i64 (zextloadi1 (add (i32 IntRegs:$src1),
4455 s11_0ExtPred:$offset))),
4456 (i64 (A2_combinew (A2_tfrsi 0), (L2_loadrub_io IntRegs:$src1,
4457 s11_0ExtPred:$offset)))>,
4461 def: Pat <(i64 (zextloadi16 ADDRriS11_1:$src1)),
4462 (i64 (A2_combinew (A2_tfrsi 0), (L2_loadruh_io AddrFI:$src1, 0)))>,
4465 let AddedComplexity = 20 in
4466 def: Pat <(i64 (zextloadi16 (add (i32 IntRegs:$src1),
4467 s11_1ExtPred:$offset))),
4468 (i64 (A2_combinew (A2_tfrsi 0), (L2_loadruh_io IntRegs:$src1,
4469 s11_1ExtPred:$offset)))>,
4473 def: Pat <(i64 (zextloadi32 ADDRriS11_2:$src1)),
4474 (i64 (A2_combinew (A2_tfrsi 0), (L2_loadri_io AddrFI:$src1, 0)))>,
4477 let AddedComplexity = 100 in
4478 def: Pat <(i64 (zextloadi32 (i32 (add IntRegs:$src1, s11_2ExtPred:$offset)))),
4479 (i64 (A2_combinew (A2_tfrsi 0), (L2_loadri_io IntRegs:$src1,
4480 s11_2ExtPred:$offset)))>,
4483 let AddedComplexity = 10 in
4484 def: Pat <(i32 (zextloadi1 ADDRriS11_0:$src1)),
4485 (i32 (L2_loadri_io AddrFI:$src1, 0))>;
4487 // Map from Rs = Pd to Pd = mux(Pd, #1, #0)
4488 def : Pat <(i32 (zext (i1 PredRegs:$src1))),
4489 (i32 (C2_muxii (i1 PredRegs:$src1), 1, 0))>;
4491 // Map from Rs = Pd to Pd = mux(Pd, #1, #0)
4492 def : Pat <(i32 (anyext (i1 PredRegs:$src1))),
4493 (i32 (C2_muxii (i1 PredRegs:$src1), 1, 0))>;
4495 // Map from Rss = Pd to Rdd = A2_sxtw (mux(Pd, #1, #0))
4496 def : Pat <(i64 (anyext (i1 PredRegs:$src1))),
4497 (i64 (A2_sxtw (i32 (C2_muxii (i1 PredRegs:$src1), 1, 0))))>;
4500 let AddedComplexity = 100 in
4501 def: Pat<(i64 (or (i64 (shl (i64 DoubleRegs:$srcHigh),
4503 (i64 (zextloadi32 (i32 (add IntRegs:$src2,
4504 s11_2ExtPred:$offset2)))))),
4505 (i64 (A2_combinew (EXTRACT_SUBREG (i64 DoubleRegs:$srcHigh), subreg_loreg),
4506 (L2_loadri_io IntRegs:$src2,
4507 s11_2ExtPred:$offset2)))>;
4509 def: Pat<(i64 (or (i64 (shl (i64 DoubleRegs:$srcHigh),
4511 (i64 (zextloadi32 ADDRriS11_2:$srcLow)))),
4512 (i64 (A2_combinew (EXTRACT_SUBREG (i64 DoubleRegs:$srcHigh), subreg_loreg),
4513 (L2_loadri_io AddrFI:$srcLow, 0)))>;
4515 def: Pat<(i64 (or (i64 (shl (i64 DoubleRegs:$srcHigh),
4517 (i64 (zext (i32 IntRegs:$srcLow))))),
4518 (i64 (A2_combinew (EXTRACT_SUBREG (i64 DoubleRegs:$srcHigh), subreg_loreg),
4521 let AddedComplexity = 100 in
4522 def: Pat<(i64 (or (i64 (shl (i64 DoubleRegs:$srcHigh),
4524 (i64 (zextloadi32 (i32 (add IntRegs:$src2,
4525 s11_2ExtPred:$offset2)))))),
4526 (i64 (A2_combinew (EXTRACT_SUBREG (i64 DoubleRegs:$srcHigh), subreg_loreg),
4527 (L2_loadri_io IntRegs:$src2,
4528 s11_2ExtPred:$offset2)))>;
4530 def: Pat<(i64 (or (i64 (shl (i64 DoubleRegs:$srcHigh),
4532 (i64 (zextloadi32 ADDRriS11_2:$srcLow)))),
4533 (i64 (A2_combinew (EXTRACT_SUBREG (i64 DoubleRegs:$srcHigh), subreg_loreg),
4534 (L2_loadri_io AddrFI:$srcLow, 0)))>;
4536 def: Pat<(i64 (or (i64 (shl (i64 DoubleRegs:$srcHigh),
4538 (i64 (zext (i32 IntRegs:$srcLow))))),
4539 (i64 (A2_combinew (EXTRACT_SUBREG (i64 DoubleRegs:$srcHigh), subreg_loreg),
4542 // Any extended 64-bit load.
4543 // anyext i32 -> i64
4544 def: Pat <(i64 (extloadi32 ADDRriS11_2:$src1)),
4545 (i64 (A2_combinew (A2_tfrsi 0), (L2_loadri_io AddrFI:$src1, 0)))>,
4548 // When there is an offset we should prefer the pattern below over the pattern above.
4549 // The complexity of the above is 13 (gleaned from HexagonGenDAGIsel.inc)
4550 // So this complexity below is comfortably higher to allow for choosing the below.
4551 // If this is not done then we generate addresses such as
4552 // ********************************************
4553 // r1 = add (r0, #4)
4554 // r1 = memw(r1 + #0)
4556 // r1 = memw(r0 + #4)
4557 // ********************************************
4558 let AddedComplexity = 100 in
4559 def: Pat <(i64 (extloadi32 (i32 (add IntRegs:$src1, s11_2ExtPred:$offset)))),
4560 (i64 (A2_combinew (A2_tfrsi 0), (L2_loadri_io IntRegs:$src1,
4561 s11_2ExtPred:$offset)))>,
4564 // anyext i16 -> i64.
4565 def: Pat <(i64 (extloadi16 ADDRriS11_2:$src1)),
4566 (i64 (A2_combinew (A2_tfrsi 0), (L2_loadrh_io AddrFI:$src1, 0)))>,
4569 let AddedComplexity = 20 in
4570 def: Pat <(i64 (extloadi16 (add (i32 IntRegs:$src1),
4571 s11_1ExtPred:$offset))),
4572 (i64 (A2_combinew (A2_tfrsi 0), (L2_loadrh_io IntRegs:$src1,
4573 s11_1ExtPred:$offset)))>,
4576 // Map from Rdd = zxtw(Rs) -> Rdd = combine(0, Rs).
4577 def : Pat<(i64 (zext (i32 IntRegs:$src1))),
4578 (i64 (A2_combinew (A2_tfrsi 0), (i32 IntRegs:$src1)))>,
4581 // Multiply 64-bit unsigned and use upper result.
4582 def : Pat <(mulhu (i64 DoubleRegs:$src1), (i64 DoubleRegs:$src2)),
4597 (A2_combinew (A2_tfrsi 0),
4604 (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src1),
4606 (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src2),
4607 subreg_loreg)))), 32)),
4609 (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src1), subreg_hireg)),
4610 (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src2), subreg_loreg)))),
4611 (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src1), subreg_loreg)),
4612 (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src2), subreg_hireg)))),
4613 32)), subreg_loreg)))),
4614 (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src1), subreg_hireg)),
4615 (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src2), subreg_hireg))))>;
4617 // Multiply 64-bit signed and use upper result.
4618 def : Pat <(mulhs (i64 DoubleRegs:$src1), (i64 DoubleRegs:$src2)),
4622 (A2_combinew (A2_tfrsi 0),
4632 (A2_combinew (A2_tfrsi 0),
4639 (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src1),
4641 (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src2),
4642 subreg_loreg)))), 32)),
4644 (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src1), subreg_hireg)),
4645 (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src2), subreg_loreg)))),
4646 (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src1), subreg_loreg)),
4647 (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src2), subreg_hireg)))),
4648 32)), subreg_loreg)))),
4649 (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src1), subreg_hireg)),
4650 (i32 (EXTRACT_SUBREG (i64 DoubleRegs:$src2), subreg_hireg))))>;
4652 // Hexagon specific ISD nodes.
4653 //def SDTHexagonADJDYNALLOC : SDTypeProfile<1, 2, [SDTCisSameAs<0, 1>]>;
4654 def SDTHexagonADJDYNALLOC : SDTypeProfile<1, 2,
4655 [SDTCisVT<0, i32>, SDTCisVT<1, i32>]>;
4656 def Hexagon_ADJDYNALLOC : SDNode<"HexagonISD::ADJDYNALLOC",
4657 SDTHexagonADJDYNALLOC>;
4658 // Needed to tag these instructions for stack layout.
4659 let usesCustomInserter = 1 in
4660 def ADJDYNALLOC : ALU32_ri<(outs IntRegs:$dst), (ins IntRegs:$src1,
4662 "$dst = add($src1, #$src2)",
4663 [(set (i32 IntRegs:$dst),
4664 (Hexagon_ADJDYNALLOC (i32 IntRegs:$src1),
4665 s16ImmPred:$src2))]>;
4667 def SDTHexagonARGEXTEND : SDTypeProfile<1, 1, [SDTCisVT<0, i32>]>;
4668 def Hexagon_ARGEXTEND : SDNode<"HexagonISD::ARGEXTEND", SDTHexagonARGEXTEND>;
4669 def ARGEXTEND : ALU32_rr <(outs IntRegs:$dst), (ins IntRegs:$src1),
4671 [(set (i32 IntRegs:$dst),
4672 (Hexagon_ARGEXTEND (i32 IntRegs:$src1)))]>;
4674 let AddedComplexity = 100 in
4675 def : Pat<(i32 (sext_inreg (Hexagon_ARGEXTEND (i32 IntRegs:$src1)), i16)),
4676 (COPY (i32 IntRegs:$src1))>;
4678 def HexagonWrapperJT: SDNode<"HexagonISD::WrapperJT", SDTIntUnaryOp>;
4680 def : Pat<(HexagonWrapperJT tjumptable:$dst),
4681 (i32 (CONST32_set_jt tjumptable:$dst))>;
4685 //===----------------------------------------------------------------------===//
4687 // Shift by immediate/register and accumulate/logical
4688 //===----------------------------------------------------------------------===//
4690 // Rx[+-&|]=asr(Rs,#u5)
4691 // Rx[+-&|^]=lsr(Rs,#u5)
4692 // Rx[+-&|^]=asl(Rs,#u5)
4694 let hasNewValue = 1, opNewValue = 0 in
4695 class T_shift_imm_acc_r <string opc1, string opc2, SDNode OpNode1,
4696 SDNode OpNode2, bits<3> majOp, bits<2> minOp>
4697 : SInst_acc<(outs IntRegs:$Rx),
4698 (ins IntRegs:$src1, IntRegs:$Rs, u5Imm:$u5),
4699 "$Rx "#opc2#opc1#"($Rs, #$u5)",
4700 [(set (i32 IntRegs:$Rx),
4701 (OpNode2 (i32 IntRegs:$src1),
4702 (OpNode1 (i32 IntRegs:$Rs), u5ImmPred:$u5)))],
4703 "$src1 = $Rx", S_2op_tc_2_SLOT23> {
4708 let IClass = 0b1000;
4710 let Inst{27-24} = 0b1110;
4711 let Inst{23-22} = majOp{2-1};
4713 let Inst{7} = majOp{0};
4714 let Inst{6-5} = minOp;
4716 let Inst{20-16} = Rs;
4717 let Inst{12-8} = u5;
4720 // Rx[+-&|]=asr(Rs,Rt)
4721 // Rx[+-&|^]=lsr(Rs,Rt)
4722 // Rx[+-&|^]=asl(Rs,Rt)
4724 let hasNewValue = 1, opNewValue = 0 in
4725 class T_shift_reg_acc_r <string opc1, string opc2, SDNode OpNode1,
4726 SDNode OpNode2, bits<2> majOp, bits<2> minOp>
4727 : SInst_acc<(outs IntRegs:$Rx),
4728 (ins IntRegs:$src1, IntRegs:$Rs, IntRegs:$Rt),
4729 "$Rx "#opc2#opc1#"($Rs, $Rt)",
4730 [(set (i32 IntRegs:$Rx),
4731 (OpNode2 (i32 IntRegs:$src1),
4732 (OpNode1 (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))))],
4733 "$src1 = $Rx", S_3op_tc_2_SLOT23 > {
4738 let IClass = 0b1100;
4740 let Inst{27-24} = 0b1100;
4741 let Inst{23-22} = majOp;
4742 let Inst{7-6} = minOp;
4744 let Inst{20-16} = Rs;
4745 let Inst{12-8} = Rt;
4748 // Rxx[+-&|]=asr(Rss,#u6)
4749 // Rxx[+-&|^]=lsr(Rss,#u6)
4750 // Rxx[+-&|^]=asl(Rss,#u6)
4752 class T_shift_imm_acc_p <string opc1, string opc2, SDNode OpNode1,
4753 SDNode OpNode2, bits<3> majOp, bits<2> minOp>
4754 : SInst_acc<(outs DoubleRegs:$Rxx),
4755 (ins DoubleRegs:$src1, DoubleRegs:$Rss, u6Imm:$u6),
4756 "$Rxx "#opc2#opc1#"($Rss, #$u6)",
4757 [(set (i64 DoubleRegs:$Rxx),
4758 (OpNode2 (i64 DoubleRegs:$src1),
4759 (OpNode1 (i64 DoubleRegs:$Rss), u6ImmPred:$u6)))],
4760 "$src1 = $Rxx", S_2op_tc_2_SLOT23> {
4765 let IClass = 0b1000;
4767 let Inst{27-24} = 0b0010;
4768 let Inst{23-22} = majOp{2-1};
4769 let Inst{7} = majOp{0};
4770 let Inst{6-5} = minOp;
4771 let Inst{4-0} = Rxx;
4772 let Inst{20-16} = Rss;
4773 let Inst{13-8} = u6;
4777 // Rxx[+-&|]=asr(Rss,Rt)
4778 // Rxx[+-&|^]=lsr(Rss,Rt)
4779 // Rxx[+-&|^]=asl(Rss,Rt)
4780 // Rxx[+-&|^]=lsl(Rss,Rt)
4782 class T_shift_reg_acc_p <string opc1, string opc2, SDNode OpNode1,
4783 SDNode OpNode2, bits<3> majOp, bits<2> minOp>
4784 : SInst_acc<(outs DoubleRegs:$Rxx),
4785 (ins DoubleRegs:$src1, DoubleRegs:$Rss, IntRegs:$Rt),
4786 "$Rxx "#opc2#opc1#"($Rss, $Rt)",
4787 [(set (i64 DoubleRegs:$Rxx),
4788 (OpNode2 (i64 DoubleRegs:$src1),
4789 (OpNode1 (i64 DoubleRegs:$Rss), (i32 IntRegs:$Rt))))],
4790 "$src1 = $Rxx", S_3op_tc_2_SLOT23> {
4795 let IClass = 0b1100;
4797 let Inst{27-24} = 0b1011;
4798 let Inst{23-21} = majOp;
4799 let Inst{20-16} = Rss;
4800 let Inst{12-8} = Rt;
4801 let Inst{7-6} = minOp;
4802 let Inst{4-0} = Rxx;
4805 //===----------------------------------------------------------------------===//
4806 // Multi-class for the shift instructions with logical/arithmetic operators.
4807 //===----------------------------------------------------------------------===//
4809 multiclass xtype_imm_base<string OpcStr1, string OpcStr2, SDNode OpNode1,
4810 SDNode OpNode2, bits<3> majOp, bits<2> minOp > {
4811 def _i_r#NAME : T_shift_imm_acc_r< OpcStr1, OpcStr2, OpNode1,
4812 OpNode2, majOp, minOp >;
4813 def _i_p#NAME : T_shift_imm_acc_p< OpcStr1, OpcStr2, OpNode1,
4814 OpNode2, majOp, minOp >;
4817 multiclass xtype_imm_acc<string opc1, SDNode OpNode, bits<2>minOp> {
4818 let AddedComplexity = 100 in
4819 defm _acc : xtype_imm_base< opc1, "+= ", OpNode, add, 0b001, minOp>;
4821 defm _nac : xtype_imm_base< opc1, "-= ", OpNode, sub, 0b000, minOp>;
4822 defm _and : xtype_imm_base< opc1, "&= ", OpNode, and, 0b010, minOp>;
4823 defm _or : xtype_imm_base< opc1, "|= ", OpNode, or, 0b011, minOp>;
4826 multiclass xtype_xor_imm_acc<string opc1, SDNode OpNode, bits<2>minOp> {
4827 let AddedComplexity = 100 in
4828 defm _xacc : xtype_imm_base< opc1, "^= ", OpNode, xor, 0b100, minOp>;
4831 let isCodeGenOnly = 0 in {
4832 defm S2_asr : xtype_imm_acc<"asr", sra, 0b00>;
4834 defm S2_lsr : xtype_imm_acc<"lsr", srl, 0b01>,
4835 xtype_xor_imm_acc<"lsr", srl, 0b01>;
4837 defm S2_asl : xtype_imm_acc<"asl", shl, 0b10>,
4838 xtype_xor_imm_acc<"asl", shl, 0b10>;
4841 multiclass xtype_reg_acc_r<string opc1, SDNode OpNode, bits<2>minOp> {
4842 let AddedComplexity = 100 in
4843 def _acc : T_shift_reg_acc_r <opc1, "+= ", OpNode, add, 0b11, minOp>;
4845 def _nac : T_shift_reg_acc_r <opc1, "-= ", OpNode, sub, 0b10, minOp>;
4846 def _and : T_shift_reg_acc_r <opc1, "&= ", OpNode, and, 0b01, minOp>;
4847 def _or : T_shift_reg_acc_r <opc1, "|= ", OpNode, or, 0b00, minOp>;
4850 multiclass xtype_reg_acc_p<string opc1, SDNode OpNode, bits<2>minOp> {
4851 let AddedComplexity = 100 in
4852 def _acc : T_shift_reg_acc_p <opc1, "+= ", OpNode, add, 0b110, minOp>;
4854 def _nac : T_shift_reg_acc_p <opc1, "-= ", OpNode, sub, 0b100, minOp>;
4855 def _and : T_shift_reg_acc_p <opc1, "&= ", OpNode, and, 0b010, minOp>;
4856 def _or : T_shift_reg_acc_p <opc1, "|= ", OpNode, or, 0b000, minOp>;
4857 def _xor : T_shift_reg_acc_p <opc1, "^= ", OpNode, xor, 0b011, minOp>;
4860 multiclass xtype_reg_acc<string OpcStr, SDNode OpNode, bits<2> minOp > {
4861 defm _r_r : xtype_reg_acc_r <OpcStr, OpNode, minOp>;
4862 defm _r_p : xtype_reg_acc_p <OpcStr, OpNode, minOp>;
4865 let isCodeGenOnly = 0 in {
4866 defm S2_asl : xtype_reg_acc<"asl", shl, 0b10>;
4867 defm S2_asr : xtype_reg_acc<"asr", sra, 0b00>;
4868 defm S2_lsr : xtype_reg_acc<"lsr", srl, 0b01>;
4869 defm S2_lsl : xtype_reg_acc<"lsl", shl, 0b11>;
4872 //===----------------------------------------------------------------------===//
4873 let hasSideEffects = 0 in
4874 class T_S3op_1 <string mnemonic, RegisterClass RC, bits<2> MajOp, bits<3> MinOp,
4875 bit SwapOps, bit isSat = 0, bit isRnd = 0, bit hasShift = 0>
4876 : SInst <(outs RC:$dst),
4877 (ins DoubleRegs:$src1, DoubleRegs:$src2),
4878 "$dst = "#mnemonic#"($src1, $src2)"#!if(isRnd, ":rnd", "")
4879 #!if(hasShift,":>>1","")
4880 #!if(isSat, ":sat", ""),
4881 [], "", S_3op_tc_2_SLOT23 > {
4886 let IClass = 0b1100;
4888 let Inst{27-24} = 0b0001;
4889 let Inst{23-22} = MajOp;
4890 let Inst{20-16} = !if (SwapOps, src2, src1);
4891 let Inst{12-8} = !if (SwapOps, src1, src2);
4892 let Inst{7-5} = MinOp;
4893 let Inst{4-0} = dst;
4896 class T_S3op_64 <string mnemonic, bits<2> MajOp, bits<3> MinOp, bit SwapOps,
4897 bit isSat = 0, bit isRnd = 0, bit hasShift = 0 >
4898 : T_S3op_1 <mnemonic, DoubleRegs, MajOp, MinOp, SwapOps,
4899 isSat, isRnd, hasShift>;
4901 let isCodeGenOnly = 0 in
4902 def S2_lfsp : T_S3op_64 < "lfs", 0b10, 0b110, 0>;
4904 let hasSideEffects = 0 in
4905 class T_S3op_2 <string mnemonic, bits<3> MajOp, bit SwapOps>
4906 : SInst < (outs DoubleRegs:$Rdd),
4907 (ins DoubleRegs:$Rss, DoubleRegs:$Rtt, PredRegs:$Pu),
4908 "$Rdd = "#mnemonic#"($Rss, $Rtt, $Pu)",
4909 [], "", S_3op_tc_1_SLOT23 > {
4915 let IClass = 0b1100;
4917 let Inst{27-24} = 0b0010;
4918 let Inst{23-21} = MajOp;
4919 let Inst{20-16} = !if (SwapOps, Rtt, Rss);
4920 let Inst{12-8} = !if (SwapOps, Rss, Rtt);
4922 let Inst{4-0} = Rdd;
4925 let isCodeGenOnly = 0 in {
4926 def S2_valignrb : T_S3op_2 < "valignb", 0b000, 1>;
4927 def S2_vsplicerb : T_S3op_2 < "vspliceb", 0b100, 0>;
4930 //===----------------------------------------------------------------------===//
4931 // Template class used by vector shift, vector rotate, vector neg,
4932 // 32-bit shift, 64-bit shifts, etc.
4933 //===----------------------------------------------------------------------===//
4935 let hasSideEffects = 0 in
4936 class T_S3op_3 <string mnemonic, RegisterClass RC, bits<2> MajOp,
4937 bits<2> MinOp, bit isSat = 0, list<dag> pattern = [] >
4938 : SInst <(outs RC:$dst),
4939 (ins RC:$src1, IntRegs:$src2),
4940 "$dst = "#mnemonic#"($src1, $src2)"#!if(isSat, ":sat", ""),
4941 pattern, "", S_3op_tc_1_SLOT23> {
4946 let IClass = 0b1100;
4948 let Inst{27-24} = !if(!eq(!cast<string>(RC), "IntRegs"), 0b0110, 0b0011);
4949 let Inst{23-22} = MajOp;
4950 let Inst{20-16} = src1;
4951 let Inst{12-8} = src2;
4952 let Inst{7-6} = MinOp;
4953 let Inst{4-0} = dst;
4956 let hasNewValue = 1 in
4957 class T_S3op_shift32 <string mnemonic, SDNode OpNode, bits<2> MinOp>
4958 : T_S3op_3 <mnemonic, IntRegs, 0b01, MinOp, 0,
4959 [(set (i32 IntRegs:$dst), (OpNode (i32 IntRegs:$src1),
4960 (i32 IntRegs:$src2)))]>;
4962 let hasNewValue = 1, Itinerary = S_3op_tc_2_SLOT23 in
4963 class T_S3op_shift32_Sat <string mnemonic, bits<2> MinOp>
4964 : T_S3op_3 <mnemonic, IntRegs, 0b00, MinOp, 1, []>;
4967 class T_S3op_shift64 <string mnemonic, SDNode OpNode, bits<2> MinOp>
4968 : T_S3op_3 <mnemonic, DoubleRegs, 0b10, MinOp, 0,
4969 [(set (i64 DoubleRegs:$dst), (OpNode (i64 DoubleRegs:$src1),
4970 (i32 IntRegs:$src2)))]>;
4973 class T_S3op_shiftVect <string mnemonic, bits<2> MajOp, bits<2> MinOp>
4974 : T_S3op_3 <mnemonic, DoubleRegs, MajOp, MinOp, 0, []>;
4977 // Shift by register
4978 // Rdd=[asr|lsr|asl|lsl](Rss,Rt)
4980 let isCodeGenOnly = 0 in {
4981 def S2_asr_r_p : T_S3op_shift64 < "asr", sra, 0b00>;
4982 def S2_lsr_r_p : T_S3op_shift64 < "lsr", srl, 0b01>;
4983 def S2_asl_r_p : T_S3op_shift64 < "asl", shl, 0b10>;
4984 def S2_lsl_r_p : T_S3op_shift64 < "lsl", shl, 0b11>;
4987 // Rd=[asr|lsr|asl|lsl](Rs,Rt)
4989 let isCodeGenOnly = 0 in {
4990 def S2_asr_r_r : T_S3op_shift32<"asr", sra, 0b00>;
4991 def S2_lsr_r_r : T_S3op_shift32<"lsr", srl, 0b01>;
4992 def S2_asl_r_r : T_S3op_shift32<"asl", shl, 0b10>;
4993 def S2_lsl_r_r : T_S3op_shift32<"lsl", shl, 0b11>;
4996 // Shift by register with saturation
4997 // Rd=asr(Rs,Rt):sat
4998 // Rd=asl(Rs,Rt):sat
5000 let Defs = [USR_OVF], isCodeGenOnly = 0 in {
5001 def S2_asr_r_r_sat : T_S3op_shift32_Sat<"asr", 0b00>;
5002 def S2_asl_r_r_sat : T_S3op_shift32_Sat<"asl", 0b10>;
5005 //===----------------------------------------------------------------------===//
5006 // Template class for 'insert bitfield' instructions
5007 //===----------------------------------------------------------------------===//
5008 let hasSideEffects = 0 in
5009 class T_S3op_insert <string mnemonic, RegisterClass RC>
5010 : SInst <(outs RC:$dst),
5011 (ins RC:$src1, RC:$src2, DoubleRegs:$src3),
5012 "$dst = "#mnemonic#"($src2, $src3)" ,
5013 [], "$src1 = $dst", S_3op_tc_1_SLOT23 > {
5018 let IClass = 0b1100;
5020 let Inst{27-26} = 0b10;
5021 let Inst{25-24} = !if(!eq(!cast<string>(RC), "IntRegs"), 0b00, 0b10);
5023 let Inst{20-16} = src2;
5024 let Inst{12-8} = src3;
5025 let Inst{4-0} = dst;
5028 let hasSideEffects = 0 in
5029 class T_S2op_insert <bits<4> RegTyBits, RegisterClass RC, Operand ImmOp>
5030 : SInst <(outs RC:$dst), (ins RC:$dst2, RC:$src1, ImmOp:$src2, ImmOp:$src3),
5031 "$dst = insert($src1, #$src2, #$src3)",
5032 [], "$dst2 = $dst", S_2op_tc_2_SLOT23> {
5039 string ImmOpStr = !cast<string>(ImmOp);
5041 let bit23 = !if (!eq(ImmOpStr, "u6Imm"), src3{5}, 0);
5042 let bit13 = !if (!eq(ImmOpStr, "u6Imm"), src2{5}, 0);
5044 let IClass = 0b1000;
5046 let Inst{27-24} = RegTyBits;
5047 let Inst{23} = bit23;
5048 let Inst{22-21} = src3{4-3};
5049 let Inst{20-16} = src1;
5050 let Inst{13} = bit13;
5051 let Inst{12-8} = src2{4-0};
5052 let Inst{7-5} = src3{2-0};
5053 let Inst{4-0} = dst;
5056 // Rx=insert(Rs,Rtt)
5057 // Rx=insert(Rs,#u5,#U5)
5058 let hasNewValue = 1, isCodeGenOnly = 0 in {
5059 def S2_insert_rp : T_S3op_insert <"insert", IntRegs>;
5060 def S2_insert : T_S2op_insert <0b1111, IntRegs, u5Imm>;
5063 // Rxx=insert(Rss,Rtt)
5064 // Rxx=insert(Rss,#u6,#U6)
5065 let isCodeGenOnly = 0 in {
5066 def S2_insertp_rp : T_S3op_insert<"insert", DoubleRegs>;
5067 def S2_insertp : T_S2op_insert <0b0011, DoubleRegs, u6Imm>;
5070 //===----------------------------------------------------------------------===//
5071 // Template class for 'extract bitfield' instructions
5072 //===----------------------------------------------------------------------===//
5073 let hasNewValue = 1, hasSideEffects = 0 in
5074 class T_S3op_extract <string mnemonic, bits<2> MinOp>
5075 : SInst <(outs IntRegs:$Rd), (ins IntRegs:$Rs, DoubleRegs:$Rtt),
5076 "$Rd = "#mnemonic#"($Rs, $Rtt)",
5077 [], "", S_3op_tc_2_SLOT23 > {
5082 let IClass = 0b1100;
5084 let Inst{27-22} = 0b100100;
5085 let Inst{20-16} = Rs;
5086 let Inst{12-8} = Rtt;
5087 let Inst{7-6} = MinOp;
5091 let hasSideEffects = 0 in
5092 class T_S2op_extract <string mnemonic, bits<4> RegTyBits,
5093 RegisterClass RC, Operand ImmOp>
5094 : SInst <(outs RC:$dst), (ins RC:$src1, ImmOp:$src2, ImmOp:$src3),
5095 "$dst = "#mnemonic#"($src1, #$src2, #$src3)",
5096 [], "", S_2op_tc_2_SLOT23> {
5103 string ImmOpStr = !cast<string>(ImmOp);
5105 let bit23 = !if (!eq(ImmOpStr, "u6Imm"), src3{5},
5106 !if (!eq(mnemonic, "extractu"), 0, 1));
5108 let bit13 = !if (!eq(ImmOpStr, "u6Imm"), src2{5}, 0);
5110 let IClass = 0b1000;
5112 let Inst{27-24} = RegTyBits;
5113 let Inst{23} = bit23;
5114 let Inst{22-21} = src3{4-3};
5115 let Inst{20-16} = src1;
5116 let Inst{13} = bit13;
5117 let Inst{12-8} = src2{4-0};
5118 let Inst{7-5} = src3{2-0};
5119 let Inst{4-0} = dst;
5124 // Rdd=extractu(Rss,Rtt)
5125 // Rdd=extractu(Rss,#u6,#U6)
5126 let isCodeGenOnly = 0 in {
5127 def S2_extractup_rp : T_S3op_64 < "extractu", 0b00, 0b000, 0>;
5128 def S2_extractup : T_S2op_extract <"extractu", 0b0001, DoubleRegs, u6Imm>;
5131 // Rd=extractu(Rs,Rtt)
5132 // Rd=extractu(Rs,#u5,#U5)
5133 let hasNewValue = 1, isCodeGenOnly = 0 in {
5134 def S2_extractu_rp : T_S3op_extract<"extractu", 0b00>;
5135 def S2_extractu : T_S2op_extract <"extractu", 0b1101, IntRegs, u5Imm>;
5138 //===----------------------------------------------------------------------===//
5139 // :raw for of tableindx[bdhw] insns
5140 //===----------------------------------------------------------------------===//
5142 let hasSideEffects = 0, hasNewValue = 1, opNewValue = 0 in
5143 class tableidxRaw<string OpStr, bits<2>MinOp>
5144 : SInst <(outs IntRegs:$Rx),
5145 (ins IntRegs:$_dst_, IntRegs:$Rs, u4Imm:$u4, s6Imm:$S6),
5146 "$Rx = "#OpStr#"($Rs, #$u4, #$S6):raw",
5147 [], "$Rx = $_dst_" > {
5153 let IClass = 0b1000;
5155 let Inst{27-24} = 0b0111;
5156 let Inst{23-22} = MinOp;
5157 let Inst{21} = u4{3};
5158 let Inst{20-16} = Rs;
5159 let Inst{13-8} = S6;
5160 let Inst{7-5} = u4{2-0};
5164 let isCodeGenOnly = 0 in {
5165 def S2_tableidxb : tableidxRaw<"tableidxb", 0b00>;
5166 def S2_tableidxh : tableidxRaw<"tableidxh", 0b01>;
5167 def S2_tableidxw : tableidxRaw<"tableidxw", 0b10>;
5168 def S2_tableidxd : tableidxRaw<"tableidxd", 0b11>;
5171 // Change the sign of the immediate for Rd=-mpyi(Rs,#u8)
5172 def : Pat <(mul (i32 IntRegs:$src1), (ineg n8ImmPred:$src2)),
5173 (i32 (M2_mpysin (i32 IntRegs:$src1), u8ImmPred:$src2))>;
5175 //===----------------------------------------------------------------------===//
5176 // V3 Instructions +
5177 //===----------------------------------------------------------------------===//
5179 include "HexagonInstrInfoV3.td"
5181 //===----------------------------------------------------------------------===//
5182 // V3 Instructions -
5183 //===----------------------------------------------------------------------===//
5185 //===----------------------------------------------------------------------===//
5186 // V4 Instructions +
5187 //===----------------------------------------------------------------------===//
5189 include "HexagonInstrInfoV4.td"
5191 //===----------------------------------------------------------------------===//
5192 // V4 Instructions -
5193 //===----------------------------------------------------------------------===//
5195 //===----------------------------------------------------------------------===//
5196 // V5 Instructions +
5197 //===----------------------------------------------------------------------===//
5199 include "HexagonInstrInfoV5.td"
5201 //===----------------------------------------------------------------------===//
5202 // V5 Instructions -
5203 //===----------------------------------------------------------------------===//