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 let hasSideEffects = 0 in
15 class T_Immext<Operand ImmType>
16 : EXTENDERInst<(outs), (ins ImmType:$imm),
17 "immext(#$imm)", []> {
21 let Inst{27-16} = imm{31-20};
22 let Inst{13-0} = imm{19-6};
25 def A4_ext : T_Immext<u26_6Imm>;
26 let isCodeGenOnly = 1 in {
28 def A4_ext_b : T_Immext<brtarget>;
30 def A4_ext_c : T_Immext<calltarget>;
31 def A4_ext_g : T_Immext<globaladdress>;
34 def BITPOS32 : SDNodeXForm<imm, [{
35 // Return the bit position we will set [0-31].
37 int32_t imm = N->getSExtValue();
38 return XformMskToBitPosU5Imm(imm);
41 // Fold (add (CONST32 tglobaladdr:$addr) <offset>) into a global address.
42 def FoldGlobalAddr : ComplexPattern<i32, 1, "foldGlobalAddress", [], []>;
44 // Fold (add (CONST32_GP tglobaladdr:$addr) <offset>) into a global address.
45 def FoldGlobalAddrGP : ComplexPattern<i32, 1, "foldGlobalAddressGP", [], []>;
47 def NumUsesBelowThresCONST32 : PatFrag<(ops node:$addr),
48 (HexagonCONST32 node:$addr), [{
49 return hasNumUsesBelowThresGA(N->getOperand(0).getNode());
52 // Hexagon V4 Architecture spec defines 8 instruction classes:
53 // LD ST ALU32 XTYPE J JR MEMOP NV CR SYSTEM(system is not implemented in the
57 // ========================================
58 // Loads (8/16/32/64 bit)
62 // ========================================
63 // Stores (8/16/32/64 bit)
66 // ALU32 Instructions:
67 // ========================================
68 // Arithmetic / Logical (32 bit)
71 // XTYPE Instructions (32/64 bit):
72 // ========================================
73 // Arithmetic, Logical, Bit Manipulation
74 // Multiply (Integer, Fractional, Complex)
75 // Permute / Vector Permute Operations
76 // Predicate Operations
77 // Shift / Shift with Add/Sub/Logical
79 // Vector Halfword (ALU, Shift, Multiply)
80 // Vector Word (ALU, Shift)
83 // ========================================
84 // Jump/Call PC-relative
87 // ========================================
90 // MEMOP Instructions:
91 // ========================================
92 // Operation on memory (8/16/32 bit)
95 // ========================================
100 // ========================================
101 // Control-Register Transfers
102 // Hardware Loop Setup
103 // Predicate Logicals & Reductions
105 // SYSTEM Instructions (not implemented in the compiler):
106 // ========================================
112 //===----------------------------------------------------------------------===//
114 //===----------------------------------------------------------------------===//
116 class T_ALU32_3op_not<string mnemonic, bits<3> MajOp, bits<3> MinOp,
118 : T_ALU32_3op<mnemonic, MajOp, MinOp, OpsRev, 0> {
119 let AsmString = "$Rd = "#mnemonic#"($Rs, ~$Rt)";
122 let BaseOpcode = "andn_rr", CextOpcode = "andn", isCodeGenOnly = 0 in
123 def A4_andn : T_ALU32_3op_not<"and", 0b001, 0b100, 1>;
124 let BaseOpcode = "orn_rr", CextOpcode = "orn", isCodeGenOnly = 0 in
125 def A4_orn : T_ALU32_3op_not<"or", 0b001, 0b101, 1>;
127 let CextOpcode = "rcmp.eq", isCodeGenOnly = 0 in
128 def A4_rcmpeq : T_ALU32_3op<"cmp.eq", 0b011, 0b010, 0, 1>;
129 let CextOpcode = "!rcmp.eq", isCodeGenOnly = 0 in
130 def A4_rcmpneq : T_ALU32_3op<"!cmp.eq", 0b011, 0b011, 0, 1>;
132 let isCodeGenOnly = 0 in {
133 def C4_cmpneq : T_ALU32_3op_cmp<"!cmp.eq", 0b00, 1, 1>;
134 def C4_cmplte : T_ALU32_3op_cmp<"!cmp.gt", 0b10, 1, 0>;
135 def C4_cmplteu : T_ALU32_3op_cmp<"!cmp.gtu", 0b11, 1, 0>;
138 // Pats for instruction selection.
140 // A class to embed the usual comparison patfrags within a zext to i32.
141 // The seteq/setne frags use "lhs" and "rhs" as operands, so use the same
142 // names, or else the frag's "body" won't match the operands.
143 class CmpInReg<PatFrag Op>
144 : PatFrag<(ops node:$lhs, node:$rhs),(i32 (zext (i1 Op.Fragment)))>;
146 def: T_cmp32_rr_pat<A4_rcmpeq, CmpInReg<seteq>, i32>;
147 def: T_cmp32_rr_pat<A4_rcmpneq, CmpInReg<setne>, i32>;
149 def: T_cmp32_rr_pat<C4_cmpneq, setne, i1>;
151 class T_CMP_rrbh<string mnemonic, bits<3> MinOp, bit IsComm>
152 : SInst<(outs PredRegs:$Pd), (ins IntRegs:$Rs, IntRegs:$Rt),
153 "$Pd = "#mnemonic#"($Rs, $Rt)", [], "", S_3op_tc_2early_SLOT23>,
155 let validSubTargets = HasV4SubT;
156 let InputType = "reg";
157 let CextOpcode = mnemonic;
159 let isCommutable = IsComm;
160 let hasSideEffects = 0;
167 let Inst{27-21} = 0b0111110;
168 let Inst{20-16} = Rs;
170 let Inst{7-5} = MinOp;
174 let isCodeGenOnly = 0 in {
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>;
183 class T_CMP_ribh<string mnemonic, bits<2> MajOp, bit IsHalf, bit IsComm,
184 Operand ImmType, bit IsImmExt, bit IsImmSigned, int ImmBits>
185 : ALU64Inst<(outs PredRegs:$Pd), (ins IntRegs:$Rs, ImmType:$Imm),
186 "$Pd = "#mnemonic#"($Rs, #$Imm)", [], "", ALU64_tc_2early_SLOT23>,
188 let validSubTargets = HasV4SubT;
189 let InputType = "imm";
190 let CextOpcode = mnemonic;
192 let isCommutable = IsComm;
193 let hasSideEffects = 0;
194 let isExtendable = IsImmExt;
195 let opExtendable = !if (IsImmExt, 2, 0);
196 let isExtentSigned = IsImmSigned;
197 let opExtentBits = ImmBits;
204 let Inst{27-24} = 0b1101;
205 let Inst{22-21} = MajOp;
206 let Inst{20-16} = Rs;
207 let Inst{12-5} = Imm;
209 let Inst{3} = IsHalf;
213 let isCodeGenOnly = 0 in {
214 def A4_cmpbeqi : T_CMP_ribh<"cmpb.eq", 0b00, 0, 1, u8Imm, 0, 0, 8>;
215 def A4_cmpbgti : T_CMP_ribh<"cmpb.gt", 0b01, 0, 0, s8Imm, 0, 1, 8>;
216 def A4_cmpbgtui : T_CMP_ribh<"cmpb.gtu", 0b10, 0, 0, u7Ext, 1, 0, 7>;
217 def A4_cmpheqi : T_CMP_ribh<"cmph.eq", 0b00, 1, 1, s8Ext, 1, 1, 8>;
218 def A4_cmphgti : T_CMP_ribh<"cmph.gt", 0b01, 1, 0, s8Ext, 1, 1, 8>;
219 def A4_cmphgtui : T_CMP_ribh<"cmph.gtu", 0b10, 1, 0, u7Ext, 1, 0, 7>;
221 class T_RCMP_EQ_ri<string mnemonic, bit IsNeg>
222 : ALU32_ri<(outs IntRegs:$Rd), (ins IntRegs:$Rs, s8Ext:$s8),
223 "$Rd = "#mnemonic#"($Rs, #$s8)", [], "", ALU32_2op_tc_1_SLOT0123>,
225 let validSubTargets = HasV4SubT;
226 let InputType = "imm";
227 let CextOpcode = !if (IsNeg, "!rcmp.eq", "rcmp.eq");
228 let isExtendable = 1;
229 let opExtendable = 2;
230 let isExtentSigned = 1;
231 let opExtentBits = 8;
239 let Inst{27-24} = 0b0011;
241 let Inst{21} = IsNeg;
242 let Inst{20-16} = Rs;
248 let isCodeGenOnly = 0 in {
249 def A4_rcmpeqi : T_RCMP_EQ_ri<"cmp.eq", 0>;
250 def A4_rcmpneqi : T_RCMP_EQ_ri<"!cmp.eq", 1>;
253 def: Pat<(i32 (zext (i1 (seteq (i32 IntRegs:$Rs), s8ExtPred:$s8)))),
254 (A4_rcmpeqi IntRegs:$Rs, s8ExtPred:$s8)>;
255 def: Pat<(i32 (zext (i1 (setne (i32 IntRegs:$Rs), s8ExtPred:$s8)))),
256 (A4_rcmpneqi IntRegs:$Rs, s8ExtPred:$s8)>;
258 // Preserve the S2_tstbit_r generation
259 def: Pat<(i32 (zext (i1 (setne (i32 (and (i32 (shl 1, (i32 IntRegs:$src2))),
260 (i32 IntRegs:$src1))), 0)))),
261 (C2_muxii (S2_tstbit_r IntRegs:$src1, IntRegs:$src2), 1, 0)>;
264 //===----------------------------------------------------------------------===//
266 //===----------------------------------------------------------------------===//
269 //===----------------------------------------------------------------------===//
271 //===----------------------------------------------------------------------===//
273 // Combine a word and an immediate into a register pair.
274 let hasSideEffects = 0, isExtentSigned = 1, isExtendable = 1,
276 class T_Combine1 <bits<2> MajOp, dag ins, string AsmStr>
277 : ALU32Inst <(outs DoubleRegs:$Rdd), ins, AsmStr> {
283 let Inst{27-24} = 0b0011;
284 let Inst{22-21} = MajOp;
285 let Inst{20-16} = Rs;
291 let opExtendable = 2, isCodeGenOnly = 0 in
292 def A4_combineri : T_Combine1<0b00, (ins IntRegs:$Rs, s8Ext:$s8),
293 "$Rdd = combine($Rs, #$s8)">;
295 let opExtendable = 1, isCodeGenOnly = 0 in
296 def A4_combineir : T_Combine1<0b01, (ins s8Ext:$s8, IntRegs:$Rs),
297 "$Rdd = combine(#$s8, $Rs)">;
299 def HexagonWrapperCombineRI_V4 :
300 SDNode<"HexagonISD::WrapperCombineRI_V4", SDTHexagonI64I32I32>;
301 def HexagonWrapperCombineIR_V4 :
302 SDNode<"HexagonISD::WrapperCombineIR_V4", SDTHexagonI64I32I32>;
304 def : Pat <(HexagonWrapperCombineRI_V4 IntRegs:$r, s8ExtPred:$i),
305 (A4_combineri IntRegs:$r, s8ExtPred:$i)>,
308 def : Pat <(HexagonWrapperCombineIR_V4 s8ExtPred:$i, IntRegs:$r),
309 (A4_combineir s8ExtPred:$i, IntRegs:$r)>,
312 // A4_combineii: Set two small immediates.
313 let hasSideEffects = 0, isExtendable = 1, opExtentBits = 6, opExtendable = 2 in
314 def A4_combineii: ALU32Inst<(outs DoubleRegs:$Rdd), (ins s8Imm:$s8, u6Ext:$U6),
315 "$Rdd = combine(#$s8, #$U6)"> {
321 let Inst{27-23} = 0b11001;
322 let Inst{20-16} = U6{5-1};
323 let Inst{13} = U6{0};
328 //===----------------------------------------------------------------------===//
330 //===----------------------------------------------------------------------===//
332 //===----------------------------------------------------------------------===//
334 //===----------------------------------------------------------------------===//
335 //===----------------------------------------------------------------------===//
336 // Template class for load instructions with Absolute set addressing mode.
337 //===----------------------------------------------------------------------===//
338 let isExtended = 1, opExtendable = 2, opExtentBits = 6, addrMode = AbsoluteSet,
339 hasSideEffects = 0 in
340 class T_LD_abs_set<string mnemonic, RegisterClass RC, bits<4>MajOp>:
341 LDInst<(outs RC:$dst1, IntRegs:$dst2),
343 "$dst1 = "#mnemonic#"($dst2 = #$addr)",
351 let Inst{27-25} = 0b101;
352 let Inst{24-21} = MajOp;
353 let Inst{13-12} = 0b01;
354 let Inst{4-0} = dst1;
355 let Inst{20-16} = dst2;
356 let Inst{11-8} = addr{5-2};
357 let Inst{6-5} = addr{1-0};
360 let accessSize = ByteAccess, hasNewValue = 1, isCodeGenOnly = 0 in {
361 def L4_loadrb_ap : T_LD_abs_set <"memb", IntRegs, 0b1000>;
362 def L4_loadrub_ap : T_LD_abs_set <"memub", IntRegs, 0b1001>;
365 let accessSize = HalfWordAccess, hasNewValue = 1, isCodeGenOnly = 0 in {
366 def L4_loadrh_ap : T_LD_abs_set <"memh", IntRegs, 0b1010>;
367 def L4_loadruh_ap : T_LD_abs_set <"memuh", IntRegs, 0b1011>;
370 let accessSize = WordAccess, hasNewValue = 1, isCodeGenOnly = 0 in
371 def L4_loadri_ap : T_LD_abs_set <"memw", IntRegs, 0b1100>;
373 let accessSize = DoubleWordAccess, isCodeGenOnly = 0 in
374 def L4_loadrd_ap : T_LD_abs_set <"memd", DoubleRegs, 0b1110>;
375 // Load - Indirect with long offset
376 let InputType = "imm", addrMode = BaseLongOffset, isExtended = 1,
377 opExtentBits = 6, opExtendable = 3 in
378 class T_LoadAbsReg <string mnemonic, string CextOp, RegisterClass RC,
380 : LDInst <(outs RC:$dst), (ins IntRegs:$src1, u2Imm:$src2, u6Ext:$src3),
381 "$dst = "#mnemonic#"($src1<<#$src2 + #$src3)",
387 let CextOpcode = CextOp;
388 let hasNewValue = !if (!eq(!cast<string>(RC), "DoubleRegs"), 0, 1);
391 let Inst{27-25} = 0b110;
392 let Inst{24-21} = MajOp;
393 let Inst{20-16} = src1;
394 let Inst{13} = src2{1};
396 let Inst{11-8} = src3{5-2};
397 let Inst{7} = src2{0};
398 let Inst{6-5} = src3{1-0};
402 let accessSize = ByteAccess, isCodeGenOnly = 0 in {
403 def L4_loadrb_ur : T_LoadAbsReg<"memb", "LDrib", IntRegs, 0b1000>;
404 def L4_loadrub_ur : T_LoadAbsReg<"memub", "LDriub", IntRegs, 0b1001>;
405 def L4_loadalignb_ur : T_LoadAbsReg<"memb_fifo", "LDrib_fifo",
409 let accessSize = HalfWordAccess, isCodeGenOnly = 0 in {
410 def L4_loadrh_ur : T_LoadAbsReg<"memh", "LDrih", IntRegs, 0b1010>;
411 def L4_loadruh_ur : T_LoadAbsReg<"memuh", "LDriuh", IntRegs, 0b1011>;
412 def L4_loadbsw2_ur : T_LoadAbsReg<"membh", "LDribh2", IntRegs, 0b0001>;
413 def L4_loadbzw2_ur : T_LoadAbsReg<"memubh", "LDriubh2", IntRegs, 0b0011>;
414 def L4_loadalignh_ur : T_LoadAbsReg<"memh_fifo", "LDrih_fifo",
418 let accessSize = WordAccess, isCodeGenOnly = 0 in {
419 def L4_loadri_ur : T_LoadAbsReg<"memw", "LDriw", IntRegs, 0b1100>;
420 def L4_loadbsw4_ur : T_LoadAbsReg<"membh", "LDribh4", DoubleRegs, 0b0111>;
421 def L4_loadbzw4_ur : T_LoadAbsReg<"memubh", "LDriubh4", DoubleRegs, 0b0101>;
424 let accessSize = DoubleWordAccess, isCodeGenOnly = 0 in
425 def L4_loadrd_ur : T_LoadAbsReg<"memd", "LDrid", DoubleRegs, 0b1110>;
428 multiclass T_LoadAbsReg_Pat <PatFrag ldOp, InstHexagon MI, ValueType VT = i32> {
429 def : Pat <(VT (ldOp (add (shl IntRegs:$src1, u2ImmPred:$src2),
430 (HexagonCONST32 tglobaladdr:$src3)))),
431 (MI IntRegs:$src1, u2ImmPred:$src2, tglobaladdr:$src3)>;
433 def : Pat <(VT (ldOp (add IntRegs:$src1,
434 (HexagonCONST32 tglobaladdr:$src2)))),
435 (MI IntRegs:$src1, 0, tglobaladdr:$src2)>;
438 let AddedComplexity = 60 in {
439 defm : T_LoadAbsReg_Pat <sextloadi8, L4_loadrb_ur>;
440 defm : T_LoadAbsReg_Pat <zextloadi8, L4_loadrub_ur>;
441 defm : T_LoadAbsReg_Pat <extloadi8, L4_loadrub_ur>;
443 defm : T_LoadAbsReg_Pat <sextloadi16, L4_loadrh_ur>;
444 defm : T_LoadAbsReg_Pat <zextloadi16, L4_loadruh_ur>;
445 defm : T_LoadAbsReg_Pat <extloadi16, L4_loadruh_ur>;
447 defm : T_LoadAbsReg_Pat <load, L4_loadri_ur>;
448 defm : T_LoadAbsReg_Pat <load, L4_loadrd_ur, i64>;
451 //===----------------------------------------------------------------------===//
452 // Template classes for the non-predicated load instructions with
453 // base + register offset addressing mode
454 //===----------------------------------------------------------------------===//
455 class T_load_rr <string mnemonic, RegisterClass RC, bits<3> MajOp>:
456 LDInst<(outs RC:$dst), (ins IntRegs:$src1, IntRegs:$src2, u2Imm:$u2),
457 "$dst = "#mnemonic#"($src1 + $src2<<#$u2)",
458 [], "", V4LDST_tc_ld_SLOT01>, ImmRegShl, AddrModeRel {
466 let Inst{27-24} = 0b1010;
467 let Inst{23-21} = MajOp;
468 let Inst{20-16} = src1;
469 let Inst{12-8} = src2;
470 let Inst{13} = u2{1};
475 //===----------------------------------------------------------------------===//
476 // Template classes for the predicated load instructions with
477 // base + register offset addressing mode
478 //===----------------------------------------------------------------------===//
479 let isPredicated = 1 in
480 class T_pload_rr <string mnemonic, RegisterClass RC, bits<3> MajOp,
481 bit isNot, bit isPredNew>:
482 LDInst <(outs RC:$dst),
483 (ins PredRegs:$src1, IntRegs:$src2, IntRegs:$src3, u2Imm:$u2),
484 !if(isNot, "if (!$src1", "if ($src1")#!if(isPredNew, ".new) ",
485 ") ")#"$dst = "#mnemonic#"($src2+$src3<<#$u2)",
486 [], "", V4LDST_tc_ld_SLOT01>, AddrModeRel {
493 let isPredicatedFalse = isNot;
494 let isPredicatedNew = isPredNew;
498 let Inst{27-26} = 0b00;
499 let Inst{25} = isPredNew;
500 let Inst{24} = isNot;
501 let Inst{23-21} = MajOp;
502 let Inst{20-16} = src2;
503 let Inst{12-8} = src3;
504 let Inst{13} = u2{1};
506 let Inst{6-5} = src1;
510 //===----------------------------------------------------------------------===//
511 // multiclass for load instructions with base + register offset
513 //===----------------------------------------------------------------------===//
514 let hasSideEffects = 0, addrMode = BaseRegOffset in
515 multiclass ld_idxd_shl <string mnemonic, string CextOp, RegisterClass RC,
517 let CextOpcode = CextOp, BaseOpcode = CextOp#_indexed_shl,
518 InputType = "reg" in {
519 let isPredicable = 1 in
520 def L4_#NAME#_rr : T_load_rr <mnemonic, RC, MajOp>;
523 def L4_p#NAME#t_rr : T_pload_rr <mnemonic, RC, MajOp, 0, 0>;
524 def L4_p#NAME#f_rr : T_pload_rr <mnemonic, RC, MajOp, 1, 0>;
527 def L4_p#NAME#tnew_rr : T_pload_rr <mnemonic, RC, MajOp, 0, 1>;
528 def L4_p#NAME#fnew_rr : T_pload_rr <mnemonic, RC, MajOp, 1, 1>;
532 let hasNewValue = 1, accessSize = ByteAccess, isCodeGenOnly = 0 in {
533 defm loadrb : ld_idxd_shl<"memb", "LDrib", IntRegs, 0b000>;
534 defm loadrub : ld_idxd_shl<"memub", "LDriub", IntRegs, 0b001>;
537 let hasNewValue = 1, accessSize = HalfWordAccess, isCodeGenOnly = 0 in {
538 defm loadrh : ld_idxd_shl<"memh", "LDrih", IntRegs, 0b010>;
539 defm loadruh : ld_idxd_shl<"memuh", "LDriuh", IntRegs, 0b011>;
542 let hasNewValue = 1, accessSize = WordAccess, isCodeGenOnly = 0 in
543 defm loadri : ld_idxd_shl<"memw", "LDriw", IntRegs, 0b100>;
545 let accessSize = DoubleWordAccess, isCodeGenOnly = 0 in
546 defm loadrd : ld_idxd_shl<"memd", "LDrid", DoubleRegs, 0b110>;
548 // 'def pats' for load instructions with base + register offset and non-zero
549 // immediate value. Immediate value is used to left-shift the second
551 let AddedComplexity = 40 in {
552 def : Pat <(i32 (sextloadi8 (add IntRegs:$src1,
553 (shl IntRegs:$src2, u2ImmPred:$offset)))),
554 (L4_loadrb_rr IntRegs:$src1,
555 IntRegs:$src2, u2ImmPred:$offset)>,
558 def : Pat <(i32 (zextloadi8 (add IntRegs:$src1,
559 (shl IntRegs:$src2, u2ImmPred:$offset)))),
560 (L4_loadrub_rr IntRegs:$src1,
561 IntRegs:$src2, u2ImmPred:$offset)>,
564 def : Pat <(i32 (extloadi8 (add IntRegs:$src1,
565 (shl IntRegs:$src2, u2ImmPred:$offset)))),
566 (L4_loadrub_rr IntRegs:$src1,
567 IntRegs:$src2, u2ImmPred:$offset)>,
570 def : Pat <(i32 (sextloadi16 (add IntRegs:$src1,
571 (shl IntRegs:$src2, u2ImmPred:$offset)))),
572 (L4_loadrh_rr IntRegs:$src1,
573 IntRegs:$src2, u2ImmPred:$offset)>,
576 def : Pat <(i32 (zextloadi16 (add IntRegs:$src1,
577 (shl IntRegs:$src2, u2ImmPred:$offset)))),
578 (L4_loadruh_rr IntRegs:$src1,
579 IntRegs:$src2, u2ImmPred:$offset)>,
582 def : Pat <(i32 (extloadi16 (add IntRegs:$src1,
583 (shl IntRegs:$src2, u2ImmPred:$offset)))),
584 (L4_loadruh_rr IntRegs:$src1,
585 IntRegs:$src2, u2ImmPred:$offset)>,
588 def : Pat <(i32 (load (add IntRegs:$src1,
589 (shl IntRegs:$src2, u2ImmPred:$offset)))),
590 (L4_loadri_rr IntRegs:$src1,
591 IntRegs:$src2, u2ImmPred:$offset)>,
594 def : Pat <(i64 (load (add IntRegs:$src1,
595 (shl IntRegs:$src2, u2ImmPred:$offset)))),
596 (L4_loadrd_rr IntRegs:$src1,
597 IntRegs:$src2, u2ImmPred:$offset)>,
601 // 'def pats' for load instruction base + register offset and
602 // zero immediate value.
603 class Loadxs_simple_pat<PatFrag Load, ValueType VT, InstHexagon MI>
604 : Pat<(VT (Load (add (i32 IntRegs:$Rs), (i32 IntRegs:$Rt)))),
605 (VT (MI IntRegs:$Rs, IntRegs:$Rt, 0))>;
607 let AddedComplexity = 20 in {
608 def: Loadxs_simple_pat<extloadi8, i32, L4_loadrub_rr>;
609 def: Loadxs_simple_pat<zextloadi8, i32, L4_loadrub_rr>;
610 def: Loadxs_simple_pat<sextloadi8, i32, L4_loadrb_rr>;
611 def: Loadxs_simple_pat<extloadi16, i32, L4_loadruh_rr>;
612 def: Loadxs_simple_pat<zextloadi16, i32, L4_loadruh_rr>;
613 def: Loadxs_simple_pat<sextloadi16, i32, L4_loadrh_rr>;
614 def: Loadxs_simple_pat<load, i32, L4_loadri_rr>;
615 def: Loadxs_simple_pat<load, i64, L4_loadrd_rr>;
619 def : Pat <(i64 (zext (i1 PredRegs:$src1))),
620 (i64 (A4_combineir 0, (C2_muxii (i1 PredRegs:$src1), 1, 0)))>,
624 def : Pat <(i64 (zext (i32 IntRegs:$src1))),
625 (i64 (A4_combineir 0, (i32 IntRegs:$src1)))>,
628 def: Pat <(i64 (zextloadi8 ADDRriS11_0:$src1)),
629 (i64 (A4_combineir 0, (L2_loadrub_io AddrFI:$src1, 0)))>,
632 let AddedComplexity = 20 in
633 def: Pat <(i64 (zextloadi8 (add (i32 IntRegs:$src1),
634 s11_0ExtPred:$offset))),
635 (i64 (A4_combineir 0, (L2_loadrub_io IntRegs:$src1,
636 s11_0ExtPred:$offset)))>,
640 def: Pat <(i64 (zextloadi1 ADDRriS11_0:$src1)),
641 (i64 (A4_combineir 0, (L2_loadrub_io AddrFI:$src1, 0)))>,
644 let AddedComplexity = 20 in
645 def: Pat <(i64 (zextloadi1 (add (i32 IntRegs:$src1),
646 s11_0ExtPred:$offset))),
647 (i64 (A4_combineir 0, (L2_loadrub_io IntRegs:$src1,
648 s11_0ExtPred:$offset)))>,
652 def: Pat <(i64 (zextloadi16 ADDRriS11_1:$src1)),
653 (i64 (A4_combineir 0, (L2_loadruh_io AddrFI:$src1, 0)))>,
656 let AddedComplexity = 20 in
657 def: Pat <(i64 (zextloadi16 (add (i32 IntRegs:$src1),
658 s11_1ExtPred:$offset))),
659 (i64 (A4_combineir 0, (L2_loadruh_io IntRegs:$src1,
660 s11_1ExtPred:$offset)))>,
664 def: Pat <(i64 (extloadi16 ADDRriS11_2:$src1)),
665 (i64 (A4_combineir 0, (L2_loadrh_io AddrFI:$src1, 0)))>,
668 let AddedComplexity = 20 in
669 def: Pat <(i64 (extloadi16 (add (i32 IntRegs:$src1),
670 s11_1ExtPred:$offset))),
671 (i64 (A4_combineir 0, (L2_loadrh_io IntRegs:$src1,
672 s11_1ExtPred:$offset)))>,
676 def: Pat <(i64 (zextloadi32 ADDRriS11_2:$src1)),
677 (i64 (A4_combineir 0, (L2_loadri_io AddrFI:$src1, 0)))>,
680 let AddedComplexity = 100 in
681 def: Pat <(i64 (zextloadi32 (i32 (add IntRegs:$src1, s11_2ExtPred:$offset)))),
682 (i64 (A4_combineir 0, (L2_loadri_io IntRegs:$src1,
683 s11_2ExtPred:$offset)))>,
687 def: Pat <(i64 (extloadi32 ADDRriS11_2:$src1)),
688 (i64 (A4_combineir 0, (L2_loadri_io AddrFI:$src1, 0)))>,
691 let AddedComplexity = 100 in
692 def: Pat <(i64 (extloadi32 (i32 (add IntRegs:$src1, s11_2ExtPred:$offset)))),
693 (i64 (A4_combineir 0, (L2_loadri_io IntRegs:$src1,
694 s11_2ExtPred:$offset)))>,
699 //===----------------------------------------------------------------------===//
701 //===----------------------------------------------------------------------===//
703 //===----------------------------------------------------------------------===//
705 //===----------------------------------------------------------------------===//
707 //===----------------------------------------------------------------------===//
708 // Template class for store instructions with Absolute set addressing mode.
709 //===----------------------------------------------------------------------===//
710 let isExtended = 1, opExtendable = 1, opExtentBits = 6,
711 addrMode = AbsoluteSet, isNVStorable = 1 in
712 class T_ST_absset <string mnemonic, string BaseOp, RegisterClass RC,
713 bits<3> MajOp, MemAccessSize AccessSz, bit isHalf = 0>
714 : STInst<(outs IntRegs:$dst),
715 (ins u6Ext:$addr, RC:$src),
716 mnemonic#"($dst = #$addr) = $src"#!if(isHalf, ".h","")>, NewValueRel {
720 let accessSize = AccessSz;
721 let BaseOpcode = BaseOp#"_AbsSet";
725 let Inst{27-24} = 0b1011;
726 let Inst{23-21} = MajOp;
727 let Inst{20-16} = dst;
729 let Inst{12-8} = src;
731 let Inst{5-0} = addr;
734 def S4_storerb_ap : T_ST_absset <"memb", "STrib", IntRegs, 0b000, ByteAccess>;
735 def S4_storerh_ap : T_ST_absset <"memh", "STrih", IntRegs, 0b010,
737 def S4_storeri_ap : T_ST_absset <"memw", "STriw", IntRegs, 0b100, WordAccess>;
739 let isNVStorable = 0 in {
740 def S4_storerf_ap : T_ST_absset <"memh", "STrif", IntRegs,
741 0b011, HalfWordAccess, 1>;
742 def S4_storerd_ap : T_ST_absset <"memd", "STrid", DoubleRegs,
743 0b110, DoubleWordAccess>;
746 let opExtendable = 1, isNewValue = 1, isNVStore = 1, opNewValue = 2,
747 isExtended = 1, opExtentBits= 6 in
748 class T_ST_absset_nv <string mnemonic, string BaseOp, bits<2> MajOp,
749 MemAccessSize AccessSz >
750 : NVInst <(outs IntRegs:$dst),
751 (ins u6Ext:$addr, IntRegs:$src),
752 mnemonic#"($dst = #$addr) = $src.new">, NewValueRel {
756 let accessSize = AccessSz;
757 let BaseOpcode = BaseOp#"_AbsSet";
761 let Inst{27-21} = 0b1011101;
762 let Inst{20-16} = dst;
763 let Inst{13-11} = 0b000;
764 let Inst{12-11} = MajOp;
765 let Inst{10-8} = src;
767 let Inst{5-0} = addr;
770 let mayStore = 1, addrMode = AbsoluteSet, isCodeGenOnly = 0 in {
771 def S4_storerbnew_ap : T_ST_absset_nv <"memb", "STrib", 0b00, ByteAccess>;
772 def S4_storerhnew_ap : T_ST_absset_nv <"memh", "STrih", 0b01, HalfWordAccess>;
773 def S4_storerinew_ap : T_ST_absset_nv <"memw", "STriw", 0b10, WordAccess>;
776 let isExtended = 1, opExtendable = 2, opExtentBits = 6, InputType = "imm",
777 addrMode = BaseLongOffset, AddedComplexity = 40 in
778 class T_StoreAbsReg <string mnemonic, string CextOp, RegisterClass RC,
779 bits<3> MajOp, MemAccessSize AccessSz, bit isHalf = 0>
781 (ins IntRegs:$src1, u2Imm:$src2, u6Ext:$src3, RC:$src4),
782 mnemonic#"($src1<<#$src2 + #$src3) = $src4"#!if(isHalf, ".h",""),
783 []>, ImmRegShl, NewValueRel {
790 let accessSize = AccessSz;
791 let CextOpcode = CextOp;
792 let BaseOpcode = CextOp#"_shl";
795 let Inst{27-24} =0b1101;
796 let Inst{23-21} = MajOp;
797 let Inst{20-16} = src1;
798 let Inst{13} = src2{1};
799 let Inst{12-8} = src4;
801 let Inst{6} = src2{0};
802 let Inst{5-0} = src3;
805 let isCodeGenOnly = 0 in {
806 def S4_storerb_ur : T_StoreAbsReg <"memb", "STrib", IntRegs, 0b000, ByteAccess>;
807 def S4_storerh_ur : T_StoreAbsReg <"memh", "STrih", IntRegs, 0b010,
809 def S4_storerf_ur : T_StoreAbsReg <"memh", "STrif", IntRegs, 0b011,
811 def S4_storeri_ur : T_StoreAbsReg <"memw", "STriw", IntRegs, 0b100, WordAccess>;
812 def S4_storerd_ur : T_StoreAbsReg <"memd", "STrid", DoubleRegs, 0b110,
816 let AddedComplexity = 40 in
817 multiclass T_StoreAbsReg_Pats <InstHexagon MI, RegisterClass RC, ValueType VT,
819 def : Pat<(stOp (VT RC:$src4),
820 (add (shl (i32 IntRegs:$src1), u2ImmPred:$src2),
821 u0AlwaysExtPred:$src3)),
822 (MI IntRegs:$src1, u2ImmPred:$src2, u0AlwaysExtPred:$src3, RC:$src4)>;
824 def : Pat<(stOp (VT RC:$src4),
825 (add (shl IntRegs:$src1, u2ImmPred:$src2),
826 (HexagonCONST32 tglobaladdr:$src3))),
827 (MI IntRegs:$src1, u2ImmPred:$src2, tglobaladdr:$src3, RC:$src4)>;
829 def : Pat<(stOp (VT RC:$src4),
830 (add IntRegs:$src1, (HexagonCONST32 tglobaladdr:$src3))),
831 (MI IntRegs:$src1, 0, tglobaladdr:$src3, RC:$src4)>;
834 defm : T_StoreAbsReg_Pats <S4_storerd_ur, DoubleRegs, i64, store>;
835 defm : T_StoreAbsReg_Pats <S4_storeri_ur, IntRegs, i32, store>;
836 defm : T_StoreAbsReg_Pats <S4_storerb_ur, IntRegs, i32, truncstorei8>;
837 defm : T_StoreAbsReg_Pats <S4_storerh_ur, IntRegs, i32, truncstorei16>;
839 let mayStore = 1, isNVStore = 1, isExtended = 1, addrMode = BaseLongOffset,
840 opExtentBits = 6, isNewValue = 1, opNewValue = 3, opExtendable = 2 in
841 class T_StoreAbsRegNV <string mnemonic, string CextOp, bits<2> MajOp,
842 MemAccessSize AccessSz>
844 (ins IntRegs:$src1, u2Imm:$src2, u6Ext:$src3, IntRegs:$src4),
845 mnemonic#"($src1<<#$src2 + #$src3) = $src4.new">, NewValueRel {
851 let CextOpcode = CextOp;
852 let BaseOpcode = CextOp#"_shl";
855 let Inst{27-21} = 0b1101101;
856 let Inst{12-11} = 0b00;
858 let Inst{20-16} = src1;
859 let Inst{13} = src2{1};
860 let Inst{12-11} = MajOp;
861 let Inst{10-8} = src4;
862 let Inst{6} = src2{0};
863 let Inst{5-0} = src3;
866 let isCodeGenOnly = 0 in {
867 def S4_storerbnew_ur : T_StoreAbsRegNV <"memb", "STrib", 0b00, ByteAccess>;
868 def S4_storerhnew_ur : T_StoreAbsRegNV <"memh", "STrih", 0b01, HalfWordAccess>;
869 def S4_storerinew_ur : T_StoreAbsRegNV <"memw", "STriw", 0b10, WordAccess>;
872 //===----------------------------------------------------------------------===//
873 // Template classes for the non-predicated store instructions with
874 // base + register offset addressing mode
875 //===----------------------------------------------------------------------===//
876 let isPredicable = 1 in
877 class T_store_rr <string mnemonic, RegisterClass RC, bits<3> MajOp, bit isH>
878 : STInst < (outs ), (ins IntRegs:$Rs, IntRegs:$Ru, u2Imm:$u2, RC:$Rt),
879 mnemonic#"($Rs + $Ru<<#$u2) = $Rt"#!if(isH, ".h",""),
880 [],"",V4LDST_tc_st_SLOT01>, ImmRegShl, AddrModeRel {
889 let Inst{27-24} = 0b1011;
890 let Inst{23-21} = MajOp;
891 let Inst{20-16} = Rs;
893 let Inst{13} = u2{1};
898 //===----------------------------------------------------------------------===//
899 // Template classes for the predicated store instructions with
900 // base + register offset addressing mode
901 //===----------------------------------------------------------------------===//
902 let isPredicated = 1 in
903 class T_pstore_rr <string mnemonic, RegisterClass RC, bits<3> MajOp,
904 bit isNot, bit isPredNew, bit isH>
906 (ins PredRegs:$Pv, IntRegs:$Rs, IntRegs:$Ru, u2Imm:$u2, RC:$Rt),
908 !if(isNot, "if (!$Pv", "if ($Pv")#!if(isPredNew, ".new) ",
909 ") ")#mnemonic#"($Rs+$Ru<<#$u2) = $Rt"#!if(isH, ".h",""),
910 [], "", V4LDST_tc_st_SLOT01> , AddrModeRel{
917 let isPredicatedFalse = isNot;
918 let isPredicatedNew = isPredNew;
922 let Inst{27-26} = 0b01;
923 let Inst{25} = isPredNew;
924 let Inst{24} = isNot;
925 let Inst{23-21} = MajOp;
926 let Inst{20-16} = Rs;
928 let Inst{13} = u2{1};
934 //===----------------------------------------------------------------------===//
935 // Template classes for the new-value store instructions with
936 // base + register offset addressing mode
937 //===----------------------------------------------------------------------===//
938 let isPredicable = 1, isNewValue = 1, opNewValue = 3 in
939 class T_store_new_rr <string mnemonic, bits<2> MajOp> :
940 NVInst < (outs ), (ins IntRegs:$Rs, IntRegs:$Ru, u2Imm:$u2, IntRegs:$Nt),
941 mnemonic#"($Rs + $Ru<<#$u2) = $Nt.new",
942 [],"",V4LDST_tc_st_SLOT0>, ImmRegShl, AddrModeRel {
951 let Inst{27-21} = 0b1011101;
952 let Inst{20-16} = Rs;
954 let Inst{13} = u2{1};
956 let Inst{4-3} = MajOp;
960 //===----------------------------------------------------------------------===//
961 // Template classes for the predicated new-value store instructions with
962 // base + register offset addressing mode
963 //===----------------------------------------------------------------------===//
964 let isPredicated = 1, isNewValue = 1, opNewValue = 4 in
965 class T_pstore_new_rr <string mnemonic, bits<2> MajOp, bit isNot, bit isPredNew>
967 (ins PredRegs:$Pv, IntRegs:$Rs, IntRegs:$Ru, u2Imm:$u2, IntRegs:$Nt),
968 !if(isNot, "if (!$Pv", "if ($Pv")#!if(isPredNew, ".new) ",
969 ") ")#mnemonic#"($Rs+$Ru<<#$u2) = $Nt.new",
970 [], "", V4LDST_tc_st_SLOT0>, AddrModeRel {
977 let isPredicatedFalse = isNot;
978 let isPredicatedNew = isPredNew;
981 let Inst{27-26} = 0b01;
982 let Inst{25} = isPredNew;
983 let Inst{24} = isNot;
984 let Inst{23-21} = 0b101;
985 let Inst{20-16} = Rs;
987 let Inst{13} = u2{1};
990 let Inst{4-3} = MajOp;
994 //===----------------------------------------------------------------------===//
995 // multiclass for store instructions with base + register offset addressing
997 //===----------------------------------------------------------------------===//
998 let isNVStorable = 1 in
999 multiclass ST_Idxd_shl<string mnemonic, string CextOp, RegisterClass RC,
1000 bits<3> MajOp, bit isH = 0> {
1001 let CextOpcode = CextOp, BaseOpcode = CextOp#_indexed_shl in {
1002 def S4_#NAME#_rr : T_store_rr <mnemonic, RC, MajOp, isH>;
1005 def S4_p#NAME#t_rr : T_pstore_rr <mnemonic, RC, MajOp, 0, 0, isH>;
1006 def S4_p#NAME#f_rr : T_pstore_rr <mnemonic, RC, MajOp, 1, 0, isH>;
1009 def S4_p#NAME#tnew_rr : T_pstore_rr <mnemonic, RC, MajOp, 0, 1, isH>;
1010 def S4_p#NAME#fnew_rr : T_pstore_rr <mnemonic, RC, MajOp, 1, 1, isH>;
1014 //===----------------------------------------------------------------------===//
1015 // multiclass for new-value store instructions with base + register offset
1017 //===----------------------------------------------------------------------===//
1018 let mayStore = 1, isNVStore = 1 in
1019 multiclass ST_Idxd_shl_nv <string mnemonic, string CextOp, RegisterClass RC,
1021 let CextOpcode = CextOp, BaseOpcode = CextOp#_indexed_shl in {
1022 def S4_#NAME#new_rr : T_store_new_rr<mnemonic, MajOp>;
1025 def S4_p#NAME#newt_rr : T_pstore_new_rr <mnemonic, MajOp, 0, 0>;
1026 def S4_p#NAME#newf_rr : T_pstore_new_rr <mnemonic, MajOp, 1, 0>;
1029 def S4_p#NAME#newtnew_rr : T_pstore_new_rr <mnemonic, MajOp, 0, 1>;
1030 def S4_p#NAME#newfnew_rr : T_pstore_new_rr <mnemonic, MajOp, 1, 1>;
1034 let addrMode = BaseRegOffset, InputType = "reg", hasSideEffects = 0,
1035 isCodeGenOnly = 0 in {
1036 let accessSize = ByteAccess in
1037 defm storerb: ST_Idxd_shl<"memb", "STrib", IntRegs, 0b000>,
1038 ST_Idxd_shl_nv<"memb", "STrib", IntRegs, 0b00>;
1040 let accessSize = HalfWordAccess in
1041 defm storerh: ST_Idxd_shl<"memh", "STrih", IntRegs, 0b010>,
1042 ST_Idxd_shl_nv<"memh", "STrih", IntRegs, 0b01>;
1044 let accessSize = WordAccess in
1045 defm storeri: ST_Idxd_shl<"memw", "STriw", IntRegs, 0b100>,
1046 ST_Idxd_shl_nv<"memw", "STriw", IntRegs, 0b10>;
1048 let isNVStorable = 0, accessSize = DoubleWordAccess in
1049 defm storerd: ST_Idxd_shl<"memd", "STrid", DoubleRegs, 0b110>;
1051 let isNVStorable = 0, accessSize = HalfWordAccess in
1052 defm storerf: ST_Idxd_shl<"memh", "STrif", IntRegs, 0b011, 1>;
1055 class Storexs_pat<PatFrag Store, PatFrag Value, InstHexagon MI>
1056 : Pat<(Store Value:$Ru, (add (i32 IntRegs:$Rs),
1057 (i32 (shl (i32 IntRegs:$Rt), u2ImmPred:$u2)))),
1058 (MI IntRegs:$Rs, IntRegs:$Rt, imm:$u2, Value:$Ru)>;
1060 let AddedComplexity = 40 in {
1061 def: Storexs_pat<truncstorei8, I32, S4_storerb_rr>;
1062 def: Storexs_pat<truncstorei16, I32, S4_storerh_rr>;
1063 def: Storexs_pat<store, I32, S4_storeri_rr>;
1064 def: Storexs_pat<store, I64, S4_storerd_rr>;
1067 // memd(Rx++#s4:3)=Rtt
1068 // memd(Rx++#s4:3:circ(Mu))=Rtt
1069 // memd(Rx++I:circ(Mu))=Rtt
1071 // memd(Rx++Mu:brev)=Rtt
1072 // memd(gp+#u16:3)=Rtt
1074 // Store doubleword conditionally.
1075 // if ([!]Pv[.new]) memd(#u6)=Rtt
1076 // TODO: needs to be implemented.
1078 //===----------------------------------------------------------------------===//
1080 //===----------------------------------------------------------------------===//
1081 let isPredicable = 1, isExtendable = 1, isExtentSigned = 1, opExtentBits = 8,
1083 class T_StoreImm <string mnemonic, Operand OffsetOp, bits<2> MajOp >
1084 : STInst <(outs ), (ins IntRegs:$Rs, OffsetOp:$offset, s8Ext:$S8),
1085 mnemonic#"($Rs+#$offset)=#$S8",
1086 [], "", V4LDST_tc_st_SLOT01>,
1087 ImmRegRel, PredNewRel {
1093 string OffsetOpStr = !cast<string>(OffsetOp);
1094 let offsetBits = !if (!eq(OffsetOpStr, "u6_2Imm"), offset{7-2},
1095 !if (!eq(OffsetOpStr, "u6_1Imm"), offset{6-1},
1096 /* u6_0Imm */ offset{5-0}));
1098 let IClass = 0b0011;
1100 let Inst{27-25} = 0b110;
1101 let Inst{22-21} = MajOp;
1102 let Inst{20-16} = Rs;
1103 let Inst{12-7} = offsetBits;
1104 let Inst{13} = S8{7};
1105 let Inst{6-0} = S8{6-0};
1108 let isPredicated = 1, isExtendable = 1, isExtentSigned = 1, opExtentBits = 6,
1110 class T_StoreImm_pred <string mnemonic, Operand OffsetOp, bits<2> MajOp,
1111 bit isPredNot, bit isPredNew >
1113 (ins PredRegs:$Pv, IntRegs:$Rs, OffsetOp:$offset, s6Ext:$S6),
1114 !if(isPredNot, "if (!$Pv", "if ($Pv")#!if(isPredNew, ".new) ",
1115 ") ")#mnemonic#"($Rs+#$offset)=#$S6",
1116 [], "", V4LDST_tc_st_SLOT01>,
1117 ImmRegRel, PredNewRel {
1124 string OffsetOpStr = !cast<string>(OffsetOp);
1125 let offsetBits = !if (!eq(OffsetOpStr, "u6_2Imm"), offset{7-2},
1126 !if (!eq(OffsetOpStr, "u6_1Imm"), offset{6-1},
1127 /* u6_0Imm */ offset{5-0}));
1128 let isPredicatedNew = isPredNew;
1129 let isPredicatedFalse = isPredNot;
1131 let IClass = 0b0011;
1133 let Inst{27-25} = 0b100;
1134 let Inst{24} = isPredNew;
1135 let Inst{23} = isPredNot;
1136 let Inst{22-21} = MajOp;
1137 let Inst{20-16} = Rs;
1138 let Inst{13} = S6{5};
1139 let Inst{12-7} = offsetBits;
1141 let Inst{4-0} = S6{4-0};
1145 //===----------------------------------------------------------------------===//
1146 // multiclass for store instructions with base + immediate offset
1147 // addressing mode and immediate stored value.
1148 // mem[bhw](Rx++#s4:3)=#s8
1149 // if ([!]Pv[.new]) mem[bhw](Rx++#s4:3)=#s6
1150 //===----------------------------------------------------------------------===//
1152 multiclass ST_Imm_Pred <string mnemonic, Operand OffsetOp, bits<2> MajOp,
1154 def _io : T_StoreImm_pred <mnemonic, OffsetOp, MajOp, PredNot, 0>;
1156 def new_io : T_StoreImm_pred <mnemonic, OffsetOp, MajOp, PredNot, 1>;
1159 multiclass ST_Imm <string mnemonic, string CextOp, Operand OffsetOp,
1161 let CextOpcode = CextOp, BaseOpcode = CextOp#_imm in {
1162 def _io : T_StoreImm <mnemonic, OffsetOp, MajOp>;
1164 defm t : ST_Imm_Pred <mnemonic, OffsetOp, MajOp, 0>;
1165 defm f : ST_Imm_Pred <mnemonic, OffsetOp, MajOp, 1>;
1169 let hasSideEffects = 0, validSubTargets = HasV4SubT, addrMode = BaseImmOffset,
1170 InputType = "imm", isCodeGenOnly = 0 in {
1171 let accessSize = ByteAccess in
1172 defm S4_storeirb : ST_Imm<"memb", "STrib", u6_0Imm, 0b00>;
1174 let accessSize = HalfWordAccess in
1175 defm S4_storeirh : ST_Imm<"memh", "STrih", u6_1Imm, 0b01>;
1177 let accessSize = WordAccess in
1178 defm S4_storeiri : ST_Imm<"memw", "STriw", u6_2Imm, 0b10>;
1181 let Predicates = [HasV4T], AddedComplexity = 10 in {
1182 def: Pat<(truncstorei8 s8ExtPred:$src3, (add IntRegs:$src1, u6_0ImmPred:$src2)),
1183 (S4_storeirb_io IntRegs:$src1, u6_0ImmPred:$src2, s8ExtPred:$src3)>;
1185 def: Pat<(truncstorei16 s8ExtPred:$src3, (add IntRegs:$src1,
1186 u6_1ImmPred:$src2)),
1187 (S4_storeirh_io IntRegs:$src1, u6_1ImmPred:$src2, s8ExtPred:$src3)>;
1189 def: Pat<(store s8ExtPred:$src3, (add IntRegs:$src1, u6_2ImmPred:$src2)),
1190 (S4_storeiri_io IntRegs:$src1, u6_2ImmPred:$src2, s8ExtPred:$src3)>;
1193 let AddedComplexity = 6 in
1194 def : Pat <(truncstorei8 s8ExtPred:$src2, (i32 IntRegs:$src1)),
1195 (S4_storeirb_io IntRegs:$src1, 0, s8ExtPred:$src2)>,
1198 // memb(Rx++#s4:0:circ(Mu))=Rt
1199 // memb(Rx++I:circ(Mu))=Rt
1201 // memb(Rx++Mu:brev)=Rt
1202 // memb(gp+#u16:0)=Rt
1206 // TODO: needs to be implemented
1207 // memh(Re=#U6)=Rt.H
1208 // memh(Rs+#s11:1)=Rt.H
1209 let AddedComplexity = 6 in
1210 def : Pat <(truncstorei16 s8ExtPred:$src2, (i32 IntRegs:$src1)),
1211 (S4_storeirh_io IntRegs:$src1, 0, s8ExtPred:$src2)>,
1214 // memh(Rs+Ru<<#u2)=Rt.H
1215 // TODO: needs to be implemented.
1217 // memh(Ru<<#u2+#U6)=Rt.H
1218 // memh(Rx++#s4:1:circ(Mu))=Rt.H
1219 // memh(Rx++#s4:1:circ(Mu))=Rt
1220 // memh(Rx++I:circ(Mu))=Rt.H
1221 // memh(Rx++I:circ(Mu))=Rt
1222 // memh(Rx++Mu)=Rt.H
1224 // memh(Rx++Mu:brev)=Rt.H
1225 // memh(Rx++Mu:brev)=Rt
1226 // memh(gp+#u16:1)=Rt
1227 // if ([!]Pv[.new]) memh(#u6)=Rt.H
1228 // if ([!]Pv[.new]) memh(#u6)=Rt
1231 // if ([!]Pv[.new]) memh(Rs+#u6:1)=Rt.H
1232 // TODO: needs to be implemented.
1234 // if ([!]Pv[.new]) memh(Rx++#s4:1)=Rt.H
1235 // TODO: Needs to be implemented.
1239 // TODO: Needs to be implemented.
1242 let hasSideEffects = 0 in
1243 def STriw_pred_V4 : STInst2<(outs),
1244 (ins MEMri:$addr, PredRegs:$src1),
1245 "Error; should not emit",
1249 let AddedComplexity = 6 in
1250 def : Pat <(store s8ExtPred:$src2, (i32 IntRegs:$src1)),
1251 (S4_storeiri_io IntRegs:$src1, 0, s8ExtPred:$src2)>,
1254 // memw(Rx++#s4:2)=Rt
1255 // memw(Rx++#s4:2:circ(Mu))=Rt
1256 // memw(Rx++I:circ(Mu))=Rt
1258 // memw(Rx++Mu:brev)=Rt
1260 //===----------------------------------------------------------------------===
1262 //===----------------------------------------------------------------------===
1265 //===----------------------------------------------------------------------===//
1267 //===----------------------------------------------------------------------===//
1269 let opNewValue = 2, opExtendable = 1, isExtentSigned = 1, isPredicable = 1 in
1270 class T_store_io_nv <string mnemonic, RegisterClass RC,
1271 Operand ImmOp, bits<2>MajOp>
1272 : NVInst_V4 <(outs),
1273 (ins IntRegs:$src1, ImmOp:$src2, RC:$src3),
1274 mnemonic#"($src1+#$src2) = $src3.new",
1275 [],"",ST_tc_st_SLOT0> {
1277 bits<13> src2; // Actual address offset
1279 bits<11> offsetBits; // Represents offset encoding
1281 let opExtentBits = !if (!eq(mnemonic, "memb"), 11,
1282 !if (!eq(mnemonic, "memh"), 12,
1283 !if (!eq(mnemonic, "memw"), 13, 0)));
1285 let opExtentAlign = !if (!eq(mnemonic, "memb"), 0,
1286 !if (!eq(mnemonic, "memh"), 1,
1287 !if (!eq(mnemonic, "memw"), 2, 0)));
1289 let offsetBits = !if (!eq(mnemonic, "memb"), src2{10-0},
1290 !if (!eq(mnemonic, "memh"), src2{11-1},
1291 !if (!eq(mnemonic, "memw"), src2{12-2}, 0)));
1293 let IClass = 0b1010;
1296 let Inst{26-25} = offsetBits{10-9};
1297 let Inst{24-21} = 0b1101;
1298 let Inst{20-16} = src1;
1299 let Inst{13} = offsetBits{8};
1300 let Inst{12-11} = MajOp;
1301 let Inst{10-8} = src3;
1302 let Inst{7-0} = offsetBits{7-0};
1305 let opExtendable = 2, opNewValue = 3, isPredicated = 1 in
1306 class T_pstore_io_nv <string mnemonic, RegisterClass RC, Operand predImmOp,
1307 bits<2>MajOp, bit PredNot, bit isPredNew>
1308 : NVInst_V4 <(outs),
1309 (ins PredRegs:$src1, IntRegs:$src2, predImmOp:$src3, RC:$src4),
1310 !if(PredNot, "if (!$src1", "if ($src1")#!if(isPredNew, ".new) ",
1311 ") ")#mnemonic#"($src2+#$src3) = $src4.new",
1312 [],"",V2LDST_tc_st_SLOT0> {
1317 bits<6> offsetBits; // Represents offset encoding
1319 let isPredicatedNew = isPredNew;
1320 let isPredicatedFalse = PredNot;
1321 let opExtentBits = !if (!eq(mnemonic, "memb"), 6,
1322 !if (!eq(mnemonic, "memh"), 7,
1323 !if (!eq(mnemonic, "memw"), 8, 0)));
1325 let opExtentAlign = !if (!eq(mnemonic, "memb"), 0,
1326 !if (!eq(mnemonic, "memh"), 1,
1327 !if (!eq(mnemonic, "memw"), 2, 0)));
1329 let offsetBits = !if (!eq(mnemonic, "memb"), src3{5-0},
1330 !if (!eq(mnemonic, "memh"), src3{6-1},
1331 !if (!eq(mnemonic, "memw"), src3{7-2}, 0)));
1333 let IClass = 0b0100;
1336 let Inst{26} = PredNot;
1337 let Inst{25} = isPredNew;
1338 let Inst{24-21} = 0b0101;
1339 let Inst{20-16} = src2;
1340 let Inst{13} = offsetBits{5};
1341 let Inst{12-11} = MajOp;
1342 let Inst{10-8} = src4;
1343 let Inst{7-3} = offsetBits{4-0};
1345 let Inst{1-0} = src1;
1348 // multiclass for new-value store instructions with base + immediate offset.
1350 let mayStore = 1, isNVStore = 1, isNewValue = 1, hasSideEffects = 0,
1352 multiclass ST_Idxd_nv<string mnemonic, string CextOp, RegisterClass RC,
1353 Operand ImmOp, Operand predImmOp, bits<2> MajOp> {
1355 let CextOpcode = CextOp, BaseOpcode = CextOp#_indexed in {
1356 def S2_#NAME#new_io : T_store_io_nv <mnemonic, RC, ImmOp, MajOp>;
1358 def S2_p#NAME#newt_io :T_pstore_io_nv <mnemonic, RC, predImmOp, MajOp, 0, 0>;
1359 def S2_p#NAME#newf_io :T_pstore_io_nv <mnemonic, RC, predImmOp, MajOp, 1, 0>;
1361 def S4_p#NAME#newtnew_io :T_pstore_io_nv <mnemonic, RC, predImmOp,
1363 def S4_p#NAME#newfnew_io :T_pstore_io_nv <mnemonic, RC, predImmOp,
1368 let addrMode = BaseImmOffset, InputType = "imm", isCodeGenOnly = 0 in {
1369 let accessSize = ByteAccess in
1370 defm storerb: ST_Idxd_nv<"memb", "STrib", IntRegs, s11_0Ext,
1371 u6_0Ext, 0b00>, AddrModeRel;
1373 let accessSize = HalfWordAccess, opExtentAlign = 1 in
1374 defm storerh: ST_Idxd_nv<"memh", "STrih", IntRegs, s11_1Ext,
1375 u6_1Ext, 0b01>, AddrModeRel;
1377 let accessSize = WordAccess, opExtentAlign = 2 in
1378 defm storeri: ST_Idxd_nv<"memw", "STriw", IntRegs, s11_2Ext,
1379 u6_2Ext, 0b10>, AddrModeRel;
1382 //===----------------------------------------------------------------------===//
1383 // Post increment loads with register offset.
1384 //===----------------------------------------------------------------------===//
1386 let hasNewValue = 1, isCodeGenOnly = 0 in
1387 def L2_loadbsw2_pr : T_load_pr <"membh", IntRegs, 0b0001, HalfWordAccess>;
1389 let isCodeGenOnly = 0 in
1390 def L2_loadbsw4_pr : T_load_pr <"membh", DoubleRegs, 0b0111, WordAccess>;
1392 //===----------------------------------------------------------------------===//
1393 // Template class for non-predicated post increment .new stores
1394 // mem[bhwd](Rx++#s4:[0123])=Nt.new
1395 //===----------------------------------------------------------------------===//
1396 let isPredicable = 1, hasSideEffects = 0, validSubTargets = HasV4SubT,
1397 addrMode = PostInc, isNVStore = 1, isNewValue = 1, opNewValue = 3 in
1398 class T_StorePI_nv <string mnemonic, Operand ImmOp, bits<2> MajOp >
1399 : NVInstPI_V4 <(outs IntRegs:$_dst_),
1400 (ins IntRegs:$src1, ImmOp:$offset, IntRegs:$src2),
1401 mnemonic#"($src1++#$offset) = $src2.new",
1402 [], "$src1 = $_dst_">,
1409 string ImmOpStr = !cast<string>(ImmOp);
1410 let offsetBits = !if (!eq(ImmOpStr, "s4_2Imm"), offset{5-2},
1411 !if (!eq(ImmOpStr, "s4_1Imm"), offset{4-1},
1412 /* s4_0Imm */ offset{3-0}));
1413 let IClass = 0b1010;
1415 let Inst{27-21} = 0b1011101;
1416 let Inst{20-16} = src1;
1418 let Inst{12-11} = MajOp;
1419 let Inst{10-8} = src2;
1421 let Inst{6-3} = offsetBits;
1425 //===----------------------------------------------------------------------===//
1426 // Template class for predicated post increment .new stores
1427 // if([!]Pv[.new]) mem[bhwd](Rx++#s4:[0123])=Nt.new
1428 //===----------------------------------------------------------------------===//
1429 let isPredicated = 1, hasSideEffects = 0, validSubTargets = HasV4SubT,
1430 addrMode = PostInc, isNVStore = 1, isNewValue = 1, opNewValue = 4 in
1431 class T_StorePI_nv_pred <string mnemonic, Operand ImmOp,
1432 bits<2> MajOp, bit isPredNot, bit isPredNew >
1433 : NVInstPI_V4 <(outs IntRegs:$_dst_),
1434 (ins PredRegs:$src1, IntRegs:$src2,
1435 ImmOp:$offset, IntRegs:$src3),
1436 !if(isPredNot, "if (!$src1", "if ($src1")#!if(isPredNew, ".new) ",
1437 ") ")#mnemonic#"($src2++#$offset) = $src3.new",
1438 [], "$src2 = $_dst_">,
1446 string ImmOpStr = !cast<string>(ImmOp);
1447 let offsetBits = !if (!eq(ImmOpStr, "s4_2Imm"), offset{5-2},
1448 !if (!eq(ImmOpStr, "s4_1Imm"), offset{4-1},
1449 /* s4_0Imm */ offset{3-0}));
1450 let isPredicatedNew = isPredNew;
1451 let isPredicatedFalse = isPredNot;
1453 let IClass = 0b1010;
1455 let Inst{27-21} = 0b1011101;
1456 let Inst{20-16} = src2;
1458 let Inst{12-11} = MajOp;
1459 let Inst{10-8} = src3;
1460 let Inst{7} = isPredNew;
1461 let Inst{6-3} = offsetBits;
1462 let Inst{2} = isPredNot;
1463 let Inst{1-0} = src1;
1466 multiclass ST_PostInc_Pred_nv<string mnemonic, Operand ImmOp,
1467 bits<2> MajOp, bit PredNot> {
1468 def _pi : T_StorePI_nv_pred <mnemonic, ImmOp, MajOp, PredNot, 0>;
1471 def new_pi : T_StorePI_nv_pred <mnemonic, ImmOp, MajOp, PredNot, 1>;
1474 multiclass ST_PostInc_nv<string mnemonic, string BaseOp, Operand ImmOp,
1476 let BaseOpcode = "POST_"#BaseOp in {
1477 def S2_#NAME#_pi : T_StorePI_nv <mnemonic, ImmOp, MajOp>;
1480 defm S2_p#NAME#t : ST_PostInc_Pred_nv <mnemonic, ImmOp, MajOp, 0>;
1481 defm S2_p#NAME#f : ST_PostInc_Pred_nv <mnemonic, ImmOp, MajOp, 1>;
1485 let accessSize = ByteAccess, isCodeGenOnly = 0 in
1486 defm storerbnew: ST_PostInc_nv <"memb", "STrib", s4_0Imm, 0b00>;
1488 let accessSize = HalfWordAccess, isCodeGenOnly = 0 in
1489 defm storerhnew: ST_PostInc_nv <"memh", "STrih", s4_1Imm, 0b01>;
1491 let accessSize = WordAccess, isCodeGenOnly = 0 in
1492 defm storerinew: ST_PostInc_nv <"memw", "STriw", s4_2Imm, 0b10>;
1494 //===----------------------------------------------------------------------===//
1495 // Template class for post increment .new stores with register offset
1496 //===----------------------------------------------------------------------===//
1497 let isNewValue = 1, mayStore = 1, isNVStore = 1, opNewValue = 3 in
1498 class T_StorePI_RegNV <string mnemonic, bits<2> MajOp, MemAccessSize AccessSz>
1499 : NVInstPI_V4 <(outs IntRegs:$_dst_),
1500 (ins IntRegs:$src1, ModRegs:$src2, IntRegs:$src3),
1501 #mnemonic#"($src1++$src2) = $src3.new",
1502 [], "$src1 = $_dst_"> {
1506 let accessSize = AccessSz;
1508 let IClass = 0b1010;
1510 let Inst{27-21} = 0b1101101;
1511 let Inst{20-16} = src1;
1512 let Inst{13} = src2;
1513 let Inst{12-11} = MajOp;
1514 let Inst{10-8} = src3;
1518 let isCodeGenOnly = 0 in {
1519 def S2_storerbnew_pr : T_StorePI_RegNV<"memb", 0b00, ByteAccess>;
1520 def S2_storerhnew_pr : T_StorePI_RegNV<"memh", 0b01, HalfWordAccess>;
1521 def S2_storerinew_pr : T_StorePI_RegNV<"memw", 0b10, WordAccess>;
1524 // memb(Rx++#s4:0:circ(Mu))=Nt.new
1525 // memb(Rx++I:circ(Mu))=Nt.new
1526 // memb(Rx++Mu)=Nt.new
1527 // memb(Rx++Mu:brev)=Nt.new
1528 // memh(Rx++#s4:1:circ(Mu))=Nt.new
1529 // memh(Rx++I:circ(Mu))=Nt.new
1530 // memh(Rx++Mu)=Nt.new
1531 // memh(Rx++Mu:brev)=Nt.new
1533 // memw(Rx++#s4:2:circ(Mu))=Nt.new
1534 // memw(Rx++I:circ(Mu))=Nt.new
1535 // memw(Rx++Mu)=Nt.new
1536 // memw(Rx++Mu:brev)=Nt.new
1538 //===----------------------------------------------------------------------===//
1540 //===----------------------------------------------------------------------===//
1542 //===----------------------------------------------------------------------===//
1544 //===----------------------------------------------------------------------===//
1546 //===----------------------------------------------------------------------===//
1547 // multiclass/template class for the new-value compare jumps with the register
1549 //===----------------------------------------------------------------------===//
1551 let isExtendable = 1, opExtendable = 2, isExtentSigned = 1, opExtentBits = 11,
1552 opExtentAlign = 2 in
1553 class NVJrr_template<string mnemonic, bits<3> majOp, bit NvOpNum,
1554 bit isNegCond, bit isTak>
1556 (ins IntRegs:$src1, IntRegs:$src2, brtarget:$offset),
1557 "if ("#!if(isNegCond, "!","")#mnemonic#
1558 "($src1"#!if(!eq(NvOpNum, 0),".new, ",", ")#
1559 "$src2"#!if(!eq(NvOpNum, 1),".new))","))")#" jump:"
1560 #!if(isTak, "t","nt")#" $offset", []> {
1564 bits<3> Ns; // New-Value Operand
1565 bits<5> RegOp; // Non-New-Value Operand
1568 let isTaken = isTak;
1569 let isPredicatedFalse = isNegCond;
1570 let opNewValue{0} = NvOpNum;
1572 let Ns = !if(!eq(NvOpNum, 0), src1{2-0}, src2{2-0});
1573 let RegOp = !if(!eq(NvOpNum, 0), src2, src1);
1575 let IClass = 0b0010;
1577 let Inst{25-23} = majOp;
1578 let Inst{22} = isNegCond;
1579 let Inst{18-16} = Ns;
1580 let Inst{13} = isTak;
1581 let Inst{12-8} = RegOp;
1582 let Inst{21-20} = offset{10-9};
1583 let Inst{7-1} = offset{8-2};
1587 multiclass NVJrr_cond<string mnemonic, bits<3> majOp, bit NvOpNum,
1589 // Branch not taken:
1590 def _nt_V4: NVJrr_template<mnemonic, majOp, NvOpNum, isNegCond, 0>;
1592 def _t_V4: NVJrr_template<mnemonic, majOp, NvOpNum, isNegCond, 1>;
1595 // NvOpNum = 0 -> First Operand is a new-value Register
1596 // NvOpNum = 1 -> Second Operand is a new-value Register
1598 multiclass NVJrr_base<string mnemonic, string BaseOp, bits<3> majOp,
1600 let BaseOpcode = BaseOp#_NVJ in {
1601 defm _t_Jumpnv : NVJrr_cond<mnemonic, majOp, NvOpNum, 0>; // True cond
1602 defm _f_Jumpnv : NVJrr_cond<mnemonic, majOp, NvOpNum, 1>; // False cond
1606 // if ([!]cmp.eq(Ns.new,Rt)) jump:[n]t #r9:2
1607 // if ([!]cmp.gt(Ns.new,Rt)) jump:[n]t #r9:2
1608 // if ([!]cmp.gtu(Ns.new,Rt)) jump:[n]t #r9:2
1609 // if ([!]cmp.gt(Rt,Ns.new)) jump:[n]t #r9:2
1610 // if ([!]cmp.gtu(Rt,Ns.new)) jump:[n]t #r9:2
1612 let isPredicated = 1, isBranch = 1, isNewValue = 1, isTerminator = 1,
1613 Defs = [PC], hasSideEffects = 0, validSubTargets = HasV4SubT,
1614 isCodeGenOnly = 0 in {
1615 defm CMPEQrr : NVJrr_base<"cmp.eq", "CMPEQ", 0b000, 0>, PredRel;
1616 defm CMPGTrr : NVJrr_base<"cmp.gt", "CMPGT", 0b001, 0>, PredRel;
1617 defm CMPGTUrr : NVJrr_base<"cmp.gtu", "CMPGTU", 0b010, 0>, PredRel;
1618 defm CMPLTrr : NVJrr_base<"cmp.gt", "CMPLT", 0b011, 1>, PredRel;
1619 defm CMPLTUrr : NVJrr_base<"cmp.gtu", "CMPLTU", 0b100, 1>, PredRel;
1622 //===----------------------------------------------------------------------===//
1623 // multiclass/template class for the new-value compare jumps instruction
1624 // with a register and an unsigned immediate (U5) operand.
1625 //===----------------------------------------------------------------------===//
1627 let isExtendable = 1, opExtendable = 2, isExtentSigned = 1, opExtentBits = 11,
1628 opExtentAlign = 2 in
1629 class NVJri_template<string mnemonic, bits<3> majOp, bit isNegCond,
1632 (ins IntRegs:$src1, u5Imm:$src2, brtarget:$offset),
1633 "if ("#!if(isNegCond, "!","")#mnemonic#"($src1.new, #$src2)) jump:"
1634 #!if(isTak, "t","nt")#" $offset", []> {
1636 let isTaken = isTak;
1637 let isPredicatedFalse = isNegCond;
1638 let isTaken = isTak;
1644 let IClass = 0b0010;
1646 let Inst{25-23} = majOp;
1647 let Inst{22} = isNegCond;
1648 let Inst{18-16} = src1;
1649 let Inst{13} = isTak;
1650 let Inst{12-8} = src2;
1651 let Inst{21-20} = offset{10-9};
1652 let Inst{7-1} = offset{8-2};
1655 multiclass NVJri_cond<string mnemonic, bits<3> majOp, bit isNegCond> {
1656 // Branch not taken:
1657 def _nt_V4: NVJri_template<mnemonic, majOp, isNegCond, 0>;
1659 def _t_V4: NVJri_template<mnemonic, majOp, isNegCond, 1>;
1662 multiclass NVJri_base<string mnemonic, string BaseOp, bits<3> majOp> {
1663 let BaseOpcode = BaseOp#_NVJri in {
1664 defm _t_Jumpnv : NVJri_cond<mnemonic, majOp, 0>; // True Cond
1665 defm _f_Jumpnv : NVJri_cond<mnemonic, majOp, 1>; // False cond
1669 // if ([!]cmp.eq(Ns.new,#U5)) jump:[n]t #r9:2
1670 // if ([!]cmp.gt(Ns.new,#U5)) jump:[n]t #r9:2
1671 // if ([!]cmp.gtu(Ns.new,#U5)) jump:[n]t #r9:2
1673 let isPredicated = 1, isBranch = 1, isNewValue = 1, isTerminator = 1,
1674 Defs = [PC], hasSideEffects = 0, validSubTargets = HasV4SubT,
1675 isCodeGenOnly = 0 in {
1676 defm CMPEQri : NVJri_base<"cmp.eq", "CMPEQ", 0b000>, PredRel;
1677 defm CMPGTri : NVJri_base<"cmp.gt", "CMPGT", 0b001>, PredRel;
1678 defm CMPGTUri : NVJri_base<"cmp.gtu", "CMPGTU", 0b010>, PredRel;
1681 //===----------------------------------------------------------------------===//
1682 // multiclass/template class for the new-value compare jumps instruction
1683 // with a register and an hardcoded 0/-1 immediate value.
1684 //===----------------------------------------------------------------------===//
1686 let isExtendable = 1, opExtendable = 1, isExtentSigned = 1, opExtentBits = 11,
1687 opExtentAlign = 2 in
1688 class NVJ_ConstImm_template<string mnemonic, bits<3> majOp, string ImmVal,
1689 bit isNegCond, bit isTak>
1691 (ins IntRegs:$src1, brtarget:$offset),
1692 "if ("#!if(isNegCond, "!","")#mnemonic
1693 #"($src1.new, #"#ImmVal#")) jump:"
1694 #!if(isTak, "t","nt")#" $offset", []> {
1696 let isTaken = isTak;
1697 let isPredicatedFalse = isNegCond;
1698 let isTaken = isTak;
1702 let IClass = 0b0010;
1704 let Inst{25-23} = majOp;
1705 let Inst{22} = isNegCond;
1706 let Inst{18-16} = src1;
1707 let Inst{13} = isTak;
1708 let Inst{21-20} = offset{10-9};
1709 let Inst{7-1} = offset{8-2};
1712 multiclass NVJ_ConstImm_cond<string mnemonic, bits<3> majOp, string ImmVal,
1714 // Branch not taken:
1715 def _nt_V4: NVJ_ConstImm_template<mnemonic, majOp, ImmVal, isNegCond, 0>;
1717 def _t_V4: NVJ_ConstImm_template<mnemonic, majOp, ImmVal, isNegCond, 1>;
1720 multiclass NVJ_ConstImm_base<string mnemonic, string BaseOp, bits<3> majOp,
1722 let BaseOpcode = BaseOp#_NVJ_ConstImm in {
1723 defm _t_Jumpnv : NVJ_ConstImm_cond<mnemonic, majOp, ImmVal, 0>; // True
1724 defm _f_Jumpnv : NVJ_ConstImm_cond<mnemonic, majOp, ImmVal, 1>; // False
1728 // if ([!]tstbit(Ns.new,#0)) jump:[n]t #r9:2
1729 // if ([!]cmp.eq(Ns.new,#-1)) jump:[n]t #r9:2
1730 // if ([!]cmp.gt(Ns.new,#-1)) jump:[n]t #r9:2
1732 let isPredicated = 1, isBranch = 1, isNewValue = 1, isTerminator=1,
1733 Defs = [PC], hasSideEffects = 0, isCodeGenOnly = 0 in {
1734 defm TSTBIT0 : NVJ_ConstImm_base<"tstbit", "TSTBIT", 0b011, "0">, PredRel;
1735 defm CMPEQn1 : NVJ_ConstImm_base<"cmp.eq", "CMPEQ", 0b100, "-1">, PredRel;
1736 defm CMPGTn1 : NVJ_ConstImm_base<"cmp.gt", "CMPGT", 0b101, "-1">, PredRel;
1739 // J4_hintjumpr: Hint indirect conditional jump.
1740 let isBranch = 1, isIndirectBranch = 1, hasSideEffects = 0, isCodeGenOnly = 0 in
1741 def J4_hintjumpr: JRInst <
1746 let IClass = 0b0101;
1747 let Inst{27-21} = 0b0010101;
1748 let Inst{20-16} = Rs;
1751 //===----------------------------------------------------------------------===//
1753 //===----------------------------------------------------------------------===//
1755 //===----------------------------------------------------------------------===//
1757 //===----------------------------------------------------------------------===//
1760 let hasNewValue = 1, isExtendable = 1, opExtendable = 1,
1761 isExtentSigned = 0, opExtentBits = 6, hasSideEffects = 0,
1762 Uses = [PC], validSubTargets = HasV4SubT, isCodeGenOnly = 0 in
1763 def C4_addipc : CRInst <(outs IntRegs:$Rd), (ins u6Ext:$u6),
1764 "$Rd = add(pc, #$u6)", [], "", CR_tc_2_SLOT3 > {
1768 let IClass = 0b0110;
1769 let Inst{27-16} = 0b101001001001;
1770 let Inst{12-7} = u6;
1776 let hasSideEffects = 0 in
1777 class T_LOGICAL_3OP<string MnOp1, string MnOp2, bits<2> OpBits, bit IsNeg>
1778 : CRInst<(outs PredRegs:$Pd),
1779 (ins PredRegs:$Ps, PredRegs:$Pt, PredRegs:$Pu),
1780 "$Pd = " # MnOp1 # "($Ps, " # MnOp2 # "($Pt, " #
1781 !if (IsNeg,"!","") # "$Pu))",
1782 [], "", CR_tc_2early_SLOT23> {
1788 let IClass = 0b0110;
1789 let Inst{27-24} = 0b1011;
1790 let Inst{23} = IsNeg;
1791 let Inst{22-21} = OpBits;
1793 let Inst{17-16} = Ps;
1800 let isCodeGenOnly = 0 in {
1801 def C4_and_and : T_LOGICAL_3OP<"and", "and", 0b00, 0>;
1802 def C4_and_or : T_LOGICAL_3OP<"and", "or", 0b01, 0>;
1803 def C4_or_and : T_LOGICAL_3OP<"or", "and", 0b10, 0>;
1804 def C4_or_or : T_LOGICAL_3OP<"or", "or", 0b11, 0>;
1805 def C4_and_andn : T_LOGICAL_3OP<"and", "and", 0b00, 1>;
1806 def C4_and_orn : T_LOGICAL_3OP<"and", "or", 0b01, 1>;
1807 def C4_or_andn : T_LOGICAL_3OP<"or", "and", 0b10, 1>;
1808 def C4_or_orn : T_LOGICAL_3OP<"or", "or", 0b11, 1>;
1811 //===----------------------------------------------------------------------===//
1813 //===----------------------------------------------------------------------===//
1815 //===----------------------------------------------------------------------===//
1817 //===----------------------------------------------------------------------===//
1819 // Logical with-not instructions.
1820 let validSubTargets = HasV4SubT, isCodeGenOnly = 0 in {
1821 def A4_andnp : T_ALU64_logical<"and", 0b001, 1, 0, 1>;
1822 def A4_ornp : T_ALU64_logical<"or", 0b011, 1, 0, 1>;
1825 let hasNewValue = 1, hasSideEffects = 0, isCodeGenOnly = 0 in
1826 def S4_parity: ALU64Inst<(outs IntRegs:$Rd), (ins IntRegs:$Rs, IntRegs:$Rt),
1827 "$Rd = parity($Rs, $Rt)", [], "", ALU64_tc_2_SLOT23> {
1832 let IClass = 0b1101;
1833 let Inst{27-21} = 0b0101111;
1834 let Inst{20-16} = Rs;
1835 let Inst{12-8} = Rt;
1838 // Add and accumulate.
1839 // Rd=add(Rs,add(Ru,#s6))
1840 let isExtentSigned = 1, hasNewValue = 1, isExtendable = 1, opExtentBits = 6,
1841 opExtendable = 3, isCodeGenOnly = 0 in
1842 def S4_addaddi : ALU64Inst <(outs IntRegs:$Rd),
1843 (ins IntRegs:$Rs, IntRegs:$Ru, s6Ext:$s6),
1844 "$Rd = add($Rs, add($Ru, #$s6))" ,
1845 [(set (i32 IntRegs:$Rd), (add (i32 IntRegs:$Rs),
1846 (add (i32 IntRegs:$Ru), s6_16ExtPred:$s6)))],
1847 "", ALU64_tc_2_SLOT23> {
1853 let IClass = 0b1101;
1855 let Inst{27-23} = 0b10110;
1856 let Inst{22-21} = s6{5-4};
1857 let Inst{20-16} = Rs;
1858 let Inst{13} = s6{3};
1859 let Inst{12-8} = Rd;
1860 let Inst{7-5} = s6{2-0};
1864 let isExtentSigned = 1, hasSideEffects = 0, hasNewValue = 1, isExtendable = 1,
1865 opExtentBits = 6, opExtendable = 2, isCodeGenOnly = 0 in
1866 def S4_subaddi: ALU64Inst <(outs IntRegs:$Rd),
1867 (ins IntRegs:$Rs, s6Ext:$s6, IntRegs:$Ru),
1868 "$Rd = add($Rs, sub(#$s6, $Ru))",
1869 [], "", ALU64_tc_2_SLOT23> {
1875 let IClass = 0b1101;
1877 let Inst{27-23} = 0b10111;
1878 let Inst{22-21} = s6{5-4};
1879 let Inst{20-16} = Rs;
1880 let Inst{13} = s6{3};
1881 let Inst{12-8} = Rd;
1882 let Inst{7-5} = s6{2-0};
1887 // Rdd=extract(Rss,#u6,#U6)
1888 // Rdd=extract(Rss,Rtt)
1889 // Rd=extract(Rs,Rtt)
1890 // Rd=extract(Rs,#u5,#U5)
1892 let isCodeGenOnly = 0 in {
1893 def S4_extractp_rp : T_S3op_64 < "extract", 0b11, 0b100, 0>;
1894 def S4_extractp : T_S2op_extract <"extract", 0b1010, DoubleRegs, u6Imm>;
1897 let hasNewValue = 1, isCodeGenOnly = 0 in {
1898 def S4_extract_rp : T_S3op_extract<"extract", 0b01>;
1899 def S4_extract : T_S2op_extract <"extract", 0b1101, IntRegs, u5Imm>;
1902 // Complex add/sub halfwords/words
1903 let Defs = [USR_OVF], isCodeGenOnly = 0 in {
1904 def S4_vxaddsubh : T_S3op_64 < "vxaddsubh", 0b01, 0b100, 0, 1>;
1905 def S4_vxaddsubw : T_S3op_64 < "vxaddsubw", 0b01, 0b000, 0, 1>;
1906 def S4_vxsubaddh : T_S3op_64 < "vxsubaddh", 0b01, 0b110, 0, 1>;
1907 def S4_vxsubaddw : T_S3op_64 < "vxsubaddw", 0b01, 0b010, 0, 1>;
1910 let Defs = [USR_OVF], isCodeGenOnly = 0 in {
1911 def S4_vxaddsubhr : T_S3op_64 < "vxaddsubh", 0b11, 0b000, 0, 1, 1, 1>;
1912 def S4_vxsubaddhr : T_S3op_64 < "vxsubaddh", 0b11, 0b010, 0, 1, 1, 1>;
1915 let Itinerary = M_tc_3x_SLOT23, Defs = [USR_OVF], isCodeGenOnly = 0 in {
1916 def M4_mac_up_s1_sat: T_MType_acc_rr<"+= mpy", 0b011, 0b000, 0, [], 0, 1, 1>;
1917 def M4_nac_up_s1_sat: T_MType_acc_rr<"-= mpy", 0b011, 0b001, 0, [], 0, 1, 1>;
1920 // Logical xor with xor accumulation.
1921 // Rxx^=xor(Rss,Rtt)
1922 let hasSideEffects = 0, isCodeGenOnly = 0 in
1924 : SInst <(outs DoubleRegs:$Rxx),
1925 (ins DoubleRegs:$dst2, DoubleRegs:$Rss, DoubleRegs:$Rtt),
1926 "$Rxx ^= xor($Rss, $Rtt)",
1927 [(set (i64 DoubleRegs:$Rxx),
1928 (xor (i64 DoubleRegs:$dst2), (xor (i64 DoubleRegs:$Rss),
1929 (i64 DoubleRegs:$Rtt))))],
1930 "$dst2 = $Rxx", S_3op_tc_1_SLOT23> {
1935 let IClass = 0b1100;
1937 let Inst{27-23} = 0b10101;
1938 let Inst{20-16} = Rss;
1939 let Inst{12-8} = Rtt;
1940 let Inst{4-0} = Rxx;
1943 // Rotate and reduce bytes
1944 // Rdd=vrcrotate(Rss,Rt,#u2)
1945 let hasSideEffects = 0, isCodeGenOnly = 0 in
1947 : SInst <(outs DoubleRegs:$Rdd),
1948 (ins DoubleRegs:$Rss, IntRegs:$Rt, u2Imm:$u2),
1949 "$Rdd = vrcrotate($Rss, $Rt, #$u2)",
1950 [], "", S_3op_tc_3x_SLOT23> {
1956 let IClass = 0b1100;
1958 let Inst{27-22} = 0b001111;
1959 let Inst{20-16} = Rss;
1960 let Inst{13} = u2{1};
1961 let Inst{12-8} = Rt;
1962 let Inst{7-6} = 0b11;
1963 let Inst{5} = u2{0};
1964 let Inst{4-0} = Rdd;
1967 // Rotate and reduce bytes with accumulation
1968 // Rxx+=vrcrotate(Rss,Rt,#u2)
1969 let hasSideEffects = 0, isCodeGenOnly = 0 in
1970 def S4_vrcrotate_acc
1971 : SInst <(outs DoubleRegs:$Rxx),
1972 (ins DoubleRegs:$dst2, DoubleRegs:$Rss, IntRegs:$Rt, u2Imm:$u2),
1973 "$Rxx += vrcrotate($Rss, $Rt, #$u2)", [],
1974 "$dst2 = $Rxx", S_3op_tc_3x_SLOT23> {
1980 let IClass = 0b1100;
1982 let Inst{27-21} = 0b1011101;
1983 let Inst{20-16} = Rss;
1984 let Inst{13} = u2{1};
1985 let Inst{12-8} = Rt;
1986 let Inst{5} = u2{0};
1987 let Inst{4-0} = Rxx;
1991 // Vector reduce conditional negate halfwords
1992 let hasSideEffects = 0, isCodeGenOnly = 0 in
1994 : SInst <(outs DoubleRegs:$Rxx),
1995 (ins DoubleRegs:$dst2, DoubleRegs:$Rss, IntRegs:$Rt),
1996 "$Rxx += vrcnegh($Rss, $Rt)", [],
1997 "$dst2 = $Rxx", S_3op_tc_3x_SLOT23> {
2002 let IClass = 0b1100;
2004 let Inst{27-21} = 0b1011001;
2005 let Inst{20-16} = Rss;
2007 let Inst{12-8} = Rt;
2008 let Inst{7-5} = 0b111;
2009 let Inst{4-0} = Rxx;
2013 let isCodeGenOnly = 0 in
2014 def A4_bitspliti : T_S2op_2_di <"bitsplit", 0b110, 0b100>;
2016 // Arithmetic/Convergent round
2017 let isCodeGenOnly = 0 in
2018 def A4_cround_ri : T_S2op_2_ii <"cround", 0b111, 0b000>;
2020 let isCodeGenOnly = 0 in
2021 def A4_round_ri : T_S2op_2_ii <"round", 0b111, 0b100>;
2023 let Defs = [USR_OVF], isCodeGenOnly = 0 in
2024 def A4_round_ri_sat : T_S2op_2_ii <"round", 0b111, 0b110, 1>;
2026 // Logical-logical words.
2027 // Compound or-and -- Rx=or(Ru,and(Rx,#s10))
2028 let isExtentSigned = 1, hasNewValue = 1, isExtendable = 1, opExtentBits = 10,
2029 opExtendable = 3, isCodeGenOnly = 0 in
2031 ALU64Inst<(outs IntRegs:$Rx),
2032 (ins IntRegs:$Ru, IntRegs:$_src_, s10Ext:$s10),
2033 "$Rx = or($Ru, and($_src_, #$s10))" ,
2034 [(set (i32 IntRegs:$Rx),
2035 (or (i32 IntRegs:$Ru), (and (i32 IntRegs:$_src_), s10ExtPred:$s10)))] ,
2036 "$_src_ = $Rx", ALU64_tc_2_SLOT23> {
2041 let IClass = 0b1101;
2043 let Inst{27-22} = 0b101001;
2044 let Inst{20-16} = Rx;
2045 let Inst{21} = s10{9};
2046 let Inst{13-5} = s10{8-0};
2050 // Miscellaneous ALU64 instructions.
2052 let hasNewValue = 1, hasSideEffects = 0, isCodeGenOnly = 0 in
2053 def A4_modwrapu: ALU64Inst<(outs IntRegs:$Rd), (ins IntRegs:$Rs, IntRegs:$Rt),
2054 "$Rd = modwrap($Rs, $Rt)", [], "", ALU64_tc_2_SLOT23> {
2059 let IClass = 0b1101;
2060 let Inst{27-21} = 0b0011111;
2061 let Inst{20-16} = Rs;
2062 let Inst{12-8} = Rt;
2063 let Inst{7-5} = 0b111;
2067 let hasSideEffects = 0, isCodeGenOnly = 0 in
2068 def A4_bitsplit: ALU64Inst<(outs DoubleRegs:$Rd),
2069 (ins IntRegs:$Rs, IntRegs:$Rt),
2070 "$Rd = bitsplit($Rs, $Rt)", [], "", ALU64_tc_1_SLOT23> {
2075 let IClass = 0b1101;
2076 let Inst{27-24} = 0b0100;
2078 let Inst{20-16} = Rs;
2079 let Inst{12-8} = Rt;
2083 let isCodeGenOnly = 0 in {
2084 // Rx[&|]=xor(Rs,Rt)
2085 def M4_or_xor : T_MType_acc_rr < "|= xor", 0b110, 0b001, 0>;
2086 def M4_and_xor : T_MType_acc_rr < "&= xor", 0b010, 0b010, 0>;
2088 // Rx[&|^]=or(Rs,Rt)
2089 def M4_xor_or : T_MType_acc_rr < "^= or", 0b110, 0b011, 0>;
2091 let CextOpcode = "ORr_ORr" in
2092 def M4_or_or : T_MType_acc_rr < "|= or", 0b110, 0b000, 0>;
2093 def M4_and_or : T_MType_acc_rr < "&= or", 0b010, 0b001, 0>;
2095 // Rx[&|^]=and(Rs,Rt)
2096 def M4_xor_and : T_MType_acc_rr < "^= and", 0b110, 0b010, 0>;
2098 let CextOpcode = "ORr_ANDr" in
2099 def M4_or_and : T_MType_acc_rr < "|= and", 0b010, 0b011, 0>;
2100 def M4_and_and : T_MType_acc_rr < "&= and", 0b010, 0b000, 0>;
2102 // Rx[&|^]=and(Rs,~Rt)
2103 def M4_xor_andn : T_MType_acc_rr < "^= and", 0b001, 0b010, 0, [], 1>;
2104 def M4_or_andn : T_MType_acc_rr < "|= and", 0b001, 0b000, 0, [], 1>;
2105 def M4_and_andn : T_MType_acc_rr < "&= and", 0b001, 0b001, 0, [], 1>;
2108 // Compound or-or and or-and
2109 let isExtentSigned = 1, InputType = "imm", hasNewValue = 1, isExtendable = 1,
2110 opExtentBits = 10, opExtendable = 3 in
2111 class T_CompOR <string mnemonic, bits<2> MajOp, SDNode OpNode>
2112 : MInst_acc <(outs IntRegs:$Rx),
2113 (ins IntRegs:$src1, IntRegs:$Rs, s10Ext:$s10),
2114 "$Rx |= "#mnemonic#"($Rs, #$s10)",
2115 [(set (i32 IntRegs:$Rx), (or (i32 IntRegs:$src1),
2116 (OpNode (i32 IntRegs:$Rs), s10ExtPred:$s10)))],
2117 "$src1 = $Rx", ALU64_tc_2_SLOT23>, ImmRegRel {
2122 let IClass = 0b1101;
2124 let Inst{27-24} = 0b1010;
2125 let Inst{23-22} = MajOp;
2126 let Inst{20-16} = Rs;
2127 let Inst{21} = s10{9};
2128 let Inst{13-5} = s10{8-0};
2132 let CextOpcode = "ORr_ANDr", isCodeGenOnly = 0 in
2133 def S4_or_andi : T_CompOR <"and", 0b00, and>;
2135 let CextOpcode = "ORr_ORr", isCodeGenOnly = 0 in
2136 def S4_or_ori : T_CompOR <"or", 0b10, or>;
2139 // Rd=modwrap(Rs,Rt)
2141 // Rd=cround(Rs,#u5)
2143 // Rd=round(Rs,#u5)[:sat]
2144 // Rd=round(Rs,Rt)[:sat]
2145 // Vector reduce add unsigned halfwords
2146 // Rd=vraddh(Rss,Rtt)
2148 // Rdd=vaddb(Rss,Rtt)
2149 // Vector conditional negate
2150 // Rdd=vcnegh(Rss,Rt)
2151 // Rxx+=vrcnegh(Rss,Rt)
2152 // Vector maximum bytes
2153 // Rdd=vmaxb(Rtt,Rss)
2154 // Vector reduce maximum halfwords
2155 // Rxx=vrmaxh(Rss,Ru)
2156 // Rxx=vrmaxuh(Rss,Ru)
2157 // Vector reduce maximum words
2158 // Rxx=vrmaxuw(Rss,Ru)
2159 // Rxx=vrmaxw(Rss,Ru)
2160 // Vector minimum bytes
2161 // Rdd=vminb(Rtt,Rss)
2162 // Vector reduce minimum halfwords
2163 // Rxx=vrminh(Rss,Ru)
2164 // Rxx=vrminuh(Rss,Ru)
2165 // Vector reduce minimum words
2166 // Rxx=vrminuw(Rss,Ru)
2167 // Rxx=vrminw(Rss,Ru)
2168 // Vector subtract bytes
2169 // Rdd=vsubb(Rss,Rtt)
2171 //===----------------------------------------------------------------------===//
2173 //===----------------------------------------------------------------------===//
2175 //===----------------------------------------------------------------------===//
2177 //===----------------------------------------------------------------------===//
2180 let isCodeGenOnly = 0 in
2181 def S2_brevp : T_S2op_3 <"brev", 0b11, 0b110>;
2184 let isCodeGenOnly = 0 in {
2185 def S2_ct0p : T_COUNT_LEADING_64<"ct0", 0b111, 0b010>;
2186 def S2_ct1p : T_COUNT_LEADING_64<"ct1", 0b111, 0b100>;
2187 def S4_clbpnorm : T_COUNT_LEADING_64<"normamt", 0b011, 0b000>;
2190 def: Pat<(i32 (trunc (cttz (i64 DoubleRegs:$Rss)))),
2191 (S2_ct0p (i64 DoubleRegs:$Rss))>;
2192 def: Pat<(i32 (trunc (cttz (not (i64 DoubleRegs:$Rss))))),
2193 (S2_ct1p (i64 DoubleRegs:$Rss))>;
2195 let hasSideEffects = 0, hasNewValue = 1, isCodeGenOnly = 0 in
2196 def S4_clbaddi : SInst<(outs IntRegs:$Rd), (ins IntRegs:$Rs, s6Imm:$s6),
2197 "$Rd = add(clb($Rs), #$s6)", [], "", S_2op_tc_2_SLOT23> {
2201 let IClass = 0b1000;
2202 let Inst{27-24} = 0b1100;
2203 let Inst{23-21} = 0b001;
2204 let Inst{20-16} = Rs;
2205 let Inst{13-8} = s6;
2206 let Inst{7-5} = 0b000;
2210 let hasSideEffects = 0, hasNewValue = 1, isCodeGenOnly = 0 in
2211 def S4_clbpaddi : SInst<(outs IntRegs:$Rd), (ins DoubleRegs:$Rs, s6Imm:$s6),
2212 "$Rd = add(clb($Rs), #$s6)", [], "", S_2op_tc_2_SLOT23> {
2216 let IClass = 0b1000;
2217 let Inst{27-24} = 0b1000;
2218 let Inst{23-21} = 0b011;
2219 let Inst{20-16} = Rs;
2220 let Inst{13-8} = s6;
2221 let Inst{7-5} = 0b010;
2226 // Bit test/set/clear
2227 let isCodeGenOnly = 0 in {
2228 def S4_ntstbit_i : T_TEST_BIT_IMM<"!tstbit", 0b001>;
2229 def S4_ntstbit_r : T_TEST_BIT_REG<"!tstbit", 1>;
2232 let AddedComplexity = 20 in { // Complexity greater than cmp reg-imm.
2233 def: Pat<(i1 (seteq (and (shl 1, u5ImmPred:$u5), (i32 IntRegs:$Rs)), 0)),
2234 (S4_ntstbit_i (i32 IntRegs:$Rs), u5ImmPred:$u5)>;
2235 def: Pat<(i1 (seteq (and (shl 1, (i32 IntRegs:$Rt)), (i32 IntRegs:$Rs)), 0)),
2236 (S4_ntstbit_r (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))>;
2239 // Add extra complexity to prefer these instructions over bitsset/bitsclr.
2240 // The reason is that tstbit/ntstbit can be folded into a compound instruction:
2241 // if ([!]tstbit(...)) jump ...
2242 let AddedComplexity = 100 in
2243 def: Pat<(i1 (setne (and (i32 IntRegs:$Rs), (i32 Set5ImmPred:$u5)), (i32 0))),
2244 (S2_tstbit_i (i32 IntRegs:$Rs), (BITPOS32 Set5ImmPred:$u5))>;
2246 let AddedComplexity = 100 in
2247 def: Pat<(i1 (seteq (and (i32 IntRegs:$Rs), (i32 Set5ImmPred:$u5)), (i32 0))),
2248 (S4_ntstbit_i (i32 IntRegs:$Rs), (BITPOS32 Set5ImmPred:$u5))>;
2250 let isCodeGenOnly = 0 in {
2251 def C4_nbitsset : T_TEST_BITS_REG<"!bitsset", 0b01, 1>;
2252 def C4_nbitsclr : T_TEST_BITS_REG<"!bitsclr", 0b10, 1>;
2253 def C4_nbitsclri : T_TEST_BITS_IMM<"!bitsclr", 0b10, 1>;
2256 // Do not increase complexity of these patterns. In the DAG, "cmp i8" may be
2257 // represented as a compare against "value & 0xFF", which is an exact match
2258 // for cmpb (same for cmph). The patterns below do not contain any additional
2259 // complexity that would make them preferable, and if they were actually used
2260 // instead of cmpb/cmph, they would result in a compare against register that
2261 // is loaded with the byte/half mask (i.e. 0xFF or 0xFFFF).
2262 def: Pat<(i1 (setne (and I32:$Rs, u6ImmPred:$u6), 0)),
2263 (C4_nbitsclri I32:$Rs, u6ImmPred:$u6)>;
2264 def: Pat<(i1 (setne (and I32:$Rs, I32:$Rt), 0)),
2265 (C4_nbitsclr I32:$Rs, I32:$Rt)>;
2266 def: Pat<(i1 (setne (and I32:$Rs, I32:$Rt), I32:$Rt)),
2267 (C4_nbitsset I32:$Rs, I32:$Rt)>;
2269 //===----------------------------------------------------------------------===//
2271 //===----------------------------------------------------------------------===//
2273 //===----------------------------------------------------------------------===//
2275 //===----------------------------------------------------------------------===//
2277 // Rd=add(#u6,mpyi(Rs,#U6)) -- Multiply by immed and add immed.
2279 let hasNewValue = 1, isExtendable = 1, opExtentBits = 6, opExtendable = 1,
2280 isCodeGenOnly = 0 in
2281 def M4_mpyri_addi : MInst<(outs IntRegs:$Rd),
2282 (ins u6Ext:$u6, IntRegs:$Rs, u6Imm:$U6),
2283 "$Rd = add(#$u6, mpyi($Rs, #$U6))" ,
2284 [(set (i32 IntRegs:$Rd),
2285 (add (mul (i32 IntRegs:$Rs), u6ImmPred:$U6),
2286 u6ExtPred:$u6))] ,"",ALU64_tc_3x_SLOT23> {
2292 let IClass = 0b1101;
2294 let Inst{27-24} = 0b1000;
2295 let Inst{23} = U6{5};
2296 let Inst{22-21} = u6{5-4};
2297 let Inst{20-16} = Rs;
2298 let Inst{13} = u6{3};
2299 let Inst{12-8} = Rd;
2300 let Inst{7-5} = u6{2-0};
2301 let Inst{4-0} = U6{4-0};
2304 // Rd=add(#u6,mpyi(Rs,Rt))
2305 let CextOpcode = "ADD_MPY", InputType = "imm", hasNewValue = 1,
2306 isExtendable = 1, opExtentBits = 6, opExtendable = 1, isCodeGenOnly = 0 in
2307 def M4_mpyrr_addi : MInst <(outs IntRegs:$Rd),
2308 (ins u6Ext:$u6, IntRegs:$Rs, IntRegs:$Rt),
2309 "$Rd = add(#$u6, mpyi($Rs, $Rt))" ,
2310 [(set (i32 IntRegs:$Rd),
2311 (add (mul (i32 IntRegs:$Rs), (i32 IntRegs:$Rt)), u6ExtPred:$u6))],
2312 "", ALU64_tc_3x_SLOT23>, ImmRegRel {
2318 let IClass = 0b1101;
2320 let Inst{27-23} = 0b01110;
2321 let Inst{22-21} = u6{5-4};
2322 let Inst{20-16} = Rs;
2323 let Inst{13} = u6{3};
2324 let Inst{12-8} = Rt;
2325 let Inst{7-5} = u6{2-0};
2329 let hasNewValue = 1 in
2330 class T_AddMpy <bit MajOp, PatLeaf ImmPred, dag ins>
2331 : ALU64Inst <(outs IntRegs:$dst), ins,
2332 "$dst = add($src1, mpyi("#!if(MajOp,"$src3, #$src2))",
2334 [(set (i32 IntRegs:$dst),
2335 (add (i32 IntRegs:$src1), (mul (i32 IntRegs:$src3), ImmPred:$src2)))],
2336 "", ALU64_tc_3x_SLOT23> {
2342 let IClass = 0b1101;
2344 bits<6> ImmValue = !if(MajOp, src2{5-0}, src2{7-2});
2346 let Inst{27-24} = 0b1111;
2347 let Inst{23} = MajOp;
2348 let Inst{22-21} = ImmValue{5-4};
2349 let Inst{20-16} = src3;
2350 let Inst{13} = ImmValue{3};
2351 let Inst{12-8} = dst;
2352 let Inst{7-5} = ImmValue{2-0};
2353 let Inst{4-0} = src1;
2356 let isCodeGenOnly = 0 in
2357 def M4_mpyri_addr_u2 : T_AddMpy<0b0, u6_2ImmPred,
2358 (ins IntRegs:$src1, u6_2Imm:$src2, IntRegs:$src3)>;
2360 let isExtendable = 1, opExtentBits = 6, opExtendable = 3,
2361 CextOpcode = "ADD_MPY", InputType = "imm", isCodeGenOnly = 0 in
2362 def M4_mpyri_addr : T_AddMpy<0b1, u6ExtPred,
2363 (ins IntRegs:$src1, IntRegs:$src3, u6Ext:$src2)>, ImmRegRel;
2365 // Rx=add(Ru,mpyi(Rx,Rs))
2366 let validSubTargets = HasV4SubT, CextOpcode = "ADD_MPY", InputType = "reg",
2367 hasNewValue = 1, isCodeGenOnly = 0 in
2368 def M4_mpyrr_addr: MInst_acc <(outs IntRegs:$Rx),
2369 (ins IntRegs:$Ru, IntRegs:$_src_, IntRegs:$Rs),
2370 "$Rx = add($Ru, mpyi($_src_, $Rs))",
2371 [(set (i32 IntRegs:$Rx), (add (i32 IntRegs:$Ru),
2372 (mul (i32 IntRegs:$_src_), (i32 IntRegs:$Rs))))],
2373 "$_src_ = $Rx", M_tc_3x_SLOT23>, ImmRegRel {
2378 let IClass = 0b1110;
2380 let Inst{27-21} = 0b0011000;
2381 let Inst{12-8} = Rx;
2383 let Inst{20-16} = Rs;
2386 // Rd=add(##,mpyi(Rs,#U6))
2387 def : Pat <(add (mul (i32 IntRegs:$src2), u6ImmPred:$src3),
2388 (HexagonCONST32 tglobaladdr:$src1)),
2389 (i32 (M4_mpyri_addi tglobaladdr:$src1, IntRegs:$src2,
2392 // Rd=add(##,mpyi(Rs,Rt))
2393 def : Pat <(add (mul (i32 IntRegs:$src2), (i32 IntRegs:$src3)),
2394 (HexagonCONST32 tglobaladdr:$src1)),
2395 (i32 (M4_mpyrr_addi tglobaladdr:$src1, IntRegs:$src2,
2398 // Vector reduce multiply word by signed half (32x16)
2399 //Rdd=vrmpyweh(Rss,Rtt)[:<<1]
2400 let isCodeGenOnly = 0 in {
2401 def M4_vrmpyeh_s0 : T_M2_vmpy<"vrmpyweh", 0b010, 0b100, 0, 0, 0>;
2402 def M4_vrmpyeh_s1 : T_M2_vmpy<"vrmpyweh", 0b110, 0b100, 1, 0, 0>;
2405 //Rdd=vrmpywoh(Rss,Rtt)[:<<1]
2406 let isCodeGenOnly = 0 in {
2407 def M4_vrmpyoh_s0 : T_M2_vmpy<"vrmpywoh", 0b001, 0b010, 0, 0, 0>;
2408 def M4_vrmpyoh_s1 : T_M2_vmpy<"vrmpywoh", 0b101, 0b010, 1, 0, 0>;
2410 //Rdd+=vrmpyweh(Rss,Rtt)[:<<1]
2411 let isCodeGenOnly = 0 in {
2412 def M4_vrmpyeh_acc_s0: T_M2_vmpy_acc<"vrmpyweh", 0b001, 0b110, 0, 0>;
2413 def M4_vrmpyeh_acc_s1: T_M2_vmpy_acc<"vrmpyweh", 0b101, 0b110, 1, 0>;
2416 //Rdd=vrmpywoh(Rss,Rtt)[:<<1]
2417 let isCodeGenOnly = 0 in {
2418 def M4_vrmpyoh_acc_s0: T_M2_vmpy_acc<"vrmpywoh", 0b011, 0b110, 0, 0>;
2419 def M4_vrmpyoh_acc_s1: T_M2_vmpy_acc<"vrmpywoh", 0b111, 0b110, 1, 0>;
2422 // Vector multiply halfwords, signed by unsigned
2423 // Rdd=vmpyhsu(Rs,Rt)[:<<]:sat
2424 let isCodeGenOnly = 0 in {
2425 def M2_vmpy2su_s0 : T_XTYPE_mpy64 < "vmpyhsu", 0b000, 0b111, 1, 0, 0>;
2426 def M2_vmpy2su_s1 : T_XTYPE_mpy64 < "vmpyhsu", 0b100, 0b111, 1, 1, 0>;
2429 // Rxx+=vmpyhsu(Rs,Rt)[:<<1]:sat
2430 let isCodeGenOnly = 0 in {
2431 def M2_vmac2su_s0 : T_XTYPE_mpy64_acc < "vmpyhsu", "+", 0b011, 0b101, 1, 0, 0>;
2432 def M2_vmac2su_s1 : T_XTYPE_mpy64_acc < "vmpyhsu", "+", 0b111, 0b101, 1, 1, 0>;
2435 // Vector polynomial multiply halfwords
2436 // Rdd=vpmpyh(Rs,Rt)
2437 let isCodeGenOnly = 0 in
2438 def M4_vpmpyh : T_XTYPE_mpy64 < "vpmpyh", 0b110, 0b111, 0, 0, 0>;
2440 // Rxx^=vpmpyh(Rs,Rt)
2441 let isCodeGenOnly = 0 in
2442 def M4_vpmpyh_acc : T_XTYPE_mpy64_acc < "vpmpyh", "^", 0b101, 0b111, 0, 0, 0>;
2444 // Polynomial multiply words
2446 let isCodeGenOnly = 0 in
2447 def M4_pmpyw : T_XTYPE_mpy64 < "pmpyw", 0b010, 0b111, 0, 0, 0>;
2449 // Rxx^=pmpyw(Rs,Rt)
2450 let isCodeGenOnly = 0 in
2451 def M4_pmpyw_acc : T_XTYPE_mpy64_acc < "pmpyw", "^", 0b001, 0b111, 0, 0, 0>;
2453 //===----------------------------------------------------------------------===//
2455 //===----------------------------------------------------------------------===//
2458 //===----------------------------------------------------------------------===//
2459 // ALU64/Vector compare
2460 //===----------------------------------------------------------------------===//
2461 //===----------------------------------------------------------------------===//
2462 // Template class for vector compare
2463 //===----------------------------------------------------------------------===//
2465 let hasSideEffects = 0 in
2466 class T_vcmpImm <string Str, bits<2> cmpOp, bits<2> minOp, Operand ImmOprnd>
2467 : ALU64_rr <(outs PredRegs:$Pd),
2468 (ins DoubleRegs:$Rss, ImmOprnd:$Imm),
2469 "$Pd = "#Str#"($Rss, #$Imm)",
2470 [], "", ALU64_tc_2early_SLOT23> {
2475 let ImmBits{6-0} = Imm{6-0};
2476 let ImmBits{7} = !if (!eq(cmpOp,0b10), 0b0, Imm{7}); // 0 for vcmp[bhw].gtu
2478 let IClass = 0b1101;
2480 let Inst{27-24} = 0b1100;
2481 let Inst{22-21} = cmpOp;
2482 let Inst{20-16} = Rss;
2483 let Inst{12-5} = ImmBits;
2484 let Inst{4-3} = minOp;
2488 // Vector compare bytes
2489 let isCodeGenOnly = 0 in
2490 def A4_vcmpbgt : T_vcmp <"vcmpb.gt", 0b1010>;
2491 def: T_vcmp_pat<A4_vcmpbgt, setgt, v8i8>;
2493 let AsmString = "$Pd = any8(vcmpb.eq($Rss, $Rtt))" in
2494 let isCodeGenOnly = 0 in
2495 def A4_vcmpbeq_any : T_vcmp <"any8(vcmpb.gt", 0b1000>;
2497 let isCodeGenOnly = 0 in {
2498 def A4_vcmpbeqi : T_vcmpImm <"vcmpb.eq", 0b00, 0b00, u8Imm>;
2499 def A4_vcmpbgti : T_vcmpImm <"vcmpb.gt", 0b01, 0b00, s8Imm>;
2500 def A4_vcmpbgtui : T_vcmpImm <"vcmpb.gtu", 0b10, 0b00, u7Imm>;
2503 // Vector compare halfwords
2504 let isCodeGenOnly = 0 in {
2505 def A4_vcmpheqi : T_vcmpImm <"vcmph.eq", 0b00, 0b01, s8Imm>;
2506 def A4_vcmphgti : T_vcmpImm <"vcmph.gt", 0b01, 0b01, s8Imm>;
2507 def A4_vcmphgtui : T_vcmpImm <"vcmph.gtu", 0b10, 0b01, u7Imm>;
2510 // Vector compare words
2511 let isCodeGenOnly = 0 in {
2512 def A4_vcmpweqi : T_vcmpImm <"vcmpw.eq", 0b00, 0b10, s8Imm>;
2513 def A4_vcmpwgti : T_vcmpImm <"vcmpw.gt", 0b01, 0b10, s8Imm>;
2514 def A4_vcmpwgtui : T_vcmpImm <"vcmpw.gtu", 0b10, 0b10, u7Imm>;
2517 //===----------------------------------------------------------------------===//
2519 //===----------------------------------------------------------------------===//
2520 // Shift by immediate and accumulate/logical.
2521 // Rx=add(#u8,asl(Rx,#U5)) Rx=add(#u8,lsr(Rx,#U5))
2522 // Rx=sub(#u8,asl(Rx,#U5)) Rx=sub(#u8,lsr(Rx,#U5))
2523 // Rx=and(#u8,asl(Rx,#U5)) Rx=and(#u8,lsr(Rx,#U5))
2524 // Rx=or(#u8,asl(Rx,#U5)) Rx=or(#u8,lsr(Rx,#U5))
2525 let isExtendable = 1, opExtendable = 1, isExtentSigned = 0, opExtentBits = 8,
2526 hasNewValue = 1, opNewValue = 0, validSubTargets = HasV4SubT in
2527 class T_S4_ShiftOperate<string MnOp, string MnSh, SDNode Op, SDNode Sh,
2528 bit asl_lsr, bits<2> MajOp, InstrItinClass Itin>
2529 : MInst_acc<(outs IntRegs:$Rd), (ins u8Ext:$u8, IntRegs:$Rx, u5Imm:$U5),
2530 "$Rd = "#MnOp#"(#$u8, "#MnSh#"($Rx, #$U5))",
2531 [(set (i32 IntRegs:$Rd),
2532 (Op (Sh I32:$Rx, u5ImmPred:$U5), u8ExtPred:$u8))],
2533 "$Rd = $Rx", Itin> {
2540 let IClass = 0b1101;
2541 let Inst{27-24} = 0b1110;
2542 let Inst{23-21} = u8{7-5};
2543 let Inst{20-16} = Rd;
2544 let Inst{13} = u8{4};
2545 let Inst{12-8} = U5;
2546 let Inst{7-5} = u8{3-1};
2547 let Inst{4} = asl_lsr;
2548 let Inst{3} = u8{0};
2549 let Inst{2-1} = MajOp;
2552 multiclass T_ShiftOperate<string mnemonic, SDNode Op, bits<2> MajOp,
2553 InstrItinClass Itin> {
2554 def _asl_ri : T_S4_ShiftOperate<mnemonic, "asl", Op, shl, 0, MajOp, Itin>;
2555 def _lsr_ri : T_S4_ShiftOperate<mnemonic, "lsr", Op, srl, 1, MajOp, Itin>;
2558 let AddedComplexity = 200, isCodeGenOnly = 0 in {
2559 defm S4_addi : T_ShiftOperate<"add", add, 0b10, ALU64_tc_2_SLOT23>;
2560 defm S4_andi : T_ShiftOperate<"and", and, 0b00, ALU64_tc_2_SLOT23>;
2563 let AddedComplexity = 30, isCodeGenOnly = 0 in
2564 defm S4_ori : T_ShiftOperate<"or", or, 0b01, ALU64_tc_1_SLOT23>;
2566 let isCodeGenOnly = 0 in
2567 defm S4_subi : T_ShiftOperate<"sub", sub, 0b11, ALU64_tc_1_SLOT23>;
2569 // Vector conditional negate
2570 // Rdd=vcnegh(Rss,Rt)
2571 let Defs = [USR_OVF], Itinerary = S_3op_tc_2_SLOT23, isCodeGenOnly = 0 in
2572 def S2_vcnegh : T_S3op_shiftVect < "vcnegh", 0b11, 0b01>;
2574 // Rd=[cround|round](Rs,Rt)
2575 let hasNewValue = 1, Itinerary = S_3op_tc_2_SLOT23, isCodeGenOnly = 0 in {
2576 def A4_cround_rr : T_S3op_3 < "cround", IntRegs, 0b11, 0b00>;
2577 def A4_round_rr : T_S3op_3 < "round", IntRegs, 0b11, 0b10>;
2580 // Rd=round(Rs,Rt):sat
2581 let hasNewValue = 1, Defs = [USR_OVF], Itinerary = S_3op_tc_2_SLOT23,
2582 isCodeGenOnly = 0 in
2583 def A4_round_rr_sat : T_S3op_3 < "round", IntRegs, 0b11, 0b11, 1>;
2585 // Rd=[cmpyiwh|cmpyrwh](Rss,Rt):<<1:rnd:sat
2586 let Defs = [USR_OVF], Itinerary = S_3op_tc_3x_SLOT23, isCodeGenOnly = 0 in {
2587 def M4_cmpyi_wh : T_S3op_8<"cmpyiwh", 0b100, 1, 1, 1>;
2588 def M4_cmpyr_wh : T_S3op_8<"cmpyrwh", 0b110, 1, 1, 1>;
2591 // Rdd=[add|sub](Rss,Rtt,Px):carry
2592 let isPredicateLate = 1, hasSideEffects = 0 in
2593 class T_S3op_carry <string mnemonic, bits<3> MajOp>
2594 : SInst < (outs DoubleRegs:$Rdd, PredRegs:$Px),
2595 (ins DoubleRegs:$Rss, DoubleRegs:$Rtt, PredRegs:$Pu),
2596 "$Rdd = "#mnemonic#"($Rss, $Rtt, $Pu):carry",
2597 [], "$Px = $Pu", S_3op_tc_1_SLOT23 > {
2603 let IClass = 0b1100;
2605 let Inst{27-24} = 0b0010;
2606 let Inst{23-21} = MajOp;
2607 let Inst{20-16} = Rss;
2608 let Inst{12-8} = Rtt;
2610 let Inst{4-0} = Rdd;
2613 let isCodeGenOnly = 0 in {
2614 def A4_addp_c : T_S3op_carry < "add", 0b110 >;
2615 def A4_subp_c : T_S3op_carry < "sub", 0b111 >;
2618 let Itinerary = S_3op_tc_3_SLOT23, hasSideEffects = 0 in
2619 class T_S3op_6 <string mnemonic, bits<3> MinOp, bit isUnsigned>
2620 : SInst <(outs DoubleRegs:$Rxx),
2621 (ins DoubleRegs:$dst2, DoubleRegs:$Rss, IntRegs:$Ru),
2622 "$Rxx = "#mnemonic#"($Rss, $Ru)" ,
2623 [] , "$dst2 = $Rxx"> {
2628 let IClass = 0b1100;
2630 let Inst{27-21} = 0b1011001;
2631 let Inst{20-16} = Rss;
2632 let Inst{13} = isUnsigned;
2633 let Inst{12-8} = Rxx;
2634 let Inst{7-5} = MinOp;
2638 // Vector reduce maximum halfwords
2639 // Rxx=vrmax[u]h(Rss,Ru)
2640 let isCodeGenOnly = 0 in {
2641 def A4_vrmaxh : T_S3op_6 < "vrmaxh", 0b001, 0>;
2642 def A4_vrmaxuh : T_S3op_6 < "vrmaxuh", 0b001, 1>;
2644 // Vector reduce maximum words
2645 // Rxx=vrmax[u]w(Rss,Ru)
2646 let isCodeGenOnly = 0 in {
2647 def A4_vrmaxw : T_S3op_6 < "vrmaxw", 0b010, 0>;
2648 def A4_vrmaxuw : T_S3op_6 < "vrmaxuw", 0b010, 1>;
2650 // Vector reduce minimum halfwords
2651 // Rxx=vrmin[u]h(Rss,Ru)
2652 let isCodeGenOnly = 0 in {
2653 def A4_vrminh : T_S3op_6 < "vrminh", 0b101, 0>;
2654 def A4_vrminuh : T_S3op_6 < "vrminuh", 0b101, 1>;
2657 // Vector reduce minimum words
2658 // Rxx=vrmin[u]w(Rss,Ru)
2659 let isCodeGenOnly = 0 in {
2660 def A4_vrminw : T_S3op_6 < "vrminw", 0b110, 0>;
2661 def A4_vrminuw : T_S3op_6 < "vrminuw", 0b110, 1>;
2664 // Shift an immediate left by register amount.
2665 let hasNewValue = 1, hasSideEffects = 0, isCodeGenOnly = 0 in
2666 def S4_lsli: SInst <(outs IntRegs:$Rd), (ins s6Imm:$s6, IntRegs:$Rt),
2667 "$Rd = lsl(#$s6, $Rt)" ,
2668 [(set (i32 IntRegs:$Rd), (shl s6ImmPred:$s6,
2669 (i32 IntRegs:$Rt)))],
2670 "", S_3op_tc_1_SLOT23> {
2675 let IClass = 0b1100;
2677 let Inst{27-22} = 0b011010;
2678 let Inst{20-16} = s6{5-1};
2679 let Inst{12-8} = Rt;
2680 let Inst{7-6} = 0b11;
2682 let Inst{5} = s6{0};
2685 //===----------------------------------------------------------------------===//
2687 //===----------------------------------------------------------------------===//
2689 //===----------------------------------------------------------------------===//
2690 // MEMOP: Word, Half, Byte
2691 //===----------------------------------------------------------------------===//
2693 def MEMOPIMM : SDNodeXForm<imm, [{
2694 // Call the transformation function XformM5ToU5Imm to get the negative
2695 // immediate's positive counterpart.
2696 int32_t imm = N->getSExtValue();
2697 return XformM5ToU5Imm(imm);
2700 def MEMOPIMM_HALF : SDNodeXForm<imm, [{
2701 // -1 .. -31 represented as 65535..65515
2702 // assigning to a short restores our desired signed value.
2703 // Call the transformation function XformM5ToU5Imm to get the negative
2704 // immediate's positive counterpart.
2705 int16_t imm = N->getSExtValue();
2706 return XformM5ToU5Imm(imm);
2709 def MEMOPIMM_BYTE : SDNodeXForm<imm, [{
2710 // -1 .. -31 represented as 255..235
2711 // assigning to a char restores our desired signed value.
2712 // Call the transformation function XformM5ToU5Imm to get the negative
2713 // immediate's positive counterpart.
2714 int8_t imm = N->getSExtValue();
2715 return XformM5ToU5Imm(imm);
2718 def SETMEMIMM : SDNodeXForm<imm, [{
2719 // Return the bit position we will set [0-31].
2721 int32_t imm = N->getSExtValue();
2722 return XformMskToBitPosU5Imm(imm);
2725 def CLRMEMIMM : SDNodeXForm<imm, [{
2726 // Return the bit position we will clear [0-31].
2728 // we bit negate the value first
2729 int32_t imm = ~(N->getSExtValue());
2730 return XformMskToBitPosU5Imm(imm);
2733 def SETMEMIMM_SHORT : SDNodeXForm<imm, [{
2734 // Return the bit position we will set [0-15].
2736 int16_t imm = N->getSExtValue();
2737 return XformMskToBitPosU4Imm(imm);
2740 def CLRMEMIMM_SHORT : SDNodeXForm<imm, [{
2741 // Return the bit position we will clear [0-15].
2743 // we bit negate the value first
2744 int16_t imm = ~(N->getSExtValue());
2745 return XformMskToBitPosU4Imm(imm);
2748 def SETMEMIMM_BYTE : SDNodeXForm<imm, [{
2749 // Return the bit position we will set [0-7].
2751 int8_t imm = N->getSExtValue();
2752 return XformMskToBitPosU3Imm(imm);
2755 def CLRMEMIMM_BYTE : SDNodeXForm<imm, [{
2756 // Return the bit position we will clear [0-7].
2758 // we bit negate the value first
2759 int8_t imm = ~(N->getSExtValue());
2760 return XformMskToBitPosU3Imm(imm);
2763 //===----------------------------------------------------------------------===//
2764 // Template class for MemOp instructions with the register value.
2765 //===----------------------------------------------------------------------===//
2766 class MemOp_rr_base <string opc, bits<2> opcBits, Operand ImmOp,
2767 string memOp, bits<2> memOpBits> :
2769 (ins IntRegs:$base, ImmOp:$offset, IntRegs:$delta),
2770 opc#"($base+#$offset)"#memOp#"$delta",
2772 Requires<[UseMEMOP]> {
2777 bits<6> offsetBits; // memb - u6:0 , memh - u6:1, memw - u6:2
2779 let offsetBits = !if (!eq(opcBits, 0b00), offset{5-0},
2780 !if (!eq(opcBits, 0b01), offset{6-1},
2781 !if (!eq(opcBits, 0b10), offset{7-2},0)));
2783 let opExtentAlign = opcBits;
2784 let IClass = 0b0011;
2785 let Inst{27-24} = 0b1110;
2786 let Inst{22-21} = opcBits;
2787 let Inst{20-16} = base;
2789 let Inst{12-7} = offsetBits;
2790 let Inst{6-5} = memOpBits;
2791 let Inst{4-0} = delta;
2794 //===----------------------------------------------------------------------===//
2795 // Template class for MemOp instructions with the immediate value.
2796 //===----------------------------------------------------------------------===//
2797 class MemOp_ri_base <string opc, bits<2> opcBits, Operand ImmOp,
2798 string memOp, bits<2> memOpBits> :
2800 (ins IntRegs:$base, ImmOp:$offset, u5Imm:$delta),
2801 opc#"($base+#$offset)"#memOp#"#$delta"
2802 #!if(memOpBits{1},")", ""), // clrbit, setbit - include ')'
2804 Requires<[UseMEMOP]> {
2809 bits<6> offsetBits; // memb - u6:0 , memh - u6:1, memw - u6:2
2811 let offsetBits = !if (!eq(opcBits, 0b00), offset{5-0},
2812 !if (!eq(opcBits, 0b01), offset{6-1},
2813 !if (!eq(opcBits, 0b10), offset{7-2},0)));
2815 let opExtentAlign = opcBits;
2816 let IClass = 0b0011;
2817 let Inst{27-24} = 0b1111;
2818 let Inst{22-21} = opcBits;
2819 let Inst{20-16} = base;
2821 let Inst{12-7} = offsetBits;
2822 let Inst{6-5} = memOpBits;
2823 let Inst{4-0} = delta;
2826 // multiclass to define MemOp instructions with register operand.
2827 multiclass MemOp_rr<string opc, bits<2> opcBits, Operand ImmOp> {
2828 def L4_add#NAME : MemOp_rr_base <opc, opcBits, ImmOp, " += ", 0b00>; // add
2829 def L4_sub#NAME : MemOp_rr_base <opc, opcBits, ImmOp, " -= ", 0b01>; // sub
2830 def L4_and#NAME : MemOp_rr_base <opc, opcBits, ImmOp, " &= ", 0b10>; // and
2831 def L4_or#NAME : MemOp_rr_base <opc, opcBits, ImmOp, " |= ", 0b11>; // or
2834 // multiclass to define MemOp instructions with immediate Operand.
2835 multiclass MemOp_ri<string opc, bits<2> opcBits, Operand ImmOp> {
2836 def L4_iadd#NAME : MemOp_ri_base <opc, opcBits, ImmOp, " += ", 0b00 >;
2837 def L4_isub#NAME : MemOp_ri_base <opc, opcBits, ImmOp, " -= ", 0b01 >;
2838 def L4_iand#NAME : MemOp_ri_base<opc, opcBits, ImmOp, " = clrbit(", 0b10>;
2839 def L4_ior#NAME : MemOp_ri_base<opc, opcBits, ImmOp, " = setbit(", 0b11>;
2842 multiclass MemOp_base <string opc, bits<2> opcBits, Operand ImmOp> {
2843 defm _#NAME : MemOp_rr <opc, opcBits, ImmOp>;
2844 defm _#NAME : MemOp_ri <opc, opcBits, ImmOp>;
2847 // Define MemOp instructions.
2848 let isExtendable = 1, opExtendable = 1, isExtentSigned = 0,
2849 validSubTargets =HasV4SubT in {
2850 let opExtentBits = 6, accessSize = ByteAccess, isCodeGenOnly = 0 in
2851 defm memopb_io : MemOp_base <"memb", 0b00, u6_0Ext>;
2853 let opExtentBits = 7, accessSize = HalfWordAccess, isCodeGenOnly = 0 in
2854 defm memoph_io : MemOp_base <"memh", 0b01, u6_1Ext>;
2856 let opExtentBits = 8, accessSize = WordAccess, isCodeGenOnly = 0 in
2857 defm memopw_io : MemOp_base <"memw", 0b10, u6_2Ext>;
2860 //===----------------------------------------------------------------------===//
2861 // Multiclass to define 'Def Pats' for ALU operations on the memory
2862 // Here value used for the ALU operation is an immediate value.
2863 // mem[bh](Rs+#0) += #U5
2864 // mem[bh](Rs+#u6) += #U5
2865 //===----------------------------------------------------------------------===//
2867 multiclass MemOpi_u5Pats <PatFrag ldOp, PatFrag stOp, PatLeaf ExtPred,
2868 InstHexagon MI, SDNode OpNode> {
2869 let AddedComplexity = 180 in
2870 def : Pat < (stOp (OpNode (ldOp IntRegs:$addr), u5ImmPred:$addend),
2872 (MI IntRegs:$addr, #0, u5ImmPred:$addend )>;
2874 let AddedComplexity = 190 in
2875 def : Pat <(stOp (OpNode (ldOp (add IntRegs:$base, ExtPred:$offset)),
2877 (add IntRegs:$base, ExtPred:$offset)),
2878 (MI IntRegs:$base, ExtPred:$offset, u5ImmPred:$addend)>;
2881 multiclass MemOpi_u5ALUOp<PatFrag ldOp, PatFrag stOp, PatLeaf ExtPred,
2882 InstHexagon addMI, InstHexagon subMI> {
2883 defm : MemOpi_u5Pats<ldOp, stOp, ExtPred, addMI, add>;
2884 defm : MemOpi_u5Pats<ldOp, stOp, ExtPred, subMI, sub>;
2887 multiclass MemOpi_u5ExtType<PatFrag ldOpByte, PatFrag ldOpHalf > {
2889 defm : MemOpi_u5ALUOp <ldOpHalf, truncstorei16, u6_1ExtPred,
2890 L4_iadd_memoph_io, L4_isub_memoph_io>;
2892 defm : MemOpi_u5ALUOp <ldOpByte, truncstorei8, u6ExtPred,
2893 L4_iadd_memopb_io, L4_isub_memopb_io>;
2896 let Predicates = [HasV4T, UseMEMOP] in {
2897 defm : MemOpi_u5ExtType<zextloadi8, zextloadi16>; // zero extend
2898 defm : MemOpi_u5ExtType<sextloadi8, sextloadi16>; // sign extend
2899 defm : MemOpi_u5ExtType<extloadi8, extloadi16>; // any extend
2902 defm : MemOpi_u5ALUOp <load, store, u6_2ExtPred, L4_iadd_memopw_io,
2906 //===----------------------------------------------------------------------===//
2907 // multiclass to define 'Def Pats' for ALU operations on the memory.
2908 // Here value used for the ALU operation is a negative value.
2909 // mem[bh](Rs+#0) += #m5
2910 // mem[bh](Rs+#u6) += #m5
2911 //===----------------------------------------------------------------------===//
2913 multiclass MemOpi_m5Pats <PatFrag ldOp, PatFrag stOp, PatLeaf extPred,
2914 PatLeaf immPred, ComplexPattern addrPred,
2915 SDNodeXForm xformFunc, InstHexagon MI> {
2916 let AddedComplexity = 190 in
2917 def : Pat <(stOp (add (ldOp IntRegs:$addr), immPred:$subend),
2919 (MI IntRegs:$addr, #0, (xformFunc immPred:$subend) )>;
2921 let AddedComplexity = 195 in
2922 def : Pat<(stOp (add (ldOp (add IntRegs:$base, extPred:$offset)),
2924 (add IntRegs:$base, extPred:$offset)),
2925 (MI IntRegs:$base, extPred:$offset, (xformFunc immPred:$subend))>;
2928 multiclass MemOpi_m5ExtType<PatFrag ldOpByte, PatFrag ldOpHalf > {
2930 defm : MemOpi_m5Pats <ldOpHalf, truncstorei16, u6_1ExtPred, m5HImmPred,
2931 ADDRriU6_1, MEMOPIMM_HALF, L4_isub_memoph_io>;
2933 defm : MemOpi_m5Pats <ldOpByte, truncstorei8, u6ExtPred, m5BImmPred,
2934 ADDRriU6_0, MEMOPIMM_BYTE, L4_isub_memopb_io>;
2937 let Predicates = [HasV4T, UseMEMOP] in {
2938 defm : MemOpi_m5ExtType<zextloadi8, zextloadi16>; // zero extend
2939 defm : MemOpi_m5ExtType<sextloadi8, sextloadi16>; // sign extend
2940 defm : MemOpi_m5ExtType<extloadi8, extloadi16>; // any extend
2943 defm : MemOpi_m5Pats <load, store, u6_2ExtPred, m5ImmPred,
2944 ADDRriU6_2, MEMOPIMM, L4_isub_memopw_io>;
2947 //===----------------------------------------------------------------------===//
2948 // Multiclass to define 'def Pats' for bit operations on the memory.
2949 // mem[bhw](Rs+#0) = [clrbit|setbit](#U5)
2950 // mem[bhw](Rs+#u6) = [clrbit|setbit](#U5)
2951 //===----------------------------------------------------------------------===//
2953 multiclass MemOpi_bitPats <PatFrag ldOp, PatFrag stOp, PatLeaf immPred,
2954 PatLeaf extPred, ComplexPattern addrPred,
2955 SDNodeXForm xformFunc, InstHexagon MI, SDNode OpNode> {
2957 // mem[bhw](Rs+#u6:[012]) = [clrbit|setbit](#U5)
2958 let AddedComplexity = 250 in
2959 def : Pat<(stOp (OpNode (ldOp (add IntRegs:$base, extPred:$offset)),
2961 (add IntRegs:$base, extPred:$offset)),
2962 (MI IntRegs:$base, extPred:$offset, (xformFunc immPred:$bitend))>;
2964 // mem[bhw](Rs+#0) = [clrbit|setbit](#U5)
2965 let AddedComplexity = 225 in
2966 def : Pat <(stOp (OpNode (ldOp (addrPred IntRegs:$addr, extPred:$offset)),
2968 (addrPred (i32 IntRegs:$addr), extPred:$offset)),
2969 (MI IntRegs:$addr, extPred:$offset, (xformFunc immPred:$bitend))>;
2972 multiclass MemOpi_bitExtType<PatFrag ldOpByte, PatFrag ldOpHalf > {
2974 defm : MemOpi_bitPats<ldOpByte, truncstorei8, Clr3ImmPred, u6ExtPred,
2975 ADDRriU6_0, CLRMEMIMM_BYTE, L4_iand_memopb_io, and>;
2977 defm : MemOpi_bitPats<ldOpByte, truncstorei8, Set3ImmPred, u6ExtPred,
2978 ADDRriU6_0, SETMEMIMM_BYTE, L4_ior_memopb_io, or>;
2979 // Half Word - clrbit
2980 defm : MemOpi_bitPats<ldOpHalf, truncstorei16, Clr4ImmPred, u6_1ExtPred,
2981 ADDRriU6_1, CLRMEMIMM_SHORT, L4_iand_memoph_io, and>;
2982 // Half Word - setbit
2983 defm : MemOpi_bitPats<ldOpHalf, truncstorei16, Set4ImmPred, u6_1ExtPred,
2984 ADDRriU6_1, SETMEMIMM_SHORT, L4_ior_memoph_io, or>;
2987 let Predicates = [HasV4T, UseMEMOP] in {
2988 // mem[bh](Rs+#0) = [clrbit|setbit](#U5)
2989 // mem[bh](Rs+#u6:[01]) = [clrbit|setbit](#U5)
2990 defm : MemOpi_bitExtType<zextloadi8, zextloadi16>; // zero extend
2991 defm : MemOpi_bitExtType<sextloadi8, sextloadi16>; // sign extend
2992 defm : MemOpi_bitExtType<extloadi8, extloadi16>; // any extend
2994 // memw(Rs+#0) = [clrbit|setbit](#U5)
2995 // memw(Rs+#u6:2) = [clrbit|setbit](#U5)
2996 defm : MemOpi_bitPats<load, store, Clr5ImmPred, u6_2ExtPred, ADDRriU6_2,
2997 CLRMEMIMM, L4_iand_memopw_io, and>;
2998 defm : MemOpi_bitPats<load, store, Set5ImmPred, u6_2ExtPred, ADDRriU6_2,
2999 SETMEMIMM, L4_ior_memopw_io, or>;
3002 //===----------------------------------------------------------------------===//
3003 // Multiclass to define 'def Pats' for ALU operations on the memory
3004 // where addend is a register.
3005 // mem[bhw](Rs+#0) [+-&|]= Rt
3006 // mem[bhw](Rs+#U6:[012]) [+-&|]= Rt
3007 //===----------------------------------------------------------------------===//
3009 multiclass MemOpr_Pats <PatFrag ldOp, PatFrag stOp, ComplexPattern addrPred,
3010 PatLeaf extPred, InstHexagon MI, SDNode OpNode> {
3011 let AddedComplexity = 141 in
3012 // mem[bhw](Rs+#0) [+-&|]= Rt
3013 def : Pat <(stOp (OpNode (ldOp (addrPred IntRegs:$addr, extPred:$offset)),
3014 (i32 IntRegs:$addend)),
3015 (addrPred (i32 IntRegs:$addr), extPred:$offset)),
3016 (MI IntRegs:$addr, extPred:$offset, (i32 IntRegs:$addend) )>;
3018 // mem[bhw](Rs+#U6:[012]) [+-&|]= Rt
3019 let AddedComplexity = 150 in
3020 def : Pat <(stOp (OpNode (ldOp (add IntRegs:$base, extPred:$offset)),
3021 (i32 IntRegs:$orend)),
3022 (add IntRegs:$base, extPred:$offset)),
3023 (MI IntRegs:$base, extPred:$offset, (i32 IntRegs:$orend) )>;
3026 multiclass MemOPr_ALUOp<PatFrag ldOp, PatFrag stOp,
3027 ComplexPattern addrPred, PatLeaf extPred,
3028 InstHexagon addMI, InstHexagon subMI,
3029 InstHexagon andMI, InstHexagon orMI > {
3031 defm : MemOpr_Pats <ldOp, stOp, addrPred, extPred, addMI, add>;
3032 defm : MemOpr_Pats <ldOp, stOp, addrPred, extPred, subMI, sub>;
3033 defm : MemOpr_Pats <ldOp, stOp, addrPred, extPred, andMI, and>;
3034 defm : MemOpr_Pats <ldOp, stOp, addrPred, extPred, orMI, or>;
3037 multiclass MemOPr_ExtType<PatFrag ldOpByte, PatFrag ldOpHalf > {
3039 defm : MemOPr_ALUOp <ldOpHalf, truncstorei16, ADDRriU6_1, u6_1ExtPred,
3040 L4_add_memoph_io, L4_sub_memoph_io,
3041 L4_and_memoph_io, L4_or_memoph_io>;
3043 defm : MemOPr_ALUOp <ldOpByte, truncstorei8, ADDRriU6_0, u6ExtPred,
3044 L4_add_memopb_io, L4_sub_memopb_io,
3045 L4_and_memopb_io, L4_or_memopb_io>;
3048 // Define 'def Pats' for MemOps with register addend.
3049 let Predicates = [HasV4T, UseMEMOP] in {
3051 defm : MemOPr_ExtType<zextloadi8, zextloadi16>; // zero extend
3052 defm : MemOPr_ExtType<sextloadi8, sextloadi16>; // sign extend
3053 defm : MemOPr_ExtType<extloadi8, extloadi16>; // any extend
3055 defm : MemOPr_ALUOp <load, store, ADDRriU6_2, u6_2ExtPred, L4_add_memopw_io,
3056 L4_sub_memopw_io, L4_and_memopw_io, L4_or_memopw_io >;
3059 //===----------------------------------------------------------------------===//
3061 //===----------------------------------------------------------------------===//
3063 // Hexagon V4 only supports these flavors of byte/half compare instructions:
3064 // EQ/GT/GTU. Other flavors like GE/GEU/LT/LTU/LE/LEU are not supported by
3065 // hardware. However, compiler can still implement these patterns through
3066 // appropriate patterns combinations based on current implemented patterns.
3067 // The implemented patterns are: EQ/GT/GTU.
3068 // Missing patterns are: GE/GEU/LT/LTU/LE/LEU.
3070 // Following instruction is not being extended as it results into the
3071 // incorrect code for negative numbers.
3072 // Pd=cmpb.eq(Rs,#u8)
3074 // p=!cmp.eq(r1,#s10)
3075 let isCodeGenOnly = 0 in {
3076 def C4_cmpneqi : T_CMP <"cmp.eq", 0b00, 1, s10Ext>;
3077 def C4_cmpltei : T_CMP <"cmp.gt", 0b01, 1, s10Ext>;
3078 def C4_cmplteui : T_CMP <"cmp.gtu", 0b10, 1, u9Ext>;
3081 def : T_CMP_pat <C4_cmpneqi, setne, s10ExtPred>;
3082 def : T_CMP_pat <C4_cmpltei, setle, s10ExtPred>;
3083 def : T_CMP_pat <C4_cmplteui, setule, u9ImmPred>;
3085 // rs <= rt -> !(rs > rt).
3087 def: Pat<(i1 (setle (i32 IntRegs:$src1), s10ExtPred:$src2)),
3088 (C2_not (C2_cmpgti IntRegs:$src1, s10ExtPred:$src2))>;
3089 // (C4_cmpltei IntRegs:$src1, s10ExtPred:$src2)>;
3091 // Map cmplt(Rs, Imm) -> !cmpgt(Rs, Imm-1).
3092 def: Pat<(i1 (setlt (i32 IntRegs:$src1), s8ExtPred:$src2)),
3093 (C4_cmpltei IntRegs:$src1, (DEC_CONST_SIGNED s8ExtPred:$src2))>;
3095 // rs != rt -> !(rs == rt).
3096 def: Pat<(i1 (setne (i32 IntRegs:$src1), s10ExtPred:$src2)),
3097 (C4_cmpneqi IntRegs:$src1, s10ExtPred:$src2)>;
3099 // SDNode for converting immediate C to C-1.
3100 def DEC_CONST_BYTE : SDNodeXForm<imm, [{
3101 // Return the byte immediate const-1 as an SDNode.
3102 int32_t imm = N->getSExtValue();
3103 return XformU7ToU7M1Imm(imm);
3107 // zext( seteq ( and(Rs, 255), u8))
3109 // Pd=cmpb.eq(Rs, #u8)
3110 // if (Pd.new) Rd=#1
3111 // if (!Pd.new) Rd=#0
3112 def : Pat <(i32 (zext (i1 (seteq (i32 (and (i32 IntRegs:$Rs), 255)),
3114 (i32 (TFR_condset_ii (i1 (A4_cmpbeqi (i32 IntRegs:$Rs),
3120 // zext( setne ( and(Rs, 255), u8))
3122 // Pd=cmpb.eq(Rs, #u8)
3123 // if (Pd.new) Rd=#0
3124 // if (!Pd.new) Rd=#1
3125 def : Pat <(i32 (zext (i1 (setne (i32 (and (i32 IntRegs:$Rs), 255)),
3127 (i32 (TFR_condset_ii (i1 (A4_cmpbeqi (i32 IntRegs:$Rs),
3133 // zext( seteq (Rs, and(Rt, 255)))
3135 // Pd=cmpb.eq(Rs, Rt)
3136 // if (Pd.new) Rd=#1
3137 // if (!Pd.new) Rd=#0
3138 def : Pat <(i32 (zext (i1 (seteq (i32 IntRegs:$Rt),
3139 (i32 (and (i32 IntRegs:$Rs), 255)))))),
3140 (i32 (TFR_condset_ii (i1 (A4_cmpbeq (i32 IntRegs:$Rs),
3141 (i32 IntRegs:$Rt))),
3146 // zext( setne (Rs, and(Rt, 255)))
3148 // Pd=cmpb.eq(Rs, Rt)
3149 // if (Pd.new) Rd=#0
3150 // if (!Pd.new) Rd=#1
3151 def : Pat <(i32 (zext (i1 (setne (i32 IntRegs:$Rt),
3152 (i32 (and (i32 IntRegs:$Rs), 255)))))),
3153 (i32 (TFR_condset_ii (i1 (A4_cmpbeq (i32 IntRegs:$Rs),
3154 (i32 IntRegs:$Rt))),
3159 // zext( setugt ( and(Rs, 255), u8))
3161 // Pd=cmpb.gtu(Rs, #u8)
3162 // if (Pd.new) Rd=#1
3163 // if (!Pd.new) Rd=#0
3164 def : Pat <(i32 (zext (i1 (setugt (i32 (and (i32 IntRegs:$Rs), 255)),
3166 (i32 (TFR_condset_ii (i1 (A4_cmpbgtui (i32 IntRegs:$Rs),
3172 // zext( setugt ( and(Rs, 254), u8))
3174 // Pd=cmpb.gtu(Rs, #u8)
3175 // if (Pd.new) Rd=#1
3176 // if (!Pd.new) Rd=#0
3177 def : Pat <(i32 (zext (i1 (setugt (i32 (and (i32 IntRegs:$Rs), 254)),
3179 (i32 (TFR_condset_ii (i1 (A4_cmpbgtui (i32 IntRegs:$Rs),
3185 // zext( setult ( Rs, Rt))
3187 // Pd=cmp.ltu(Rs, Rt)
3188 // if (Pd.new) Rd=#1
3189 // if (!Pd.new) Rd=#0
3190 // cmp.ltu(Rs, Rt) -> cmp.gtu(Rt, Rs)
3191 def : Pat <(i32 (zext (i1 (setult (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))))),
3192 (i32 (TFR_condset_ii (i1 (C2_cmpgtu (i32 IntRegs:$Rt),
3193 (i32 IntRegs:$Rs))),
3198 // zext( setlt ( Rs, Rt))
3200 // Pd=cmp.lt(Rs, Rt)
3201 // if (Pd.new) Rd=#1
3202 // if (!Pd.new) Rd=#0
3203 // cmp.lt(Rs, Rt) -> cmp.gt(Rt, Rs)
3204 def : Pat <(i32 (zext (i1 (setlt (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))))),
3205 (i32 (TFR_condset_ii (i1 (C2_cmpgt (i32 IntRegs:$Rt),
3206 (i32 IntRegs:$Rs))),
3211 // zext( setugt ( Rs, Rt))
3213 // Pd=cmp.gtu(Rs, Rt)
3214 // if (Pd.new) Rd=#1
3215 // if (!Pd.new) Rd=#0
3216 def : Pat <(i32 (zext (i1 (setugt (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))))),
3217 (i32 (TFR_condset_ii (i1 (C2_cmpgtu (i32 IntRegs:$Rs),
3218 (i32 IntRegs:$Rt))),
3222 // This pattern interefers with coremark performance, not implementing at this
3225 // zext( setgt ( Rs, Rt))
3227 // Pd=cmp.gt(Rs, Rt)
3228 // if (Pd.new) Rd=#1
3229 // if (!Pd.new) Rd=#0
3232 // zext( setuge ( Rs, Rt))
3234 // Pd=cmp.ltu(Rs, Rt)
3235 // if (Pd.new) Rd=#0
3236 // if (!Pd.new) Rd=#1
3237 // cmp.ltu(Rs, Rt) -> cmp.gtu(Rt, Rs)
3238 def : Pat <(i32 (zext (i1 (setuge (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))))),
3239 (i32 (TFR_condset_ii (i1 (C2_cmpgtu (i32 IntRegs:$Rt),
3240 (i32 IntRegs:$Rs))),
3245 // zext( setge ( Rs, Rt))
3247 // Pd=cmp.lt(Rs, Rt)
3248 // if (Pd.new) Rd=#0
3249 // if (!Pd.new) Rd=#1
3250 // cmp.lt(Rs, Rt) -> cmp.gt(Rt, Rs)
3251 def : Pat <(i32 (zext (i1 (setge (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))))),
3252 (i32 (TFR_condset_ii (i1 (C2_cmpgt (i32 IntRegs:$Rt),
3253 (i32 IntRegs:$Rs))),
3258 // zext( setule ( Rs, Rt))
3260 // Pd=cmp.gtu(Rs, Rt)
3261 // if (Pd.new) Rd=#0
3262 // if (!Pd.new) Rd=#1
3263 def : Pat <(i32 (zext (i1 (setule (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))))),
3264 (i32 (TFR_condset_ii (i1 (C2_cmpgtu (i32 IntRegs:$Rs),
3265 (i32 IntRegs:$Rt))),
3270 // zext( setle ( Rs, Rt))
3272 // Pd=cmp.gt(Rs, Rt)
3273 // if (Pd.new) Rd=#0
3274 // if (!Pd.new) Rd=#1
3275 def : Pat <(i32 (zext (i1 (setle (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))))),
3276 (i32 (TFR_condset_ii (i1 (C2_cmpgt (i32 IntRegs:$Rs),
3277 (i32 IntRegs:$Rt))),
3282 // zext( setult ( and(Rs, 255), u8))
3283 // Use the isdigit transformation below
3285 // Generate code of the form 'mux_ii(cmpbgtu(Rdd, C-1),0,1)'
3286 // for C code of the form r = ((c>='0') & (c<='9')) ? 1 : 0;.
3287 // The isdigit transformation relies on two 'clever' aspects:
3288 // 1) The data type is unsigned which allows us to eliminate a zero test after
3289 // biasing the expression by 48. We are depending on the representation of
3290 // the unsigned types, and semantics.
3291 // 2) The front end has converted <= 9 into < 10 on entry to LLVM
3294 // retval = ((c>='0') & (c<='9')) ? 1 : 0;
3295 // The code is transformed upstream of llvm into
3296 // retval = (c-48) < 10 ? 1 : 0;
3297 let AddedComplexity = 139 in
3298 def : Pat <(i32 (zext (i1 (setult (i32 (and (i32 IntRegs:$src1), 255)),
3299 u7StrictPosImmPred:$src2)))),
3300 (i32 (C2_muxii (i1 (A4_cmpbgtui (i32 IntRegs:$src1),
3301 (DEC_CONST_BYTE u7StrictPosImmPred:$src2))),
3305 //===----------------------------------------------------------------------===//
3307 //===----------------------------------------------------------------------===//
3309 //===----------------------------------------------------------------------===//
3310 // Multiclass for DeallocReturn
3311 //===----------------------------------------------------------------------===//
3312 class L4_RETURN<string mnemonic, bit isNot, bit isPredNew, bit isTak>
3313 : LD0Inst<(outs), (ins PredRegs:$src),
3314 !if(isNot, "if (!$src", "if ($src")#
3315 !if(isPredNew, ".new) ", ") ")#mnemonic#
3316 !if(isPredNew, #!if(isTak,":t", ":nt"),""),
3317 [], "", LD_tc_3or4stall_SLOT0> {
3320 let BaseOpcode = "L4_RETURN";
3321 let isPredicatedFalse = isNot;
3322 let isPredicatedNew = isPredNew;
3323 let isTaken = isTak;
3324 let IClass = 0b1001;
3326 let Inst{27-16} = 0b011000011110;
3328 let Inst{13} = isNot;
3329 let Inst{12} = isTak;
3330 let Inst{11} = isPredNew;
3332 let Inst{9-8} = src;
3333 let Inst{4-0} = 0b11110;
3336 // Produce all predicated forms, p, !p, p.new, !p.new, :t, :nt
3337 multiclass L4_RETURN_PRED<string mnemonic, bit PredNot> {
3338 let isPredicated = 1 in {
3339 def _#NAME# : L4_RETURN <mnemonic, PredNot, 0, 1>;
3340 def _#NAME#new_pnt : L4_RETURN <mnemonic, PredNot, 1, 0>;
3341 def _#NAME#new_pt : L4_RETURN <mnemonic, PredNot, 1, 1>;
3345 multiclass LD_MISC_L4_RETURN<string mnemonic> {
3346 let isBarrier = 1, isPredicable = 1 in
3347 def NAME : LD0Inst <(outs), (ins), mnemonic, [], "",
3348 LD_tc_3or4stall_SLOT0> {
3349 let BaseOpcode = "L4_RETURN";
3350 let IClass = 0b1001;
3351 let Inst{27-16} = 0b011000011110;
3352 let Inst{13-10} = 0b0000;
3353 let Inst{4-0} = 0b11110;
3355 defm t : L4_RETURN_PRED<mnemonic, 0 >;
3356 defm f : L4_RETURN_PRED<mnemonic, 1 >;
3359 let isReturn = 1, isTerminator = 1,
3360 Defs = [R29, R30, R31, PC], Uses = [R30], hasSideEffects = 0,
3361 validSubTargets = HasV4SubT, isCodeGenOnly = 0 in
3362 defm L4_return: LD_MISC_L4_RETURN <"dealloc_return">, PredNewRel;
3364 // Restore registers and dealloc return function call.
3365 let isCall = 1, isBarrier = 1, isReturn = 1, isTerminator = 1,
3366 Defs = [R29, R30, R31, PC], isAsmParserOnly = 1 in {
3367 let validSubTargets = HasV4SubT in
3368 def RESTORE_DEALLOC_RET_JMP_V4 : JInst<(outs),
3369 (ins calltarget:$dst),
3375 // Restore registers and dealloc frame before a tail call.
3376 let isCall = 1, isBarrier = 1, isAsmParserOnly = 1,
3377 Defs = [R29, R30, R31, PC] in {
3378 let validSubTargets = HasV4SubT in
3379 def RESTORE_DEALLOC_BEFORE_TAILCALL_V4 : JInst<(outs),
3380 (ins calltarget:$dst),
3386 // Save registers function call.
3387 let isCall = 1, isBarrier = 1, isAsmParserOnly = 1,
3388 Uses = [R29, R31] in {
3389 def SAVE_REGISTERS_CALL_V4 : JInst<(outs),
3390 (ins calltarget:$dst),
3391 "call $dst // Save_calle_saved_registers",
3396 //===----------------------------------------------------------------------===//
3397 // Template class for non predicated store instructions with
3398 // GP-Relative or absolute addressing.
3399 //===----------------------------------------------------------------------===//
3400 let hasSideEffects = 0, isPredicable = 1, isNVStorable = 1 in
3401 class T_StoreAbsGP <string mnemonic, RegisterClass RC, Operand ImmOp,
3402 bits<2>MajOp, Operand AddrOp, bit isAbs, bit isHalf>
3403 : STInst<(outs), (ins AddrOp:$addr, RC:$src),
3404 mnemonic # !if(isAbs, "(##", "(#")#"$addr) = $src"#!if(isHalf, ".h",""),
3405 [], "", V2LDST_tc_st_SLOT01> {
3408 bits<16> offsetBits;
3410 string ImmOpStr = !cast<string>(ImmOp);
3411 let offsetBits = !if (!eq(ImmOpStr, "u16_3Imm"), addr{18-3},
3412 !if (!eq(ImmOpStr, "u16_2Imm"), addr{17-2},
3413 !if (!eq(ImmOpStr, "u16_1Imm"), addr{16-1},
3414 /* u16_0Imm */ addr{15-0})));
3415 let IClass = 0b0100;
3417 let Inst{26-25} = offsetBits{15-14};
3419 let Inst{23-22} = MajOp;
3420 let Inst{21} = isHalf;
3421 let Inst{20-16} = offsetBits{13-9};
3422 let Inst{13} = offsetBits{8};
3423 let Inst{12-8} = src;
3424 let Inst{7-0} = offsetBits{7-0};
3427 //===----------------------------------------------------------------------===//
3428 // Template class for predicated store instructions with
3429 // GP-Relative or absolute addressing.
3430 //===----------------------------------------------------------------------===//
3431 let hasSideEffects = 0, isPredicated = 1, isNVStorable = 1, opExtentBits = 6,
3433 class T_StoreAbs_Pred <string mnemonic, RegisterClass RC, bits<2> MajOp,
3434 bit isHalf, bit isNot, bit isNew>
3435 : STInst<(outs), (ins PredRegs:$src1, u6Ext:$absaddr, RC: $src2),
3436 !if(isNot, "if (!$src1", "if ($src1")#!if(isNew, ".new) ",
3437 ") ")#mnemonic#"(#$absaddr) = $src2"#!if(isHalf, ".h",""),
3438 [], "", ST_tc_st_SLOT01>, AddrModeRel {
3443 let isPredicatedNew = isNew;
3444 let isPredicatedFalse = isNot;
3446 let IClass = 0b1010;
3448 let Inst{27-24} = 0b1111;
3449 let Inst{23-22} = MajOp;
3450 let Inst{21} = isHalf;
3451 let Inst{17-16} = absaddr{5-4};
3452 let Inst{13} = isNew;
3453 let Inst{12-8} = src2;
3455 let Inst{6-3} = absaddr{3-0};
3456 let Inst{2} = isNot;
3457 let Inst{1-0} = src1;
3460 //===----------------------------------------------------------------------===//
3461 // Template class for predicated store instructions with absolute addressing.
3462 //===----------------------------------------------------------------------===//
3463 class T_StoreAbs <string mnemonic, RegisterClass RC, Operand ImmOp,
3464 bits<2> MajOp, bit isHalf>
3465 : T_StoreAbsGP <mnemonic, RC, ImmOp, MajOp, u0AlwaysExt, 1, isHalf>,
3467 string ImmOpStr = !cast<string>(ImmOp);
3468 let opExtentBits = !if (!eq(ImmOpStr, "u16_3Imm"), 19,
3469 !if (!eq(ImmOpStr, "u16_2Imm"), 18,
3470 !if (!eq(ImmOpStr, "u16_1Imm"), 17,
3471 /* u16_0Imm */ 16)));
3473 let opExtentAlign = !if (!eq(ImmOpStr, "u16_3Imm"), 3,
3474 !if (!eq(ImmOpStr, "u16_2Imm"), 2,
3475 !if (!eq(ImmOpStr, "u16_1Imm"), 1,
3476 /* u16_0Imm */ 0)));
3479 //===----------------------------------------------------------------------===//
3480 // Multiclass for store instructions with absolute addressing.
3481 //===----------------------------------------------------------------------===//
3482 let validSubTargets = HasV4SubT, addrMode = Absolute, isExtended = 1 in
3483 multiclass ST_Abs<string mnemonic, string CextOp, RegisterClass RC,
3484 Operand ImmOp, bits<2> MajOp, bit isHalf = 0> {
3485 let CextOpcode = CextOp, BaseOpcode = CextOp#_abs in {
3486 let opExtendable = 0, isPredicable = 1 in
3487 def S2_#NAME#abs : T_StoreAbs <mnemonic, RC, ImmOp, MajOp, isHalf>;
3490 def S4_p#NAME#t_abs : T_StoreAbs_Pred<mnemonic, RC, MajOp, isHalf, 0, 0>;
3491 def S4_p#NAME#f_abs : T_StoreAbs_Pred<mnemonic, RC, MajOp, isHalf, 1, 0>;
3494 def S4_p#NAME#tnew_abs : T_StoreAbs_Pred<mnemonic, RC, MajOp, isHalf, 0, 1>;
3495 def S4_p#NAME#fnew_abs : T_StoreAbs_Pred<mnemonic, RC, MajOp, isHalf, 1, 1>;
3499 //===----------------------------------------------------------------------===//
3500 // Template class for non predicated new-value store instructions with
3501 // GP-Relative or absolute addressing.
3502 //===----------------------------------------------------------------------===//
3503 let hasSideEffects = 0, isPredicable = 1, mayStore = 1, isNVStore = 1,
3504 isNewValue = 1, opNewValue = 1 in
3505 class T_StoreAbsGP_NV <string mnemonic, Operand ImmOp, bits<2>MajOp, bit isAbs>
3506 : NVInst_V4<(outs), (ins u0AlwaysExt:$addr, IntRegs:$src),
3507 mnemonic # !if(isAbs, "(##", "(#")#"$addr) = $src.new",
3508 [], "", V2LDST_tc_st_SLOT0> {
3511 bits<16> offsetBits;
3513 string ImmOpStr = !cast<string>(ImmOp);
3514 let offsetBits = !if (!eq(ImmOpStr, "u16_3Imm"), addr{18-3},
3515 !if (!eq(ImmOpStr, "u16_2Imm"), addr{17-2},
3516 !if (!eq(ImmOpStr, "u16_1Imm"), addr{16-1},
3517 /* u16_0Imm */ addr{15-0})));
3518 let IClass = 0b0100;
3521 let Inst{26-25} = offsetBits{15-14};
3522 let Inst{24-21} = 0b0101;
3523 let Inst{20-16} = offsetBits{13-9};
3524 let Inst{13} = offsetBits{8};
3525 let Inst{12-11} = MajOp;
3526 let Inst{10-8} = src;
3527 let Inst{7-0} = offsetBits{7-0};
3530 //===----------------------------------------------------------------------===//
3531 // Template class for predicated new-value store instructions with
3532 // absolute addressing.
3533 //===----------------------------------------------------------------------===//
3534 let hasSideEffects = 0, isPredicated = 1, mayStore = 1, isNVStore = 1,
3535 isNewValue = 1, opNewValue = 2, opExtentBits = 6, opExtendable = 1 in
3536 class T_StoreAbs_NV_Pred <string mnemonic, bits<2> MajOp, bit isNot, bit isNew>
3537 : NVInst_V4<(outs), (ins PredRegs:$src1, u6Ext:$absaddr, IntRegs:$src2),
3538 !if(isNot, "if (!$src1", "if ($src1")#!if(isNew, ".new) ",
3539 ") ")#mnemonic#"(#$absaddr) = $src2.new",
3540 [], "", ST_tc_st_SLOT0>, AddrModeRel {
3545 let isPredicatedNew = isNew;
3546 let isPredicatedFalse = isNot;
3548 let IClass = 0b1010;
3550 let Inst{27-24} = 0b1111;
3551 let Inst{23-21} = 0b101;
3552 let Inst{17-16} = absaddr{5-4};
3553 let Inst{13} = isNew;
3554 let Inst{12-11} = MajOp;
3555 let Inst{10-8} = src2;
3557 let Inst{6-3} = absaddr{3-0};
3558 let Inst{2} = isNot;
3559 let Inst{1-0} = src1;
3562 //===----------------------------------------------------------------------===//
3563 // Template class for non-predicated new-value store instructions with
3564 // absolute addressing.
3565 //===----------------------------------------------------------------------===//
3566 class T_StoreAbs_NV <string mnemonic, Operand ImmOp, bits<2> MajOp>
3567 : T_StoreAbsGP_NV <mnemonic, ImmOp, MajOp, 1>, AddrModeRel {
3569 string ImmOpStr = !cast<string>(ImmOp);
3570 let opExtentBits = !if (!eq(ImmOpStr, "u16_3Imm"), 19,
3571 !if (!eq(ImmOpStr, "u16_2Imm"), 18,
3572 !if (!eq(ImmOpStr, "u16_1Imm"), 17,
3573 /* u16_0Imm */ 16)));
3575 let opExtentAlign = !if (!eq(ImmOpStr, "u16_3Imm"), 3,
3576 !if (!eq(ImmOpStr, "u16_2Imm"), 2,
3577 !if (!eq(ImmOpStr, "u16_1Imm"), 1,
3578 /* u16_0Imm */ 0)));
3581 //===----------------------------------------------------------------------===//
3582 // Multiclass for new-value store instructions with absolute addressing.
3583 //===----------------------------------------------------------------------===//
3584 let validSubTargets = HasV4SubT, addrMode = Absolute, isExtended = 1 in
3585 multiclass ST_Abs_NV <string mnemonic, string CextOp, Operand ImmOp,
3587 let CextOpcode = CextOp, BaseOpcode = CextOp#_abs in {
3588 let opExtendable = 0, isPredicable = 1 in
3589 def S2_#NAME#newabs : T_StoreAbs_NV <mnemonic, ImmOp, MajOp>;
3592 def S4_p#NAME#newt_abs : T_StoreAbs_NV_Pred <mnemonic, MajOp, 0, 0>;
3593 def S4_p#NAME#newf_abs : T_StoreAbs_NV_Pred <mnemonic, MajOp, 1, 0>;
3596 def S4_p#NAME#newtnew_abs : T_StoreAbs_NV_Pred <mnemonic, MajOp, 0, 1>;
3597 def S4_p#NAME#newfnew_abs : T_StoreAbs_NV_Pred <mnemonic, MajOp, 1, 1>;
3601 //===----------------------------------------------------------------------===//
3602 // Stores with absolute addressing
3603 //===----------------------------------------------------------------------===//
3604 let accessSize = ByteAccess, isCodeGenOnly = 0 in
3605 defm storerb : ST_Abs <"memb", "STrib", IntRegs, u16_0Imm, 0b00>,
3606 ST_Abs_NV <"memb", "STrib", u16_0Imm, 0b00>;
3608 let accessSize = HalfWordAccess, isCodeGenOnly = 0 in
3609 defm storerh : ST_Abs <"memh", "STrih", IntRegs, u16_1Imm, 0b01>,
3610 ST_Abs_NV <"memh", "STrih", u16_1Imm, 0b01>;
3612 let accessSize = WordAccess, isCodeGenOnly = 0 in
3613 defm storeri : ST_Abs <"memw", "STriw", IntRegs, u16_2Imm, 0b10>,
3614 ST_Abs_NV <"memw", "STriw", u16_2Imm, 0b10>;
3616 let isNVStorable = 0, accessSize = DoubleWordAccess, isCodeGenOnly = 0 in
3617 defm storerd : ST_Abs <"memd", "STrid", DoubleRegs, u16_3Imm, 0b11>;
3619 let isNVStorable = 0, accessSize = HalfWordAccess, isCodeGenOnly = 0 in
3620 defm storerf : ST_Abs <"memh", "STrif", IntRegs, u16_1Imm, 0b01, 1>;
3622 //===----------------------------------------------------------------------===//
3623 // GP-relative stores.
3624 // mem[bhwd](#global)=Rt
3625 // Once predicated, these instructions map to absolute addressing mode.
3626 // if ([!]Pv[.new]) mem[bhwd](##global)=Rt
3627 //===----------------------------------------------------------------------===//
3629 let validSubTargets = HasV4SubT, isAsmParserOnly = 1 in
3630 class T_StoreGP <string mnemonic, string BaseOp, RegisterClass RC,
3631 Operand ImmOp, bits<2> MajOp, bit isHalf = 0>
3632 : T_StoreAbsGP <mnemonic, RC, ImmOp, MajOp, globaladdress, 0, isHalf> {
3633 // Set BaseOpcode same as absolute addressing instructions so that
3634 // non-predicated GP-Rel instructions can have relate with predicated
3635 // Absolute instruction.
3636 let BaseOpcode = BaseOp#_abs;
3639 let validSubTargets = HasV4SubT, isAsmParserOnly = 1 in
3640 multiclass ST_GP <string mnemonic, string BaseOp, Operand ImmOp,
3641 bits<2> MajOp, bit isHalf = 0> {
3642 // Set BaseOpcode same as absolute addressing instructions so that
3643 // non-predicated GP-Rel instructions can have relate with predicated
3644 // Absolute instruction.
3645 let BaseOpcode = BaseOp#_abs in {
3646 def NAME#gp : T_StoreAbsGP <mnemonic, IntRegs, ImmOp, MajOp,
3647 globaladdress, 0, isHalf>;
3649 def NAME#newgp : T_StoreAbsGP_NV <mnemonic, ImmOp, MajOp, 0> ;
3653 let accessSize = ByteAccess in
3654 defm S2_storerb : ST_GP<"memb", "STrib", u16_0Imm, 0b00>, NewValueRel;
3656 let accessSize = HalfWordAccess in
3657 defm S2_storerh : ST_GP<"memh", "STrih", u16_1Imm, 0b01>, NewValueRel;
3659 let accessSize = WordAccess in
3660 defm S2_storeri : ST_GP<"memw", "STriw", u16_2Imm, 0b10>, NewValueRel;
3662 let isNVStorable = 0, accessSize = DoubleWordAccess in
3663 def S2_storerdgp : T_StoreGP <"memd", "STrid", DoubleRegs,
3664 u16_3Imm, 0b11>, PredNewRel;
3666 let isNVStorable = 0, accessSize = HalfWordAccess in
3667 def S2_storerfgp : T_StoreGP <"memh", "STrif", IntRegs,
3668 u16_1Imm, 0b01, 1>, PredNewRel;
3670 let Predicates = [HasV4T], AddedComplexity = 30 in {
3671 def : Pat<(truncstorei8 (i32 IntRegs:$src1),
3672 (HexagonCONST32 tglobaladdr:$absaddr)),
3673 (S2_storerbabs tglobaladdr: $absaddr, IntRegs: $src1)>;
3675 def : Pat<(truncstorei16 (i32 IntRegs:$src1),
3676 (HexagonCONST32 tglobaladdr:$absaddr)),
3677 (S2_storerhabs tglobaladdr: $absaddr, IntRegs: $src1)>;
3679 def : Pat<(store (i32 IntRegs:$src1), (HexagonCONST32 tglobaladdr:$absaddr)),
3680 (S2_storeriabs tglobaladdr: $absaddr, IntRegs: $src1)>;
3682 def : Pat<(store (i64 DoubleRegs:$src1),
3683 (HexagonCONST32 tglobaladdr:$absaddr)),
3684 (S2_storerdabs tglobaladdr: $absaddr, DoubleRegs: $src1)>;
3687 // 64 bit atomic store
3688 def : Pat <(atomic_store_64 (HexagonCONST32_GP tglobaladdr:$global),
3689 (i64 DoubleRegs:$src1)),
3690 (S2_storerdgp tglobaladdr:$global, (i64 DoubleRegs:$src1))>,
3693 // Map from store(globaladdress) -> memd(#foo)
3694 let AddedComplexity = 100 in
3695 def : Pat <(store (i64 DoubleRegs:$src1),
3696 (HexagonCONST32_GP tglobaladdr:$global)),
3697 (S2_storerdgp tglobaladdr:$global, (i64 DoubleRegs:$src1))>;
3699 // 8 bit atomic store
3700 def : Pat < (atomic_store_8 (HexagonCONST32_GP tglobaladdr:$global),
3701 (i32 IntRegs:$src1)),
3702 (S2_storerbgp tglobaladdr:$global, (i32 IntRegs:$src1))>;
3704 // Map from store(globaladdress) -> memb(#foo)
3705 let AddedComplexity = 100 in
3706 def : Pat<(truncstorei8 (i32 IntRegs:$src1),
3707 (HexagonCONST32_GP tglobaladdr:$global)),
3708 (S2_storerbgp tglobaladdr:$global, (i32 IntRegs:$src1))>;
3710 // Map from "i1 = constant<-1>; memw(CONST32(#foo)) = i1"
3711 // to "r0 = 1; memw(#foo) = r0"
3712 let AddedComplexity = 100 in
3713 def : Pat<(store (i1 -1), (HexagonCONST32_GP tglobaladdr:$global)),
3714 (S2_storerbgp tglobaladdr:$global, (A2_tfrsi 1))>;
3716 def : Pat<(atomic_store_16 (HexagonCONST32_GP tglobaladdr:$global),
3717 (i32 IntRegs:$src1)),
3718 (S2_storerhgp tglobaladdr:$global, (i32 IntRegs:$src1))>;
3720 // Map from store(globaladdress) -> memh(#foo)
3721 let AddedComplexity = 100 in
3722 def : Pat<(truncstorei16 (i32 IntRegs:$src1),
3723 (HexagonCONST32_GP tglobaladdr:$global)),
3724 (S2_storerhgp tglobaladdr:$global, (i32 IntRegs:$src1))>;
3726 // 32 bit atomic store
3727 def : Pat<(atomic_store_32 (HexagonCONST32_GP tglobaladdr:$global),
3728 (i32 IntRegs:$src1)),
3729 (S2_storerigp tglobaladdr:$global, (i32 IntRegs:$src1))>;
3731 // Map from store(globaladdress) -> memw(#foo)
3732 let AddedComplexity = 100 in
3733 def : Pat<(store (i32 IntRegs:$src1), (HexagonCONST32_GP tglobaladdr:$global)),
3734 (S2_storerigp tglobaladdr:$global, (i32 IntRegs:$src1))>;
3736 //===----------------------------------------------------------------------===//
3737 // Template class for non predicated load instructions with
3738 // absolute addressing mode.
3739 //===----------------------------------------------------------------------===//
3740 let isPredicable = 1, hasSideEffects = 0, validSubTargets = HasV4SubT in
3741 class T_LoadAbsGP <string mnemonic, RegisterClass RC, Operand ImmOp,
3742 bits<3> MajOp, Operand AddrOp, bit isAbs>
3743 : LDInst <(outs RC:$dst), (ins AddrOp:$addr),
3744 "$dst = "#mnemonic# !if(isAbs, "(##", "(#")#"$addr)",
3745 [], "", V2LDST_tc_ld_SLOT01> {
3748 bits<16> offsetBits;
3750 string ImmOpStr = !cast<string>(ImmOp);
3751 let offsetBits = !if (!eq(ImmOpStr, "u16_3Imm"), addr{18-3},
3752 !if (!eq(ImmOpStr, "u16_2Imm"), addr{17-2},
3753 !if (!eq(ImmOpStr, "u16_1Imm"), addr{16-1},
3754 /* u16_0Imm */ addr{15-0})));
3756 let IClass = 0b0100;
3759 let Inst{26-25} = offsetBits{15-14};
3761 let Inst{23-21} = MajOp;
3762 let Inst{20-16} = offsetBits{13-9};
3763 let Inst{13-5} = offsetBits{8-0};
3764 let Inst{4-0} = dst;
3767 class T_LoadAbs <string mnemonic, RegisterClass RC, Operand ImmOp,
3769 : T_LoadAbsGP <mnemonic, RC, ImmOp, MajOp, u0AlwaysExt, 1>, AddrModeRel {
3771 string ImmOpStr = !cast<string>(ImmOp);
3772 let opExtentBits = !if (!eq(ImmOpStr, "u16_3Imm"), 19,
3773 !if (!eq(ImmOpStr, "u16_2Imm"), 18,
3774 !if (!eq(ImmOpStr, "u16_1Imm"), 17,
3775 /* u16_0Imm */ 16)));
3777 let opExtentAlign = !if (!eq(ImmOpStr, "u16_3Imm"), 3,
3778 !if (!eq(ImmOpStr, "u16_2Imm"), 2,
3779 !if (!eq(ImmOpStr, "u16_1Imm"), 1,
3780 /* u16_0Imm */ 0)));
3782 //===----------------------------------------------------------------------===//
3783 // Template class for predicated load instructions with
3784 // absolute addressing mode.
3785 //===----------------------------------------------------------------------===//
3786 let isPredicated = 1, hasNewValue = 1, opExtentBits = 6, opExtendable = 2 in
3787 class T_LoadAbs_Pred <string mnemonic, RegisterClass RC, bits<3> MajOp,
3788 bit isPredNot, bit isPredNew>
3789 : LDInst <(outs RC:$dst), (ins PredRegs:$src1, u6Ext:$absaddr),
3790 !if(isPredNot, "if (!$src1", "if ($src1")#!if(isPredNew, ".new) ",
3791 ") ")#"$dst = "#mnemonic#"(#$absaddr)">, AddrModeRel {
3796 let isPredicatedNew = isPredNew;
3797 let isPredicatedFalse = isPredNot;
3799 let IClass = 0b1001;
3801 let Inst{27-24} = 0b1111;
3802 let Inst{23-21} = MajOp;
3803 let Inst{20-16} = absaddr{5-1};
3805 let Inst{12} = isPredNew;
3806 let Inst{11} = isPredNot;
3807 let Inst{10-9} = src1;
3808 let Inst{8} = absaddr{0};
3810 let Inst{4-0} = dst;
3813 //===----------------------------------------------------------------------===//
3814 // Multiclass for the load instructions with absolute addressing mode.
3815 //===----------------------------------------------------------------------===//
3816 multiclass LD_Abs_Pred<string mnemonic, RegisterClass RC, bits<3> MajOp,
3818 def _abs : T_LoadAbs_Pred <mnemonic, RC, MajOp, PredNot, 0>;
3820 def new_abs : T_LoadAbs_Pred <mnemonic, RC, MajOp, PredNot, 1>;
3823 let addrMode = Absolute, isExtended = 1 in
3824 multiclass LD_Abs<string mnemonic, string CextOp, RegisterClass RC,
3825 Operand ImmOp, bits<3> MajOp> {
3826 let CextOpcode = CextOp, BaseOpcode = CextOp#_abs in {
3827 let opExtendable = 1, isPredicable = 1 in
3828 def L4_#NAME#_abs: T_LoadAbs <mnemonic, RC, ImmOp, MajOp>;
3831 defm L4_p#NAME#t : LD_Abs_Pred<mnemonic, RC, MajOp, 0>;
3832 defm L4_p#NAME#f : LD_Abs_Pred<mnemonic, RC, MajOp, 1>;
3836 let accessSize = ByteAccess, hasNewValue = 1, isCodeGenOnly = 0 in {
3837 defm loadrb : LD_Abs<"memb", "LDrib", IntRegs, u16_0Imm, 0b000>;
3838 defm loadrub : LD_Abs<"memub", "LDriub", IntRegs, u16_0Imm, 0b001>;
3841 let accessSize = HalfWordAccess, hasNewValue = 1, isCodeGenOnly = 0 in {
3842 defm loadrh : LD_Abs<"memh", "LDrih", IntRegs, u16_1Imm, 0b010>;
3843 defm loadruh : LD_Abs<"memuh", "LDriuh", IntRegs, u16_1Imm, 0b011>;
3846 let accessSize = WordAccess, hasNewValue = 1, isCodeGenOnly = 0 in
3847 defm loadri : LD_Abs<"memw", "LDriw", IntRegs, u16_2Imm, 0b100>;
3849 let accessSize = DoubleWordAccess, isCodeGenOnly = 0 in
3850 defm loadrd : LD_Abs<"memd", "LDrid", DoubleRegs, u16_3Imm, 0b110>;
3852 //===----------------------------------------------------------------------===//
3853 // multiclass for load instructions with GP-relative addressing mode.
3854 // Rx=mem[bhwd](##global)
3855 // Once predicated, these instructions map to absolute addressing mode.
3856 // if ([!]Pv[.new]) Rx=mem[bhwd](##global)
3857 //===----------------------------------------------------------------------===//
3859 let isAsmParserOnly = 1 in
3860 class T_LoadGP <string mnemonic, string BaseOp, RegisterClass RC, Operand ImmOp,
3862 : T_LoadAbsGP <mnemonic, RC, ImmOp, MajOp, globaladdress, 0>, PredNewRel {
3863 let BaseOpcode = BaseOp#_abs;
3866 let accessSize = ByteAccess, hasNewValue = 1 in {
3867 def L2_loadrbgp : T_LoadGP<"memb", "LDrib", IntRegs, u16_0Imm, 0b000>;
3868 def L2_loadrubgp : T_LoadGP<"memub", "LDriub", IntRegs, u16_0Imm, 0b001>;
3871 let accessSize = HalfWordAccess, hasNewValue = 1 in {
3872 def L2_loadrhgp : T_LoadGP<"memh", "LDrih", IntRegs, u16_1Imm, 0b010>;
3873 def L2_loadruhgp : T_LoadGP<"memuh", "LDriuh", IntRegs, u16_1Imm, 0b011>;
3876 let accessSize = WordAccess, hasNewValue = 1 in
3877 def L2_loadrigp : T_LoadGP<"memw", "LDriw", IntRegs, u16_2Imm, 0b100>;
3879 let accessSize = DoubleWordAccess in
3880 def L2_loadrdgp : T_LoadGP<"memd", "LDrid", DoubleRegs, u16_3Imm, 0b110>;
3882 let Predicates = [HasV4T], AddedComplexity = 30 in {
3883 def : Pat<(i32 (load (HexagonCONST32 tglobaladdr:$absaddr))),
3884 (L4_loadri_abs tglobaladdr: $absaddr)>;
3886 def : Pat<(i32 (sextloadi8 (HexagonCONST32 tglobaladdr:$absaddr))),
3887 (L4_loadrb_abs tglobaladdr:$absaddr)>;
3889 def : Pat<(i32 (zextloadi8 (HexagonCONST32 tglobaladdr:$absaddr))),
3890 (L4_loadrub_abs tglobaladdr:$absaddr)>;
3892 def : Pat<(i32 (sextloadi16 (HexagonCONST32 tglobaladdr:$absaddr))),
3893 (L4_loadrh_abs tglobaladdr:$absaddr)>;
3895 def : Pat<(i32 (zextloadi16 (HexagonCONST32 tglobaladdr:$absaddr))),
3896 (L4_loadruh_abs tglobaladdr:$absaddr)>;
3899 def : Pat <(atomic_load_64 (HexagonCONST32_GP tglobaladdr:$global)),
3900 (i64 (L2_loadrdgp tglobaladdr:$global))>;
3902 def : Pat <(atomic_load_32 (HexagonCONST32_GP tglobaladdr:$global)),
3903 (i32 (L2_loadrigp tglobaladdr:$global))>;
3905 def : Pat <(atomic_load_16 (HexagonCONST32_GP tglobaladdr:$global)),
3906 (i32 (L2_loadruhgp tglobaladdr:$global))>;
3908 def : Pat <(atomic_load_8 (HexagonCONST32_GP tglobaladdr:$global)),
3909 (i32 (L2_loadrubgp tglobaladdr:$global))>;
3911 // Map from load(globaladdress) -> memw(#foo + 0)
3912 let AddedComplexity = 100 in
3913 def : Pat <(i64 (load (HexagonCONST32_GP tglobaladdr:$global))),
3914 (i64 (L2_loadrdgp tglobaladdr:$global))>;
3916 // Map from Pd = load(globaladdress) -> Rd = memb(globaladdress), Pd = Rd
3917 let AddedComplexity = 100 in
3918 def : Pat <(i1 (load (HexagonCONST32_GP tglobaladdr:$global))),
3919 (i1 (C2_tfrrp (i32 (L2_loadrbgp tglobaladdr:$global))))>;
3921 // When the Interprocedural Global Variable optimizer realizes that a certain
3922 // global variable takes only two constant values, it shrinks the global to
3923 // a boolean. Catch those loads here in the following 3 patterns.
3924 let AddedComplexity = 100 in
3925 def : Pat <(i32 (extloadi1 (HexagonCONST32_GP tglobaladdr:$global))),
3926 (i32 (L2_loadrbgp tglobaladdr:$global))>;
3928 let AddedComplexity = 100 in
3929 def : Pat <(i32 (sextloadi1 (HexagonCONST32_GP tglobaladdr:$global))),
3930 (i32 (L2_loadrbgp tglobaladdr:$global))>;
3932 // Map from load(globaladdress) -> memb(#foo)
3933 let AddedComplexity = 100 in
3934 def : Pat <(i32 (extloadi8 (HexagonCONST32_GP tglobaladdr:$global))),
3935 (i32 (L2_loadrbgp tglobaladdr:$global))>;
3937 // Map from load(globaladdress) -> memb(#foo)
3938 let AddedComplexity = 100 in
3939 def : Pat <(i32 (sextloadi8 (HexagonCONST32_GP tglobaladdr:$global))),
3940 (i32 (L2_loadrbgp tglobaladdr:$global))>;
3942 let AddedComplexity = 100 in
3943 def : Pat <(i32 (zextloadi1 (HexagonCONST32_GP tglobaladdr:$global))),
3944 (i32 (L2_loadrubgp tglobaladdr:$global))>;
3946 // Map from load(globaladdress) -> memub(#foo)
3947 let AddedComplexity = 100 in
3948 def : Pat <(i32 (zextloadi8 (HexagonCONST32_GP tglobaladdr:$global))),
3949 (i32 (L2_loadrubgp tglobaladdr:$global))>;
3951 // Map from load(globaladdress) -> memh(#foo)
3952 let AddedComplexity = 100 in
3953 def : Pat <(i32 (extloadi16 (HexagonCONST32_GP tglobaladdr:$global))),
3954 (i32 (L2_loadrhgp tglobaladdr:$global))>;
3956 // Map from load(globaladdress) -> memh(#foo)
3957 let AddedComplexity = 100 in
3958 def : Pat <(i32 (sextloadi16 (HexagonCONST32_GP tglobaladdr:$global))),
3959 (i32 (L2_loadrhgp tglobaladdr:$global))>;
3961 // Map from load(globaladdress) -> memuh(#foo)
3962 let AddedComplexity = 100 in
3963 def : Pat <(i32 (zextloadi16 (HexagonCONST32_GP tglobaladdr:$global))),
3964 (i32 (L2_loadruhgp tglobaladdr:$global))>;
3966 // Map from load(globaladdress) -> memw(#foo)
3967 let AddedComplexity = 100 in
3968 def : Pat <(i32 (load (HexagonCONST32_GP tglobaladdr:$global))),
3969 (i32 (L2_loadrigp tglobaladdr:$global))>;
3972 // Transfer global address into a register
3973 let isExtended = 1, opExtendable = 1, AddedComplexity=50, isMoveImm = 1,
3974 isAsCheapAsAMove = 1, isReMaterializable = 1, validSubTargets = HasV4SubT in
3975 def TFRI_V4 : ALU32_ri<(outs IntRegs:$dst), (ins s16Ext:$src1),
3977 [(set IntRegs:$dst, (HexagonCONST32 tglobaladdr:$src1))]>,
3980 // Transfer a block address into a register
3981 def : Pat<(HexagonCONST32_GP tblockaddress:$src1),
3982 (TFRI_V4 tblockaddress:$src1)>,
3985 let isExtended = 1, opExtendable = 2, AddedComplexity=50,
3986 hasSideEffects = 0, isPredicated = 1, validSubTargets = HasV4SubT in
3987 def TFRI_cPt_V4 : ALU32_ri<(outs IntRegs:$dst),
3988 (ins PredRegs:$src1, s16Ext:$src2),
3989 "if($src1) $dst = #$src2",
3993 let isExtended = 1, opExtendable = 2, AddedComplexity=50, isPredicatedFalse = 1,
3994 hasSideEffects = 0, isPredicated = 1, validSubTargets = HasV4SubT in
3995 def TFRI_cNotPt_V4 : ALU32_ri<(outs IntRegs:$dst),
3996 (ins PredRegs:$src1, s16Ext:$src2),
3997 "if(!$src1) $dst = #$src2",
4001 let isExtended = 1, opExtendable = 2, AddedComplexity=50,
4002 hasSideEffects = 0, isPredicated = 1, validSubTargets = HasV4SubT in
4003 def TFRI_cdnPt_V4 : ALU32_ri<(outs IntRegs:$dst),
4004 (ins PredRegs:$src1, s16Ext:$src2),
4005 "if($src1.new) $dst = #$src2",
4009 let isExtended = 1, opExtendable = 2, AddedComplexity=50, isPredicatedFalse = 1,
4010 hasSideEffects = 0, isPredicated = 1, validSubTargets = HasV4SubT in
4011 def TFRI_cdnNotPt_V4 : ALU32_ri<(outs IntRegs:$dst),
4012 (ins PredRegs:$src1, s16Ext:$src2),
4013 "if(!$src1.new) $dst = #$src2",
4017 let AddedComplexity = 50, Predicates = [HasV4T] in
4018 def : Pat<(HexagonCONST32_GP tglobaladdr:$src1),
4019 (TFRI_V4 tglobaladdr:$src1)>,
4022 let Predicates = [HasV4T], AddedComplexity = 30 in {
4023 def : Pat<(truncstorei8 (i32 IntRegs:$src1), u0AlwaysExtPred:$src2),
4024 (S2_storerbabs u0AlwaysExtPred:$src2, IntRegs: $src1)>;
4026 def : Pat<(truncstorei16 (i32 IntRegs:$src1), u0AlwaysExtPred:$src2),
4027 (S2_storerhabs u0AlwaysExtPred:$src2, IntRegs: $src1)>;
4029 def : Pat<(store (i32 IntRegs:$src1), u0AlwaysExtPred:$src2),
4030 (S2_storeriabs u0AlwaysExtPred:$src2, IntRegs: $src1)>;
4033 let Predicates = [HasV4T], AddedComplexity = 30 in {
4034 def : Pat<(i32 (load u0AlwaysExtPred:$src)),
4035 (L4_loadri_abs u0AlwaysExtPred:$src)>;
4037 def : Pat<(i32 (sextloadi8 u0AlwaysExtPred:$src)),
4038 (L4_loadrb_abs u0AlwaysExtPred:$src)>;
4040 def : Pat<(i32 (zextloadi8 u0AlwaysExtPred:$src)),
4041 (L4_loadrub_abs u0AlwaysExtPred:$src)>;
4043 def : Pat<(i32 (sextloadi16 u0AlwaysExtPred:$src)),
4044 (L4_loadrh_abs u0AlwaysExtPred:$src)>;
4046 def : Pat<(i32 (zextloadi16 u0AlwaysExtPred:$src)),
4047 (L4_loadruh_abs u0AlwaysExtPred:$src)>;
4050 // Indexed store word - global address.
4051 // memw(Rs+#u6:2)=#S8
4052 let AddedComplexity = 10 in
4053 def STriw_offset_ext_V4 : STInst<(outs),
4054 (ins IntRegs:$src1, u6_2Imm:$src2, globaladdress:$src3),
4055 "memw($src1+#$src2) = ##$src3",
4056 [(store (HexagonCONST32 tglobaladdr:$src3),
4057 (add IntRegs:$src1, u6_2ImmPred:$src2))]>,
4060 def : Pat<(i64 (ctlz (i64 DoubleRegs:$src1))),
4061 (i64 (A4_combineir (i32 0), (i32 (S2_cl0p DoubleRegs:$src1))))>,
4064 def : Pat<(i64 (cttz (i64 DoubleRegs:$src1))),
4065 (i64 (A4_combineir (i32 0), (i32 (S2_ct0p DoubleRegs:$src1))))>,
4070 // We need a complexity of 120 here to override preceding handling of
4072 let Predicates = [HasV4T], AddedComplexity = 120 in {
4073 def: Pat <(i64 (extloadi8 (NumUsesBelowThresCONST32 tglobaladdr:$addr))),
4074 (i64 (A4_combineir 0, (L4_loadrb_abs tglobaladdr:$addr)))>;
4076 def: Pat <(i64 (zextloadi8 (NumUsesBelowThresCONST32 tglobaladdr:$addr))),
4077 (i64 (A4_combineir 0, (L4_loadrub_abs tglobaladdr:$addr)))>;
4079 def: Pat <(i64 (sextloadi8 (NumUsesBelowThresCONST32 tglobaladdr:$addr))),
4080 (i64 (A2_sxtw (L4_loadrb_abs tglobaladdr:$addr)))>;
4082 def: Pat <(i64 (extloadi8 FoldGlobalAddr:$addr)),
4083 (i64 (A4_combineir 0, (L4_loadrb_abs FoldGlobalAddr:$addr)))>;
4085 def: Pat <(i64 (zextloadi8 FoldGlobalAddr:$addr)),
4086 (i64 (A4_combineir 0, (L4_loadrub_abs FoldGlobalAddr:$addr)))>;
4088 def: Pat <(i64 (sextloadi8 FoldGlobalAddr:$addr)),
4089 (i64 (A2_sxtw (L4_loadrb_abs FoldGlobalAddr:$addr)))>;
4092 // We need a complexity of 120 here to override preceding handling of
4094 let AddedComplexity = 120 in {
4095 def: Pat <(i64 (extloadi16 (NumUsesBelowThresCONST32 tglobaladdr:$addr))),
4096 (i64 (A4_combineir 0, (L4_loadrh_abs tglobaladdr:$addr)))>,
4099 def: Pat <(i64 (zextloadi16 (NumUsesBelowThresCONST32 tglobaladdr:$addr))),
4100 (i64 (A4_combineir 0, (L4_loadruh_abs tglobaladdr:$addr)))>,
4103 def: Pat <(i64 (sextloadi16 (NumUsesBelowThresCONST32 tglobaladdr:$addr))),
4104 (i64 (A2_sxtw (L4_loadrh_abs tglobaladdr:$addr)))>,
4107 def: Pat <(i64 (extloadi16 FoldGlobalAddr:$addr)),
4108 (i64 (A4_combineir 0, (L4_loadrh_abs FoldGlobalAddr:$addr)))>,
4111 def: Pat <(i64 (zextloadi16 FoldGlobalAddr:$addr)),
4112 (i64 (A4_combineir 0, (L4_loadruh_abs FoldGlobalAddr:$addr)))>,
4115 def: Pat <(i64 (sextloadi16 FoldGlobalAddr:$addr)),
4116 (i64 (A2_sxtw (L4_loadrh_abs FoldGlobalAddr:$addr)))>,
4120 // We need a complexity of 120 here to override preceding handling of
4122 let AddedComplexity = 120 in {
4123 def: Pat <(i64 (extloadi32 (NumUsesBelowThresCONST32 tglobaladdr:$addr))),
4124 (i64 (A4_combineir 0, (L4_loadri_abs tglobaladdr:$addr)))>,
4127 def: Pat <(i64 (zextloadi32 (NumUsesBelowThresCONST32 tglobaladdr:$addr))),
4128 (i64 (A4_combineir 0, (L4_loadri_abs tglobaladdr:$addr)))>,
4131 def: Pat <(i64 (sextloadi32 (NumUsesBelowThresCONST32 tglobaladdr:$addr))),
4132 (i64 (A2_sxtw (L4_loadri_abs tglobaladdr:$addr)))>,
4135 def: Pat <(i64 (extloadi32 FoldGlobalAddr:$addr)),
4136 (i64 (A4_combineir 0, (L4_loadri_abs FoldGlobalAddr:$addr)))>,
4139 def: Pat <(i64 (zextloadi32 FoldGlobalAddr:$addr)),
4140 (i64 (A4_combineir 0, (L4_loadri_abs FoldGlobalAddr:$addr)))>,
4143 def: Pat <(i64 (sextloadi32 FoldGlobalAddr:$addr)),
4144 (i64 (A2_sxtw (L4_loadri_abs FoldGlobalAddr:$addr)))>,
4148 // Indexed store double word - global address.
4149 // memw(Rs+#u6:2)=#S8
4150 let AddedComplexity = 10 in
4151 def STrih_offset_ext_V4 : STInst<(outs),
4152 (ins IntRegs:$src1, u6_1Imm:$src2, globaladdress:$src3),
4153 "memh($src1+#$src2) = ##$src3",
4154 [(truncstorei16 (HexagonCONST32 tglobaladdr:$src3),
4155 (add IntRegs:$src1, u6_1ImmPred:$src2))]>,
4157 // Map from store(globaladdress + x) -> memd(#foo + x)
4158 let AddedComplexity = 100 in
4159 def : Pat<(store (i64 DoubleRegs:$src1),
4160 FoldGlobalAddrGP:$addr),
4161 (S2_storerdabs FoldGlobalAddrGP:$addr, (i64 DoubleRegs:$src1))>,
4164 def : Pat<(atomic_store_64 FoldGlobalAddrGP:$addr,
4165 (i64 DoubleRegs:$src1)),
4166 (S2_storerdabs FoldGlobalAddrGP:$addr, (i64 DoubleRegs:$src1))>,
4169 // Map from store(globaladdress + x) -> memb(#foo + x)
4170 let AddedComplexity = 100 in
4171 def : Pat<(truncstorei8 (i32 IntRegs:$src1), FoldGlobalAddrGP:$addr),
4172 (S2_storerbabs FoldGlobalAddrGP:$addr, (i32 IntRegs:$src1))>,
4175 def : Pat<(atomic_store_8 FoldGlobalAddrGP:$addr, (i32 IntRegs:$src1)),
4176 (S2_storerbabs FoldGlobalAddrGP:$addr, (i32 IntRegs:$src1))>,
4179 // Map from store(globaladdress + x) -> memh(#foo + x)
4180 let AddedComplexity = 100 in
4181 def : Pat<(truncstorei16 (i32 IntRegs:$src1), FoldGlobalAddrGP:$addr),
4182 (S2_storerhabs FoldGlobalAddrGP:$addr, (i32 IntRegs:$src1))>,
4185 def : Pat<(atomic_store_16 FoldGlobalAddrGP:$addr, (i32 IntRegs:$src1)),
4186 (S2_storerhabs FoldGlobalAddrGP:$addr, (i32 IntRegs:$src1))>,
4189 // Map from store(globaladdress + x) -> memw(#foo + x)
4190 let AddedComplexity = 100 in
4191 def : Pat<(store (i32 IntRegs:$src1), FoldGlobalAddrGP:$addr),
4192 (S2_storeriabs FoldGlobalAddrGP:$addr, (i32 IntRegs:$src1))>,
4195 def : Pat<(atomic_store_32 FoldGlobalAddrGP:$addr, (i32 IntRegs:$src1)),
4196 (S2_storeriabs FoldGlobalAddrGP:$addr, (i32 IntRegs:$src1))>,
4199 // Map from load(globaladdress + x) -> memd(#foo + x)
4200 let AddedComplexity = 100 in
4201 def : Pat<(i64 (load FoldGlobalAddrGP:$addr)),
4202 (i64 (L4_loadrd_abs FoldGlobalAddrGP:$addr))>,
4205 def : Pat<(atomic_load_64 FoldGlobalAddrGP:$addr),
4206 (i64 (L4_loadrd_abs FoldGlobalAddrGP:$addr))>,
4209 // Map from load(globaladdress + x) -> memb(#foo + x)
4210 let AddedComplexity = 100 in
4211 def : Pat<(i32 (extloadi8 FoldGlobalAddrGP:$addr)),
4212 (i32 (L4_loadrb_abs FoldGlobalAddrGP:$addr))>,
4215 // Map from load(globaladdress + x) -> memb(#foo + x)
4216 let AddedComplexity = 100 in
4217 def : Pat<(i32 (sextloadi8 FoldGlobalAddrGP:$addr)),
4218 (i32 (L4_loadrb_abs FoldGlobalAddrGP:$addr))>,
4221 //let AddedComplexity = 100 in
4222 let AddedComplexity = 100 in
4223 def : Pat<(i32 (extloadi16 FoldGlobalAddrGP:$addr)),
4224 (i32 (L4_loadrh_abs FoldGlobalAddrGP:$addr))>,
4227 // Map from load(globaladdress + x) -> memh(#foo + x)
4228 let AddedComplexity = 100 in
4229 def : Pat<(i32 (sextloadi16 FoldGlobalAddrGP:$addr)),
4230 (i32 (L4_loadrh_abs FoldGlobalAddrGP:$addr))>,
4233 // Map from load(globaladdress + x) -> memuh(#foo + x)
4234 let AddedComplexity = 100 in
4235 def : Pat<(i32 (zextloadi16 FoldGlobalAddrGP:$addr)),
4236 (i32 (L4_loadruh_abs FoldGlobalAddrGP:$addr))>,
4239 def : Pat<(atomic_load_16 FoldGlobalAddrGP:$addr),
4240 (i32 (L4_loadruh_abs FoldGlobalAddrGP:$addr))>,
4243 // Map from load(globaladdress + x) -> memub(#foo + x)
4244 let AddedComplexity = 100 in
4245 def : Pat<(i32 (zextloadi8 FoldGlobalAddrGP:$addr)),
4246 (i32 (L4_loadrub_abs FoldGlobalAddrGP:$addr))>,
4249 def : Pat<(atomic_load_8 FoldGlobalAddrGP:$addr),
4250 (i32 (L4_loadrub_abs FoldGlobalAddrGP:$addr))>,
4253 // Map from load(globaladdress + x) -> memw(#foo + x)
4254 let AddedComplexity = 100 in
4255 def : Pat<(i32 (load FoldGlobalAddrGP:$addr)),
4256 (i32 (L4_loadri_abs FoldGlobalAddrGP:$addr))>,
4259 def : Pat<(atomic_load_32 FoldGlobalAddrGP:$addr),
4260 (i32 (L4_loadri_abs FoldGlobalAddrGP:$addr))>,
4263 //===----------------------------------------------------------------------===//
4264 // :raw for of boundscheck:hi:lo insns
4265 //===----------------------------------------------------------------------===//
4267 // A4_boundscheck_lo: Detect if a register is within bounds.
4268 let hasSideEffects = 0, isCodeGenOnly = 0 in
4269 def A4_boundscheck_lo: ALU64Inst <
4270 (outs PredRegs:$Pd),
4271 (ins DoubleRegs:$Rss, DoubleRegs:$Rtt),
4272 "$Pd = boundscheck($Rss, $Rtt):raw:lo"> {
4277 let IClass = 0b1101;
4279 let Inst{27-23} = 0b00100;
4281 let Inst{7-5} = 0b100;
4283 let Inst{20-16} = Rss;
4284 let Inst{12-8} = Rtt;
4287 // A4_boundscheck_hi: Detect if a register is within bounds.
4288 let hasSideEffects = 0, isCodeGenOnly = 0 in
4289 def A4_boundscheck_hi: ALU64Inst <
4290 (outs PredRegs:$Pd),
4291 (ins DoubleRegs:$Rss, DoubleRegs:$Rtt),
4292 "$Pd = boundscheck($Rss, $Rtt):raw:hi"> {
4297 let IClass = 0b1101;
4299 let Inst{27-23} = 0b00100;
4301 let Inst{7-5} = 0b101;
4303 let Inst{20-16} = Rss;
4304 let Inst{12-8} = Rtt;
4307 let hasSideEffects = 0, isAsmParserOnly = 1 in
4308 def A4_boundscheck : MInst <
4309 (outs PredRegs:$Pd), (ins IntRegs:$Rs, DoubleRegs:$Rtt),
4310 "$Pd=boundscheck($Rs,$Rtt)">;
4312 // A4_tlbmatch: Detect if a VA/ASID matches a TLB entry.
4313 let isPredicateLate = 1, hasSideEffects = 0, isCodeGenOnly = 0 in
4314 def A4_tlbmatch : ALU64Inst<(outs PredRegs:$Pd),
4315 (ins DoubleRegs:$Rs, IntRegs:$Rt),
4316 "$Pd = tlbmatch($Rs, $Rt)",
4317 [], "", ALU64_tc_2early_SLOT23> {
4322 let IClass = 0b1101;
4323 let Inst{27-23} = 0b00100;
4324 let Inst{20-16} = Rs;
4326 let Inst{12-8} = Rt;
4327 let Inst{7-5} = 0b011;
4331 // We need custom lowering of ISD::PREFETCH into HexagonISD::DCFETCH
4332 // because the SDNode ISD::PREFETCH has properties MayLoad and MayStore.
4333 // We don't really want either one here.
4334 def SDTHexagonDCFETCH : SDTypeProfile<0, 2, [SDTCisPtrTy<0>,SDTCisInt<1>]>;
4335 def HexagonDCFETCH : SDNode<"HexagonISD::DCFETCH", SDTHexagonDCFETCH,
4338 // Use LD0Inst for dcfetch, but set "mayLoad" to 0 because this doesn't
4339 // really do a load.
4340 let hasSideEffects = 1, mayLoad = 0, isCodeGenOnly = 0 in
4341 def Y2_dcfetchbo : LD0Inst<(outs), (ins IntRegs:$Rs, u11_3Imm:$u11_3),
4342 "dcfetch($Rs + #$u11_3)",
4343 [(HexagonDCFETCH IntRegs:$Rs, u11_3ImmPred:$u11_3)],
4344 "", LD_tc_ld_SLOT0> {
4348 let IClass = 0b1001;
4349 let Inst{27-21} = 0b0100000;
4350 let Inst{20-16} = Rs;
4352 let Inst{10-0} = u11_3{13-3};
4355 //===----------------------------------------------------------------------===//
4356 // Compound instructions
4357 //===----------------------------------------------------------------------===//
4359 let isBranch = 1, hasSideEffects = 0, isExtentSigned = 1,
4360 isPredicated = 1, isPredicatedNew = 1, isExtendable = 1,
4361 opExtentBits = 11, opExtentAlign = 2, opExtendable = 1,
4362 isTerminator = 1, validSubTargets = HasV4SubT in
4363 class CJInst_tstbit_R0<string px, bit np, string tnt>
4364 : InstHexagon<(outs), (ins IntRegs:$Rs, brtarget:$r9_2),
4365 ""#px#" = tstbit($Rs, #0); if ("
4366 #!if(np, "!","")#""#px#".new) jump:"#tnt#" $r9_2",
4367 [], "", COMPOUND, TypeCOMPOUND> {
4372 let isPredicatedFalse = np;
4373 // tnt: Taken/Not Taken
4374 let isBrTaken = !if (!eq(tnt, "t"), "true", "false");
4375 let isTaken = !if (!eq(tnt, "t"), 1, 0);
4377 let IClass = 0b0001;
4378 let Inst{27-26} = 0b00;
4379 let Inst{25} = !if (!eq(px, "!p1"), 1,
4380 !if (!eq(px, "p1"), 1, 0));
4381 let Inst{24-23} = 0b11;
4383 let Inst{21-20} = r9_2{10-9};
4384 let Inst{19-16} = Rs;
4385 let Inst{13} = !if (!eq(tnt, "t"), 1, 0);
4386 let Inst{9-8} = 0b11;
4387 let Inst{7-1} = r9_2{8-2};
4390 let Defs = [PC, P0], Uses = [P0], isCodeGenOnly = 0 in {
4391 def J4_tstbit0_tp0_jump_nt : CJInst_tstbit_R0<"p0", 0, "nt">;
4392 def J4_tstbit0_tp0_jump_t : CJInst_tstbit_R0<"p0", 0, "t">;
4393 def J4_tstbit0_fp0_jump_nt : CJInst_tstbit_R0<"p0", 1, "nt">;
4394 def J4_tstbit0_fp0_jump_t : CJInst_tstbit_R0<"p0", 1, "t">;
4397 let Defs = [PC, P1], Uses = [P1], isCodeGenOnly = 0 in {
4398 def J4_tstbit0_tp1_jump_nt : CJInst_tstbit_R0<"p1", 0, "nt">;
4399 def J4_tstbit0_tp1_jump_t : CJInst_tstbit_R0<"p1", 0, "t">;
4400 def J4_tstbit0_fp1_jump_nt : CJInst_tstbit_R0<"p1", 1, "nt">;
4401 def J4_tstbit0_fp1_jump_t : CJInst_tstbit_R0<"p1", 1, "t">;
4405 let isBranch = 1, hasSideEffects = 0,
4406 isExtentSigned = 1, isPredicated = 1, isPredicatedNew = 1,
4407 isExtendable = 1, opExtentBits = 11, opExtentAlign = 2,
4408 opExtendable = 2, isTerminator = 1, validSubTargets = HasV4SubT in
4409 class CJInst_RR<string px, string op, bit np, string tnt>
4410 : InstHexagon<(outs), (ins IntRegs:$Rs, IntRegs:$Rt, brtarget:$r9_2),
4411 ""#px#" = cmp."#op#"($Rs, $Rt); if ("
4412 #!if(np, "!","")#""#px#".new) jump:"#tnt#" $r9_2",
4413 [], "", COMPOUND, TypeCOMPOUND> {
4419 let isPredicatedFalse = np;
4420 // tnt: Taken/Not Taken
4421 let isBrTaken = !if (!eq(tnt, "t"), "true", "false");
4422 let isTaken = !if (!eq(tnt, "t"), 1, 0);
4424 let IClass = 0b0001;
4425 let Inst{27-23} = !if (!eq(op, "eq"), 0b01000,
4426 !if (!eq(op, "gt"), 0b01001,
4427 !if (!eq(op, "gtu"), 0b01010, 0)));
4429 let Inst{21-20} = r9_2{10-9};
4430 let Inst{19-16} = Rs;
4431 let Inst{13} = !if (!eq(tnt, "t"), 1, 0);
4432 // px: Predicate reg 0/1
4433 let Inst{12} = !if (!eq(px, "!p1"), 1,
4434 !if (!eq(px, "p1"), 1, 0));
4435 let Inst{11-8} = Rt;
4436 let Inst{7-1} = r9_2{8-2};
4439 // P[10] taken/not taken.
4440 multiclass T_tnt_CJInst_RR<string op, bit np> {
4441 let Defs = [PC, P0], Uses = [P0] in {
4442 def NAME#p0_jump_nt : CJInst_RR<"p0", op, np, "nt">;
4443 def NAME#p0_jump_t : CJInst_RR<"p0", op, np, "t">;
4445 let Defs = [PC, P1], Uses = [P1] in {
4446 def NAME#p1_jump_nt : CJInst_RR<"p1", op, np, "nt">;
4447 def NAME#p1_jump_t : CJInst_RR<"p1", op, np, "t">;
4450 // Predicate / !Predicate
4451 multiclass T_pnp_CJInst_RR<string op>{
4452 defm J4_cmp#NAME#_t : T_tnt_CJInst_RR<op, 0>;
4453 defm J4_cmp#NAME#_f : T_tnt_CJInst_RR<op, 1>;
4455 // TypeCJ Instructions compare RR and jump
4456 let isCodeGenOnly = 0 in {
4457 defm eq : T_pnp_CJInst_RR<"eq">;
4458 defm gt : T_pnp_CJInst_RR<"gt">;
4459 defm gtu : T_pnp_CJInst_RR<"gtu">;
4462 let isBranch = 1, hasSideEffects = 0, isExtentSigned = 1,
4463 isPredicated = 1, isPredicatedNew = 1, isExtendable = 1, opExtentBits = 11,
4464 opExtentAlign = 2, opExtendable = 2, isTerminator = 1,
4465 validSubTargets = HasV4SubT in
4466 class CJInst_RU5<string px, string op, bit np, string tnt>
4467 : InstHexagon<(outs), (ins IntRegs:$Rs, u5Imm:$U5, brtarget:$r9_2),
4468 ""#px#" = cmp."#op#"($Rs, #$U5); if ("
4469 #!if(np, "!","")#""#px#".new) jump:"#tnt#" $r9_2",
4470 [], "", COMPOUND, TypeCOMPOUND> {
4476 let isPredicatedFalse = np;
4477 // tnt: Taken/Not Taken
4478 let isBrTaken = !if (!eq(tnt, "t"), "true", "false");
4479 let isTaken = !if (!eq(tnt, "t"), 1, 0);
4481 let IClass = 0b0001;
4482 let Inst{27-26} = 0b00;
4483 // px: Predicate reg 0/1
4484 let Inst{25} = !if (!eq(px, "!p1"), 1,
4485 !if (!eq(px, "p1"), 1, 0));
4486 let Inst{24-23} = !if (!eq(op, "eq"), 0b00,
4487 !if (!eq(op, "gt"), 0b01,
4488 !if (!eq(op, "gtu"), 0b10, 0)));
4490 let Inst{21-20} = r9_2{10-9};
4491 let Inst{19-16} = Rs;
4492 let Inst{13} = !if (!eq(tnt, "t"), 1, 0);
4493 let Inst{12-8} = U5;
4494 let Inst{7-1} = r9_2{8-2};
4496 // P[10] taken/not taken.
4497 multiclass T_tnt_CJInst_RU5<string op, bit np> {
4498 let Defs = [PC, P0], Uses = [P0] in {
4499 def NAME#p0_jump_nt : CJInst_RU5<"p0", op, np, "nt">;
4500 def NAME#p0_jump_t : CJInst_RU5<"p0", op, np, "t">;
4502 let Defs = [PC, P1], Uses = [P1] in {
4503 def NAME#p1_jump_nt : CJInst_RU5<"p1", op, np, "nt">;
4504 def NAME#p1_jump_t : CJInst_RU5<"p1", op, np, "t">;
4507 // Predicate / !Predicate
4508 multiclass T_pnp_CJInst_RU5<string op>{
4509 defm J4_cmp#NAME#i_t : T_tnt_CJInst_RU5<op, 0>;
4510 defm J4_cmp#NAME#i_f : T_tnt_CJInst_RU5<op, 1>;
4512 // TypeCJ Instructions compare RI and jump
4513 let isCodeGenOnly = 0 in {
4514 defm eq : T_pnp_CJInst_RU5<"eq">;
4515 defm gt : T_pnp_CJInst_RU5<"gt">;
4516 defm gtu : T_pnp_CJInst_RU5<"gtu">;
4519 let isBranch = 1, hasSideEffects = 0, isExtentSigned = 1,
4520 isPredicated = 1, isPredicatedFalse = 1, isPredicatedNew = 1,
4521 isExtendable = 1, opExtentBits = 11, opExtentAlign = 2, opExtendable = 1,
4522 isTerminator = 1, validSubTargets = HasV4SubT in
4523 class CJInst_Rn1<string px, string op, bit np, string tnt>
4524 : InstHexagon<(outs), (ins IntRegs:$Rs, brtarget:$r9_2),
4525 ""#px#" = cmp."#op#"($Rs,#-1); if ("
4526 #!if(np, "!","")#""#px#".new) jump:"#tnt#" $r9_2",
4527 [], "", COMPOUND, TypeCOMPOUND> {
4532 let isPredicatedFalse = np;
4533 // tnt: Taken/Not Taken
4534 let isBrTaken = !if (!eq(tnt, "t"), "true", "false");
4535 let isTaken = !if (!eq(tnt, "t"), 1, 0);
4537 let IClass = 0b0001;
4538 let Inst{27-26} = 0b00;
4539 let Inst{25} = !if (!eq(px, "!p1"), 1,
4540 !if (!eq(px, "p1"), 1, 0));
4542 let Inst{24-23} = 0b11;
4544 let Inst{21-20} = r9_2{10-9};
4545 let Inst{19-16} = Rs;
4546 let Inst{13} = !if (!eq(tnt, "t"), 1, 0);
4547 let Inst{9-8} = !if (!eq(op, "eq"), 0b00,
4548 !if (!eq(op, "gt"), 0b01, 0));
4549 let Inst{7-1} = r9_2{8-2};
4552 // P[10] taken/not taken.
4553 multiclass T_tnt_CJInst_Rn1<string op, bit np> {
4554 let Defs = [PC, P0], Uses = [P0] in {
4555 def NAME#p0_jump_nt : CJInst_Rn1<"p0", op, np, "nt">;
4556 def NAME#p0_jump_t : CJInst_Rn1<"p0", op, np, "t">;
4558 let Defs = [PC, P1], Uses = [P1] in {
4559 def NAME#p1_jump_nt : CJInst_Rn1<"p1", op, np, "nt">;
4560 def NAME#p1_jump_t : CJInst_Rn1<"p1", op, np, "t">;
4563 // Predicate / !Predicate
4564 multiclass T_pnp_CJInst_Rn1<string op>{
4565 defm J4_cmp#NAME#n1_t : T_tnt_CJInst_Rn1<op, 0>;
4566 defm J4_cmp#NAME#n1_f : T_tnt_CJInst_Rn1<op, 1>;
4568 // TypeCJ Instructions compare -1 and jump
4569 let isCodeGenOnly = 0 in {
4570 defm eq : T_pnp_CJInst_Rn1<"eq">;
4571 defm gt : T_pnp_CJInst_Rn1<"gt">;
4574 // J4_jumpseti: Direct unconditional jump and set register to immediate.
4575 let Defs = [PC], isBranch = 1, hasSideEffects = 0, hasNewValue = 1,
4576 isExtentSigned = 1, opNewValue = 0, isExtendable = 1, opExtentBits = 11,
4577 opExtentAlign = 2, opExtendable = 2, validSubTargets = HasV4SubT,
4578 isCodeGenOnly = 0 in
4579 def J4_jumpseti: CJInst <
4581 (ins u6Imm:$U6, brtarget:$r9_2),
4582 "$Rd = #$U6 ; jump $r9_2"> {
4587 let IClass = 0b0001;
4588 let Inst{27-24} = 0b0110;
4589 let Inst{21-20} = r9_2{10-9};
4590 let Inst{19-16} = Rd;
4591 let Inst{13-8} = U6;
4592 let Inst{7-1} = r9_2{8-2};
4595 // J4_jumpsetr: Direct unconditional jump and transfer register.
4596 let Defs = [PC], isBranch = 1, hasSideEffects = 0, hasNewValue = 1,
4597 isExtentSigned = 1, opNewValue = 0, isExtendable = 1, opExtentBits = 11,
4598 opExtentAlign = 2, opExtendable = 2, validSubTargets = HasV4SubT,
4599 isCodeGenOnly = 0 in
4600 def J4_jumpsetr: CJInst <
4602 (ins IntRegs:$Rs, brtarget:$r9_2),
4603 "$Rd = $Rs ; jump $r9_2"> {
4608 let IClass = 0b0001;
4609 let Inst{27-24} = 0b0111;
4610 let Inst{21-20} = r9_2{10-9};
4611 let Inst{11-8} = Rd;
4612 let Inst{19-16} = Rs;
4613 let Inst{7-1} = r9_2{8-2};