1 //=- HexagonInstrInfoV4.td - Target Desc. for Hexagon Target -*- 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 V4 instructions in TableGen format.
12 //===----------------------------------------------------------------------===//
14 def addrga: PatLeaf<(i32 AddrGA:$Addr)>;
15 def addrgp: PatLeaf<(i32 AddrGP:$Addr)>;
17 let hasSideEffects = 0 in
18 class T_Immext<Operand ImmType>
19 : EXTENDERInst<(outs), (ins ImmType:$imm),
20 "immext(#$imm)", []> {
24 let Inst{27-16} = imm{31-20};
25 let Inst{13-0} = imm{19-6};
28 def A4_ext : T_Immext<u26_6Imm>;
29 let isCodeGenOnly = 1 in {
31 def A4_ext_b : T_Immext<brtarget>;
33 def A4_ext_c : T_Immext<calltarget>;
34 def A4_ext_g : T_Immext<globaladdress>;
37 def BITPOS32 : SDNodeXForm<imm, [{
38 // Return the bit position we will set [0-31].
40 int32_t imm = N->getSExtValue();
41 return XformMskToBitPosU5Imm(imm);
44 // Fold (add (CONST32 tglobaladdr:$addr) <offset>) into a global address.
45 def FoldGlobalAddr : ComplexPattern<i32, 1, "foldGlobalAddress", [], []>;
47 // Fold (add (CONST32_GP tglobaladdr:$addr) <offset>) into a global address.
48 def FoldGlobalAddrGP : ComplexPattern<i32, 1, "foldGlobalAddressGP", [], []>;
50 def NumUsesBelowThresCONST32 : PatFrag<(ops node:$addr),
51 (HexagonCONST32 node:$addr), [{
52 return hasNumUsesBelowThresGA(N->getOperand(0).getNode());
55 // Hexagon V4 Architecture spec defines 8 instruction classes:
56 // LD ST ALU32 XTYPE J JR MEMOP NV CR SYSTEM(system is not implemented in the
60 // ========================================
61 // Loads (8/16/32/64 bit)
65 // ========================================
66 // Stores (8/16/32/64 bit)
69 // ALU32 Instructions:
70 // ========================================
71 // Arithmetic / Logical (32 bit)
74 // XTYPE Instructions (32/64 bit):
75 // ========================================
76 // Arithmetic, Logical, Bit Manipulation
77 // Multiply (Integer, Fractional, Complex)
78 // Permute / Vector Permute Operations
79 // Predicate Operations
80 // Shift / Shift with Add/Sub/Logical
82 // Vector Halfword (ALU, Shift, Multiply)
83 // Vector Word (ALU, Shift)
86 // ========================================
87 // Jump/Call PC-relative
90 // ========================================
93 // MEMOP Instructions:
94 // ========================================
95 // Operation on memory (8/16/32 bit)
98 // ========================================
103 // ========================================
104 // Control-Register Transfers
105 // Hardware Loop Setup
106 // Predicate Logicals & Reductions
108 // SYSTEM Instructions (not implemented in the compiler):
109 // ========================================
115 //===----------------------------------------------------------------------===//
117 //===----------------------------------------------------------------------===//
119 class T_ALU32_3op_not<string mnemonic, bits<3> MajOp, bits<3> MinOp,
121 : T_ALU32_3op<mnemonic, MajOp, MinOp, OpsRev, 0> {
122 let AsmString = "$Rd = "#mnemonic#"($Rs, ~$Rt)";
125 let BaseOpcode = "andn_rr", CextOpcode = "andn" in
126 def A4_andn : T_ALU32_3op_not<"and", 0b001, 0b100, 1>;
127 let BaseOpcode = "orn_rr", CextOpcode = "orn" in
128 def A4_orn : T_ALU32_3op_not<"or", 0b001, 0b101, 1>;
130 let CextOpcode = "rcmp.eq" in
131 def A4_rcmpeq : T_ALU32_3op<"cmp.eq", 0b011, 0b010, 0, 1>;
132 let CextOpcode = "!rcmp.eq" in
133 def A4_rcmpneq : T_ALU32_3op<"!cmp.eq", 0b011, 0b011, 0, 1>;
135 def C4_cmpneq : T_ALU32_3op_cmp<"!cmp.eq", 0b00, 1, 1>;
136 def C4_cmplte : T_ALU32_3op_cmp<"!cmp.gt", 0b10, 1, 0>;
137 def C4_cmplteu : T_ALU32_3op_cmp<"!cmp.gtu", 0b11, 1, 0>;
139 // Pats for instruction selection.
141 // A class to embed the usual comparison patfrags within a zext to i32.
142 // The seteq/setne frags use "lhs" and "rhs" as operands, so use the same
143 // names, or else the frag's "body" won't match the operands.
144 class CmpInReg<PatFrag Op>
145 : PatFrag<(ops node:$lhs, node:$rhs),(i32 (zext (i1 Op.Fragment)))>;
147 def: T_cmp32_rr_pat<A4_rcmpeq, CmpInReg<seteq>, i32>;
148 def: T_cmp32_rr_pat<A4_rcmpneq, CmpInReg<setne>, i32>;
150 def: T_cmp32_rr_pat<C4_cmpneq, setne, i1>;
152 class T_CMP_rrbh<string mnemonic, bits<3> MinOp, bit IsComm>
153 : SInst<(outs PredRegs:$Pd), (ins IntRegs:$Rs, IntRegs:$Rt),
154 "$Pd = "#mnemonic#"($Rs, $Rt)", [], "", S_3op_tc_2early_SLOT23>,
156 let validSubTargets = HasV4SubT;
157 let InputType = "reg";
158 let CextOpcode = mnemonic;
160 let isCommutable = IsComm;
161 let hasSideEffects = 0;
168 let Inst{27-21} = 0b0111110;
169 let Inst{20-16} = Rs;
171 let Inst{7-5} = MinOp;
175 def A4_cmpbeq : T_CMP_rrbh<"cmpb.eq", 0b110, 1>;
176 def A4_cmpbgt : T_CMP_rrbh<"cmpb.gt", 0b010, 0>;
177 def A4_cmpbgtu : T_CMP_rrbh<"cmpb.gtu", 0b111, 0>;
178 def A4_cmpheq : T_CMP_rrbh<"cmph.eq", 0b011, 1>;
179 def A4_cmphgt : T_CMP_rrbh<"cmph.gt", 0b100, 0>;
180 def A4_cmphgtu : T_CMP_rrbh<"cmph.gtu", 0b101, 0>;
182 class T_CMP_ribh<string mnemonic, bits<2> MajOp, bit IsHalf, bit IsComm,
183 Operand ImmType, bit IsImmExt, bit IsImmSigned, int ImmBits>
184 : ALU64Inst<(outs PredRegs:$Pd), (ins IntRegs:$Rs, ImmType:$Imm),
185 "$Pd = "#mnemonic#"($Rs, #$Imm)", [], "", ALU64_tc_2early_SLOT23>,
187 let validSubTargets = HasV4SubT;
188 let InputType = "imm";
189 let CextOpcode = mnemonic;
191 let isCommutable = IsComm;
192 let hasSideEffects = 0;
193 let isExtendable = IsImmExt;
194 let opExtendable = !if (IsImmExt, 2, 0);
195 let isExtentSigned = IsImmSigned;
196 let opExtentBits = ImmBits;
203 let Inst{27-24} = 0b1101;
204 let Inst{22-21} = MajOp;
205 let Inst{20-16} = Rs;
206 let Inst{12-5} = Imm;
208 let Inst{3} = IsHalf;
212 def A4_cmpbeqi : T_CMP_ribh<"cmpb.eq", 0b00, 0, 1, u8Imm, 0, 0, 8>;
213 def A4_cmpbgti : T_CMP_ribh<"cmpb.gt", 0b01, 0, 0, s8Imm, 0, 1, 8>;
214 def A4_cmpbgtui : T_CMP_ribh<"cmpb.gtu", 0b10, 0, 0, u7Ext, 1, 0, 7>;
215 def A4_cmpheqi : T_CMP_ribh<"cmph.eq", 0b00, 1, 1, s8Ext, 1, 1, 8>;
216 def A4_cmphgti : T_CMP_ribh<"cmph.gt", 0b01, 1, 0, s8Ext, 1, 1, 8>;
217 def A4_cmphgtui : T_CMP_ribh<"cmph.gtu", 0b10, 1, 0, u7Ext, 1, 0, 7>;
219 class T_RCMP_EQ_ri<string mnemonic, bit IsNeg>
220 : ALU32_ri<(outs IntRegs:$Rd), (ins IntRegs:$Rs, s8Ext:$s8),
221 "$Rd = "#mnemonic#"($Rs, #$s8)", [], "", ALU32_2op_tc_1_SLOT0123>,
223 let validSubTargets = HasV4SubT;
224 let InputType = "imm";
225 let CextOpcode = !if (IsNeg, "!rcmp.eq", "rcmp.eq");
226 let isExtendable = 1;
227 let opExtendable = 2;
228 let isExtentSigned = 1;
229 let opExtentBits = 8;
237 let Inst{27-24} = 0b0011;
239 let Inst{21} = IsNeg;
240 let Inst{20-16} = Rs;
246 def A4_rcmpeqi : T_RCMP_EQ_ri<"cmp.eq", 0>;
247 def A4_rcmpneqi : T_RCMP_EQ_ri<"!cmp.eq", 1>;
249 def: Pat<(i32 (zext (i1 (seteq (i32 IntRegs:$Rs), s8ExtPred:$s8)))),
250 (A4_rcmpeqi IntRegs:$Rs, s8ExtPred:$s8)>;
251 def: Pat<(i32 (zext (i1 (setne (i32 IntRegs:$Rs), s8ExtPred:$s8)))),
252 (A4_rcmpneqi IntRegs:$Rs, s8ExtPred:$s8)>;
254 // Preserve the S2_tstbit_r generation
255 def: Pat<(i32 (zext (i1 (setne (i32 (and (i32 (shl 1, (i32 IntRegs:$src2))),
256 (i32 IntRegs:$src1))), 0)))),
257 (C2_muxii (S2_tstbit_r IntRegs:$src1, IntRegs:$src2), 1, 0)>;
260 //===----------------------------------------------------------------------===//
262 //===----------------------------------------------------------------------===//
265 //===----------------------------------------------------------------------===//
267 //===----------------------------------------------------------------------===//
269 // Combine a word and an immediate into a register pair.
270 let hasSideEffects = 0, isExtentSigned = 1, isExtendable = 1,
272 class T_Combine1 <bits<2> MajOp, dag ins, string AsmStr>
273 : ALU32Inst <(outs DoubleRegs:$Rdd), ins, AsmStr> {
279 let Inst{27-24} = 0b0011;
280 let Inst{22-21} = MajOp;
281 let Inst{20-16} = Rs;
287 let opExtendable = 2 in
288 def A4_combineri : T_Combine1<0b00, (ins IntRegs:$Rs, s8Ext:$s8),
289 "$Rdd = combine($Rs, #$s8)">;
291 let opExtendable = 1 in
292 def A4_combineir : T_Combine1<0b01, (ins s8Ext:$s8, IntRegs:$Rs),
293 "$Rdd = combine(#$s8, $Rs)">;
295 def HexagonWrapperCombineRI_V4 :
296 SDNode<"HexagonISD::WrapperCombineRI_V4", SDTHexagonI64I32I32>;
297 def HexagonWrapperCombineIR_V4 :
298 SDNode<"HexagonISD::WrapperCombineIR_V4", SDTHexagonI64I32I32>;
300 def : Pat <(HexagonWrapperCombineRI_V4 IntRegs:$r, s8ExtPred:$i),
301 (A4_combineri IntRegs:$r, s8ExtPred:$i)>,
304 def : Pat <(HexagonWrapperCombineIR_V4 s8ExtPred:$i, IntRegs:$r),
305 (A4_combineir s8ExtPred:$i, IntRegs:$r)>,
308 // A4_combineii: Set two small immediates.
309 let hasSideEffects = 0, isExtendable = 1, opExtentBits = 6, opExtendable = 2 in
310 def A4_combineii: ALU32Inst<(outs DoubleRegs:$Rdd), (ins s8Imm:$s8, u6Ext:$U6),
311 "$Rdd = combine(#$s8, #$U6)"> {
317 let Inst{27-23} = 0b11001;
318 let Inst{20-16} = U6{5-1};
319 let Inst{13} = U6{0};
324 //===----------------------------------------------------------------------===//
326 //===----------------------------------------------------------------------===//
328 //===----------------------------------------------------------------------===//
330 //===----------------------------------------------------------------------===//
332 def Zext64: OutPatFrag<(ops node:$Rs),
333 (i64 (A4_combineir 0, (i32 $Rs)))>;
334 def Sext64: OutPatFrag<(ops node:$Rs),
335 (i64 (A2_sxtw (i32 $Rs)))>;
337 // Patterns to generate indexed loads with different forms of the address:
340 // - base (without offset).
341 multiclass Loadxm_pat<PatFrag Load, ValueType VT, PatFrag ValueMod,
342 PatLeaf ImmPred, InstHexagon MI> {
343 def: Pat<(VT (Load AddrFI:$fi)),
344 (VT (ValueMod (MI AddrFI:$fi, 0)))>;
345 def: Pat<(VT (Load (add IntRegs:$Rs, ImmPred:$Off))),
346 (VT (ValueMod (MI IntRegs:$Rs, imm:$Off)))>;
347 def: Pat<(VT (Load (i32 IntRegs:$Rs))),
348 (VT (ValueMod (MI IntRegs:$Rs, 0)))>;
351 defm: Loadxm_pat<extloadi1, i64, Zext64, s11_0ExtPred, L2_loadrub_io>;
352 defm: Loadxm_pat<extloadi8, i64, Zext64, s11_0ExtPred, L2_loadrub_io>;
353 defm: Loadxm_pat<extloadi16, i64, Zext64, s11_1ExtPred, L2_loadruh_io>;
354 defm: Loadxm_pat<zextloadi1, i64, Zext64, s11_0ExtPred, L2_loadrub_io>;
355 defm: Loadxm_pat<zextloadi8, i64, Zext64, s11_0ExtPred, L2_loadrub_io>;
356 defm: Loadxm_pat<zextloadi16, i64, Zext64, s11_1ExtPred, L2_loadruh_io>;
357 defm: Loadxm_pat<sextloadi8, i64, Sext64, s11_0ExtPred, L2_loadrb_io>;
358 defm: Loadxm_pat<sextloadi16, i64, Sext64, s11_1ExtPred, L2_loadrh_io>;
360 // Map Rdd = anyext(Rs) -> Rdd = combine(#0, Rs).
361 def: Pat<(i64 (anyext (i32 IntRegs:$src1))), (Zext64 IntRegs:$src1)>;
363 //===----------------------------------------------------------------------===//
364 // Template class for load instructions with Absolute set addressing mode.
365 //===----------------------------------------------------------------------===//
366 let isExtended = 1, opExtendable = 2, opExtentBits = 6, addrMode = AbsoluteSet,
367 hasSideEffects = 0 in
368 class T_LD_abs_set<string mnemonic, RegisterClass RC, bits<4>MajOp>:
369 LDInst<(outs RC:$dst1, IntRegs:$dst2),
371 "$dst1 = "#mnemonic#"($dst2 = #$addr)",
379 let Inst{27-25} = 0b101;
380 let Inst{24-21} = MajOp;
381 let Inst{13-12} = 0b01;
382 let Inst{4-0} = dst1;
383 let Inst{20-16} = dst2;
384 let Inst{11-8} = addr{5-2};
385 let Inst{6-5} = addr{1-0};
388 let accessSize = ByteAccess, hasNewValue = 1 in {
389 def L4_loadrb_ap : T_LD_abs_set <"memb", IntRegs, 0b1000>;
390 def L4_loadrub_ap : T_LD_abs_set <"memub", IntRegs, 0b1001>;
393 let accessSize = HalfWordAccess, hasNewValue = 1 in {
394 def L4_loadrh_ap : T_LD_abs_set <"memh", IntRegs, 0b1010>;
395 def L4_loadruh_ap : T_LD_abs_set <"memuh", IntRegs, 0b1011>;
398 let accessSize = WordAccess, hasNewValue = 1 in
399 def L4_loadri_ap : T_LD_abs_set <"memw", IntRegs, 0b1100>;
401 let accessSize = DoubleWordAccess in
402 def L4_loadrd_ap : T_LD_abs_set <"memd", DoubleRegs, 0b1110>;
403 // Load - Indirect with long offset
404 let InputType = "imm", addrMode = BaseLongOffset, isExtended = 1,
405 opExtentBits = 6, opExtendable = 3 in
406 class T_LoadAbsReg <string mnemonic, string CextOp, RegisterClass RC,
408 : LDInst <(outs RC:$dst), (ins IntRegs:$src1, u2Imm:$src2, u6Ext:$src3),
409 "$dst = "#mnemonic#"($src1<<#$src2 + #$src3)",
415 let CextOpcode = CextOp;
416 let hasNewValue = !if (!eq(!cast<string>(RC), "DoubleRegs"), 0, 1);
419 let Inst{27-25} = 0b110;
420 let Inst{24-21} = MajOp;
421 let Inst{20-16} = src1;
422 let Inst{13} = src2{1};
424 let Inst{11-8} = src3{5-2};
425 let Inst{7} = src2{0};
426 let Inst{6-5} = src3{1-0};
430 let accessSize = ByteAccess in {
431 def L4_loadrb_ur : T_LoadAbsReg<"memb", "LDrib", IntRegs, 0b1000>;
432 def L4_loadrub_ur : T_LoadAbsReg<"memub", "LDriub", IntRegs, 0b1001>;
433 def L4_loadalignb_ur : T_LoadAbsReg<"memb_fifo", "LDrib_fifo",
437 let accessSize = HalfWordAccess in {
438 def L4_loadrh_ur : T_LoadAbsReg<"memh", "LDrih", IntRegs, 0b1010>;
439 def L4_loadruh_ur : T_LoadAbsReg<"memuh", "LDriuh", IntRegs, 0b1011>;
440 def L4_loadbsw2_ur : T_LoadAbsReg<"membh", "LDribh2", IntRegs, 0b0001>;
441 def L4_loadbzw2_ur : T_LoadAbsReg<"memubh", "LDriubh2", IntRegs, 0b0011>;
442 def L4_loadalignh_ur : T_LoadAbsReg<"memh_fifo", "LDrih_fifo",
446 let accessSize = WordAccess in {
447 def L4_loadri_ur : T_LoadAbsReg<"memw", "LDriw", IntRegs, 0b1100>;
448 def L4_loadbsw4_ur : T_LoadAbsReg<"membh", "LDribh4", DoubleRegs, 0b0111>;
449 def L4_loadbzw4_ur : T_LoadAbsReg<"memubh", "LDriubh4", DoubleRegs, 0b0101>;
452 let accessSize = DoubleWordAccess in
453 def L4_loadrd_ur : T_LoadAbsReg<"memd", "LDrid", DoubleRegs, 0b1110>;
456 multiclass T_LoadAbsReg_Pat <PatFrag ldOp, InstHexagon MI, ValueType VT = i32> {
457 def : Pat <(VT (ldOp (add (shl IntRegs:$src1, u2ImmPred:$src2),
458 (HexagonCONST32 tglobaladdr:$src3)))),
459 (MI IntRegs:$src1, u2ImmPred:$src2, tglobaladdr:$src3)>;
461 def : Pat <(VT (ldOp (add IntRegs:$src1,
462 (HexagonCONST32 tglobaladdr:$src2)))),
463 (MI IntRegs:$src1, 0, tglobaladdr:$src2)>;
466 let AddedComplexity = 60 in {
467 defm : T_LoadAbsReg_Pat <sextloadi8, L4_loadrb_ur>;
468 defm : T_LoadAbsReg_Pat <zextloadi8, L4_loadrub_ur>;
469 defm : T_LoadAbsReg_Pat <extloadi8, L4_loadrub_ur>;
471 defm : T_LoadAbsReg_Pat <sextloadi16, L4_loadrh_ur>;
472 defm : T_LoadAbsReg_Pat <zextloadi16, L4_loadruh_ur>;
473 defm : T_LoadAbsReg_Pat <extloadi16, L4_loadruh_ur>;
475 defm : T_LoadAbsReg_Pat <load, L4_loadri_ur>;
476 defm : T_LoadAbsReg_Pat <load, L4_loadrd_ur, i64>;
479 //===----------------------------------------------------------------------===//
480 // Template classes for the non-predicated load instructions with
481 // base + register offset addressing mode
482 //===----------------------------------------------------------------------===//
483 class T_load_rr <string mnemonic, RegisterClass RC, bits<3> MajOp>:
484 LDInst<(outs RC:$dst), (ins IntRegs:$src1, IntRegs:$src2, u2Imm:$u2),
485 "$dst = "#mnemonic#"($src1 + $src2<<#$u2)",
486 [], "", V4LDST_tc_ld_SLOT01>, ImmRegShl, AddrModeRel {
494 let Inst{27-24} = 0b1010;
495 let Inst{23-21} = MajOp;
496 let Inst{20-16} = src1;
497 let Inst{12-8} = src2;
498 let Inst{13} = u2{1};
503 //===----------------------------------------------------------------------===//
504 // Template classes for the predicated load instructions with
505 // base + register offset addressing mode
506 //===----------------------------------------------------------------------===//
507 let isPredicated = 1 in
508 class T_pload_rr <string mnemonic, RegisterClass RC, bits<3> MajOp,
509 bit isNot, bit isPredNew>:
510 LDInst <(outs RC:$dst),
511 (ins PredRegs:$src1, IntRegs:$src2, IntRegs:$src3, u2Imm:$u2),
512 !if(isNot, "if (!$src1", "if ($src1")#!if(isPredNew, ".new) ",
513 ") ")#"$dst = "#mnemonic#"($src2+$src3<<#$u2)",
514 [], "", V4LDST_tc_ld_SLOT01>, AddrModeRel {
521 let isPredicatedFalse = isNot;
522 let isPredicatedNew = isPredNew;
526 let Inst{27-26} = 0b00;
527 let Inst{25} = isPredNew;
528 let Inst{24} = isNot;
529 let Inst{23-21} = MajOp;
530 let Inst{20-16} = src2;
531 let Inst{12-8} = src3;
532 let Inst{13} = u2{1};
534 let Inst{6-5} = src1;
538 //===----------------------------------------------------------------------===//
539 // multiclass for load instructions with base + register offset
541 //===----------------------------------------------------------------------===//
542 let hasSideEffects = 0, addrMode = BaseRegOffset in
543 multiclass ld_idxd_shl <string mnemonic, string CextOp, RegisterClass RC,
545 let CextOpcode = CextOp, BaseOpcode = CextOp#_indexed_shl,
546 InputType = "reg" in {
547 let isPredicable = 1 in
548 def L4_#NAME#_rr : T_load_rr <mnemonic, RC, MajOp>;
551 def L4_p#NAME#t_rr : T_pload_rr <mnemonic, RC, MajOp, 0, 0>;
552 def L4_p#NAME#f_rr : T_pload_rr <mnemonic, RC, MajOp, 1, 0>;
555 def L4_p#NAME#tnew_rr : T_pload_rr <mnemonic, RC, MajOp, 0, 1>;
556 def L4_p#NAME#fnew_rr : T_pload_rr <mnemonic, RC, MajOp, 1, 1>;
560 let hasNewValue = 1, accessSize = ByteAccess in {
561 defm loadrb : ld_idxd_shl<"memb", "LDrib", IntRegs, 0b000>;
562 defm loadrub : ld_idxd_shl<"memub", "LDriub", IntRegs, 0b001>;
565 let hasNewValue = 1, accessSize = HalfWordAccess in {
566 defm loadrh : ld_idxd_shl<"memh", "LDrih", IntRegs, 0b010>;
567 defm loadruh : ld_idxd_shl<"memuh", "LDriuh", IntRegs, 0b011>;
570 let hasNewValue = 1, accessSize = WordAccess in
571 defm loadri : ld_idxd_shl<"memw", "LDriw", IntRegs, 0b100>;
573 let accessSize = DoubleWordAccess in
574 defm loadrd : ld_idxd_shl<"memd", "LDrid", DoubleRegs, 0b110>;
576 // 'def pats' for load instructions with base + register offset and non-zero
577 // immediate value. Immediate value is used to left-shift the second
579 class Loadxs_pat<PatFrag Load, ValueType VT, InstHexagon MI>
580 : Pat<(VT (Load (add (i32 IntRegs:$Rs),
581 (i32 (shl (i32 IntRegs:$Rt), u2ImmPred:$u2))))),
582 (VT (MI IntRegs:$Rs, IntRegs:$Rt, imm:$u2))>;
584 let AddedComplexity = 40 in {
585 def: Loadxs_pat<extloadi8, i32, L4_loadrub_rr>;
586 def: Loadxs_pat<zextloadi8, i32, L4_loadrub_rr>;
587 def: Loadxs_pat<sextloadi8, i32, L4_loadrb_rr>;
588 def: Loadxs_pat<extloadi16, i32, L4_loadruh_rr>;
589 def: Loadxs_pat<zextloadi16, i32, L4_loadruh_rr>;
590 def: Loadxs_pat<sextloadi16, i32, L4_loadrh_rr>;
591 def: Loadxs_pat<load, i32, L4_loadri_rr>;
592 def: Loadxs_pat<load, i64, L4_loadrd_rr>;
595 // 'def pats' for load instruction base + register offset and
596 // zero immediate value.
597 class Loadxs_simple_pat<PatFrag Load, ValueType VT, InstHexagon MI>
598 : Pat<(VT (Load (add (i32 IntRegs:$Rs), (i32 IntRegs:$Rt)))),
599 (VT (MI IntRegs:$Rs, IntRegs:$Rt, 0))>;
601 let AddedComplexity = 20 in {
602 def: Loadxs_simple_pat<extloadi8, i32, L4_loadrub_rr>;
603 def: Loadxs_simple_pat<zextloadi8, i32, L4_loadrub_rr>;
604 def: Loadxs_simple_pat<sextloadi8, i32, L4_loadrb_rr>;
605 def: Loadxs_simple_pat<extloadi16, i32, L4_loadruh_rr>;
606 def: Loadxs_simple_pat<zextloadi16, i32, L4_loadruh_rr>;
607 def: Loadxs_simple_pat<sextloadi16, i32, L4_loadrh_rr>;
608 def: Loadxs_simple_pat<load, i32, L4_loadri_rr>;
609 def: Loadxs_simple_pat<load, i64, L4_loadrd_rr>;
613 def: Pat<(i64 (zext (i1 PredRegs:$src1))),
614 (Zext64 (C2_muxii PredRegs:$src1, 1, 0))>;
617 def: Pat<(i64 (zext (i32 IntRegs:$src1))),
618 (Zext64 IntRegs:$src1)>;
621 def: Pat <(i64 (zextloadi32 ADDRriS11_2:$src1)),
622 (i64 (A4_combineir 0, (L2_loadri_io AddrFI:$src1, 0)))>,
625 let AddedComplexity = 100 in
626 def: Pat <(i64 (zextloadi32 (i32 (add IntRegs:$src1, s11_2ExtPred:$offset)))),
627 (i64 (A4_combineir 0, (L2_loadri_io IntRegs:$src1,
628 s11_2ExtPred:$offset)))>,
632 def: Pat <(i64 (extloadi32 ADDRriS11_2:$src1)),
633 (i64 (A4_combineir 0, (L2_loadri_io AddrFI:$src1, 0)))>,
636 let AddedComplexity = 100 in
637 def: Pat <(i64 (extloadi32 (i32 (add IntRegs:$src1, s11_2ExtPred:$offset)))),
638 (i64 (A4_combineir 0, (L2_loadri_io IntRegs:$src1,
639 s11_2ExtPred:$offset)))>,
644 //===----------------------------------------------------------------------===//
646 //===----------------------------------------------------------------------===//
648 //===----------------------------------------------------------------------===//
650 //===----------------------------------------------------------------------===//
652 //===----------------------------------------------------------------------===//
653 // Template class for store instructions with Absolute set addressing mode.
654 //===----------------------------------------------------------------------===//
655 let isExtended = 1, opExtendable = 1, opExtentBits = 6,
656 addrMode = AbsoluteSet, isNVStorable = 1 in
657 class T_ST_absset <string mnemonic, string BaseOp, RegisterClass RC,
658 bits<3> MajOp, MemAccessSize AccessSz, bit isHalf = 0>
659 : STInst<(outs IntRegs:$dst),
660 (ins u6Ext:$addr, RC:$src),
661 mnemonic#"($dst = #$addr) = $src"#!if(isHalf, ".h","")>, NewValueRel {
665 let accessSize = AccessSz;
666 let BaseOpcode = BaseOp#"_AbsSet";
670 let Inst{27-24} = 0b1011;
671 let Inst{23-21} = MajOp;
672 let Inst{20-16} = dst;
674 let Inst{12-8} = src;
676 let Inst{5-0} = addr;
679 def S4_storerb_ap : T_ST_absset <"memb", "STrib", IntRegs, 0b000, ByteAccess>;
680 def S4_storerh_ap : T_ST_absset <"memh", "STrih", IntRegs, 0b010,
682 def S4_storeri_ap : T_ST_absset <"memw", "STriw", IntRegs, 0b100, WordAccess>;
684 let isNVStorable = 0 in {
685 def S4_storerf_ap : T_ST_absset <"memh", "STrif", IntRegs,
686 0b011, HalfWordAccess, 1>;
687 def S4_storerd_ap : T_ST_absset <"memd", "STrid", DoubleRegs,
688 0b110, DoubleWordAccess>;
691 let opExtendable = 1, isNewValue = 1, isNVStore = 1, opNewValue = 2,
692 isExtended = 1, opExtentBits= 6 in
693 class T_ST_absset_nv <string mnemonic, string BaseOp, bits<2> MajOp,
694 MemAccessSize AccessSz >
695 : NVInst <(outs IntRegs:$dst),
696 (ins u6Ext:$addr, IntRegs:$src),
697 mnemonic#"($dst = #$addr) = $src.new">, NewValueRel {
701 let accessSize = AccessSz;
702 let BaseOpcode = BaseOp#"_AbsSet";
706 let Inst{27-21} = 0b1011101;
707 let Inst{20-16} = dst;
708 let Inst{13-11} = 0b000;
709 let Inst{12-11} = MajOp;
710 let Inst{10-8} = src;
712 let Inst{5-0} = addr;
715 let mayStore = 1, addrMode = AbsoluteSet in {
716 def S4_storerbnew_ap : T_ST_absset_nv <"memb", "STrib", 0b00, ByteAccess>;
717 def S4_storerhnew_ap : T_ST_absset_nv <"memh", "STrih", 0b01, HalfWordAccess>;
718 def S4_storerinew_ap : T_ST_absset_nv <"memw", "STriw", 0b10, WordAccess>;
721 let isExtended = 1, opExtendable = 2, opExtentBits = 6, InputType = "imm",
722 addrMode = BaseLongOffset, AddedComplexity = 40 in
723 class T_StoreAbsReg <string mnemonic, string CextOp, RegisterClass RC,
724 bits<3> MajOp, MemAccessSize AccessSz, bit isHalf = 0>
726 (ins IntRegs:$src1, u2Imm:$src2, u6Ext:$src3, RC:$src4),
727 mnemonic#"($src1<<#$src2 + #$src3) = $src4"#!if(isHalf, ".h",""),
728 []>, ImmRegShl, NewValueRel {
735 let accessSize = AccessSz;
736 let CextOpcode = CextOp;
737 let BaseOpcode = CextOp#"_shl";
740 let Inst{27-24} =0b1101;
741 let Inst{23-21} = MajOp;
742 let Inst{20-16} = src1;
743 let Inst{13} = src2{1};
744 let Inst{12-8} = src4;
746 let Inst{6} = src2{0};
747 let Inst{5-0} = src3;
750 def S4_storerb_ur : T_StoreAbsReg <"memb", "STrib", IntRegs, 0b000, ByteAccess>;
751 def S4_storerh_ur : T_StoreAbsReg <"memh", "STrih", IntRegs, 0b010,
753 def S4_storerf_ur : T_StoreAbsReg <"memh", "STrif", IntRegs, 0b011,
755 def S4_storeri_ur : T_StoreAbsReg <"memw", "STriw", IntRegs, 0b100, WordAccess>;
756 def S4_storerd_ur : T_StoreAbsReg <"memd", "STrid", DoubleRegs, 0b110,
759 let AddedComplexity = 40 in
760 multiclass T_StoreAbsReg_Pats <InstHexagon MI, RegisterClass RC, ValueType VT,
762 def : Pat<(stOp (VT RC:$src4),
763 (add (shl (i32 IntRegs:$src1), u2ImmPred:$src2),
764 u0AlwaysExtPred:$src3)),
765 (MI IntRegs:$src1, u2ImmPred:$src2, u0AlwaysExtPred:$src3, RC:$src4)>;
767 def : Pat<(stOp (VT RC:$src4),
768 (add (shl IntRegs:$src1, u2ImmPred:$src2),
769 (HexagonCONST32 tglobaladdr:$src3))),
770 (MI IntRegs:$src1, u2ImmPred:$src2, tglobaladdr:$src3, RC:$src4)>;
772 def : Pat<(stOp (VT RC:$src4),
773 (add IntRegs:$src1, (HexagonCONST32 tglobaladdr:$src3))),
774 (MI IntRegs:$src1, 0, tglobaladdr:$src3, RC:$src4)>;
777 defm : T_StoreAbsReg_Pats <S4_storerd_ur, DoubleRegs, i64, store>;
778 defm : T_StoreAbsReg_Pats <S4_storeri_ur, IntRegs, i32, store>;
779 defm : T_StoreAbsReg_Pats <S4_storerb_ur, IntRegs, i32, truncstorei8>;
780 defm : T_StoreAbsReg_Pats <S4_storerh_ur, IntRegs, i32, truncstorei16>;
782 let mayStore = 1, isNVStore = 1, isExtended = 1, addrMode = BaseLongOffset,
783 opExtentBits = 6, isNewValue = 1, opNewValue = 3, opExtendable = 2 in
784 class T_StoreAbsRegNV <string mnemonic, string CextOp, bits<2> MajOp,
785 MemAccessSize AccessSz>
787 (ins IntRegs:$src1, u2Imm:$src2, u6Ext:$src3, IntRegs:$src4),
788 mnemonic#"($src1<<#$src2 + #$src3) = $src4.new">, NewValueRel {
794 let CextOpcode = CextOp;
795 let BaseOpcode = CextOp#"_shl";
798 let Inst{27-21} = 0b1101101;
799 let Inst{12-11} = 0b00;
801 let Inst{20-16} = src1;
802 let Inst{13} = src2{1};
803 let Inst{12-11} = MajOp;
804 let Inst{10-8} = src4;
805 let Inst{6} = src2{0};
806 let Inst{5-0} = src3;
809 def S4_storerbnew_ur : T_StoreAbsRegNV <"memb", "STrib", 0b00, ByteAccess>;
810 def S4_storerhnew_ur : T_StoreAbsRegNV <"memh", "STrih", 0b01, HalfWordAccess>;
811 def S4_storerinew_ur : T_StoreAbsRegNV <"memw", "STriw", 0b10, WordAccess>;
813 //===----------------------------------------------------------------------===//
814 // Template classes for the non-predicated store instructions with
815 // base + register offset addressing mode
816 //===----------------------------------------------------------------------===//
817 let isPredicable = 1 in
818 class T_store_rr <string mnemonic, RegisterClass RC, bits<3> MajOp, bit isH>
819 : STInst < (outs ), (ins IntRegs:$Rs, IntRegs:$Ru, u2Imm:$u2, RC:$Rt),
820 mnemonic#"($Rs + $Ru<<#$u2) = $Rt"#!if(isH, ".h",""),
821 [],"",V4LDST_tc_st_SLOT01>, ImmRegShl, AddrModeRel {
830 let Inst{27-24} = 0b1011;
831 let Inst{23-21} = MajOp;
832 let Inst{20-16} = Rs;
834 let Inst{13} = u2{1};
839 //===----------------------------------------------------------------------===//
840 // Template classes for the predicated store instructions with
841 // base + register offset addressing mode
842 //===----------------------------------------------------------------------===//
843 let isPredicated = 1 in
844 class T_pstore_rr <string mnemonic, RegisterClass RC, bits<3> MajOp,
845 bit isNot, bit isPredNew, bit isH>
847 (ins PredRegs:$Pv, IntRegs:$Rs, IntRegs:$Ru, u2Imm:$u2, RC:$Rt),
849 !if(isNot, "if (!$Pv", "if ($Pv")#!if(isPredNew, ".new) ",
850 ") ")#mnemonic#"($Rs+$Ru<<#$u2) = $Rt"#!if(isH, ".h",""),
851 [], "", V4LDST_tc_st_SLOT01> , AddrModeRel{
858 let isPredicatedFalse = isNot;
859 let isPredicatedNew = isPredNew;
863 let Inst{27-26} = 0b01;
864 let Inst{25} = isPredNew;
865 let Inst{24} = isNot;
866 let Inst{23-21} = MajOp;
867 let Inst{20-16} = Rs;
869 let Inst{13} = u2{1};
875 //===----------------------------------------------------------------------===//
876 // Template classes for the new-value store instructions with
877 // base + register offset addressing mode
878 //===----------------------------------------------------------------------===//
879 let isPredicable = 1, isNewValue = 1, opNewValue = 3 in
880 class T_store_new_rr <string mnemonic, bits<2> MajOp> :
881 NVInst < (outs ), (ins IntRegs:$Rs, IntRegs:$Ru, u2Imm:$u2, IntRegs:$Nt),
882 mnemonic#"($Rs + $Ru<<#$u2) = $Nt.new",
883 [],"",V4LDST_tc_st_SLOT0>, ImmRegShl, AddrModeRel {
892 let Inst{27-21} = 0b1011101;
893 let Inst{20-16} = Rs;
895 let Inst{13} = u2{1};
897 let Inst{4-3} = MajOp;
901 //===----------------------------------------------------------------------===//
902 // Template classes for the predicated new-value store instructions with
903 // base + register offset addressing mode
904 //===----------------------------------------------------------------------===//
905 let isPredicated = 1, isNewValue = 1, opNewValue = 4 in
906 class T_pstore_new_rr <string mnemonic, bits<2> MajOp, bit isNot, bit isPredNew>
908 (ins PredRegs:$Pv, IntRegs:$Rs, IntRegs:$Ru, u2Imm:$u2, IntRegs:$Nt),
909 !if(isNot, "if (!$Pv", "if ($Pv")#!if(isPredNew, ".new) ",
910 ") ")#mnemonic#"($Rs+$Ru<<#$u2) = $Nt.new",
911 [], "", V4LDST_tc_st_SLOT0>, AddrModeRel {
918 let isPredicatedFalse = isNot;
919 let isPredicatedNew = isPredNew;
922 let Inst{27-26} = 0b01;
923 let Inst{25} = isPredNew;
924 let Inst{24} = isNot;
925 let Inst{23-21} = 0b101;
926 let Inst{20-16} = Rs;
928 let Inst{13} = u2{1};
931 let Inst{4-3} = MajOp;
935 //===----------------------------------------------------------------------===//
936 // multiclass for store instructions with base + register offset addressing
938 //===----------------------------------------------------------------------===//
939 let isNVStorable = 1 in
940 multiclass ST_Idxd_shl<string mnemonic, string CextOp, RegisterClass RC,
941 bits<3> MajOp, bit isH = 0> {
942 let CextOpcode = CextOp, BaseOpcode = CextOp#_indexed_shl in {
943 def S4_#NAME#_rr : T_store_rr <mnemonic, RC, MajOp, isH>;
946 def S4_p#NAME#t_rr : T_pstore_rr <mnemonic, RC, MajOp, 0, 0, isH>;
947 def S4_p#NAME#f_rr : T_pstore_rr <mnemonic, RC, MajOp, 1, 0, isH>;
950 def S4_p#NAME#tnew_rr : T_pstore_rr <mnemonic, RC, MajOp, 0, 1, isH>;
951 def S4_p#NAME#fnew_rr : T_pstore_rr <mnemonic, RC, MajOp, 1, 1, isH>;
955 //===----------------------------------------------------------------------===//
956 // multiclass for new-value store instructions with base + register offset
958 //===----------------------------------------------------------------------===//
959 let mayStore = 1, isNVStore = 1 in
960 multiclass ST_Idxd_shl_nv <string mnemonic, string CextOp, RegisterClass RC,
962 let CextOpcode = CextOp, BaseOpcode = CextOp#_indexed_shl in {
963 def S4_#NAME#new_rr : T_store_new_rr<mnemonic, MajOp>;
966 def S4_p#NAME#newt_rr : T_pstore_new_rr <mnemonic, MajOp, 0, 0>;
967 def S4_p#NAME#newf_rr : T_pstore_new_rr <mnemonic, MajOp, 1, 0>;
970 def S4_p#NAME#newtnew_rr : T_pstore_new_rr <mnemonic, MajOp, 0, 1>;
971 def S4_p#NAME#newfnew_rr : T_pstore_new_rr <mnemonic, MajOp, 1, 1>;
975 let addrMode = BaseRegOffset, InputType = "reg", hasSideEffects = 0 in {
976 let accessSize = ByteAccess in
977 defm storerb: ST_Idxd_shl<"memb", "STrib", IntRegs, 0b000>,
978 ST_Idxd_shl_nv<"memb", "STrib", IntRegs, 0b00>;
980 let accessSize = HalfWordAccess in
981 defm storerh: ST_Idxd_shl<"memh", "STrih", IntRegs, 0b010>,
982 ST_Idxd_shl_nv<"memh", "STrih", IntRegs, 0b01>;
984 let accessSize = WordAccess in
985 defm storeri: ST_Idxd_shl<"memw", "STriw", IntRegs, 0b100>,
986 ST_Idxd_shl_nv<"memw", "STriw", IntRegs, 0b10>;
988 let isNVStorable = 0, accessSize = DoubleWordAccess in
989 defm storerd: ST_Idxd_shl<"memd", "STrid", DoubleRegs, 0b110>;
991 let isNVStorable = 0, accessSize = HalfWordAccess in
992 defm storerf: ST_Idxd_shl<"memh", "STrif", IntRegs, 0b011, 1>;
995 class Storexs_pat<PatFrag Store, PatFrag Value, InstHexagon MI>
996 : Pat<(Store Value:$Ru, (add (i32 IntRegs:$Rs),
997 (i32 (shl (i32 IntRegs:$Rt), u2ImmPred:$u2)))),
998 (MI IntRegs:$Rs, IntRegs:$Rt, imm:$u2, Value:$Ru)>;
1000 let AddedComplexity = 40 in {
1001 def: Storexs_pat<truncstorei8, I32, S4_storerb_rr>;
1002 def: Storexs_pat<truncstorei16, I32, S4_storerh_rr>;
1003 def: Storexs_pat<store, I32, S4_storeri_rr>;
1004 def: Storexs_pat<store, I64, S4_storerd_rr>;
1007 // memd(Rx++#s4:3)=Rtt
1008 // memd(Rx++#s4:3:circ(Mu))=Rtt
1009 // memd(Rx++I:circ(Mu))=Rtt
1011 // memd(Rx++Mu:brev)=Rtt
1012 // memd(gp+#u16:3)=Rtt
1014 // Store doubleword conditionally.
1015 // if ([!]Pv[.new]) memd(#u6)=Rtt
1016 // TODO: needs to be implemented.
1018 //===----------------------------------------------------------------------===//
1020 //===----------------------------------------------------------------------===//
1021 let isPredicable = 1, isExtendable = 1, isExtentSigned = 1, opExtentBits = 8,
1023 class T_StoreImm <string mnemonic, Operand OffsetOp, bits<2> MajOp >
1024 : STInst <(outs ), (ins IntRegs:$Rs, OffsetOp:$offset, s8Ext:$S8),
1025 mnemonic#"($Rs+#$offset)=#$S8",
1026 [], "", V4LDST_tc_st_SLOT01>,
1027 ImmRegRel, PredNewRel {
1033 string OffsetOpStr = !cast<string>(OffsetOp);
1034 let offsetBits = !if (!eq(OffsetOpStr, "u6_2Imm"), offset{7-2},
1035 !if (!eq(OffsetOpStr, "u6_1Imm"), offset{6-1},
1036 /* u6_0Imm */ offset{5-0}));
1038 let IClass = 0b0011;
1040 let Inst{27-25} = 0b110;
1041 let Inst{22-21} = MajOp;
1042 let Inst{20-16} = Rs;
1043 let Inst{12-7} = offsetBits;
1044 let Inst{13} = S8{7};
1045 let Inst{6-0} = S8{6-0};
1048 let isPredicated = 1, isExtendable = 1, isExtentSigned = 1, opExtentBits = 6,
1050 class T_StoreImm_pred <string mnemonic, Operand OffsetOp, bits<2> MajOp,
1051 bit isPredNot, bit isPredNew >
1053 (ins PredRegs:$Pv, IntRegs:$Rs, OffsetOp:$offset, s6Ext:$S6),
1054 !if(isPredNot, "if (!$Pv", "if ($Pv")#!if(isPredNew, ".new) ",
1055 ") ")#mnemonic#"($Rs+#$offset)=#$S6",
1056 [], "", V4LDST_tc_st_SLOT01>,
1057 ImmRegRel, PredNewRel {
1064 string OffsetOpStr = !cast<string>(OffsetOp);
1065 let offsetBits = !if (!eq(OffsetOpStr, "u6_2Imm"), offset{7-2},
1066 !if (!eq(OffsetOpStr, "u6_1Imm"), offset{6-1},
1067 /* u6_0Imm */ offset{5-0}));
1068 let isPredicatedNew = isPredNew;
1069 let isPredicatedFalse = isPredNot;
1071 let IClass = 0b0011;
1073 let Inst{27-25} = 0b100;
1074 let Inst{24} = isPredNew;
1075 let Inst{23} = isPredNot;
1076 let Inst{22-21} = MajOp;
1077 let Inst{20-16} = Rs;
1078 let Inst{13} = S6{5};
1079 let Inst{12-7} = offsetBits;
1081 let Inst{4-0} = S6{4-0};
1085 //===----------------------------------------------------------------------===//
1086 // multiclass for store instructions with base + immediate offset
1087 // addressing mode and immediate stored value.
1088 // mem[bhw](Rx++#s4:3)=#s8
1089 // if ([!]Pv[.new]) mem[bhw](Rx++#s4:3)=#s6
1090 //===----------------------------------------------------------------------===//
1092 multiclass ST_Imm_Pred <string mnemonic, Operand OffsetOp, bits<2> MajOp,
1094 def _io : T_StoreImm_pred <mnemonic, OffsetOp, MajOp, PredNot, 0>;
1096 def new_io : T_StoreImm_pred <mnemonic, OffsetOp, MajOp, PredNot, 1>;
1099 multiclass ST_Imm <string mnemonic, string CextOp, Operand OffsetOp,
1101 let CextOpcode = CextOp, BaseOpcode = CextOp#_imm in {
1102 def _io : T_StoreImm <mnemonic, OffsetOp, MajOp>;
1104 defm t : ST_Imm_Pred <mnemonic, OffsetOp, MajOp, 0>;
1105 defm f : ST_Imm_Pred <mnemonic, OffsetOp, MajOp, 1>;
1109 let hasSideEffects = 0, validSubTargets = HasV4SubT, addrMode = BaseImmOffset,
1110 InputType = "imm" in {
1111 let accessSize = ByteAccess in
1112 defm S4_storeirb : ST_Imm<"memb", "STrib", u6_0Imm, 0b00>;
1114 let accessSize = HalfWordAccess in
1115 defm S4_storeirh : ST_Imm<"memh", "STrih", u6_1Imm, 0b01>;
1117 let accessSize = WordAccess in
1118 defm S4_storeiri : ST_Imm<"memw", "STriw", u6_2Imm, 0b10>;
1121 let Predicates = [HasV4T], AddedComplexity = 10 in {
1122 def: Pat<(truncstorei8 s8ExtPred:$src3, (add IntRegs:$src1, u6_0ImmPred:$src2)),
1123 (S4_storeirb_io IntRegs:$src1, u6_0ImmPred:$src2, s8ExtPred:$src3)>;
1125 def: Pat<(truncstorei16 s8ExtPred:$src3, (add IntRegs:$src1,
1126 u6_1ImmPred:$src2)),
1127 (S4_storeirh_io IntRegs:$src1, u6_1ImmPred:$src2, s8ExtPred:$src3)>;
1129 def: Pat<(store s8ExtPred:$src3, (add IntRegs:$src1, u6_2ImmPred:$src2)),
1130 (S4_storeiri_io IntRegs:$src1, u6_2ImmPred:$src2, s8ExtPred:$src3)>;
1133 let AddedComplexity = 6 in
1134 def : Pat <(truncstorei8 s8ExtPred:$src2, (i32 IntRegs:$src1)),
1135 (S4_storeirb_io IntRegs:$src1, 0, s8ExtPred:$src2)>,
1138 // memb(Rx++#s4:0:circ(Mu))=Rt
1139 // memb(Rx++I:circ(Mu))=Rt
1141 // memb(Rx++Mu:brev)=Rt
1142 // memb(gp+#u16:0)=Rt
1146 // TODO: needs to be implemented
1147 // memh(Re=#U6)=Rt.H
1148 // memh(Rs+#s11:1)=Rt.H
1149 let AddedComplexity = 6 in
1150 def : Pat <(truncstorei16 s8ExtPred:$src2, (i32 IntRegs:$src1)),
1151 (S4_storeirh_io IntRegs:$src1, 0, s8ExtPred:$src2)>,
1154 // memh(Rs+Ru<<#u2)=Rt.H
1155 // TODO: needs to be implemented.
1157 // memh(Ru<<#u2+#U6)=Rt.H
1158 // memh(Rx++#s4:1:circ(Mu))=Rt.H
1159 // memh(Rx++#s4:1:circ(Mu))=Rt
1160 // memh(Rx++I:circ(Mu))=Rt.H
1161 // memh(Rx++I:circ(Mu))=Rt
1162 // memh(Rx++Mu)=Rt.H
1164 // memh(Rx++Mu:brev)=Rt.H
1165 // memh(Rx++Mu:brev)=Rt
1166 // memh(gp+#u16:1)=Rt
1167 // if ([!]Pv[.new]) memh(#u6)=Rt.H
1168 // if ([!]Pv[.new]) memh(#u6)=Rt
1171 // if ([!]Pv[.new]) memh(Rs+#u6:1)=Rt.H
1172 // TODO: needs to be implemented.
1174 // if ([!]Pv[.new]) memh(Rx++#s4:1)=Rt.H
1175 // TODO: Needs to be implemented.
1179 // TODO: Needs to be implemented.
1181 let AddedComplexity = 6 in
1182 def : Pat <(store s8ExtPred:$src2, (i32 IntRegs:$src1)),
1183 (S4_storeiri_io IntRegs:$src1, 0, s8ExtPred:$src2)>,
1186 // memw(Rx++#s4:2)=Rt
1187 // memw(Rx++#s4:2:circ(Mu))=Rt
1188 // memw(Rx++I:circ(Mu))=Rt
1190 // memw(Rx++Mu:brev)=Rt
1192 //===----------------------------------------------------------------------===
1194 //===----------------------------------------------------------------------===
1197 //===----------------------------------------------------------------------===//
1199 //===----------------------------------------------------------------------===//
1201 let opNewValue = 2, opExtendable = 1, isExtentSigned = 1, isPredicable = 1 in
1202 class T_store_io_nv <string mnemonic, RegisterClass RC,
1203 Operand ImmOp, bits<2>MajOp>
1204 : NVInst_V4 <(outs),
1205 (ins IntRegs:$src1, ImmOp:$src2, RC:$src3),
1206 mnemonic#"($src1+#$src2) = $src3.new",
1207 [],"",ST_tc_st_SLOT0> {
1209 bits<13> src2; // Actual address offset
1211 bits<11> offsetBits; // Represents offset encoding
1213 let opExtentBits = !if (!eq(mnemonic, "memb"), 11,
1214 !if (!eq(mnemonic, "memh"), 12,
1215 !if (!eq(mnemonic, "memw"), 13, 0)));
1217 let opExtentAlign = !if (!eq(mnemonic, "memb"), 0,
1218 !if (!eq(mnemonic, "memh"), 1,
1219 !if (!eq(mnemonic, "memw"), 2, 0)));
1221 let offsetBits = !if (!eq(mnemonic, "memb"), src2{10-0},
1222 !if (!eq(mnemonic, "memh"), src2{11-1},
1223 !if (!eq(mnemonic, "memw"), src2{12-2}, 0)));
1225 let IClass = 0b1010;
1228 let Inst{26-25} = offsetBits{10-9};
1229 let Inst{24-21} = 0b1101;
1230 let Inst{20-16} = src1;
1231 let Inst{13} = offsetBits{8};
1232 let Inst{12-11} = MajOp;
1233 let Inst{10-8} = src3;
1234 let Inst{7-0} = offsetBits{7-0};
1237 let opExtendable = 2, opNewValue = 3, isPredicated = 1 in
1238 class T_pstore_io_nv <string mnemonic, RegisterClass RC, Operand predImmOp,
1239 bits<2>MajOp, bit PredNot, bit isPredNew>
1240 : NVInst_V4 <(outs),
1241 (ins PredRegs:$src1, IntRegs:$src2, predImmOp:$src3, RC:$src4),
1242 !if(PredNot, "if (!$src1", "if ($src1")#!if(isPredNew, ".new) ",
1243 ") ")#mnemonic#"($src2+#$src3) = $src4.new",
1244 [],"",V2LDST_tc_st_SLOT0> {
1249 bits<6> offsetBits; // Represents offset encoding
1251 let isPredicatedNew = isPredNew;
1252 let isPredicatedFalse = PredNot;
1253 let opExtentBits = !if (!eq(mnemonic, "memb"), 6,
1254 !if (!eq(mnemonic, "memh"), 7,
1255 !if (!eq(mnemonic, "memw"), 8, 0)));
1257 let opExtentAlign = !if (!eq(mnemonic, "memb"), 0,
1258 !if (!eq(mnemonic, "memh"), 1,
1259 !if (!eq(mnemonic, "memw"), 2, 0)));
1261 let offsetBits = !if (!eq(mnemonic, "memb"), src3{5-0},
1262 !if (!eq(mnemonic, "memh"), src3{6-1},
1263 !if (!eq(mnemonic, "memw"), src3{7-2}, 0)));
1265 let IClass = 0b0100;
1268 let Inst{26} = PredNot;
1269 let Inst{25} = isPredNew;
1270 let Inst{24-21} = 0b0101;
1271 let Inst{20-16} = src2;
1272 let Inst{13} = offsetBits{5};
1273 let Inst{12-11} = MajOp;
1274 let Inst{10-8} = src4;
1275 let Inst{7-3} = offsetBits{4-0};
1277 let Inst{1-0} = src1;
1280 // multiclass for new-value store instructions with base + immediate offset.
1282 let mayStore = 1, isNVStore = 1, isNewValue = 1, hasSideEffects = 0,
1284 multiclass ST_Idxd_nv<string mnemonic, string CextOp, RegisterClass RC,
1285 Operand ImmOp, Operand predImmOp, bits<2> MajOp> {
1287 let CextOpcode = CextOp, BaseOpcode = CextOp#_indexed in {
1288 def S2_#NAME#new_io : T_store_io_nv <mnemonic, RC, ImmOp, MajOp>;
1290 def S2_p#NAME#newt_io :T_pstore_io_nv <mnemonic, RC, predImmOp, MajOp, 0, 0>;
1291 def S2_p#NAME#newf_io :T_pstore_io_nv <mnemonic, RC, predImmOp, MajOp, 1, 0>;
1293 def S4_p#NAME#newtnew_io :T_pstore_io_nv <mnemonic, RC, predImmOp,
1295 def S4_p#NAME#newfnew_io :T_pstore_io_nv <mnemonic, RC, predImmOp,
1300 let addrMode = BaseImmOffset, InputType = "imm" in {
1301 let accessSize = ByteAccess in
1302 defm storerb: ST_Idxd_nv<"memb", "STrib", IntRegs, s11_0Ext,
1303 u6_0Ext, 0b00>, AddrModeRel;
1305 let accessSize = HalfWordAccess, opExtentAlign = 1 in
1306 defm storerh: ST_Idxd_nv<"memh", "STrih", IntRegs, s11_1Ext,
1307 u6_1Ext, 0b01>, AddrModeRel;
1309 let accessSize = WordAccess, opExtentAlign = 2 in
1310 defm storeri: ST_Idxd_nv<"memw", "STriw", IntRegs, s11_2Ext,
1311 u6_2Ext, 0b10>, AddrModeRel;
1314 //===----------------------------------------------------------------------===//
1315 // Post increment loads with register offset.
1316 //===----------------------------------------------------------------------===//
1318 let hasNewValue = 1 in
1319 def L2_loadbsw2_pr : T_load_pr <"membh", IntRegs, 0b0001, HalfWordAccess>;
1321 def L2_loadbsw4_pr : T_load_pr <"membh", DoubleRegs, 0b0111, WordAccess>;
1323 //===----------------------------------------------------------------------===//
1324 // Template class for non-predicated post increment .new stores
1325 // mem[bhwd](Rx++#s4:[0123])=Nt.new
1326 //===----------------------------------------------------------------------===//
1327 let isPredicable = 1, hasSideEffects = 0, validSubTargets = HasV4SubT,
1328 addrMode = PostInc, isNVStore = 1, isNewValue = 1, opNewValue = 3 in
1329 class T_StorePI_nv <string mnemonic, Operand ImmOp, bits<2> MajOp >
1330 : NVInstPI_V4 <(outs IntRegs:$_dst_),
1331 (ins IntRegs:$src1, ImmOp:$offset, IntRegs:$src2),
1332 mnemonic#"($src1++#$offset) = $src2.new",
1333 [], "$src1 = $_dst_">,
1340 string ImmOpStr = !cast<string>(ImmOp);
1341 let offsetBits = !if (!eq(ImmOpStr, "s4_2Imm"), offset{5-2},
1342 !if (!eq(ImmOpStr, "s4_1Imm"), offset{4-1},
1343 /* s4_0Imm */ offset{3-0}));
1344 let IClass = 0b1010;
1346 let Inst{27-21} = 0b1011101;
1347 let Inst{20-16} = src1;
1349 let Inst{12-11} = MajOp;
1350 let Inst{10-8} = src2;
1352 let Inst{6-3} = offsetBits;
1356 //===----------------------------------------------------------------------===//
1357 // Template class for predicated post increment .new stores
1358 // if([!]Pv[.new]) mem[bhwd](Rx++#s4:[0123])=Nt.new
1359 //===----------------------------------------------------------------------===//
1360 let isPredicated = 1, hasSideEffects = 0, validSubTargets = HasV4SubT,
1361 addrMode = PostInc, isNVStore = 1, isNewValue = 1, opNewValue = 4 in
1362 class T_StorePI_nv_pred <string mnemonic, Operand ImmOp,
1363 bits<2> MajOp, bit isPredNot, bit isPredNew >
1364 : NVInstPI_V4 <(outs IntRegs:$_dst_),
1365 (ins PredRegs:$src1, IntRegs:$src2,
1366 ImmOp:$offset, IntRegs:$src3),
1367 !if(isPredNot, "if (!$src1", "if ($src1")#!if(isPredNew, ".new) ",
1368 ") ")#mnemonic#"($src2++#$offset) = $src3.new",
1369 [], "$src2 = $_dst_">,
1377 string ImmOpStr = !cast<string>(ImmOp);
1378 let offsetBits = !if (!eq(ImmOpStr, "s4_2Imm"), offset{5-2},
1379 !if (!eq(ImmOpStr, "s4_1Imm"), offset{4-1},
1380 /* s4_0Imm */ offset{3-0}));
1381 let isPredicatedNew = isPredNew;
1382 let isPredicatedFalse = isPredNot;
1384 let IClass = 0b1010;
1386 let Inst{27-21} = 0b1011101;
1387 let Inst{20-16} = src2;
1389 let Inst{12-11} = MajOp;
1390 let Inst{10-8} = src3;
1391 let Inst{7} = isPredNew;
1392 let Inst{6-3} = offsetBits;
1393 let Inst{2} = isPredNot;
1394 let Inst{1-0} = src1;
1397 multiclass ST_PostInc_Pred_nv<string mnemonic, Operand ImmOp,
1398 bits<2> MajOp, bit PredNot> {
1399 def _pi : T_StorePI_nv_pred <mnemonic, ImmOp, MajOp, PredNot, 0>;
1402 def new_pi : T_StorePI_nv_pred <mnemonic, ImmOp, MajOp, PredNot, 1>;
1405 multiclass ST_PostInc_nv<string mnemonic, string BaseOp, Operand ImmOp,
1407 let BaseOpcode = "POST_"#BaseOp in {
1408 def S2_#NAME#_pi : T_StorePI_nv <mnemonic, ImmOp, MajOp>;
1411 defm S2_p#NAME#t : ST_PostInc_Pred_nv <mnemonic, ImmOp, MajOp, 0>;
1412 defm S2_p#NAME#f : ST_PostInc_Pred_nv <mnemonic, ImmOp, MajOp, 1>;
1416 let accessSize = ByteAccess in
1417 defm storerbnew: ST_PostInc_nv <"memb", "STrib", s4_0Imm, 0b00>;
1419 let accessSize = HalfWordAccess in
1420 defm storerhnew: ST_PostInc_nv <"memh", "STrih", s4_1Imm, 0b01>;
1422 let accessSize = WordAccess in
1423 defm storerinew: ST_PostInc_nv <"memw", "STriw", s4_2Imm, 0b10>;
1425 //===----------------------------------------------------------------------===//
1426 // Template class for post increment .new stores with register offset
1427 //===----------------------------------------------------------------------===//
1428 let isNewValue = 1, mayStore = 1, isNVStore = 1, opNewValue = 3 in
1429 class T_StorePI_RegNV <string mnemonic, bits<2> MajOp, MemAccessSize AccessSz>
1430 : NVInstPI_V4 <(outs IntRegs:$_dst_),
1431 (ins IntRegs:$src1, ModRegs:$src2, IntRegs:$src3),
1432 #mnemonic#"($src1++$src2) = $src3.new",
1433 [], "$src1 = $_dst_"> {
1437 let accessSize = AccessSz;
1439 let IClass = 0b1010;
1441 let Inst{27-21} = 0b1101101;
1442 let Inst{20-16} = src1;
1443 let Inst{13} = src2;
1444 let Inst{12-11} = MajOp;
1445 let Inst{10-8} = src3;
1449 def S2_storerbnew_pr : T_StorePI_RegNV<"memb", 0b00, ByteAccess>;
1450 def S2_storerhnew_pr : T_StorePI_RegNV<"memh", 0b01, HalfWordAccess>;
1451 def S2_storerinew_pr : T_StorePI_RegNV<"memw", 0b10, WordAccess>;
1453 // memb(Rx++#s4:0:circ(Mu))=Nt.new
1454 // memb(Rx++I:circ(Mu))=Nt.new
1455 // memb(Rx++Mu)=Nt.new
1456 // memb(Rx++Mu:brev)=Nt.new
1457 // memh(Rx++#s4:1:circ(Mu))=Nt.new
1458 // memh(Rx++I:circ(Mu))=Nt.new
1459 // memh(Rx++Mu)=Nt.new
1460 // memh(Rx++Mu:brev)=Nt.new
1462 // memw(Rx++#s4:2:circ(Mu))=Nt.new
1463 // memw(Rx++I:circ(Mu))=Nt.new
1464 // memw(Rx++Mu)=Nt.new
1465 // memw(Rx++Mu:brev)=Nt.new
1467 //===----------------------------------------------------------------------===//
1469 //===----------------------------------------------------------------------===//
1471 //===----------------------------------------------------------------------===//
1473 //===----------------------------------------------------------------------===//
1475 //===----------------------------------------------------------------------===//
1476 // multiclass/template class for the new-value compare jumps with the register
1478 //===----------------------------------------------------------------------===//
1480 let isExtendable = 1, opExtendable = 2, isExtentSigned = 1, opExtentBits = 11,
1481 opExtentAlign = 2 in
1482 class NVJrr_template<string mnemonic, bits<3> majOp, bit NvOpNum,
1483 bit isNegCond, bit isTak>
1485 (ins IntRegs:$src1, IntRegs:$src2, brtarget:$offset),
1486 "if ("#!if(isNegCond, "!","")#mnemonic#
1487 "($src1"#!if(!eq(NvOpNum, 0),".new, ",", ")#
1488 "$src2"#!if(!eq(NvOpNum, 1),".new))","))")#" jump:"
1489 #!if(isTak, "t","nt")#" $offset", []> {
1493 bits<3> Ns; // New-Value Operand
1494 bits<5> RegOp; // Non-New-Value Operand
1497 let isTaken = isTak;
1498 let isPredicatedFalse = isNegCond;
1499 let opNewValue{0} = NvOpNum;
1501 let Ns = !if(!eq(NvOpNum, 0), src1{2-0}, src2{2-0});
1502 let RegOp = !if(!eq(NvOpNum, 0), src2, src1);
1504 let IClass = 0b0010;
1506 let Inst{25-23} = majOp;
1507 let Inst{22} = isNegCond;
1508 let Inst{18-16} = Ns;
1509 let Inst{13} = isTak;
1510 let Inst{12-8} = RegOp;
1511 let Inst{21-20} = offset{10-9};
1512 let Inst{7-1} = offset{8-2};
1516 multiclass NVJrr_cond<string mnemonic, bits<3> majOp, bit NvOpNum,
1518 // Branch not taken:
1519 def _nt_V4: NVJrr_template<mnemonic, majOp, NvOpNum, isNegCond, 0>;
1521 def _t_V4: NVJrr_template<mnemonic, majOp, NvOpNum, isNegCond, 1>;
1524 // NvOpNum = 0 -> First Operand is a new-value Register
1525 // NvOpNum = 1 -> Second Operand is a new-value Register
1527 multiclass NVJrr_base<string mnemonic, string BaseOp, bits<3> majOp,
1529 let BaseOpcode = BaseOp#_NVJ in {
1530 defm _t_Jumpnv : NVJrr_cond<mnemonic, majOp, NvOpNum, 0>; // True cond
1531 defm _f_Jumpnv : NVJrr_cond<mnemonic, majOp, NvOpNum, 1>; // False cond
1535 // if ([!]cmp.eq(Ns.new,Rt)) jump:[n]t #r9:2
1536 // if ([!]cmp.gt(Ns.new,Rt)) jump:[n]t #r9:2
1537 // if ([!]cmp.gtu(Ns.new,Rt)) jump:[n]t #r9:2
1538 // if ([!]cmp.gt(Rt,Ns.new)) jump:[n]t #r9:2
1539 // if ([!]cmp.gtu(Rt,Ns.new)) jump:[n]t #r9:2
1541 let isPredicated = 1, isBranch = 1, isNewValue = 1, isTerminator = 1,
1542 Defs = [PC], hasSideEffects = 0, validSubTargets = HasV4SubT in {
1543 defm CMPEQrr : NVJrr_base<"cmp.eq", "CMPEQ", 0b000, 0>, PredRel;
1544 defm CMPGTrr : NVJrr_base<"cmp.gt", "CMPGT", 0b001, 0>, PredRel;
1545 defm CMPGTUrr : NVJrr_base<"cmp.gtu", "CMPGTU", 0b010, 0>, PredRel;
1546 defm CMPLTrr : NVJrr_base<"cmp.gt", "CMPLT", 0b011, 1>, PredRel;
1547 defm CMPLTUrr : NVJrr_base<"cmp.gtu", "CMPLTU", 0b100, 1>, PredRel;
1550 //===----------------------------------------------------------------------===//
1551 // multiclass/template class for the new-value compare jumps instruction
1552 // with a register and an unsigned immediate (U5) operand.
1553 //===----------------------------------------------------------------------===//
1555 let isExtendable = 1, opExtendable = 2, isExtentSigned = 1, opExtentBits = 11,
1556 opExtentAlign = 2 in
1557 class NVJri_template<string mnemonic, bits<3> majOp, bit isNegCond,
1560 (ins IntRegs:$src1, u5Imm:$src2, brtarget:$offset),
1561 "if ("#!if(isNegCond, "!","")#mnemonic#"($src1.new, #$src2)) jump:"
1562 #!if(isTak, "t","nt")#" $offset", []> {
1564 let isTaken = isTak;
1565 let isPredicatedFalse = isNegCond;
1566 let isTaken = isTak;
1572 let IClass = 0b0010;
1574 let Inst{25-23} = majOp;
1575 let Inst{22} = isNegCond;
1576 let Inst{18-16} = src1;
1577 let Inst{13} = isTak;
1578 let Inst{12-8} = src2;
1579 let Inst{21-20} = offset{10-9};
1580 let Inst{7-1} = offset{8-2};
1583 multiclass NVJri_cond<string mnemonic, bits<3> majOp, bit isNegCond> {
1584 // Branch not taken:
1585 def _nt_V4: NVJri_template<mnemonic, majOp, isNegCond, 0>;
1587 def _t_V4: NVJri_template<mnemonic, majOp, isNegCond, 1>;
1590 multiclass NVJri_base<string mnemonic, string BaseOp, bits<3> majOp> {
1591 let BaseOpcode = BaseOp#_NVJri in {
1592 defm _t_Jumpnv : NVJri_cond<mnemonic, majOp, 0>; // True Cond
1593 defm _f_Jumpnv : NVJri_cond<mnemonic, majOp, 1>; // False cond
1597 // if ([!]cmp.eq(Ns.new,#U5)) jump:[n]t #r9:2
1598 // if ([!]cmp.gt(Ns.new,#U5)) jump:[n]t #r9:2
1599 // if ([!]cmp.gtu(Ns.new,#U5)) jump:[n]t #r9:2
1601 let isPredicated = 1, isBranch = 1, isNewValue = 1, isTerminator = 1,
1602 Defs = [PC], hasSideEffects = 0, validSubTargets = HasV4SubT in {
1603 defm CMPEQri : NVJri_base<"cmp.eq", "CMPEQ", 0b000>, PredRel;
1604 defm CMPGTri : NVJri_base<"cmp.gt", "CMPGT", 0b001>, PredRel;
1605 defm CMPGTUri : NVJri_base<"cmp.gtu", "CMPGTU", 0b010>, PredRel;
1608 //===----------------------------------------------------------------------===//
1609 // multiclass/template class for the new-value compare jumps instruction
1610 // with a register and an hardcoded 0/-1 immediate value.
1611 //===----------------------------------------------------------------------===//
1613 let isExtendable = 1, opExtendable = 1, isExtentSigned = 1, opExtentBits = 11,
1614 opExtentAlign = 2 in
1615 class NVJ_ConstImm_template<string mnemonic, bits<3> majOp, string ImmVal,
1616 bit isNegCond, bit isTak>
1618 (ins IntRegs:$src1, brtarget:$offset),
1619 "if ("#!if(isNegCond, "!","")#mnemonic
1620 #"($src1.new, #"#ImmVal#")) jump:"
1621 #!if(isTak, "t","nt")#" $offset", []> {
1623 let isTaken = isTak;
1624 let isPredicatedFalse = isNegCond;
1625 let isTaken = isTak;
1629 let IClass = 0b0010;
1631 let Inst{25-23} = majOp;
1632 let Inst{22} = isNegCond;
1633 let Inst{18-16} = src1;
1634 let Inst{13} = isTak;
1635 let Inst{21-20} = offset{10-9};
1636 let Inst{7-1} = offset{8-2};
1639 multiclass NVJ_ConstImm_cond<string mnemonic, bits<3> majOp, string ImmVal,
1641 // Branch not taken:
1642 def _nt_V4: NVJ_ConstImm_template<mnemonic, majOp, ImmVal, isNegCond, 0>;
1644 def _t_V4: NVJ_ConstImm_template<mnemonic, majOp, ImmVal, isNegCond, 1>;
1647 multiclass NVJ_ConstImm_base<string mnemonic, string BaseOp, bits<3> majOp,
1649 let BaseOpcode = BaseOp#_NVJ_ConstImm in {
1650 defm _t_Jumpnv : NVJ_ConstImm_cond<mnemonic, majOp, ImmVal, 0>; // True
1651 defm _f_Jumpnv : NVJ_ConstImm_cond<mnemonic, majOp, ImmVal, 1>; // False
1655 // if ([!]tstbit(Ns.new,#0)) jump:[n]t #r9:2
1656 // if ([!]cmp.eq(Ns.new,#-1)) jump:[n]t #r9:2
1657 // if ([!]cmp.gt(Ns.new,#-1)) jump:[n]t #r9:2
1659 let isPredicated = 1, isBranch = 1, isNewValue = 1, isTerminator=1,
1660 Defs = [PC], hasSideEffects = 0 in {
1661 defm TSTBIT0 : NVJ_ConstImm_base<"tstbit", "TSTBIT", 0b011, "0">, PredRel;
1662 defm CMPEQn1 : NVJ_ConstImm_base<"cmp.eq", "CMPEQ", 0b100, "-1">, PredRel;
1663 defm CMPGTn1 : NVJ_ConstImm_base<"cmp.gt", "CMPGT", 0b101, "-1">, PredRel;
1666 // J4_hintjumpr: Hint indirect conditional jump.
1667 let isBranch = 1, isIndirectBranch = 1, hasSideEffects = 0 in
1668 def J4_hintjumpr: JRInst <
1673 let IClass = 0b0101;
1674 let Inst{27-21} = 0b0010101;
1675 let Inst{20-16} = Rs;
1678 //===----------------------------------------------------------------------===//
1680 //===----------------------------------------------------------------------===//
1682 //===----------------------------------------------------------------------===//
1684 //===----------------------------------------------------------------------===//
1687 let hasNewValue = 1, isExtendable = 1, opExtendable = 1,
1688 isExtentSigned = 0, opExtentBits = 6, hasSideEffects = 0,
1689 Uses = [PC], validSubTargets = HasV4SubT in
1690 def C4_addipc : CRInst <(outs IntRegs:$Rd), (ins u6Ext:$u6),
1691 "$Rd = add(pc, #$u6)", [], "", CR_tc_2_SLOT3 > {
1695 let IClass = 0b0110;
1696 let Inst{27-16} = 0b101001001001;
1697 let Inst{12-7} = u6;
1703 let hasSideEffects = 0 in
1704 class T_LOGICAL_3OP<string MnOp1, string MnOp2, bits<2> OpBits, bit IsNeg>
1705 : CRInst<(outs PredRegs:$Pd),
1706 (ins PredRegs:$Ps, PredRegs:$Pt, PredRegs:$Pu),
1707 "$Pd = " # MnOp1 # "($Ps, " # MnOp2 # "($Pt, " #
1708 !if (IsNeg,"!","") # "$Pu))",
1709 [], "", CR_tc_2early_SLOT23> {
1715 let IClass = 0b0110;
1716 let Inst{27-24} = 0b1011;
1717 let Inst{23} = IsNeg;
1718 let Inst{22-21} = OpBits;
1720 let Inst{17-16} = Ps;
1727 def C4_and_and : T_LOGICAL_3OP<"and", "and", 0b00, 0>;
1728 def C4_and_or : T_LOGICAL_3OP<"and", "or", 0b01, 0>;
1729 def C4_or_and : T_LOGICAL_3OP<"or", "and", 0b10, 0>;
1730 def C4_or_or : T_LOGICAL_3OP<"or", "or", 0b11, 0>;
1731 def C4_and_andn : T_LOGICAL_3OP<"and", "and", 0b00, 1>;
1732 def C4_and_orn : T_LOGICAL_3OP<"and", "or", 0b01, 1>;
1733 def C4_or_andn : T_LOGICAL_3OP<"or", "and", 0b10, 1>;
1734 def C4_or_orn : T_LOGICAL_3OP<"or", "or", 0b11, 1>;
1736 //===----------------------------------------------------------------------===//
1738 //===----------------------------------------------------------------------===//
1740 //===----------------------------------------------------------------------===//
1742 //===----------------------------------------------------------------------===//
1744 // Logical with-not instructions.
1745 let validSubTargets = HasV4SubT in {
1746 def A4_andnp : T_ALU64_logical<"and", 0b001, 1, 0, 1>;
1747 def A4_ornp : T_ALU64_logical<"or", 0b011, 1, 0, 1>;
1750 let hasNewValue = 1, hasSideEffects = 0 in
1751 def S4_parity: ALU64Inst<(outs IntRegs:$Rd), (ins IntRegs:$Rs, IntRegs:$Rt),
1752 "$Rd = parity($Rs, $Rt)", [], "", ALU64_tc_2_SLOT23> {
1757 let IClass = 0b1101;
1758 let Inst{27-21} = 0b0101111;
1759 let Inst{20-16} = Rs;
1760 let Inst{12-8} = Rt;
1763 // Add and accumulate.
1764 // Rd=add(Rs,add(Ru,#s6))
1765 let isExtentSigned = 1, hasNewValue = 1, isExtendable = 1, opExtentBits = 6,
1767 def S4_addaddi : ALU64Inst <(outs IntRegs:$Rd),
1768 (ins IntRegs:$Rs, IntRegs:$Ru, s6Ext:$s6),
1769 "$Rd = add($Rs, add($Ru, #$s6))" ,
1770 [(set (i32 IntRegs:$Rd), (add (i32 IntRegs:$Rs),
1771 (add (i32 IntRegs:$Ru), s6_16ExtPred:$s6)))],
1772 "", ALU64_tc_2_SLOT23> {
1778 let IClass = 0b1101;
1780 let Inst{27-23} = 0b10110;
1781 let Inst{22-21} = s6{5-4};
1782 let Inst{20-16} = Rs;
1783 let Inst{13} = s6{3};
1784 let Inst{12-8} = Rd;
1785 let Inst{7-5} = s6{2-0};
1789 let isExtentSigned = 1, hasSideEffects = 0, hasNewValue = 1, isExtendable = 1,
1790 opExtentBits = 6, opExtendable = 2 in
1791 def S4_subaddi: ALU64Inst <(outs IntRegs:$Rd),
1792 (ins IntRegs:$Rs, s6Ext:$s6, IntRegs:$Ru),
1793 "$Rd = add($Rs, sub(#$s6, $Ru))",
1794 [], "", ALU64_tc_2_SLOT23> {
1800 let IClass = 0b1101;
1802 let Inst{27-23} = 0b10111;
1803 let Inst{22-21} = s6{5-4};
1804 let Inst{20-16} = Rs;
1805 let Inst{13} = s6{3};
1806 let Inst{12-8} = Rd;
1807 let Inst{7-5} = s6{2-0};
1812 // Rdd=extract(Rss,#u6,#U6)
1813 // Rdd=extract(Rss,Rtt)
1814 // Rd=extract(Rs,Rtt)
1815 // Rd=extract(Rs,#u5,#U5)
1817 def S4_extractp_rp : T_S3op_64 < "extract", 0b11, 0b100, 0>;
1818 def S4_extractp : T_S2op_extract <"extract", 0b1010, DoubleRegs, u6Imm>;
1820 let hasNewValue = 1 in {
1821 def S4_extract_rp : T_S3op_extract<"extract", 0b01>;
1822 def S4_extract : T_S2op_extract <"extract", 0b1101, IntRegs, u5Imm>;
1825 // Complex add/sub halfwords/words
1826 let Defs = [USR_OVF] in {
1827 def S4_vxaddsubh : T_S3op_64 < "vxaddsubh", 0b01, 0b100, 0, 1>;
1828 def S4_vxaddsubw : T_S3op_64 < "vxaddsubw", 0b01, 0b000, 0, 1>;
1829 def S4_vxsubaddh : T_S3op_64 < "vxsubaddh", 0b01, 0b110, 0, 1>;
1830 def S4_vxsubaddw : T_S3op_64 < "vxsubaddw", 0b01, 0b010, 0, 1>;
1833 let Defs = [USR_OVF] in {
1834 def S4_vxaddsubhr : T_S3op_64 < "vxaddsubh", 0b11, 0b000, 0, 1, 1, 1>;
1835 def S4_vxsubaddhr : T_S3op_64 < "vxsubaddh", 0b11, 0b010, 0, 1, 1, 1>;
1838 let Itinerary = M_tc_3x_SLOT23, Defs = [USR_OVF] in {
1839 def M4_mac_up_s1_sat: T_MType_acc_rr<"+= mpy", 0b011, 0b000, 0, [], 0, 1, 1>;
1840 def M4_nac_up_s1_sat: T_MType_acc_rr<"-= mpy", 0b011, 0b001, 0, [], 0, 1, 1>;
1843 // Logical xor with xor accumulation.
1844 // Rxx^=xor(Rss,Rtt)
1845 let hasSideEffects = 0 in
1847 : SInst <(outs DoubleRegs:$Rxx),
1848 (ins DoubleRegs:$dst2, DoubleRegs:$Rss, DoubleRegs:$Rtt),
1849 "$Rxx ^= xor($Rss, $Rtt)",
1850 [(set (i64 DoubleRegs:$Rxx),
1851 (xor (i64 DoubleRegs:$dst2), (xor (i64 DoubleRegs:$Rss),
1852 (i64 DoubleRegs:$Rtt))))],
1853 "$dst2 = $Rxx", S_3op_tc_1_SLOT23> {
1858 let IClass = 0b1100;
1860 let Inst{27-23} = 0b10101;
1861 let Inst{20-16} = Rss;
1862 let Inst{12-8} = Rtt;
1863 let Inst{4-0} = Rxx;
1866 // Rotate and reduce bytes
1867 // Rdd=vrcrotate(Rss,Rt,#u2)
1868 let hasSideEffects = 0 in
1870 : SInst <(outs DoubleRegs:$Rdd),
1871 (ins DoubleRegs:$Rss, IntRegs:$Rt, u2Imm:$u2),
1872 "$Rdd = vrcrotate($Rss, $Rt, #$u2)",
1873 [], "", S_3op_tc_3x_SLOT23> {
1879 let IClass = 0b1100;
1881 let Inst{27-22} = 0b001111;
1882 let Inst{20-16} = Rss;
1883 let Inst{13} = u2{1};
1884 let Inst{12-8} = Rt;
1885 let Inst{7-6} = 0b11;
1886 let Inst{5} = u2{0};
1887 let Inst{4-0} = Rdd;
1890 // Rotate and reduce bytes with accumulation
1891 // Rxx+=vrcrotate(Rss,Rt,#u2)
1892 let hasSideEffects = 0 in
1893 def S4_vrcrotate_acc
1894 : SInst <(outs DoubleRegs:$Rxx),
1895 (ins DoubleRegs:$dst2, DoubleRegs:$Rss, IntRegs:$Rt, u2Imm:$u2),
1896 "$Rxx += vrcrotate($Rss, $Rt, #$u2)", [],
1897 "$dst2 = $Rxx", S_3op_tc_3x_SLOT23> {
1903 let IClass = 0b1100;
1905 let Inst{27-21} = 0b1011101;
1906 let Inst{20-16} = Rss;
1907 let Inst{13} = u2{1};
1908 let Inst{12-8} = Rt;
1909 let Inst{5} = u2{0};
1910 let Inst{4-0} = Rxx;
1914 // Vector reduce conditional negate halfwords
1915 let hasSideEffects = 0 in
1917 : SInst <(outs DoubleRegs:$Rxx),
1918 (ins DoubleRegs:$dst2, DoubleRegs:$Rss, IntRegs:$Rt),
1919 "$Rxx += vrcnegh($Rss, $Rt)", [],
1920 "$dst2 = $Rxx", S_3op_tc_3x_SLOT23> {
1925 let IClass = 0b1100;
1927 let Inst{27-21} = 0b1011001;
1928 let Inst{20-16} = Rss;
1930 let Inst{12-8} = Rt;
1931 let Inst{7-5} = 0b111;
1932 let Inst{4-0} = Rxx;
1936 def A4_bitspliti : T_S2op_2_di <"bitsplit", 0b110, 0b100>;
1938 // Arithmetic/Convergent round
1939 def A4_cround_ri : T_S2op_2_ii <"cround", 0b111, 0b000>;
1941 def A4_round_ri : T_S2op_2_ii <"round", 0b111, 0b100>;
1943 let Defs = [USR_OVF] in
1944 def A4_round_ri_sat : T_S2op_2_ii <"round", 0b111, 0b110, 1>;
1946 // Logical-logical words.
1947 // Compound or-and -- Rx=or(Ru,and(Rx,#s10))
1948 let isExtentSigned = 1, hasNewValue = 1, isExtendable = 1, opExtentBits = 10,
1951 ALU64Inst<(outs IntRegs:$Rx),
1952 (ins IntRegs:$Ru, IntRegs:$_src_, s10Ext:$s10),
1953 "$Rx = or($Ru, and($_src_, #$s10))" ,
1954 [(set (i32 IntRegs:$Rx),
1955 (or (i32 IntRegs:$Ru), (and (i32 IntRegs:$_src_), s10ExtPred:$s10)))] ,
1956 "$_src_ = $Rx", ALU64_tc_2_SLOT23> {
1961 let IClass = 0b1101;
1963 let Inst{27-22} = 0b101001;
1964 let Inst{20-16} = Rx;
1965 let Inst{21} = s10{9};
1966 let Inst{13-5} = s10{8-0};
1970 // Miscellaneous ALU64 instructions.
1972 let hasNewValue = 1, hasSideEffects = 0 in
1973 def A4_modwrapu: ALU64Inst<(outs IntRegs:$Rd), (ins IntRegs:$Rs, IntRegs:$Rt),
1974 "$Rd = modwrap($Rs, $Rt)", [], "", ALU64_tc_2_SLOT23> {
1979 let IClass = 0b1101;
1980 let Inst{27-21} = 0b0011111;
1981 let Inst{20-16} = Rs;
1982 let Inst{12-8} = Rt;
1983 let Inst{7-5} = 0b111;
1987 let hasSideEffects = 0 in
1988 def A4_bitsplit: ALU64Inst<(outs DoubleRegs:$Rd),
1989 (ins IntRegs:$Rs, IntRegs:$Rt),
1990 "$Rd = bitsplit($Rs, $Rt)", [], "", ALU64_tc_1_SLOT23> {
1995 let IClass = 0b1101;
1996 let Inst{27-24} = 0b0100;
1998 let Inst{20-16} = Rs;
1999 let Inst{12-8} = Rt;
2003 // Rx[&|]=xor(Rs,Rt)
2004 def M4_or_xor : T_MType_acc_rr < "|= xor", 0b110, 0b001, 0>;
2005 def M4_and_xor : T_MType_acc_rr < "&= xor", 0b010, 0b010, 0>;
2007 // Rx[&|^]=or(Rs,Rt)
2008 def M4_xor_or : T_MType_acc_rr < "^= or", 0b110, 0b011, 0>;
2010 let CextOpcode = "ORr_ORr" in
2011 def M4_or_or : T_MType_acc_rr < "|= or", 0b110, 0b000, 0>;
2012 def M4_and_or : T_MType_acc_rr < "&= or", 0b010, 0b001, 0>;
2014 // Rx[&|^]=and(Rs,Rt)
2015 def M4_xor_and : T_MType_acc_rr < "^= and", 0b110, 0b010, 0>;
2017 let CextOpcode = "ORr_ANDr" in
2018 def M4_or_and : T_MType_acc_rr < "|= and", 0b010, 0b011, 0>;
2019 def M4_and_and : T_MType_acc_rr < "&= and", 0b010, 0b000, 0>;
2021 // Rx[&|^]=and(Rs,~Rt)
2022 def M4_xor_andn : T_MType_acc_rr < "^= and", 0b001, 0b010, 0, [], 1>;
2023 def M4_or_andn : T_MType_acc_rr < "|= and", 0b001, 0b000, 0, [], 1>;
2024 def M4_and_andn : T_MType_acc_rr < "&= and", 0b001, 0b001, 0, [], 1>;
2026 // Compound or-or and or-and
2027 let isExtentSigned = 1, InputType = "imm", hasNewValue = 1, isExtendable = 1,
2028 opExtentBits = 10, opExtendable = 3 in
2029 class T_CompOR <string mnemonic, bits<2> MajOp, SDNode OpNode>
2030 : MInst_acc <(outs IntRegs:$Rx),
2031 (ins IntRegs:$src1, IntRegs:$Rs, s10Ext:$s10),
2032 "$Rx |= "#mnemonic#"($Rs, #$s10)",
2033 [(set (i32 IntRegs:$Rx), (or (i32 IntRegs:$src1),
2034 (OpNode (i32 IntRegs:$Rs), s10ExtPred:$s10)))],
2035 "$src1 = $Rx", ALU64_tc_2_SLOT23>, ImmRegRel {
2040 let IClass = 0b1101;
2042 let Inst{27-24} = 0b1010;
2043 let Inst{23-22} = MajOp;
2044 let Inst{20-16} = Rs;
2045 let Inst{21} = s10{9};
2046 let Inst{13-5} = s10{8-0};
2050 let CextOpcode = "ORr_ANDr" in
2051 def S4_or_andi : T_CompOR <"and", 0b00, and>;
2053 let CextOpcode = "ORr_ORr" in
2054 def S4_or_ori : T_CompOR <"or", 0b10, or>;
2057 // Rd=modwrap(Rs,Rt)
2059 // Rd=cround(Rs,#u5)
2061 // Rd=round(Rs,#u5)[:sat]
2062 // Rd=round(Rs,Rt)[:sat]
2063 // Vector reduce add unsigned halfwords
2064 // Rd=vraddh(Rss,Rtt)
2066 // Rdd=vaddb(Rss,Rtt)
2067 // Vector conditional negate
2068 // Rdd=vcnegh(Rss,Rt)
2069 // Rxx+=vrcnegh(Rss,Rt)
2070 // Vector maximum bytes
2071 // Rdd=vmaxb(Rtt,Rss)
2072 // Vector reduce maximum halfwords
2073 // Rxx=vrmaxh(Rss,Ru)
2074 // Rxx=vrmaxuh(Rss,Ru)
2075 // Vector reduce maximum words
2076 // Rxx=vrmaxuw(Rss,Ru)
2077 // Rxx=vrmaxw(Rss,Ru)
2078 // Vector minimum bytes
2079 // Rdd=vminb(Rtt,Rss)
2080 // Vector reduce minimum halfwords
2081 // Rxx=vrminh(Rss,Ru)
2082 // Rxx=vrminuh(Rss,Ru)
2083 // Vector reduce minimum words
2084 // Rxx=vrminuw(Rss,Ru)
2085 // Rxx=vrminw(Rss,Ru)
2086 // Vector subtract bytes
2087 // Rdd=vsubb(Rss,Rtt)
2089 //===----------------------------------------------------------------------===//
2091 //===----------------------------------------------------------------------===//
2093 //===----------------------------------------------------------------------===//
2095 //===----------------------------------------------------------------------===//
2098 def S2_brevp : T_S2op_3 <"brev", 0b11, 0b110>;
2101 def S2_ct0p : T_COUNT_LEADING_64<"ct0", 0b111, 0b010>;
2102 def S2_ct1p : T_COUNT_LEADING_64<"ct1", 0b111, 0b100>;
2103 def S4_clbpnorm : T_COUNT_LEADING_64<"normamt", 0b011, 0b000>;
2105 def: Pat<(i32 (trunc (cttz (i64 DoubleRegs:$Rss)))),
2106 (S2_ct0p (i64 DoubleRegs:$Rss))>;
2107 def: Pat<(i32 (trunc (cttz (not (i64 DoubleRegs:$Rss))))),
2108 (S2_ct1p (i64 DoubleRegs:$Rss))>;
2110 let hasSideEffects = 0, hasNewValue = 1 in
2111 def S4_clbaddi : SInst<(outs IntRegs:$Rd), (ins IntRegs:$Rs, s6Imm:$s6),
2112 "$Rd = add(clb($Rs), #$s6)", [], "", S_2op_tc_2_SLOT23> {
2116 let IClass = 0b1000;
2117 let Inst{27-24} = 0b1100;
2118 let Inst{23-21} = 0b001;
2119 let Inst{20-16} = Rs;
2120 let Inst{13-8} = s6;
2121 let Inst{7-5} = 0b000;
2125 let hasSideEffects = 0, hasNewValue = 1 in
2126 def S4_clbpaddi : SInst<(outs IntRegs:$Rd), (ins DoubleRegs:$Rs, s6Imm:$s6),
2127 "$Rd = add(clb($Rs), #$s6)", [], "", S_2op_tc_2_SLOT23> {
2131 let IClass = 0b1000;
2132 let Inst{27-24} = 0b1000;
2133 let Inst{23-21} = 0b011;
2134 let Inst{20-16} = Rs;
2135 let Inst{13-8} = s6;
2136 let Inst{7-5} = 0b010;
2141 // Bit test/set/clear
2142 def S4_ntstbit_i : T_TEST_BIT_IMM<"!tstbit", 0b001>;
2143 def S4_ntstbit_r : T_TEST_BIT_REG<"!tstbit", 1>;
2145 let AddedComplexity = 20 in { // Complexity greater than cmp reg-imm.
2146 def: Pat<(i1 (seteq (and (shl 1, u5ImmPred:$u5), (i32 IntRegs:$Rs)), 0)),
2147 (S4_ntstbit_i (i32 IntRegs:$Rs), u5ImmPred:$u5)>;
2148 def: Pat<(i1 (seteq (and (shl 1, (i32 IntRegs:$Rt)), (i32 IntRegs:$Rs)), 0)),
2149 (S4_ntstbit_r (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))>;
2152 // Add extra complexity to prefer these instructions over bitsset/bitsclr.
2153 // The reason is that tstbit/ntstbit can be folded into a compound instruction:
2154 // if ([!]tstbit(...)) jump ...
2155 let AddedComplexity = 100 in
2156 def: Pat<(i1 (setne (and (i32 IntRegs:$Rs), (i32 Set5ImmPred:$u5)), (i32 0))),
2157 (S2_tstbit_i (i32 IntRegs:$Rs), (BITPOS32 Set5ImmPred:$u5))>;
2159 let AddedComplexity = 100 in
2160 def: Pat<(i1 (seteq (and (i32 IntRegs:$Rs), (i32 Set5ImmPred:$u5)), (i32 0))),
2161 (S4_ntstbit_i (i32 IntRegs:$Rs), (BITPOS32 Set5ImmPred:$u5))>;
2163 def C4_nbitsset : T_TEST_BITS_REG<"!bitsset", 0b01, 1>;
2164 def C4_nbitsclr : T_TEST_BITS_REG<"!bitsclr", 0b10, 1>;
2165 def C4_nbitsclri : T_TEST_BITS_IMM<"!bitsclr", 0b10, 1>;
2167 // Do not increase complexity of these patterns. In the DAG, "cmp i8" may be
2168 // represented as a compare against "value & 0xFF", which is an exact match
2169 // for cmpb (same for cmph). The patterns below do not contain any additional
2170 // complexity that would make them preferable, and if they were actually used
2171 // instead of cmpb/cmph, they would result in a compare against register that
2172 // is loaded with the byte/half mask (i.e. 0xFF or 0xFFFF).
2173 def: Pat<(i1 (setne (and I32:$Rs, u6ImmPred:$u6), 0)),
2174 (C4_nbitsclri I32:$Rs, u6ImmPred:$u6)>;
2175 def: Pat<(i1 (setne (and I32:$Rs, I32:$Rt), 0)),
2176 (C4_nbitsclr I32:$Rs, I32:$Rt)>;
2177 def: Pat<(i1 (setne (and I32:$Rs, I32:$Rt), I32:$Rt)),
2178 (C4_nbitsset I32:$Rs, I32:$Rt)>;
2180 //===----------------------------------------------------------------------===//
2182 //===----------------------------------------------------------------------===//
2184 //===----------------------------------------------------------------------===//
2186 //===----------------------------------------------------------------------===//
2188 // Rd=add(#u6,mpyi(Rs,#U6)) -- Multiply by immed and add immed.
2190 let hasNewValue = 1, isExtendable = 1, opExtentBits = 6, opExtendable = 1 in
2191 def M4_mpyri_addi : MInst<(outs IntRegs:$Rd),
2192 (ins u6Ext:$u6, IntRegs:$Rs, u6Imm:$U6),
2193 "$Rd = add(#$u6, mpyi($Rs, #$U6))" ,
2194 [(set (i32 IntRegs:$Rd),
2195 (add (mul (i32 IntRegs:$Rs), u6ImmPred:$U6),
2196 u6ExtPred:$u6))] ,"",ALU64_tc_3x_SLOT23> {
2202 let IClass = 0b1101;
2204 let Inst{27-24} = 0b1000;
2205 let Inst{23} = U6{5};
2206 let Inst{22-21} = u6{5-4};
2207 let Inst{20-16} = Rs;
2208 let Inst{13} = u6{3};
2209 let Inst{12-8} = Rd;
2210 let Inst{7-5} = u6{2-0};
2211 let Inst{4-0} = U6{4-0};
2214 // Rd=add(#u6,mpyi(Rs,Rt))
2215 let CextOpcode = "ADD_MPY", InputType = "imm", hasNewValue = 1,
2216 isExtendable = 1, opExtentBits = 6, opExtendable = 1 in
2217 def M4_mpyrr_addi : MInst <(outs IntRegs:$Rd),
2218 (ins u6Ext:$u6, IntRegs:$Rs, IntRegs:$Rt),
2219 "$Rd = add(#$u6, mpyi($Rs, $Rt))" ,
2220 [(set (i32 IntRegs:$Rd),
2221 (add (mul (i32 IntRegs:$Rs), (i32 IntRegs:$Rt)), u6ExtPred:$u6))],
2222 "", ALU64_tc_3x_SLOT23>, ImmRegRel {
2228 let IClass = 0b1101;
2230 let Inst{27-23} = 0b01110;
2231 let Inst{22-21} = u6{5-4};
2232 let Inst{20-16} = Rs;
2233 let Inst{13} = u6{3};
2234 let Inst{12-8} = Rt;
2235 let Inst{7-5} = u6{2-0};
2239 let hasNewValue = 1 in
2240 class T_AddMpy <bit MajOp, PatLeaf ImmPred, dag ins>
2241 : ALU64Inst <(outs IntRegs:$dst), ins,
2242 "$dst = add($src1, mpyi("#!if(MajOp,"$src3, #$src2))",
2244 [(set (i32 IntRegs:$dst),
2245 (add (i32 IntRegs:$src1), (mul (i32 IntRegs:$src3), ImmPred:$src2)))],
2246 "", ALU64_tc_3x_SLOT23> {
2252 let IClass = 0b1101;
2254 bits<6> ImmValue = !if(MajOp, src2{5-0}, src2{7-2});
2256 let Inst{27-24} = 0b1111;
2257 let Inst{23} = MajOp;
2258 let Inst{22-21} = ImmValue{5-4};
2259 let Inst{20-16} = src3;
2260 let Inst{13} = ImmValue{3};
2261 let Inst{12-8} = dst;
2262 let Inst{7-5} = ImmValue{2-0};
2263 let Inst{4-0} = src1;
2266 def M4_mpyri_addr_u2 : T_AddMpy<0b0, u6_2ImmPred,
2267 (ins IntRegs:$src1, u6_2Imm:$src2, IntRegs:$src3)>;
2269 let isExtendable = 1, opExtentBits = 6, opExtendable = 3,
2270 CextOpcode = "ADD_MPY", InputType = "imm" in
2271 def M4_mpyri_addr : T_AddMpy<0b1, u6ExtPred,
2272 (ins IntRegs:$src1, IntRegs:$src3, u6Ext:$src2)>, ImmRegRel;
2274 // Rx=add(Ru,mpyi(Rx,Rs))
2275 let validSubTargets = HasV4SubT, CextOpcode = "ADD_MPY", InputType = "reg",
2277 def M4_mpyrr_addr: MInst_acc <(outs IntRegs:$Rx),
2278 (ins IntRegs:$Ru, IntRegs:$_src_, IntRegs:$Rs),
2279 "$Rx = add($Ru, mpyi($_src_, $Rs))",
2280 [(set (i32 IntRegs:$Rx), (add (i32 IntRegs:$Ru),
2281 (mul (i32 IntRegs:$_src_), (i32 IntRegs:$Rs))))],
2282 "$_src_ = $Rx", M_tc_3x_SLOT23>, ImmRegRel {
2287 let IClass = 0b1110;
2289 let Inst{27-21} = 0b0011000;
2290 let Inst{12-8} = Rx;
2292 let Inst{20-16} = Rs;
2295 // Rd=add(##,mpyi(Rs,#U6))
2296 def : Pat <(add (mul (i32 IntRegs:$src2), u6ImmPred:$src3),
2297 (HexagonCONST32 tglobaladdr:$src1)),
2298 (i32 (M4_mpyri_addi tglobaladdr:$src1, IntRegs:$src2,
2301 // Rd=add(##,mpyi(Rs,Rt))
2302 def : Pat <(add (mul (i32 IntRegs:$src2), (i32 IntRegs:$src3)),
2303 (HexagonCONST32 tglobaladdr:$src1)),
2304 (i32 (M4_mpyrr_addi tglobaladdr:$src1, IntRegs:$src2,
2307 // Vector reduce multiply word by signed half (32x16)
2308 //Rdd=vrmpyweh(Rss,Rtt)[:<<1]
2309 def M4_vrmpyeh_s0 : T_M2_vmpy<"vrmpyweh", 0b010, 0b100, 0, 0, 0>;
2310 def M4_vrmpyeh_s1 : T_M2_vmpy<"vrmpyweh", 0b110, 0b100, 1, 0, 0>;
2312 //Rdd=vrmpywoh(Rss,Rtt)[:<<1]
2313 def M4_vrmpyoh_s0 : T_M2_vmpy<"vrmpywoh", 0b001, 0b010, 0, 0, 0>;
2314 def M4_vrmpyoh_s1 : T_M2_vmpy<"vrmpywoh", 0b101, 0b010, 1, 0, 0>;
2316 //Rdd+=vrmpyweh(Rss,Rtt)[:<<1]
2317 def M4_vrmpyeh_acc_s0: T_M2_vmpy_acc<"vrmpyweh", 0b001, 0b110, 0, 0>;
2318 def M4_vrmpyeh_acc_s1: T_M2_vmpy_acc<"vrmpyweh", 0b101, 0b110, 1, 0>;
2320 //Rdd=vrmpywoh(Rss,Rtt)[:<<1]
2321 def M4_vrmpyoh_acc_s0: T_M2_vmpy_acc<"vrmpywoh", 0b011, 0b110, 0, 0>;
2322 def M4_vrmpyoh_acc_s1: T_M2_vmpy_acc<"vrmpywoh", 0b111, 0b110, 1, 0>;
2324 // Vector multiply halfwords, signed by unsigned
2325 // Rdd=vmpyhsu(Rs,Rt)[:<<]:sat
2326 def M2_vmpy2su_s0 : T_XTYPE_mpy64 < "vmpyhsu", 0b000, 0b111, 1, 0, 0>;
2327 def M2_vmpy2su_s1 : T_XTYPE_mpy64 < "vmpyhsu", 0b100, 0b111, 1, 1, 0>;
2329 // Rxx+=vmpyhsu(Rs,Rt)[:<<1]:sat
2330 def M2_vmac2su_s0 : T_XTYPE_mpy64_acc < "vmpyhsu", "+", 0b011, 0b101, 1, 0, 0>;
2331 def M2_vmac2su_s1 : T_XTYPE_mpy64_acc < "vmpyhsu", "+", 0b111, 0b101, 1, 1, 0>;
2333 // Vector polynomial multiply halfwords
2334 // Rdd=vpmpyh(Rs,Rt)
2335 def M4_vpmpyh : T_XTYPE_mpy64 < "vpmpyh", 0b110, 0b111, 0, 0, 0>;
2337 // Rxx^=vpmpyh(Rs,Rt)
2338 def M4_vpmpyh_acc : T_XTYPE_mpy64_acc < "vpmpyh", "^", 0b101, 0b111, 0, 0, 0>;
2340 // Polynomial multiply words
2342 def M4_pmpyw : T_XTYPE_mpy64 < "pmpyw", 0b010, 0b111, 0, 0, 0>;
2344 // Rxx^=pmpyw(Rs,Rt)
2345 def M4_pmpyw_acc : T_XTYPE_mpy64_acc < "pmpyw", "^", 0b001, 0b111, 0, 0, 0>;
2347 //===----------------------------------------------------------------------===//
2349 //===----------------------------------------------------------------------===//
2352 //===----------------------------------------------------------------------===//
2353 // ALU64/Vector compare
2354 //===----------------------------------------------------------------------===//
2355 //===----------------------------------------------------------------------===//
2356 // Template class for vector compare
2357 //===----------------------------------------------------------------------===//
2359 let hasSideEffects = 0 in
2360 class T_vcmpImm <string Str, bits<2> cmpOp, bits<2> minOp, Operand ImmOprnd>
2361 : ALU64_rr <(outs PredRegs:$Pd),
2362 (ins DoubleRegs:$Rss, ImmOprnd:$Imm),
2363 "$Pd = "#Str#"($Rss, #$Imm)",
2364 [], "", ALU64_tc_2early_SLOT23> {
2369 let ImmBits{6-0} = Imm{6-0};
2370 let ImmBits{7} = !if (!eq(cmpOp,0b10), 0b0, Imm{7}); // 0 for vcmp[bhw].gtu
2372 let IClass = 0b1101;
2374 let Inst{27-24} = 0b1100;
2375 let Inst{22-21} = cmpOp;
2376 let Inst{20-16} = Rss;
2377 let Inst{12-5} = ImmBits;
2378 let Inst{4-3} = minOp;
2382 // Vector compare bytes
2383 def A4_vcmpbgt : T_vcmp <"vcmpb.gt", 0b1010>;
2384 def: T_vcmp_pat<A4_vcmpbgt, setgt, v8i8>;
2386 let AsmString = "$Pd = any8(vcmpb.eq($Rss, $Rtt))" in
2387 def A4_vcmpbeq_any : T_vcmp <"any8(vcmpb.gt", 0b1000>;
2389 def A4_vcmpbeqi : T_vcmpImm <"vcmpb.eq", 0b00, 0b00, u8Imm>;
2390 def A4_vcmpbgti : T_vcmpImm <"vcmpb.gt", 0b01, 0b00, s8Imm>;
2391 def A4_vcmpbgtui : T_vcmpImm <"vcmpb.gtu", 0b10, 0b00, u7Imm>;
2393 // Vector compare halfwords
2394 def A4_vcmpheqi : T_vcmpImm <"vcmph.eq", 0b00, 0b01, s8Imm>;
2395 def A4_vcmphgti : T_vcmpImm <"vcmph.gt", 0b01, 0b01, s8Imm>;
2396 def A4_vcmphgtui : T_vcmpImm <"vcmph.gtu", 0b10, 0b01, u7Imm>;
2398 // Vector compare words
2399 def A4_vcmpweqi : T_vcmpImm <"vcmpw.eq", 0b00, 0b10, s8Imm>;
2400 def A4_vcmpwgti : T_vcmpImm <"vcmpw.gt", 0b01, 0b10, s8Imm>;
2401 def A4_vcmpwgtui : T_vcmpImm <"vcmpw.gtu", 0b10, 0b10, u7Imm>;
2403 //===----------------------------------------------------------------------===//
2405 //===----------------------------------------------------------------------===//
2406 // Shift by immediate and accumulate/logical.
2407 // Rx=add(#u8,asl(Rx,#U5)) Rx=add(#u8,lsr(Rx,#U5))
2408 // Rx=sub(#u8,asl(Rx,#U5)) Rx=sub(#u8,lsr(Rx,#U5))
2409 // Rx=and(#u8,asl(Rx,#U5)) Rx=and(#u8,lsr(Rx,#U5))
2410 // Rx=or(#u8,asl(Rx,#U5)) Rx=or(#u8,lsr(Rx,#U5))
2411 let isExtendable = 1, opExtendable = 1, isExtentSigned = 0, opExtentBits = 8,
2412 hasNewValue = 1, opNewValue = 0, validSubTargets = HasV4SubT in
2413 class T_S4_ShiftOperate<string MnOp, string MnSh, SDNode Op, SDNode Sh,
2414 bit asl_lsr, bits<2> MajOp, InstrItinClass Itin>
2415 : MInst_acc<(outs IntRegs:$Rd), (ins u8Ext:$u8, IntRegs:$Rx, u5Imm:$U5),
2416 "$Rd = "#MnOp#"(#$u8, "#MnSh#"($Rx, #$U5))",
2417 [(set (i32 IntRegs:$Rd),
2418 (Op (Sh I32:$Rx, u5ImmPred:$U5), u8ExtPred:$u8))],
2419 "$Rd = $Rx", Itin> {
2426 let IClass = 0b1101;
2427 let Inst{27-24} = 0b1110;
2428 let Inst{23-21} = u8{7-5};
2429 let Inst{20-16} = Rd;
2430 let Inst{13} = u8{4};
2431 let Inst{12-8} = U5;
2432 let Inst{7-5} = u8{3-1};
2433 let Inst{4} = asl_lsr;
2434 let Inst{3} = u8{0};
2435 let Inst{2-1} = MajOp;
2438 multiclass T_ShiftOperate<string mnemonic, SDNode Op, bits<2> MajOp,
2439 InstrItinClass Itin> {
2440 def _asl_ri : T_S4_ShiftOperate<mnemonic, "asl", Op, shl, 0, MajOp, Itin>;
2441 def _lsr_ri : T_S4_ShiftOperate<mnemonic, "lsr", Op, srl, 1, MajOp, Itin>;
2444 let AddedComplexity = 200 in {
2445 defm S4_addi : T_ShiftOperate<"add", add, 0b10, ALU64_tc_2_SLOT23>;
2446 defm S4_andi : T_ShiftOperate<"and", and, 0b00, ALU64_tc_2_SLOT23>;
2449 let AddedComplexity = 30 in
2450 defm S4_ori : T_ShiftOperate<"or", or, 0b01, ALU64_tc_1_SLOT23>;
2452 defm S4_subi : T_ShiftOperate<"sub", sub, 0b11, ALU64_tc_1_SLOT23>;
2454 // Vector conditional negate
2455 // Rdd=vcnegh(Rss,Rt)
2456 let Defs = [USR_OVF], Itinerary = S_3op_tc_2_SLOT23 in
2457 def S2_vcnegh : T_S3op_shiftVect < "vcnegh", 0b11, 0b01>;
2459 // Rd=[cround|round](Rs,Rt)
2460 let hasNewValue = 1, Itinerary = S_3op_tc_2_SLOT23 in {
2461 def A4_cround_rr : T_S3op_3 < "cround", IntRegs, 0b11, 0b00>;
2462 def A4_round_rr : T_S3op_3 < "round", IntRegs, 0b11, 0b10>;
2465 // Rd=round(Rs,Rt):sat
2466 let hasNewValue = 1, Defs = [USR_OVF], Itinerary = S_3op_tc_2_SLOT23 in
2467 def A4_round_rr_sat : T_S3op_3 < "round", IntRegs, 0b11, 0b11, 1>;
2469 // Rd=[cmpyiwh|cmpyrwh](Rss,Rt):<<1:rnd:sat
2470 let Defs = [USR_OVF], Itinerary = S_3op_tc_3x_SLOT23 in {
2471 def M4_cmpyi_wh : T_S3op_8<"cmpyiwh", 0b100, 1, 1, 1>;
2472 def M4_cmpyr_wh : T_S3op_8<"cmpyrwh", 0b110, 1, 1, 1>;
2475 // Rdd=[add|sub](Rss,Rtt,Px):carry
2476 let isPredicateLate = 1, hasSideEffects = 0 in
2477 class T_S3op_carry <string mnemonic, bits<3> MajOp>
2478 : SInst < (outs DoubleRegs:$Rdd, PredRegs:$Px),
2479 (ins DoubleRegs:$Rss, DoubleRegs:$Rtt, PredRegs:$Pu),
2480 "$Rdd = "#mnemonic#"($Rss, $Rtt, $Pu):carry",
2481 [], "$Px = $Pu", S_3op_tc_1_SLOT23 > {
2487 let IClass = 0b1100;
2489 let Inst{27-24} = 0b0010;
2490 let Inst{23-21} = MajOp;
2491 let Inst{20-16} = Rss;
2492 let Inst{12-8} = Rtt;
2494 let Inst{4-0} = Rdd;
2497 def A4_addp_c : T_S3op_carry < "add", 0b110 >;
2498 def A4_subp_c : T_S3op_carry < "sub", 0b111 >;
2500 let Itinerary = S_3op_tc_3_SLOT23, hasSideEffects = 0 in
2501 class T_S3op_6 <string mnemonic, bits<3> MinOp, bit isUnsigned>
2502 : SInst <(outs DoubleRegs:$Rxx),
2503 (ins DoubleRegs:$dst2, DoubleRegs:$Rss, IntRegs:$Ru),
2504 "$Rxx = "#mnemonic#"($Rss, $Ru)" ,
2505 [] , "$dst2 = $Rxx"> {
2510 let IClass = 0b1100;
2512 let Inst{27-21} = 0b1011001;
2513 let Inst{20-16} = Rss;
2514 let Inst{13} = isUnsigned;
2515 let Inst{12-8} = Rxx;
2516 let Inst{7-5} = MinOp;
2520 // Vector reduce maximum halfwords
2521 // Rxx=vrmax[u]h(Rss,Ru)
2522 def A4_vrmaxh : T_S3op_6 < "vrmaxh", 0b001, 0>;
2523 def A4_vrmaxuh : T_S3op_6 < "vrmaxuh", 0b001, 1>;
2525 // Vector reduce maximum words
2526 // Rxx=vrmax[u]w(Rss,Ru)
2527 def A4_vrmaxw : T_S3op_6 < "vrmaxw", 0b010, 0>;
2528 def A4_vrmaxuw : T_S3op_6 < "vrmaxuw", 0b010, 1>;
2530 // Vector reduce minimum halfwords
2531 // Rxx=vrmin[u]h(Rss,Ru)
2532 def A4_vrminh : T_S3op_6 < "vrminh", 0b101, 0>;
2533 def A4_vrminuh : T_S3op_6 < "vrminuh", 0b101, 1>;
2535 // Vector reduce minimum words
2536 // Rxx=vrmin[u]w(Rss,Ru)
2537 def A4_vrminw : T_S3op_6 < "vrminw", 0b110, 0>;
2538 def A4_vrminuw : T_S3op_6 < "vrminuw", 0b110, 1>;
2540 // Shift an immediate left by register amount.
2541 let hasNewValue = 1, hasSideEffects = 0 in
2542 def S4_lsli: SInst <(outs IntRegs:$Rd), (ins s6Imm:$s6, IntRegs:$Rt),
2543 "$Rd = lsl(#$s6, $Rt)" ,
2544 [(set (i32 IntRegs:$Rd), (shl s6ImmPred:$s6,
2545 (i32 IntRegs:$Rt)))],
2546 "", S_3op_tc_1_SLOT23> {
2551 let IClass = 0b1100;
2553 let Inst{27-22} = 0b011010;
2554 let Inst{20-16} = s6{5-1};
2555 let Inst{12-8} = Rt;
2556 let Inst{7-6} = 0b11;
2558 let Inst{5} = s6{0};
2561 //===----------------------------------------------------------------------===//
2563 //===----------------------------------------------------------------------===//
2565 //===----------------------------------------------------------------------===//
2566 // MEMOP: Word, Half, Byte
2567 //===----------------------------------------------------------------------===//
2569 def MEMOPIMM : SDNodeXForm<imm, [{
2570 // Call the transformation function XformM5ToU5Imm to get the negative
2571 // immediate's positive counterpart.
2572 int32_t imm = N->getSExtValue();
2573 return XformM5ToU5Imm(imm);
2576 def MEMOPIMM_HALF : SDNodeXForm<imm, [{
2577 // -1 .. -31 represented as 65535..65515
2578 // assigning to a short restores our desired signed value.
2579 // Call the transformation function XformM5ToU5Imm to get the negative
2580 // immediate's positive counterpart.
2581 int16_t imm = N->getSExtValue();
2582 return XformM5ToU5Imm(imm);
2585 def MEMOPIMM_BYTE : SDNodeXForm<imm, [{
2586 // -1 .. -31 represented as 255..235
2587 // assigning to a char restores our desired signed value.
2588 // Call the transformation function XformM5ToU5Imm to get the negative
2589 // immediate's positive counterpart.
2590 int8_t imm = N->getSExtValue();
2591 return XformM5ToU5Imm(imm);
2594 def SETMEMIMM : SDNodeXForm<imm, [{
2595 // Return the bit position we will set [0-31].
2597 int32_t imm = N->getSExtValue();
2598 return XformMskToBitPosU5Imm(imm);
2601 def CLRMEMIMM : SDNodeXForm<imm, [{
2602 // Return the bit position we will clear [0-31].
2604 // we bit negate the value first
2605 int32_t imm = ~(N->getSExtValue());
2606 return XformMskToBitPosU5Imm(imm);
2609 def SETMEMIMM_SHORT : SDNodeXForm<imm, [{
2610 // Return the bit position we will set [0-15].
2612 int16_t imm = N->getSExtValue();
2613 return XformMskToBitPosU4Imm(imm);
2616 def CLRMEMIMM_SHORT : SDNodeXForm<imm, [{
2617 // Return the bit position we will clear [0-15].
2619 // we bit negate the value first
2620 int16_t imm = ~(N->getSExtValue());
2621 return XformMskToBitPosU4Imm(imm);
2624 def SETMEMIMM_BYTE : SDNodeXForm<imm, [{
2625 // Return the bit position we will set [0-7].
2627 int8_t imm = N->getSExtValue();
2628 return XformMskToBitPosU3Imm(imm);
2631 def CLRMEMIMM_BYTE : SDNodeXForm<imm, [{
2632 // Return the bit position we will clear [0-7].
2634 // we bit negate the value first
2635 int8_t imm = ~(N->getSExtValue());
2636 return XformMskToBitPosU3Imm(imm);
2639 //===----------------------------------------------------------------------===//
2640 // Template class for MemOp instructions with the register value.
2641 //===----------------------------------------------------------------------===//
2642 class MemOp_rr_base <string opc, bits<2> opcBits, Operand ImmOp,
2643 string memOp, bits<2> memOpBits> :
2645 (ins IntRegs:$base, ImmOp:$offset, IntRegs:$delta),
2646 opc#"($base+#$offset)"#memOp#"$delta",
2648 Requires<[UseMEMOP]> {
2653 bits<6> offsetBits; // memb - u6:0 , memh - u6:1, memw - u6:2
2655 let offsetBits = !if (!eq(opcBits, 0b00), offset{5-0},
2656 !if (!eq(opcBits, 0b01), offset{6-1},
2657 !if (!eq(opcBits, 0b10), offset{7-2},0)));
2659 let opExtentAlign = opcBits;
2660 let IClass = 0b0011;
2661 let Inst{27-24} = 0b1110;
2662 let Inst{22-21} = opcBits;
2663 let Inst{20-16} = base;
2665 let Inst{12-7} = offsetBits;
2666 let Inst{6-5} = memOpBits;
2667 let Inst{4-0} = delta;
2670 //===----------------------------------------------------------------------===//
2671 // Template class for MemOp instructions with the immediate value.
2672 //===----------------------------------------------------------------------===//
2673 class MemOp_ri_base <string opc, bits<2> opcBits, Operand ImmOp,
2674 string memOp, bits<2> memOpBits> :
2676 (ins IntRegs:$base, ImmOp:$offset, u5Imm:$delta),
2677 opc#"($base+#$offset)"#memOp#"#$delta"
2678 #!if(memOpBits{1},")", ""), // clrbit, setbit - include ')'
2680 Requires<[UseMEMOP]> {
2685 bits<6> offsetBits; // memb - u6:0 , memh - u6:1, memw - u6:2
2687 let offsetBits = !if (!eq(opcBits, 0b00), offset{5-0},
2688 !if (!eq(opcBits, 0b01), offset{6-1},
2689 !if (!eq(opcBits, 0b10), offset{7-2},0)));
2691 let opExtentAlign = opcBits;
2692 let IClass = 0b0011;
2693 let Inst{27-24} = 0b1111;
2694 let Inst{22-21} = opcBits;
2695 let Inst{20-16} = base;
2697 let Inst{12-7} = offsetBits;
2698 let Inst{6-5} = memOpBits;
2699 let Inst{4-0} = delta;
2702 // multiclass to define MemOp instructions with register operand.
2703 multiclass MemOp_rr<string opc, bits<2> opcBits, Operand ImmOp> {
2704 def L4_add#NAME : MemOp_rr_base <opc, opcBits, ImmOp, " += ", 0b00>; // add
2705 def L4_sub#NAME : MemOp_rr_base <opc, opcBits, ImmOp, " -= ", 0b01>; // sub
2706 def L4_and#NAME : MemOp_rr_base <opc, opcBits, ImmOp, " &= ", 0b10>; // and
2707 def L4_or#NAME : MemOp_rr_base <opc, opcBits, ImmOp, " |= ", 0b11>; // or
2710 // multiclass to define MemOp instructions with immediate Operand.
2711 multiclass MemOp_ri<string opc, bits<2> opcBits, Operand ImmOp> {
2712 def L4_iadd#NAME : MemOp_ri_base <opc, opcBits, ImmOp, " += ", 0b00 >;
2713 def L4_isub#NAME : MemOp_ri_base <opc, opcBits, ImmOp, " -= ", 0b01 >;
2714 def L4_iand#NAME : MemOp_ri_base<opc, opcBits, ImmOp, " = clrbit(", 0b10>;
2715 def L4_ior#NAME : MemOp_ri_base<opc, opcBits, ImmOp, " = setbit(", 0b11>;
2718 multiclass MemOp_base <string opc, bits<2> opcBits, Operand ImmOp> {
2719 defm _#NAME : MemOp_rr <opc, opcBits, ImmOp>;
2720 defm _#NAME : MemOp_ri <opc, opcBits, ImmOp>;
2723 // Define MemOp instructions.
2724 let isExtendable = 1, opExtendable = 1, isExtentSigned = 0,
2725 validSubTargets =HasV4SubT in {
2726 let opExtentBits = 6, accessSize = ByteAccess in
2727 defm memopb_io : MemOp_base <"memb", 0b00, u6_0Ext>;
2729 let opExtentBits = 7, accessSize = HalfWordAccess in
2730 defm memoph_io : MemOp_base <"memh", 0b01, u6_1Ext>;
2732 let opExtentBits = 8, accessSize = WordAccess in
2733 defm memopw_io : MemOp_base <"memw", 0b10, u6_2Ext>;
2736 //===----------------------------------------------------------------------===//
2737 // Multiclass to define 'Def Pats' for ALU operations on the memory
2738 // Here value used for the ALU operation is an immediate value.
2739 // mem[bh](Rs+#0) += #U5
2740 // mem[bh](Rs+#u6) += #U5
2741 //===----------------------------------------------------------------------===//
2743 multiclass MemOpi_u5Pats <PatFrag ldOp, PatFrag stOp, PatLeaf ExtPred,
2744 InstHexagon MI, SDNode OpNode> {
2745 let AddedComplexity = 180 in
2746 def : Pat < (stOp (OpNode (ldOp IntRegs:$addr), u5ImmPred:$addend),
2748 (MI IntRegs:$addr, #0, u5ImmPred:$addend )>;
2750 let AddedComplexity = 190 in
2751 def : Pat <(stOp (OpNode (ldOp (add IntRegs:$base, ExtPred:$offset)),
2753 (add IntRegs:$base, ExtPred:$offset)),
2754 (MI IntRegs:$base, ExtPred:$offset, u5ImmPred:$addend)>;
2757 multiclass MemOpi_u5ALUOp<PatFrag ldOp, PatFrag stOp, PatLeaf ExtPred,
2758 InstHexagon addMI, InstHexagon subMI> {
2759 defm : MemOpi_u5Pats<ldOp, stOp, ExtPred, addMI, add>;
2760 defm : MemOpi_u5Pats<ldOp, stOp, ExtPred, subMI, sub>;
2763 multiclass MemOpi_u5ExtType<PatFrag ldOpByte, PatFrag ldOpHalf > {
2765 defm : MemOpi_u5ALUOp <ldOpHalf, truncstorei16, u6_1ExtPred,
2766 L4_iadd_memoph_io, L4_isub_memoph_io>;
2768 defm : MemOpi_u5ALUOp <ldOpByte, truncstorei8, u6ExtPred,
2769 L4_iadd_memopb_io, L4_isub_memopb_io>;
2772 let Predicates = [HasV4T, UseMEMOP] in {
2773 defm : MemOpi_u5ExtType<zextloadi8, zextloadi16>; // zero extend
2774 defm : MemOpi_u5ExtType<sextloadi8, sextloadi16>; // sign extend
2775 defm : MemOpi_u5ExtType<extloadi8, extloadi16>; // any extend
2778 defm : MemOpi_u5ALUOp <load, store, u6_2ExtPred, L4_iadd_memopw_io,
2782 //===----------------------------------------------------------------------===//
2783 // multiclass to define 'Def Pats' for ALU operations on the memory.
2784 // Here value used for the ALU operation is a negative value.
2785 // mem[bh](Rs+#0) += #m5
2786 // mem[bh](Rs+#u6) += #m5
2787 //===----------------------------------------------------------------------===//
2789 multiclass MemOpi_m5Pats <PatFrag ldOp, PatFrag stOp, PatLeaf extPred,
2790 PatLeaf immPred, ComplexPattern addrPred,
2791 SDNodeXForm xformFunc, InstHexagon MI> {
2792 let AddedComplexity = 190 in
2793 def : Pat <(stOp (add (ldOp IntRegs:$addr), immPred:$subend),
2795 (MI IntRegs:$addr, #0, (xformFunc immPred:$subend) )>;
2797 let AddedComplexity = 195 in
2798 def : Pat<(stOp (add (ldOp (add IntRegs:$base, extPred:$offset)),
2800 (add IntRegs:$base, extPred:$offset)),
2801 (MI IntRegs:$base, extPred:$offset, (xformFunc immPred:$subend))>;
2804 multiclass MemOpi_m5ExtType<PatFrag ldOpByte, PatFrag ldOpHalf > {
2806 defm : MemOpi_m5Pats <ldOpHalf, truncstorei16, u6_1ExtPred, m5HImmPred,
2807 ADDRriU6_1, MEMOPIMM_HALF, L4_isub_memoph_io>;
2809 defm : MemOpi_m5Pats <ldOpByte, truncstorei8, u6ExtPred, m5BImmPred,
2810 ADDRriU6_0, MEMOPIMM_BYTE, L4_isub_memopb_io>;
2813 let Predicates = [HasV4T, UseMEMOP] in {
2814 defm : MemOpi_m5ExtType<zextloadi8, zextloadi16>; // zero extend
2815 defm : MemOpi_m5ExtType<sextloadi8, sextloadi16>; // sign extend
2816 defm : MemOpi_m5ExtType<extloadi8, extloadi16>; // any extend
2819 defm : MemOpi_m5Pats <load, store, u6_2ExtPred, m5ImmPred,
2820 ADDRriU6_2, MEMOPIMM, L4_isub_memopw_io>;
2823 //===----------------------------------------------------------------------===//
2824 // Multiclass to define 'def Pats' for bit operations on the memory.
2825 // mem[bhw](Rs+#0) = [clrbit|setbit](#U5)
2826 // mem[bhw](Rs+#u6) = [clrbit|setbit](#U5)
2827 //===----------------------------------------------------------------------===//
2829 multiclass MemOpi_bitPats <PatFrag ldOp, PatFrag stOp, PatLeaf immPred,
2830 PatLeaf extPred, ComplexPattern addrPred,
2831 SDNodeXForm xformFunc, InstHexagon MI, SDNode OpNode> {
2833 // mem[bhw](Rs+#u6:[012]) = [clrbit|setbit](#U5)
2834 let AddedComplexity = 250 in
2835 def : Pat<(stOp (OpNode (ldOp (add IntRegs:$base, extPred:$offset)),
2837 (add IntRegs:$base, extPred:$offset)),
2838 (MI IntRegs:$base, extPred:$offset, (xformFunc immPred:$bitend))>;
2840 // mem[bhw](Rs+#0) = [clrbit|setbit](#U5)
2841 let AddedComplexity = 225 in
2842 def : Pat <(stOp (OpNode (ldOp (addrPred IntRegs:$addr, extPred:$offset)),
2844 (addrPred (i32 IntRegs:$addr), extPred:$offset)),
2845 (MI IntRegs:$addr, extPred:$offset, (xformFunc immPred:$bitend))>;
2848 multiclass MemOpi_bitExtType<PatFrag ldOpByte, PatFrag ldOpHalf > {
2850 defm : MemOpi_bitPats<ldOpByte, truncstorei8, Clr3ImmPred, u6ExtPred,
2851 ADDRriU6_0, CLRMEMIMM_BYTE, L4_iand_memopb_io, and>;
2853 defm : MemOpi_bitPats<ldOpByte, truncstorei8, Set3ImmPred, u6ExtPred,
2854 ADDRriU6_0, SETMEMIMM_BYTE, L4_ior_memopb_io, or>;
2855 // Half Word - clrbit
2856 defm : MemOpi_bitPats<ldOpHalf, truncstorei16, Clr4ImmPred, u6_1ExtPred,
2857 ADDRriU6_1, CLRMEMIMM_SHORT, L4_iand_memoph_io, and>;
2858 // Half Word - setbit
2859 defm : MemOpi_bitPats<ldOpHalf, truncstorei16, Set4ImmPred, u6_1ExtPred,
2860 ADDRriU6_1, SETMEMIMM_SHORT, L4_ior_memoph_io, or>;
2863 let Predicates = [HasV4T, UseMEMOP] in {
2864 // mem[bh](Rs+#0) = [clrbit|setbit](#U5)
2865 // mem[bh](Rs+#u6:[01]) = [clrbit|setbit](#U5)
2866 defm : MemOpi_bitExtType<zextloadi8, zextloadi16>; // zero extend
2867 defm : MemOpi_bitExtType<sextloadi8, sextloadi16>; // sign extend
2868 defm : MemOpi_bitExtType<extloadi8, extloadi16>; // any extend
2870 // memw(Rs+#0) = [clrbit|setbit](#U5)
2871 // memw(Rs+#u6:2) = [clrbit|setbit](#U5)
2872 defm : MemOpi_bitPats<load, store, Clr5ImmPred, u6_2ExtPred, ADDRriU6_2,
2873 CLRMEMIMM, L4_iand_memopw_io, and>;
2874 defm : MemOpi_bitPats<load, store, Set5ImmPred, u6_2ExtPred, ADDRriU6_2,
2875 SETMEMIMM, L4_ior_memopw_io, or>;
2878 //===----------------------------------------------------------------------===//
2879 // Multiclass to define 'def Pats' for ALU operations on the memory
2880 // where addend is a register.
2881 // mem[bhw](Rs+#0) [+-&|]= Rt
2882 // mem[bhw](Rs+#U6:[012]) [+-&|]= Rt
2883 //===----------------------------------------------------------------------===//
2885 multiclass MemOpr_Pats <PatFrag ldOp, PatFrag stOp, ComplexPattern addrPred,
2886 PatLeaf extPred, InstHexagon MI, SDNode OpNode> {
2887 let AddedComplexity = 141 in
2888 // mem[bhw](Rs+#0) [+-&|]= Rt
2889 def : Pat <(stOp (OpNode (ldOp (addrPred IntRegs:$addr, extPred:$offset)),
2890 (i32 IntRegs:$addend)),
2891 (addrPred (i32 IntRegs:$addr), extPred:$offset)),
2892 (MI IntRegs:$addr, extPred:$offset, (i32 IntRegs:$addend) )>;
2894 // mem[bhw](Rs+#U6:[012]) [+-&|]= Rt
2895 let AddedComplexity = 150 in
2896 def : Pat <(stOp (OpNode (ldOp (add IntRegs:$base, extPred:$offset)),
2897 (i32 IntRegs:$orend)),
2898 (add IntRegs:$base, extPred:$offset)),
2899 (MI IntRegs:$base, extPred:$offset, (i32 IntRegs:$orend) )>;
2902 multiclass MemOPr_ALUOp<PatFrag ldOp, PatFrag stOp,
2903 ComplexPattern addrPred, PatLeaf extPred,
2904 InstHexagon addMI, InstHexagon subMI,
2905 InstHexagon andMI, InstHexagon orMI > {
2907 defm : MemOpr_Pats <ldOp, stOp, addrPred, extPred, addMI, add>;
2908 defm : MemOpr_Pats <ldOp, stOp, addrPred, extPred, subMI, sub>;
2909 defm : MemOpr_Pats <ldOp, stOp, addrPred, extPred, andMI, and>;
2910 defm : MemOpr_Pats <ldOp, stOp, addrPred, extPred, orMI, or>;
2913 multiclass MemOPr_ExtType<PatFrag ldOpByte, PatFrag ldOpHalf > {
2915 defm : MemOPr_ALUOp <ldOpHalf, truncstorei16, ADDRriU6_1, u6_1ExtPred,
2916 L4_add_memoph_io, L4_sub_memoph_io,
2917 L4_and_memoph_io, L4_or_memoph_io>;
2919 defm : MemOPr_ALUOp <ldOpByte, truncstorei8, ADDRriU6_0, u6ExtPred,
2920 L4_add_memopb_io, L4_sub_memopb_io,
2921 L4_and_memopb_io, L4_or_memopb_io>;
2924 // Define 'def Pats' for MemOps with register addend.
2925 let Predicates = [HasV4T, UseMEMOP] in {
2927 defm : MemOPr_ExtType<zextloadi8, zextloadi16>; // zero extend
2928 defm : MemOPr_ExtType<sextloadi8, sextloadi16>; // sign extend
2929 defm : MemOPr_ExtType<extloadi8, extloadi16>; // any extend
2931 defm : MemOPr_ALUOp <load, store, ADDRriU6_2, u6_2ExtPred, L4_add_memopw_io,
2932 L4_sub_memopw_io, L4_and_memopw_io, L4_or_memopw_io >;
2935 //===----------------------------------------------------------------------===//
2937 //===----------------------------------------------------------------------===//
2939 // Hexagon V4 only supports these flavors of byte/half compare instructions:
2940 // EQ/GT/GTU. Other flavors like GE/GEU/LT/LTU/LE/LEU are not supported by
2941 // hardware. However, compiler can still implement these patterns through
2942 // appropriate patterns combinations based on current implemented patterns.
2943 // The implemented patterns are: EQ/GT/GTU.
2944 // Missing patterns are: GE/GEU/LT/LTU/LE/LEU.
2946 // Following instruction is not being extended as it results into the
2947 // incorrect code for negative numbers.
2948 // Pd=cmpb.eq(Rs,#u8)
2950 // p=!cmp.eq(r1,#s10)
2951 def C4_cmpneqi : T_CMP <"cmp.eq", 0b00, 1, s10Ext>;
2952 def C4_cmpltei : T_CMP <"cmp.gt", 0b01, 1, s10Ext>;
2953 def C4_cmplteui : T_CMP <"cmp.gtu", 0b10, 1, u9Ext>;
2955 def : T_CMP_pat <C4_cmpneqi, setne, s10ExtPred>;
2956 def : T_CMP_pat <C4_cmpltei, setle, s10ExtPred>;
2957 def : T_CMP_pat <C4_cmplteui, setule, u9ImmPred>;
2959 // rs <= rt -> !(rs > rt).
2961 def: Pat<(i1 (setle (i32 IntRegs:$src1), s10ExtPred:$src2)),
2962 (C2_not (C2_cmpgti IntRegs:$src1, s10ExtPred:$src2))>;
2963 // (C4_cmpltei IntRegs:$src1, s10ExtPred:$src2)>;
2965 // Map cmplt(Rs, Imm) -> !cmpgt(Rs, Imm-1).
2966 def: Pat<(i1 (setlt (i32 IntRegs:$src1), s8ExtPred:$src2)),
2967 (C4_cmpltei IntRegs:$src1, (DEC_CONST_SIGNED s8ExtPred:$src2))>;
2969 // rs != rt -> !(rs == rt).
2970 def: Pat<(i1 (setne (i32 IntRegs:$src1), s10ExtPred:$src2)),
2971 (C4_cmpneqi IntRegs:$src1, s10ExtPred:$src2)>;
2973 // SDNode for converting immediate C to C-1.
2974 def DEC_CONST_BYTE : SDNodeXForm<imm, [{
2975 // Return the byte immediate const-1 as an SDNode.
2976 int32_t imm = N->getSExtValue();
2977 return XformU7ToU7M1Imm(imm);
2981 // zext( seteq ( and(Rs, 255), u8))
2983 // Pd=cmpb.eq(Rs, #u8)
2984 // if (Pd.new) Rd=#1
2985 // if (!Pd.new) Rd=#0
2986 def : Pat <(i32 (zext (i1 (seteq (i32 (and (i32 IntRegs:$Rs), 255)),
2988 (i32 (TFR_condset_ii (i1 (A4_cmpbeqi (i32 IntRegs:$Rs),
2994 // zext( setne ( and(Rs, 255), u8))
2996 // Pd=cmpb.eq(Rs, #u8)
2997 // if (Pd.new) Rd=#0
2998 // if (!Pd.new) Rd=#1
2999 def : Pat <(i32 (zext (i1 (setne (i32 (and (i32 IntRegs:$Rs), 255)),
3001 (i32 (TFR_condset_ii (i1 (A4_cmpbeqi (i32 IntRegs:$Rs),
3007 // zext( seteq (Rs, and(Rt, 255)))
3009 // Pd=cmpb.eq(Rs, Rt)
3010 // if (Pd.new) Rd=#1
3011 // if (!Pd.new) Rd=#0
3012 def : Pat <(i32 (zext (i1 (seteq (i32 IntRegs:$Rt),
3013 (i32 (and (i32 IntRegs:$Rs), 255)))))),
3014 (i32 (TFR_condset_ii (i1 (A4_cmpbeq (i32 IntRegs:$Rs),
3015 (i32 IntRegs:$Rt))),
3020 // zext( setne (Rs, and(Rt, 255)))
3022 // Pd=cmpb.eq(Rs, Rt)
3023 // if (Pd.new) Rd=#0
3024 // if (!Pd.new) Rd=#1
3025 def : Pat <(i32 (zext (i1 (setne (i32 IntRegs:$Rt),
3026 (i32 (and (i32 IntRegs:$Rs), 255)))))),
3027 (i32 (TFR_condset_ii (i1 (A4_cmpbeq (i32 IntRegs:$Rs),
3028 (i32 IntRegs:$Rt))),
3033 // zext( setugt ( and(Rs, 255), u8))
3035 // Pd=cmpb.gtu(Rs, #u8)
3036 // if (Pd.new) Rd=#1
3037 // if (!Pd.new) Rd=#0
3038 def : Pat <(i32 (zext (i1 (setugt (i32 (and (i32 IntRegs:$Rs), 255)),
3040 (i32 (TFR_condset_ii (i1 (A4_cmpbgtui (i32 IntRegs:$Rs),
3046 // zext( setugt ( and(Rs, 254), u8))
3048 // Pd=cmpb.gtu(Rs, #u8)
3049 // if (Pd.new) Rd=#1
3050 // if (!Pd.new) Rd=#0
3051 def : Pat <(i32 (zext (i1 (setugt (i32 (and (i32 IntRegs:$Rs), 254)),
3053 (i32 (TFR_condset_ii (i1 (A4_cmpbgtui (i32 IntRegs:$Rs),
3059 // zext( setult ( Rs, Rt))
3061 // Pd=cmp.ltu(Rs, Rt)
3062 // if (Pd.new) Rd=#1
3063 // if (!Pd.new) Rd=#0
3064 // cmp.ltu(Rs, Rt) -> cmp.gtu(Rt, Rs)
3065 def : Pat <(i32 (zext (i1 (setult (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))))),
3066 (i32 (TFR_condset_ii (i1 (C2_cmpgtu (i32 IntRegs:$Rt),
3067 (i32 IntRegs:$Rs))),
3072 // zext( setlt ( Rs, Rt))
3074 // Pd=cmp.lt(Rs, Rt)
3075 // if (Pd.new) Rd=#1
3076 // if (!Pd.new) Rd=#0
3077 // cmp.lt(Rs, Rt) -> cmp.gt(Rt, Rs)
3078 def : Pat <(i32 (zext (i1 (setlt (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))))),
3079 (i32 (TFR_condset_ii (i1 (C2_cmpgt (i32 IntRegs:$Rt),
3080 (i32 IntRegs:$Rs))),
3085 // zext( setugt ( Rs, Rt))
3087 // Pd=cmp.gtu(Rs, Rt)
3088 // if (Pd.new) Rd=#1
3089 // if (!Pd.new) Rd=#0
3090 def : Pat <(i32 (zext (i1 (setugt (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))))),
3091 (i32 (TFR_condset_ii (i1 (C2_cmpgtu (i32 IntRegs:$Rs),
3092 (i32 IntRegs:$Rt))),
3096 // This pattern interefers with coremark performance, not implementing at this
3099 // zext( setgt ( Rs, Rt))
3101 // Pd=cmp.gt(Rs, Rt)
3102 // if (Pd.new) Rd=#1
3103 // if (!Pd.new) Rd=#0
3106 // zext( setuge ( Rs, Rt))
3108 // Pd=cmp.ltu(Rs, Rt)
3109 // if (Pd.new) Rd=#0
3110 // if (!Pd.new) Rd=#1
3111 // cmp.ltu(Rs, Rt) -> cmp.gtu(Rt, Rs)
3112 def : Pat <(i32 (zext (i1 (setuge (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))))),
3113 (i32 (TFR_condset_ii (i1 (C2_cmpgtu (i32 IntRegs:$Rt),
3114 (i32 IntRegs:$Rs))),
3119 // zext( setge ( Rs, Rt))
3121 // Pd=cmp.lt(Rs, Rt)
3122 // if (Pd.new) Rd=#0
3123 // if (!Pd.new) Rd=#1
3124 // cmp.lt(Rs, Rt) -> cmp.gt(Rt, Rs)
3125 def : Pat <(i32 (zext (i1 (setge (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))))),
3126 (i32 (TFR_condset_ii (i1 (C2_cmpgt (i32 IntRegs:$Rt),
3127 (i32 IntRegs:$Rs))),
3132 // zext( setule ( Rs, Rt))
3134 // Pd=cmp.gtu(Rs, Rt)
3135 // if (Pd.new) Rd=#0
3136 // if (!Pd.new) Rd=#1
3137 def : Pat <(i32 (zext (i1 (setule (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))))),
3138 (i32 (TFR_condset_ii (i1 (C2_cmpgtu (i32 IntRegs:$Rs),
3139 (i32 IntRegs:$Rt))),
3144 // zext( setle ( Rs, Rt))
3146 // Pd=cmp.gt(Rs, Rt)
3147 // if (Pd.new) Rd=#0
3148 // if (!Pd.new) Rd=#1
3149 def : Pat <(i32 (zext (i1 (setle (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))))),
3150 (i32 (TFR_condset_ii (i1 (C2_cmpgt (i32 IntRegs:$Rs),
3151 (i32 IntRegs:$Rt))),
3156 // zext( setult ( and(Rs, 255), u8))
3157 // Use the isdigit transformation below
3159 // Generate code of the form 'mux_ii(cmpbgtu(Rdd, C-1),0,1)'
3160 // for C code of the form r = ((c>='0') & (c<='9')) ? 1 : 0;.
3161 // The isdigit transformation relies on two 'clever' aspects:
3162 // 1) The data type is unsigned which allows us to eliminate a zero test after
3163 // biasing the expression by 48. We are depending on the representation of
3164 // the unsigned types, and semantics.
3165 // 2) The front end has converted <= 9 into < 10 on entry to LLVM
3168 // retval = ((c>='0') & (c<='9')) ? 1 : 0;
3169 // The code is transformed upstream of llvm into
3170 // retval = (c-48) < 10 ? 1 : 0;
3171 let AddedComplexity = 139 in
3172 def : Pat <(i32 (zext (i1 (setult (i32 (and (i32 IntRegs:$src1), 255)),
3173 u7StrictPosImmPred:$src2)))),
3174 (i32 (C2_muxii (i1 (A4_cmpbgtui (i32 IntRegs:$src1),
3175 (DEC_CONST_BYTE u7StrictPosImmPred:$src2))),
3179 //===----------------------------------------------------------------------===//
3181 //===----------------------------------------------------------------------===//
3183 //===----------------------------------------------------------------------===//
3184 // Multiclass for DeallocReturn
3185 //===----------------------------------------------------------------------===//
3186 class L4_RETURN<string mnemonic, bit isNot, bit isPredNew, bit isTak>
3187 : LD0Inst<(outs), (ins PredRegs:$src),
3188 !if(isNot, "if (!$src", "if ($src")#
3189 !if(isPredNew, ".new) ", ") ")#mnemonic#
3190 !if(isPredNew, #!if(isTak,":t", ":nt"),""),
3191 [], "", LD_tc_3or4stall_SLOT0> {
3194 let BaseOpcode = "L4_RETURN";
3195 let isPredicatedFalse = isNot;
3196 let isPredicatedNew = isPredNew;
3197 let isTaken = isTak;
3198 let IClass = 0b1001;
3200 let Inst{27-16} = 0b011000011110;
3202 let Inst{13} = isNot;
3203 let Inst{12} = isTak;
3204 let Inst{11} = isPredNew;
3206 let Inst{9-8} = src;
3207 let Inst{4-0} = 0b11110;
3210 // Produce all predicated forms, p, !p, p.new, !p.new, :t, :nt
3211 multiclass L4_RETURN_PRED<string mnemonic, bit PredNot> {
3212 let isPredicated = 1 in {
3213 def _#NAME# : L4_RETURN <mnemonic, PredNot, 0, 1>;
3214 def _#NAME#new_pnt : L4_RETURN <mnemonic, PredNot, 1, 0>;
3215 def _#NAME#new_pt : L4_RETURN <mnemonic, PredNot, 1, 1>;
3219 multiclass LD_MISC_L4_RETURN<string mnemonic> {
3220 let isBarrier = 1, isPredicable = 1 in
3221 def NAME : LD0Inst <(outs), (ins), mnemonic, [], "",
3222 LD_tc_3or4stall_SLOT0> {
3223 let BaseOpcode = "L4_RETURN";
3224 let IClass = 0b1001;
3225 let Inst{27-16} = 0b011000011110;
3226 let Inst{13-10} = 0b0000;
3227 let Inst{4-0} = 0b11110;
3229 defm t : L4_RETURN_PRED<mnemonic, 0 >;
3230 defm f : L4_RETURN_PRED<mnemonic, 1 >;
3233 let isReturn = 1, isTerminator = 1,
3234 Defs = [R29, R30, R31, PC], Uses = [R30], hasSideEffects = 0,
3235 validSubTargets = HasV4SubT in
3236 defm L4_return: LD_MISC_L4_RETURN <"dealloc_return">, PredNewRel;
3238 // Restore registers and dealloc return function call.
3239 let isCall = 1, isBarrier = 1, isReturn = 1, isTerminator = 1,
3240 Defs = [R29, R30, R31, PC], isAsmParserOnly = 1 in {
3241 let validSubTargets = HasV4SubT in
3242 def RESTORE_DEALLOC_RET_JMP_V4 : JInst<(outs),
3243 (ins calltarget:$dst),
3249 // Restore registers and dealloc frame before a tail call.
3250 let isCall = 1, isBarrier = 1, isAsmParserOnly = 1,
3251 Defs = [R29, R30, R31, PC] in {
3252 let validSubTargets = HasV4SubT in
3253 def RESTORE_DEALLOC_BEFORE_TAILCALL_V4 : JInst<(outs),
3254 (ins calltarget:$dst),
3260 // Save registers function call.
3261 let isCall = 1, isBarrier = 1, isAsmParserOnly = 1,
3262 Uses = [R29, R31] in {
3263 def SAVE_REGISTERS_CALL_V4 : JInst<(outs),
3264 (ins calltarget:$dst),
3265 "call $dst // Save_calle_saved_registers",
3270 //===----------------------------------------------------------------------===//
3271 // Template class for non predicated store instructions with
3272 // GP-Relative or absolute addressing.
3273 //===----------------------------------------------------------------------===//
3274 let hasSideEffects = 0, isPredicable = 1, isNVStorable = 1 in
3275 class T_StoreAbsGP <string mnemonic, RegisterClass RC, Operand ImmOp,
3276 bits<2>MajOp, Operand AddrOp, bit isAbs, bit isHalf>
3277 : STInst<(outs), (ins AddrOp:$addr, RC:$src),
3278 mnemonic # !if(isAbs, "(##", "(#")#"$addr) = $src"#!if(isHalf, ".h",""),
3279 [], "", V2LDST_tc_st_SLOT01> {
3282 bits<16> offsetBits;
3284 string ImmOpStr = !cast<string>(ImmOp);
3285 let offsetBits = !if (!eq(ImmOpStr, "u16_3Imm"), addr{18-3},
3286 !if (!eq(ImmOpStr, "u16_2Imm"), addr{17-2},
3287 !if (!eq(ImmOpStr, "u16_1Imm"), addr{16-1},
3288 /* u16_0Imm */ addr{15-0})));
3289 let IClass = 0b0100;
3291 let Inst{26-25} = offsetBits{15-14};
3293 let Inst{23-22} = MajOp;
3294 let Inst{21} = isHalf;
3295 let Inst{20-16} = offsetBits{13-9};
3296 let Inst{13} = offsetBits{8};
3297 let Inst{12-8} = src;
3298 let Inst{7-0} = offsetBits{7-0};
3301 //===----------------------------------------------------------------------===//
3302 // Template class for predicated store instructions with
3303 // GP-Relative or absolute addressing.
3304 //===----------------------------------------------------------------------===//
3305 let hasSideEffects = 0, isPredicated = 1, isNVStorable = 1, opExtentBits = 6,
3307 class T_StoreAbs_Pred <string mnemonic, RegisterClass RC, bits<2> MajOp,
3308 bit isHalf, bit isNot, bit isNew>
3309 : STInst<(outs), (ins PredRegs:$src1, u6Ext:$absaddr, RC: $src2),
3310 !if(isNot, "if (!$src1", "if ($src1")#!if(isNew, ".new) ",
3311 ") ")#mnemonic#"(#$absaddr) = $src2"#!if(isHalf, ".h",""),
3312 [], "", ST_tc_st_SLOT01>, AddrModeRel {
3317 let isPredicatedNew = isNew;
3318 let isPredicatedFalse = isNot;
3320 let IClass = 0b1010;
3322 let Inst{27-24} = 0b1111;
3323 let Inst{23-22} = MajOp;
3324 let Inst{21} = isHalf;
3325 let Inst{17-16} = absaddr{5-4};
3326 let Inst{13} = isNew;
3327 let Inst{12-8} = src2;
3329 let Inst{6-3} = absaddr{3-0};
3330 let Inst{2} = isNot;
3331 let Inst{1-0} = src1;
3334 //===----------------------------------------------------------------------===//
3335 // Template class for predicated store instructions with absolute addressing.
3336 //===----------------------------------------------------------------------===//
3337 class T_StoreAbs <string mnemonic, RegisterClass RC, Operand ImmOp,
3338 bits<2> MajOp, bit isHalf>
3339 : T_StoreAbsGP <mnemonic, RC, ImmOp, MajOp, u0AlwaysExt, 1, isHalf>,
3341 string ImmOpStr = !cast<string>(ImmOp);
3342 let opExtentBits = !if (!eq(ImmOpStr, "u16_3Imm"), 19,
3343 !if (!eq(ImmOpStr, "u16_2Imm"), 18,
3344 !if (!eq(ImmOpStr, "u16_1Imm"), 17,
3345 /* u16_0Imm */ 16)));
3347 let opExtentAlign = !if (!eq(ImmOpStr, "u16_3Imm"), 3,
3348 !if (!eq(ImmOpStr, "u16_2Imm"), 2,
3349 !if (!eq(ImmOpStr, "u16_1Imm"), 1,
3350 /* u16_0Imm */ 0)));
3353 //===----------------------------------------------------------------------===//
3354 // Multiclass for store instructions with absolute addressing.
3355 //===----------------------------------------------------------------------===//
3356 let validSubTargets = HasV4SubT, addrMode = Absolute, isExtended = 1 in
3357 multiclass ST_Abs<string mnemonic, string CextOp, RegisterClass RC,
3358 Operand ImmOp, bits<2> MajOp, bit isHalf = 0> {
3359 let CextOpcode = CextOp, BaseOpcode = CextOp#_abs in {
3360 let opExtendable = 0, isPredicable = 1 in
3361 def S2_#NAME#abs : T_StoreAbs <mnemonic, RC, ImmOp, MajOp, isHalf>;
3364 def S4_p#NAME#t_abs : T_StoreAbs_Pred<mnemonic, RC, MajOp, isHalf, 0, 0>;
3365 def S4_p#NAME#f_abs : T_StoreAbs_Pred<mnemonic, RC, MajOp, isHalf, 1, 0>;
3368 def S4_p#NAME#tnew_abs : T_StoreAbs_Pred<mnemonic, RC, MajOp, isHalf, 0, 1>;
3369 def S4_p#NAME#fnew_abs : T_StoreAbs_Pred<mnemonic, RC, MajOp, isHalf, 1, 1>;
3373 //===----------------------------------------------------------------------===//
3374 // Template class for non predicated new-value store instructions with
3375 // GP-Relative or absolute addressing.
3376 //===----------------------------------------------------------------------===//
3377 let hasSideEffects = 0, isPredicable = 1, mayStore = 1, isNVStore = 1,
3378 isNewValue = 1, opNewValue = 1 in
3379 class T_StoreAbsGP_NV <string mnemonic, Operand ImmOp, bits<2>MajOp, bit isAbs>
3380 : NVInst_V4<(outs), (ins u0AlwaysExt:$addr, IntRegs:$src),
3381 mnemonic # !if(isAbs, "(##", "(#")#"$addr) = $src.new",
3382 [], "", V2LDST_tc_st_SLOT0> {
3385 bits<16> offsetBits;
3387 string ImmOpStr = !cast<string>(ImmOp);
3388 let offsetBits = !if (!eq(ImmOpStr, "u16_3Imm"), addr{18-3},
3389 !if (!eq(ImmOpStr, "u16_2Imm"), addr{17-2},
3390 !if (!eq(ImmOpStr, "u16_1Imm"), addr{16-1},
3391 /* u16_0Imm */ addr{15-0})));
3392 let IClass = 0b0100;
3395 let Inst{26-25} = offsetBits{15-14};
3396 let Inst{24-21} = 0b0101;
3397 let Inst{20-16} = offsetBits{13-9};
3398 let Inst{13} = offsetBits{8};
3399 let Inst{12-11} = MajOp;
3400 let Inst{10-8} = src;
3401 let Inst{7-0} = offsetBits{7-0};
3404 //===----------------------------------------------------------------------===//
3405 // Template class for predicated new-value store instructions with
3406 // absolute addressing.
3407 //===----------------------------------------------------------------------===//
3408 let hasSideEffects = 0, isPredicated = 1, mayStore = 1, isNVStore = 1,
3409 isNewValue = 1, opNewValue = 2, opExtentBits = 6, opExtendable = 1 in
3410 class T_StoreAbs_NV_Pred <string mnemonic, bits<2> MajOp, bit isNot, bit isNew>
3411 : NVInst_V4<(outs), (ins PredRegs:$src1, u6Ext:$absaddr, IntRegs:$src2),
3412 !if(isNot, "if (!$src1", "if ($src1")#!if(isNew, ".new) ",
3413 ") ")#mnemonic#"(#$absaddr) = $src2.new",
3414 [], "", ST_tc_st_SLOT0>, AddrModeRel {
3419 let isPredicatedNew = isNew;
3420 let isPredicatedFalse = isNot;
3422 let IClass = 0b1010;
3424 let Inst{27-24} = 0b1111;
3425 let Inst{23-21} = 0b101;
3426 let Inst{17-16} = absaddr{5-4};
3427 let Inst{13} = isNew;
3428 let Inst{12-11} = MajOp;
3429 let Inst{10-8} = src2;
3431 let Inst{6-3} = absaddr{3-0};
3432 let Inst{2} = isNot;
3433 let Inst{1-0} = src1;
3436 //===----------------------------------------------------------------------===//
3437 // Template class for non-predicated new-value store instructions with
3438 // absolute addressing.
3439 //===----------------------------------------------------------------------===//
3440 class T_StoreAbs_NV <string mnemonic, Operand ImmOp, bits<2> MajOp>
3441 : T_StoreAbsGP_NV <mnemonic, ImmOp, MajOp, 1>, AddrModeRel {
3443 string ImmOpStr = !cast<string>(ImmOp);
3444 let opExtentBits = !if (!eq(ImmOpStr, "u16_3Imm"), 19,
3445 !if (!eq(ImmOpStr, "u16_2Imm"), 18,
3446 !if (!eq(ImmOpStr, "u16_1Imm"), 17,
3447 /* u16_0Imm */ 16)));
3449 let opExtentAlign = !if (!eq(ImmOpStr, "u16_3Imm"), 3,
3450 !if (!eq(ImmOpStr, "u16_2Imm"), 2,
3451 !if (!eq(ImmOpStr, "u16_1Imm"), 1,
3452 /* u16_0Imm */ 0)));
3455 //===----------------------------------------------------------------------===//
3456 // Multiclass for new-value store instructions with absolute addressing.
3457 //===----------------------------------------------------------------------===//
3458 let validSubTargets = HasV4SubT, addrMode = Absolute, isExtended = 1 in
3459 multiclass ST_Abs_NV <string mnemonic, string CextOp, Operand ImmOp,
3461 let CextOpcode = CextOp, BaseOpcode = CextOp#_abs in {
3462 let opExtendable = 0, isPredicable = 1 in
3463 def S2_#NAME#newabs : T_StoreAbs_NV <mnemonic, ImmOp, MajOp>;
3466 def S4_p#NAME#newt_abs : T_StoreAbs_NV_Pred <mnemonic, MajOp, 0, 0>;
3467 def S4_p#NAME#newf_abs : T_StoreAbs_NV_Pred <mnemonic, MajOp, 1, 0>;
3470 def S4_p#NAME#newtnew_abs : T_StoreAbs_NV_Pred <mnemonic, MajOp, 0, 1>;
3471 def S4_p#NAME#newfnew_abs : T_StoreAbs_NV_Pred <mnemonic, MajOp, 1, 1>;
3475 //===----------------------------------------------------------------------===//
3476 // Stores with absolute addressing
3477 //===----------------------------------------------------------------------===//
3478 let accessSize = ByteAccess in
3479 defm storerb : ST_Abs <"memb", "STrib", IntRegs, u16_0Imm, 0b00>,
3480 ST_Abs_NV <"memb", "STrib", u16_0Imm, 0b00>;
3482 let accessSize = HalfWordAccess in
3483 defm storerh : ST_Abs <"memh", "STrih", IntRegs, u16_1Imm, 0b01>,
3484 ST_Abs_NV <"memh", "STrih", u16_1Imm, 0b01>;
3486 let accessSize = WordAccess in
3487 defm storeri : ST_Abs <"memw", "STriw", IntRegs, u16_2Imm, 0b10>,
3488 ST_Abs_NV <"memw", "STriw", u16_2Imm, 0b10>;
3490 let isNVStorable = 0, accessSize = DoubleWordAccess in
3491 defm storerd : ST_Abs <"memd", "STrid", DoubleRegs, u16_3Imm, 0b11>;
3493 let isNVStorable = 0, accessSize = HalfWordAccess in
3494 defm storerf : ST_Abs <"memh", "STrif", IntRegs, u16_1Imm, 0b01, 1>;
3496 //===----------------------------------------------------------------------===//
3497 // GP-relative stores.
3498 // mem[bhwd](#global)=Rt
3499 // Once predicated, these instructions map to absolute addressing mode.
3500 // if ([!]Pv[.new]) mem[bhwd](##global)=Rt
3501 //===----------------------------------------------------------------------===//
3503 let validSubTargets = HasV4SubT, isAsmParserOnly = 1 in
3504 class T_StoreGP <string mnemonic, string BaseOp, RegisterClass RC,
3505 Operand ImmOp, bits<2> MajOp, bit isHalf = 0>
3506 : T_StoreAbsGP <mnemonic, RC, ImmOp, MajOp, globaladdress, 0, isHalf> {
3507 // Set BaseOpcode same as absolute addressing instructions so that
3508 // non-predicated GP-Rel instructions can have relate with predicated
3509 // Absolute instruction.
3510 let BaseOpcode = BaseOp#_abs;
3513 let validSubTargets = HasV4SubT, isAsmParserOnly = 1 in
3514 multiclass ST_GP <string mnemonic, string BaseOp, Operand ImmOp,
3515 bits<2> MajOp, bit isHalf = 0> {
3516 // Set BaseOpcode same as absolute addressing instructions so that
3517 // non-predicated GP-Rel instructions can have relate with predicated
3518 // Absolute instruction.
3519 let BaseOpcode = BaseOp#_abs in {
3520 def NAME#gp : T_StoreAbsGP <mnemonic, IntRegs, ImmOp, MajOp,
3521 globaladdress, 0, isHalf>;
3523 def NAME#newgp : T_StoreAbsGP_NV <mnemonic, ImmOp, MajOp, 0> ;
3527 let accessSize = ByteAccess in
3528 defm S2_storerb : ST_GP<"memb", "STrib", u16_0Imm, 0b00>, NewValueRel;
3530 let accessSize = HalfWordAccess in
3531 defm S2_storerh : ST_GP<"memh", "STrih", u16_1Imm, 0b01>, NewValueRel;
3533 let accessSize = WordAccess in
3534 defm S2_storeri : ST_GP<"memw", "STriw", u16_2Imm, 0b10>, NewValueRel;
3536 let isNVStorable = 0, accessSize = DoubleWordAccess in
3537 def S2_storerdgp : T_StoreGP <"memd", "STrid", DoubleRegs,
3538 u16_3Imm, 0b11>, PredNewRel;
3540 let isNVStorable = 0, accessSize = HalfWordAccess in
3541 def S2_storerfgp : T_StoreGP <"memh", "STrif", IntRegs,
3542 u16_1Imm, 0b01, 1>, PredNewRel;
3544 class Loada_pat<PatFrag Load, ValueType VT, PatFrag Addr, InstHexagon MI>
3545 : Pat<(VT (Load Addr:$addr)), (MI Addr:$addr)>;
3547 class Loadam_pat<PatFrag Load, ValueType VT, PatFrag Addr, PatFrag ValueMod,
3549 : Pat<(VT (Load Addr:$addr)), (ValueMod (MI Addr:$addr))>;
3551 class Storea_pat<PatFrag Store, PatFrag Value, PatFrag Addr, InstHexagon MI>
3552 : Pat<(Store Value:$val, Addr:$addr), (MI Addr:$addr, Value:$val)>;
3554 class Stoream_pat<PatFrag Store, PatFrag Value, PatFrag Addr, PatFrag ValueMod,
3556 : Pat<(Store Value:$val, Addr:$addr),
3557 (MI Addr:$addr, (ValueMod Value:$val))>;
3559 def: Storea_pat<SwapSt<atomic_store_8>, I32, addrgp, S2_storerbgp>;
3560 def: Storea_pat<SwapSt<atomic_store_16>, I32, addrgp, S2_storerhgp>;
3561 def: Storea_pat<SwapSt<atomic_store_32>, I32, addrgp, S2_storerigp>;
3562 def: Storea_pat<SwapSt<atomic_store_64>, I64, addrgp, S2_storerdgp>;
3564 let AddedComplexity = 100 in {
3565 def: Storea_pat<truncstorei8, I32, addrgp, S2_storerbgp>;
3566 def: Storea_pat<truncstorei16, I32, addrgp, S2_storerhgp>;
3567 def: Storea_pat<store, I32, addrgp, S2_storerigp>;
3568 def: Storea_pat<store, I64, addrgp, S2_storerdgp>;
3570 // Map from "i1 = constant<-1>; memw(CONST32(#foo)) = i1"
3571 // to "r0 = 1; memw(#foo) = r0"
3572 let AddedComplexity = 100 in
3573 def: Pat<(store (i1 -1), (HexagonCONST32_GP tglobaladdr:$global)),
3574 (S2_storerbgp tglobaladdr:$global, (A2_tfrsi 1))>;
3577 //===----------------------------------------------------------------------===//
3578 // Template class for non predicated load instructions with
3579 // absolute addressing mode.
3580 //===----------------------------------------------------------------------===//
3581 let isPredicable = 1, hasSideEffects = 0, validSubTargets = HasV4SubT in
3582 class T_LoadAbsGP <string mnemonic, RegisterClass RC, Operand ImmOp,
3583 bits<3> MajOp, Operand AddrOp, bit isAbs>
3584 : LDInst <(outs RC:$dst), (ins AddrOp:$addr),
3585 "$dst = "#mnemonic# !if(isAbs, "(##", "(#")#"$addr)",
3586 [], "", V2LDST_tc_ld_SLOT01> {
3589 bits<16> offsetBits;
3591 string ImmOpStr = !cast<string>(ImmOp);
3592 let offsetBits = !if (!eq(ImmOpStr, "u16_3Imm"), addr{18-3},
3593 !if (!eq(ImmOpStr, "u16_2Imm"), addr{17-2},
3594 !if (!eq(ImmOpStr, "u16_1Imm"), addr{16-1},
3595 /* u16_0Imm */ addr{15-0})));
3597 let IClass = 0b0100;
3600 let Inst{26-25} = offsetBits{15-14};
3602 let Inst{23-21} = MajOp;
3603 let Inst{20-16} = offsetBits{13-9};
3604 let Inst{13-5} = offsetBits{8-0};
3605 let Inst{4-0} = dst;
3608 class T_LoadAbs <string mnemonic, RegisterClass RC, Operand ImmOp,
3610 : T_LoadAbsGP <mnemonic, RC, ImmOp, MajOp, u0AlwaysExt, 1>, AddrModeRel {
3612 string ImmOpStr = !cast<string>(ImmOp);
3613 let opExtentBits = !if (!eq(ImmOpStr, "u16_3Imm"), 19,
3614 !if (!eq(ImmOpStr, "u16_2Imm"), 18,
3615 !if (!eq(ImmOpStr, "u16_1Imm"), 17,
3616 /* u16_0Imm */ 16)));
3618 let opExtentAlign = !if (!eq(ImmOpStr, "u16_3Imm"), 3,
3619 !if (!eq(ImmOpStr, "u16_2Imm"), 2,
3620 !if (!eq(ImmOpStr, "u16_1Imm"), 1,
3621 /* u16_0Imm */ 0)));
3623 //===----------------------------------------------------------------------===//
3624 // Template class for predicated load instructions with
3625 // absolute addressing mode.
3626 //===----------------------------------------------------------------------===//
3627 let isPredicated = 1, hasNewValue = 1, opExtentBits = 6, opExtendable = 2 in
3628 class T_LoadAbs_Pred <string mnemonic, RegisterClass RC, bits<3> MajOp,
3629 bit isPredNot, bit isPredNew>
3630 : LDInst <(outs RC:$dst), (ins PredRegs:$src1, u6Ext:$absaddr),
3631 !if(isPredNot, "if (!$src1", "if ($src1")#!if(isPredNew, ".new) ",
3632 ") ")#"$dst = "#mnemonic#"(#$absaddr)">, AddrModeRel {
3637 let isPredicatedNew = isPredNew;
3638 let isPredicatedFalse = isPredNot;
3640 let IClass = 0b1001;
3642 let Inst{27-24} = 0b1111;
3643 let Inst{23-21} = MajOp;
3644 let Inst{20-16} = absaddr{5-1};
3646 let Inst{12} = isPredNew;
3647 let Inst{11} = isPredNot;
3648 let Inst{10-9} = src1;
3649 let Inst{8} = absaddr{0};
3651 let Inst{4-0} = dst;
3654 //===----------------------------------------------------------------------===//
3655 // Multiclass for the load instructions with absolute addressing mode.
3656 //===----------------------------------------------------------------------===//
3657 multiclass LD_Abs_Pred<string mnemonic, RegisterClass RC, bits<3> MajOp,
3659 def _abs : T_LoadAbs_Pred <mnemonic, RC, MajOp, PredNot, 0>;
3661 def new_abs : T_LoadAbs_Pred <mnemonic, RC, MajOp, PredNot, 1>;
3664 let addrMode = Absolute, isExtended = 1 in
3665 multiclass LD_Abs<string mnemonic, string CextOp, RegisterClass RC,
3666 Operand ImmOp, bits<3> MajOp> {
3667 let CextOpcode = CextOp, BaseOpcode = CextOp#_abs in {
3668 let opExtendable = 1, isPredicable = 1 in
3669 def L4_#NAME#_abs: T_LoadAbs <mnemonic, RC, ImmOp, MajOp>;
3672 defm L4_p#NAME#t : LD_Abs_Pred<mnemonic, RC, MajOp, 0>;
3673 defm L4_p#NAME#f : LD_Abs_Pred<mnemonic, RC, MajOp, 1>;
3677 let accessSize = ByteAccess, hasNewValue = 1 in {
3678 defm loadrb : LD_Abs<"memb", "LDrib", IntRegs, u16_0Imm, 0b000>;
3679 defm loadrub : LD_Abs<"memub", "LDriub", IntRegs, u16_0Imm, 0b001>;
3682 let accessSize = HalfWordAccess, hasNewValue = 1 in {
3683 defm loadrh : LD_Abs<"memh", "LDrih", IntRegs, u16_1Imm, 0b010>;
3684 defm loadruh : LD_Abs<"memuh", "LDriuh", IntRegs, u16_1Imm, 0b011>;
3687 let accessSize = WordAccess, hasNewValue = 1 in
3688 defm loadri : LD_Abs<"memw", "LDriw", IntRegs, u16_2Imm, 0b100>;
3690 let accessSize = DoubleWordAccess in
3691 defm loadrd : LD_Abs<"memd", "LDrid", DoubleRegs, u16_3Imm, 0b110>;
3693 //===----------------------------------------------------------------------===//
3694 // multiclass for load instructions with GP-relative addressing mode.
3695 // Rx=mem[bhwd](##global)
3696 // Once predicated, these instructions map to absolute addressing mode.
3697 // if ([!]Pv[.new]) Rx=mem[bhwd](##global)
3698 //===----------------------------------------------------------------------===//
3700 let isAsmParserOnly = 1 in
3701 class T_LoadGP <string mnemonic, string BaseOp, RegisterClass RC, Operand ImmOp,
3703 : T_LoadAbsGP <mnemonic, RC, ImmOp, MajOp, globaladdress, 0>, PredNewRel {
3704 let BaseOpcode = BaseOp#_abs;
3707 let accessSize = ByteAccess, hasNewValue = 1 in {
3708 def L2_loadrbgp : T_LoadGP<"memb", "LDrib", IntRegs, u16_0Imm, 0b000>;
3709 def L2_loadrubgp : T_LoadGP<"memub", "LDriub", IntRegs, u16_0Imm, 0b001>;
3712 let accessSize = HalfWordAccess, hasNewValue = 1 in {
3713 def L2_loadrhgp : T_LoadGP<"memh", "LDrih", IntRegs, u16_1Imm, 0b010>;
3714 def L2_loadruhgp : T_LoadGP<"memuh", "LDriuh", IntRegs, u16_1Imm, 0b011>;
3717 let accessSize = WordAccess, hasNewValue = 1 in
3718 def L2_loadrigp : T_LoadGP<"memw", "LDriw", IntRegs, u16_2Imm, 0b100>;
3720 let accessSize = DoubleWordAccess in
3721 def L2_loadrdgp : T_LoadGP<"memd", "LDrid", DoubleRegs, u16_3Imm, 0b110>;
3723 def: Loada_pat<atomic_load_8, i32, addrgp, L2_loadrubgp>;
3724 def: Loada_pat<atomic_load_16, i32, addrgp, L2_loadruhgp>;
3725 def: Loada_pat<atomic_load_32, i32, addrgp, L2_loadrigp>;
3726 def: Loada_pat<atomic_load_64, i64, addrgp, L2_loadrdgp>;
3728 // Map from load(globaladdress) -> mem[u][bhwd](#foo)
3729 class LoadGP_pats <PatFrag ldOp, InstHexagon MI, ValueType VT = i32>
3730 : Pat <(VT (ldOp (HexagonCONST32_GP tglobaladdr:$global))),
3731 (VT (MI tglobaladdr:$global))>;
3733 let AddedComplexity = 100 in {
3734 def: LoadGP_pats <extloadi8, L2_loadrbgp>;
3735 def: LoadGP_pats <sextloadi8, L2_loadrbgp>;
3736 def: LoadGP_pats <zextloadi8, L2_loadrubgp>;
3737 def: LoadGP_pats <extloadi16, L2_loadrhgp>;
3738 def: LoadGP_pats <sextloadi16, L2_loadrhgp>;
3739 def: LoadGP_pats <zextloadi16, L2_loadruhgp>;
3740 def: LoadGP_pats <load, L2_loadrigp>;
3741 def: LoadGP_pats <load, L2_loadrdgp, i64>;
3744 // When the Interprocedural Global Variable optimizer realizes that a certain
3745 // global variable takes only two constant values, it shrinks the global to
3746 // a boolean. Catch those loads here in the following 3 patterns.
3747 let AddedComplexity = 100 in {
3748 def: LoadGP_pats <extloadi1, L2_loadrubgp>;
3749 def: LoadGP_pats <zextloadi1, L2_loadrubgp>;
3752 def: Pat<(i64 (ctlz I64:$src1)), (Zext64 (S2_cl0p I64:$src1))>;
3753 def: Pat<(i64 (cttz I64:$src1)), (Zext64 (S2_ct0p I64:$src1))>;
3755 let AddedComplexity = 30 in {
3756 def: Storea_pat<truncstorei8, I32, u0AlwaysExtPred, S2_storerbabs>;
3757 def: Storea_pat<truncstorei16, I32, u0AlwaysExtPred, S2_storerhabs>;
3758 def: Storea_pat<store, I32, u0AlwaysExtPred, S2_storeriabs>;
3761 let AddedComplexity = 30 in {
3762 def: Loada_pat<load, i32, u0AlwaysExtPred, L4_loadri_abs>;
3763 def: Loada_pat<sextloadi8, i32, u0AlwaysExtPred, L4_loadrb_abs>;
3764 def: Loada_pat<zextloadi8, i32, u0AlwaysExtPred, L4_loadrub_abs>;
3765 def: Loada_pat<sextloadi16, i32, u0AlwaysExtPred, L4_loadrh_abs>;
3766 def: Loada_pat<zextloadi16, i32, u0AlwaysExtPred, L4_loadruh_abs>;
3769 // Indexed store word - global address.
3770 // memw(Rs+#u6:2)=#S8
3771 let AddedComplexity = 100 in
3772 def: Storex_add_pat<store, addrga, u6_2ImmPred, S4_storeiri_io>;
3774 // Load from a global address that has only one use in the current basic block.
3775 let AddedComplexity = 100 in {
3776 def: Loada_pat<extloadi8, i32, addrga, L4_loadrub_abs>;
3777 def: Loada_pat<sextloadi8, i32, addrga, L4_loadrb_abs>;
3778 def: Loada_pat<zextloadi8, i32, addrga, L4_loadrub_abs>;
3780 def: Loada_pat<extloadi16, i32, addrga, L4_loadruh_abs>;
3781 def: Loada_pat<sextloadi16, i32, addrga, L4_loadrh_abs>;
3782 def: Loada_pat<zextloadi16, i32, addrga, L4_loadruh_abs>;
3784 def: Loada_pat<load, i32, addrga, L4_loadri_abs>;
3785 def: Loada_pat<load, i64, addrga, L4_loadrd_abs>;
3788 // Store to a global address that has only one use in the current basic block.
3789 let AddedComplexity = 100 in {
3790 def: Storea_pat<truncstorei8, I32, addrga, S2_storerbabs>;
3791 def: Storea_pat<truncstorei16, I32, addrga, S2_storerhabs>;
3792 def: Storea_pat<store, I32, addrga, S2_storeriabs>;
3793 def: Storea_pat<store, I64, addrga, S2_storerdabs>;
3795 def: Stoream_pat<truncstorei32, I64, addrga, LoReg, S2_storeriabs>;
3798 // Map from Pd = load(globaladdress) -> Rd = memb(globaladdress), Pd = Rd
3799 let AddedComplexity = 100 in
3800 def : Pat <(i1 (load (HexagonCONST32_GP tglobaladdr:$global))),
3801 (i1 (C2_tfrrp (i32 (L2_loadrbgp tglobaladdr:$global))))>;
3803 // Transfer global address into a register
3804 let isExtended = 1, opExtendable = 1, AddedComplexity=50, isMoveImm = 1,
3805 isAsCheapAsAMove = 1, isReMaterializable = 1, validSubTargets = HasV4SubT,
3806 isCodeGenOnly = 1 in
3807 def TFRI_V4 : ALU32_ri<(outs IntRegs:$dst), (ins s16Ext:$src1),
3809 [(set IntRegs:$dst, (HexagonCONST32 tglobaladdr:$src1))]>,
3812 // Transfer a block address into a register
3813 def : Pat<(HexagonCONST32_GP tblockaddress:$src1),
3814 (TFRI_V4 tblockaddress:$src1)>,
3817 let AddedComplexity = 50, Predicates = [HasV4T] in
3818 def : Pat<(HexagonCONST32_GP tglobaladdr:$src1),
3819 (TFRI_V4 tglobaladdr:$src1)>,
3822 // i8/i16/i32 -> i64 loads
3823 // We need a complexity of 120 here to override preceding handling of
3825 let AddedComplexity = 120 in {
3826 def: Loadam_pat<extloadi8, i64, addrga, Zext64, L4_loadrub_abs>;
3827 def: Loadam_pat<sextloadi8, i64, addrga, Sext64, L4_loadrb_abs>;
3828 def: Loadam_pat<zextloadi8, i64, addrga, Zext64, L4_loadrub_abs>;
3830 def: Loadam_pat<extloadi16, i64, addrga, Zext64, L4_loadruh_abs>;
3831 def: Loadam_pat<sextloadi16, i64, addrga, Sext64, L4_loadrh_abs>;
3832 def: Loadam_pat<zextloadi16, i64, addrga, Zext64, L4_loadruh_abs>;
3834 def: Loadam_pat<extloadi32, i64, addrga, Zext64, L4_loadri_abs>;
3835 def: Loadam_pat<sextloadi32, i64, addrga, Sext64, L4_loadri_abs>;
3836 def: Loadam_pat<zextloadi32, i64, addrga, Zext64, L4_loadri_abs>;
3838 let AddedComplexity = 100 in {
3839 def: Loada_pat<extloadi8, i32, addrgp, L4_loadrub_abs>;
3840 def: Loada_pat<sextloadi8, i32, addrgp, L4_loadrb_abs>;
3841 def: Loada_pat<zextloadi8, i32, addrgp, L4_loadrub_abs>;
3843 def: Loada_pat<extloadi16, i32, addrgp, L4_loadruh_abs>;
3844 def: Loada_pat<sextloadi16, i32, addrgp, L4_loadrh_abs>;
3845 def: Loada_pat<zextloadi16, i32, addrgp, L4_loadruh_abs>;
3847 def: Loada_pat<load, i32, addrgp, L4_loadri_abs>;
3848 def: Loada_pat<load, i64, addrgp, L4_loadrd_abs>;
3851 let AddedComplexity = 100 in {
3852 def: Storea_pat<truncstorei8, I32, addrgp, S2_storerbabs>;
3853 def: Storea_pat<truncstorei16, I32, addrgp, S2_storerhabs>;
3854 def: Storea_pat<store, I32, addrgp, S2_storeriabs>;
3855 def: Storea_pat<store, I64, addrgp, S2_storerdabs>;
3858 def: Loada_pat<atomic_load_8, i32, addrgp, L4_loadrub_abs>;
3859 def: Loada_pat<atomic_load_16, i32, addrgp, L4_loadruh_abs>;
3860 def: Loada_pat<atomic_load_32, i32, addrgp, L4_loadri_abs>;
3861 def: Loada_pat<atomic_load_64, i64, addrgp, L4_loadrd_abs>;
3863 def: Storea_pat<SwapSt<atomic_store_8>, I32, addrgp, S2_storerbabs>;
3864 def: Storea_pat<SwapSt<atomic_store_16>, I32, addrgp, S2_storerhabs>;
3865 def: Storea_pat<SwapSt<atomic_store_32>, I32, addrgp, S2_storeriabs>;
3866 def: Storea_pat<SwapSt<atomic_store_64>, I64, addrgp, S2_storerdabs>;
3868 //===----------------------------------------------------------------------===//
3869 // :raw for of boundscheck:hi:lo insns
3870 //===----------------------------------------------------------------------===//
3872 // A4_boundscheck_lo: Detect if a register is within bounds.
3873 let hasSideEffects = 0 in
3874 def A4_boundscheck_lo: ALU64Inst <
3875 (outs PredRegs:$Pd),
3876 (ins DoubleRegs:$Rss, DoubleRegs:$Rtt),
3877 "$Pd = boundscheck($Rss, $Rtt):raw:lo"> {
3882 let IClass = 0b1101;
3884 let Inst{27-23} = 0b00100;
3886 let Inst{7-5} = 0b100;
3888 let Inst{20-16} = Rss;
3889 let Inst{12-8} = Rtt;
3892 // A4_boundscheck_hi: Detect if a register is within bounds.
3893 let hasSideEffects = 0 in
3894 def A4_boundscheck_hi: ALU64Inst <
3895 (outs PredRegs:$Pd),
3896 (ins DoubleRegs:$Rss, DoubleRegs:$Rtt),
3897 "$Pd = boundscheck($Rss, $Rtt):raw:hi"> {
3902 let IClass = 0b1101;
3904 let Inst{27-23} = 0b00100;
3906 let Inst{7-5} = 0b101;
3908 let Inst{20-16} = Rss;
3909 let Inst{12-8} = Rtt;
3912 let hasSideEffects = 0, isAsmParserOnly = 1 in
3913 def A4_boundscheck : MInst <
3914 (outs PredRegs:$Pd), (ins IntRegs:$Rs, DoubleRegs:$Rtt),
3915 "$Pd=boundscheck($Rs,$Rtt)">;
3917 // A4_tlbmatch: Detect if a VA/ASID matches a TLB entry.
3918 let isPredicateLate = 1, hasSideEffects = 0 in
3919 def A4_tlbmatch : ALU64Inst<(outs PredRegs:$Pd),
3920 (ins DoubleRegs:$Rs, IntRegs:$Rt),
3921 "$Pd = tlbmatch($Rs, $Rt)",
3922 [], "", ALU64_tc_2early_SLOT23> {
3927 let IClass = 0b1101;
3928 let Inst{27-23} = 0b00100;
3929 let Inst{20-16} = Rs;
3931 let Inst{12-8} = Rt;
3932 let Inst{7-5} = 0b011;
3936 // We need custom lowering of ISD::PREFETCH into HexagonISD::DCFETCH
3937 // because the SDNode ISD::PREFETCH has properties MayLoad and MayStore.
3938 // We don't really want either one here.
3939 def SDTHexagonDCFETCH : SDTypeProfile<0, 2, [SDTCisPtrTy<0>,SDTCisInt<1>]>;
3940 def HexagonDCFETCH : SDNode<"HexagonISD::DCFETCH", SDTHexagonDCFETCH,
3943 // Use LD0Inst for dcfetch, but set "mayLoad" to 0 because this doesn't
3944 // really do a load.
3945 let hasSideEffects = 1, mayLoad = 0 in
3946 def Y2_dcfetchbo : LD0Inst<(outs), (ins IntRegs:$Rs, u11_3Imm:$u11_3),
3947 "dcfetch($Rs + #$u11_3)",
3948 [(HexagonDCFETCH IntRegs:$Rs, u11_3ImmPred:$u11_3)],
3949 "", LD_tc_ld_SLOT0> {
3953 let IClass = 0b1001;
3954 let Inst{27-21} = 0b0100000;
3955 let Inst{20-16} = Rs;
3957 let Inst{10-0} = u11_3{13-3};
3960 //===----------------------------------------------------------------------===//
3961 // Compound instructions
3962 //===----------------------------------------------------------------------===//
3964 let isBranch = 1, hasSideEffects = 0, isExtentSigned = 1,
3965 isPredicated = 1, isPredicatedNew = 1, isExtendable = 1,
3966 opExtentBits = 11, opExtentAlign = 2, opExtendable = 1,
3967 isTerminator = 1, validSubTargets = HasV4SubT in
3968 class CJInst_tstbit_R0<string px, bit np, string tnt>
3969 : InstHexagon<(outs), (ins IntRegs:$Rs, brtarget:$r9_2),
3970 ""#px#" = tstbit($Rs, #0); if ("
3971 #!if(np, "!","")#""#px#".new) jump:"#tnt#" $r9_2",
3972 [], "", COMPOUND, TypeCOMPOUND> {
3977 let isPredicatedFalse = np;
3978 // tnt: Taken/Not Taken
3979 let isBrTaken = !if (!eq(tnt, "t"), "true", "false");
3980 let isTaken = !if (!eq(tnt, "t"), 1, 0);
3982 let IClass = 0b0001;
3983 let Inst{27-26} = 0b00;
3984 let Inst{25} = !if (!eq(px, "!p1"), 1,
3985 !if (!eq(px, "p1"), 1, 0));
3986 let Inst{24-23} = 0b11;
3988 let Inst{21-20} = r9_2{10-9};
3989 let Inst{19-16} = Rs;
3990 let Inst{13} = !if (!eq(tnt, "t"), 1, 0);
3991 let Inst{9-8} = 0b11;
3992 let Inst{7-1} = r9_2{8-2};
3995 let Defs = [PC, P0], Uses = [P0] in {
3996 def J4_tstbit0_tp0_jump_nt : CJInst_tstbit_R0<"p0", 0, "nt">;
3997 def J4_tstbit0_tp0_jump_t : CJInst_tstbit_R0<"p0", 0, "t">;
3998 def J4_tstbit0_fp0_jump_nt : CJInst_tstbit_R0<"p0", 1, "nt">;
3999 def J4_tstbit0_fp0_jump_t : CJInst_tstbit_R0<"p0", 1, "t">;
4002 let Defs = [PC, P1], Uses = [P1] in {
4003 def J4_tstbit0_tp1_jump_nt : CJInst_tstbit_R0<"p1", 0, "nt">;
4004 def J4_tstbit0_tp1_jump_t : CJInst_tstbit_R0<"p1", 0, "t">;
4005 def J4_tstbit0_fp1_jump_nt : CJInst_tstbit_R0<"p1", 1, "nt">;
4006 def J4_tstbit0_fp1_jump_t : CJInst_tstbit_R0<"p1", 1, "t">;
4010 let isBranch = 1, hasSideEffects = 0,
4011 isExtentSigned = 1, isPredicated = 1, isPredicatedNew = 1,
4012 isExtendable = 1, opExtentBits = 11, opExtentAlign = 2,
4013 opExtendable = 2, isTerminator = 1, validSubTargets = HasV4SubT in
4014 class CJInst_RR<string px, string op, bit np, string tnt>
4015 : InstHexagon<(outs), (ins IntRegs:$Rs, IntRegs:$Rt, brtarget:$r9_2),
4016 ""#px#" = cmp."#op#"($Rs, $Rt); if ("
4017 #!if(np, "!","")#""#px#".new) jump:"#tnt#" $r9_2",
4018 [], "", COMPOUND, TypeCOMPOUND> {
4024 let isPredicatedFalse = np;
4025 // tnt: Taken/Not Taken
4026 let isBrTaken = !if (!eq(tnt, "t"), "true", "false");
4027 let isTaken = !if (!eq(tnt, "t"), 1, 0);
4029 let IClass = 0b0001;
4030 let Inst{27-23} = !if (!eq(op, "eq"), 0b01000,
4031 !if (!eq(op, "gt"), 0b01001,
4032 !if (!eq(op, "gtu"), 0b01010, 0)));
4034 let Inst{21-20} = r9_2{10-9};
4035 let Inst{19-16} = Rs;
4036 let Inst{13} = !if (!eq(tnt, "t"), 1, 0);
4037 // px: Predicate reg 0/1
4038 let Inst{12} = !if (!eq(px, "!p1"), 1,
4039 !if (!eq(px, "p1"), 1, 0));
4040 let Inst{11-8} = Rt;
4041 let Inst{7-1} = r9_2{8-2};
4044 // P[10] taken/not taken.
4045 multiclass T_tnt_CJInst_RR<string op, bit np> {
4046 let Defs = [PC, P0], Uses = [P0] in {
4047 def NAME#p0_jump_nt : CJInst_RR<"p0", op, np, "nt">;
4048 def NAME#p0_jump_t : CJInst_RR<"p0", op, np, "t">;
4050 let Defs = [PC, P1], Uses = [P1] in {
4051 def NAME#p1_jump_nt : CJInst_RR<"p1", op, np, "nt">;
4052 def NAME#p1_jump_t : CJInst_RR<"p1", op, np, "t">;
4055 // Predicate / !Predicate
4056 multiclass T_pnp_CJInst_RR<string op>{
4057 defm J4_cmp#NAME#_t : T_tnt_CJInst_RR<op, 0>;
4058 defm J4_cmp#NAME#_f : T_tnt_CJInst_RR<op, 1>;
4060 // TypeCJ Instructions compare RR and jump
4061 defm eq : T_pnp_CJInst_RR<"eq">;
4062 defm gt : T_pnp_CJInst_RR<"gt">;
4063 defm gtu : T_pnp_CJInst_RR<"gtu">;
4065 let isBranch = 1, hasSideEffects = 0, isExtentSigned = 1,
4066 isPredicated = 1, isPredicatedNew = 1, isExtendable = 1, opExtentBits = 11,
4067 opExtentAlign = 2, opExtendable = 2, isTerminator = 1,
4068 validSubTargets = HasV4SubT in
4069 class CJInst_RU5<string px, string op, bit np, string tnt>
4070 : InstHexagon<(outs), (ins IntRegs:$Rs, u5Imm:$U5, brtarget:$r9_2),
4071 ""#px#" = cmp."#op#"($Rs, #$U5); if ("
4072 #!if(np, "!","")#""#px#".new) jump:"#tnt#" $r9_2",
4073 [], "", COMPOUND, TypeCOMPOUND> {
4079 let isPredicatedFalse = np;
4080 // tnt: Taken/Not Taken
4081 let isBrTaken = !if (!eq(tnt, "t"), "true", "false");
4082 let isTaken = !if (!eq(tnt, "t"), 1, 0);
4084 let IClass = 0b0001;
4085 let Inst{27-26} = 0b00;
4086 // px: Predicate reg 0/1
4087 let Inst{25} = !if (!eq(px, "!p1"), 1,
4088 !if (!eq(px, "p1"), 1, 0));
4089 let Inst{24-23} = !if (!eq(op, "eq"), 0b00,
4090 !if (!eq(op, "gt"), 0b01,
4091 !if (!eq(op, "gtu"), 0b10, 0)));
4093 let Inst{21-20} = r9_2{10-9};
4094 let Inst{19-16} = Rs;
4095 let Inst{13} = !if (!eq(tnt, "t"), 1, 0);
4096 let Inst{12-8} = U5;
4097 let Inst{7-1} = r9_2{8-2};
4099 // P[10] taken/not taken.
4100 multiclass T_tnt_CJInst_RU5<string op, bit np> {
4101 let Defs = [PC, P0], Uses = [P0] in {
4102 def NAME#p0_jump_nt : CJInst_RU5<"p0", op, np, "nt">;
4103 def NAME#p0_jump_t : CJInst_RU5<"p0", op, np, "t">;
4105 let Defs = [PC, P1], Uses = [P1] in {
4106 def NAME#p1_jump_nt : CJInst_RU5<"p1", op, np, "nt">;
4107 def NAME#p1_jump_t : CJInst_RU5<"p1", op, np, "t">;
4110 // Predicate / !Predicate
4111 multiclass T_pnp_CJInst_RU5<string op>{
4112 defm J4_cmp#NAME#i_t : T_tnt_CJInst_RU5<op, 0>;
4113 defm J4_cmp#NAME#i_f : T_tnt_CJInst_RU5<op, 1>;
4115 // TypeCJ Instructions compare RI and jump
4116 defm eq : T_pnp_CJInst_RU5<"eq">;
4117 defm gt : T_pnp_CJInst_RU5<"gt">;
4118 defm gtu : T_pnp_CJInst_RU5<"gtu">;
4120 let isBranch = 1, hasSideEffects = 0, isExtentSigned = 1,
4121 isPredicated = 1, isPredicatedFalse = 1, isPredicatedNew = 1,
4122 isExtendable = 1, opExtentBits = 11, opExtentAlign = 2, opExtendable = 1,
4123 isTerminator = 1, validSubTargets = HasV4SubT in
4124 class CJInst_Rn1<string px, string op, bit np, string tnt>
4125 : InstHexagon<(outs), (ins IntRegs:$Rs, brtarget:$r9_2),
4126 ""#px#" = cmp."#op#"($Rs,#-1); if ("
4127 #!if(np, "!","")#""#px#".new) jump:"#tnt#" $r9_2",
4128 [], "", COMPOUND, TypeCOMPOUND> {
4133 let isPredicatedFalse = np;
4134 // tnt: Taken/Not Taken
4135 let isBrTaken = !if (!eq(tnt, "t"), "true", "false");
4136 let isTaken = !if (!eq(tnt, "t"), 1, 0);
4138 let IClass = 0b0001;
4139 let Inst{27-26} = 0b00;
4140 let Inst{25} = !if (!eq(px, "!p1"), 1,
4141 !if (!eq(px, "p1"), 1, 0));
4143 let Inst{24-23} = 0b11;
4145 let Inst{21-20} = r9_2{10-9};
4146 let Inst{19-16} = Rs;
4147 let Inst{13} = !if (!eq(tnt, "t"), 1, 0);
4148 let Inst{9-8} = !if (!eq(op, "eq"), 0b00,
4149 !if (!eq(op, "gt"), 0b01, 0));
4150 let Inst{7-1} = r9_2{8-2};
4153 // P[10] taken/not taken.
4154 multiclass T_tnt_CJInst_Rn1<string op, bit np> {
4155 let Defs = [PC, P0], Uses = [P0] in {
4156 def NAME#p0_jump_nt : CJInst_Rn1<"p0", op, np, "nt">;
4157 def NAME#p0_jump_t : CJInst_Rn1<"p0", op, np, "t">;
4159 let Defs = [PC, P1], Uses = [P1] in {
4160 def NAME#p1_jump_nt : CJInst_Rn1<"p1", op, np, "nt">;
4161 def NAME#p1_jump_t : CJInst_Rn1<"p1", op, np, "t">;
4164 // Predicate / !Predicate
4165 multiclass T_pnp_CJInst_Rn1<string op>{
4166 defm J4_cmp#NAME#n1_t : T_tnt_CJInst_Rn1<op, 0>;
4167 defm J4_cmp#NAME#n1_f : T_tnt_CJInst_Rn1<op, 1>;
4169 // TypeCJ Instructions compare -1 and jump
4170 defm eq : T_pnp_CJInst_Rn1<"eq">;
4171 defm gt : T_pnp_CJInst_Rn1<"gt">;
4173 // J4_jumpseti: Direct unconditional jump and set register to immediate.
4174 let Defs = [PC], isBranch = 1, hasSideEffects = 0, hasNewValue = 1,
4175 isExtentSigned = 1, opNewValue = 0, isExtendable = 1, opExtentBits = 11,
4176 opExtentAlign = 2, opExtendable = 2, validSubTargets = HasV4SubT in
4177 def J4_jumpseti: CJInst <
4179 (ins u6Imm:$U6, brtarget:$r9_2),
4180 "$Rd = #$U6 ; jump $r9_2"> {
4185 let IClass = 0b0001;
4186 let Inst{27-24} = 0b0110;
4187 let Inst{21-20} = r9_2{10-9};
4188 let Inst{19-16} = Rd;
4189 let Inst{13-8} = U6;
4190 let Inst{7-1} = r9_2{8-2};
4193 // J4_jumpsetr: Direct unconditional jump and transfer register.
4194 let Defs = [PC], isBranch = 1, hasSideEffects = 0, hasNewValue = 1,
4195 isExtentSigned = 1, opNewValue = 0, isExtendable = 1, opExtentBits = 11,
4196 opExtentAlign = 2, opExtendable = 2, validSubTargets = HasV4SubT in
4197 def J4_jumpsetr: CJInst <
4199 (ins IntRegs:$Rs, brtarget:$r9_2),
4200 "$Rd = $Rs ; jump $r9_2"> {
4205 let IClass = 0b0001;
4206 let Inst{27-24} = 0b0111;
4207 let Inst{21-20} = r9_2{10-9};
4208 let Inst{11-8} = Rd;
4209 let Inst{19-16} = Rs;
4210 let Inst{7-1} = r9_2{8-2};