[Hexagon] Since decoding conflicts have been resolved, isCodeGenOnly = 0 by default...
[oota-llvm.git] / lib / Target / Hexagon / HexagonInstrInfoV4.td
1 //=- HexagonInstrInfoV4.td - Target Desc. for Hexagon Target -*- tablegen -*-=//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // This file describes the Hexagon V4 instructions in TableGen format.
11 //
12 //===----------------------------------------------------------------------===//
13
14 def addrga: PatLeaf<(i32 AddrGA:$Addr)>;
15 def addrgp: PatLeaf<(i32 AddrGP:$Addr)>;
16
17 let hasSideEffects = 0 in
18 class T_Immext<Operand ImmType>
19   : EXTENDERInst<(outs), (ins ImmType:$imm),
20                  "immext(#$imm)", []> {
21     bits<32> imm;
22     let IClass = 0b0000;
23
24     let Inst{27-16} = imm{31-20};
25     let Inst{13-0} = imm{19-6};
26   }
27
28 def A4_ext : T_Immext<u26_6Imm>;
29 let isCodeGenOnly = 1 in {
30   let isBranch = 1 in
31     def A4_ext_b : T_Immext<brtarget>;
32   let isCall = 1 in
33     def A4_ext_c : T_Immext<calltarget>;
34   def A4_ext_g : T_Immext<globaladdress>;
35 }
36
37 def BITPOS32 : SDNodeXForm<imm, [{
38    // Return the bit position we will set [0-31].
39    // As an SDNode.
40    int32_t imm = N->getSExtValue();
41    return XformMskToBitPosU5Imm(imm);
42 }]>;
43
44 // Fold (add (CONST32 tglobaladdr:$addr) <offset>) into a global address.
45 def FoldGlobalAddr : ComplexPattern<i32, 1, "foldGlobalAddress", [], []>;
46
47 // Fold (add (CONST32_GP tglobaladdr:$addr) <offset>) into a global address.
48 def FoldGlobalAddrGP : ComplexPattern<i32, 1, "foldGlobalAddressGP", [], []>;
49
50 def NumUsesBelowThresCONST32 : PatFrag<(ops node:$addr),
51                                        (HexagonCONST32 node:$addr), [{
52   return hasNumUsesBelowThresGA(N->getOperand(0).getNode());
53 }]>;
54
55 // Hexagon V4 Architecture spec defines 8 instruction classes:
56 // LD ST ALU32 XTYPE J JR MEMOP NV CR SYSTEM(system is not implemented in the
57 // compiler)
58
59 // LD Instructions:
60 // ========================================
61 // Loads (8/16/32/64 bit)
62 // Deallocframe
63
64 // ST Instructions:
65 // ========================================
66 // Stores (8/16/32/64 bit)
67 // Allocframe
68
69 // ALU32 Instructions:
70 // ========================================
71 // Arithmetic / Logical (32 bit)
72 // Vector Halfword
73
74 // XTYPE Instructions (32/64 bit):
75 // ========================================
76 // Arithmetic, Logical, Bit Manipulation
77 // Multiply (Integer, Fractional, Complex)
78 // Permute / Vector Permute Operations
79 // Predicate Operations
80 // Shift / Shift with Add/Sub/Logical
81 // Vector Byte ALU
82 // Vector Halfword (ALU, Shift, Multiply)
83 // Vector Word (ALU, Shift)
84
85 // J Instructions:
86 // ========================================
87 // Jump/Call PC-relative
88
89 // JR Instructions:
90 // ========================================
91 // Jump/Call Register
92
93 // MEMOP Instructions:
94 // ========================================
95 // Operation on memory (8/16/32 bit)
96
97 // NV Instructions:
98 // ========================================
99 // New-value Jumps
100 // New-value Stores
101
102 // CR Instructions:
103 // ========================================
104 // Control-Register Transfers
105 // Hardware Loop Setup
106 // Predicate Logicals & Reductions
107
108 // SYSTEM Instructions (not implemented in the compiler):
109 // ========================================
110 // Prefetch
111 // Cache Maintenance
112 // Bus Operations
113
114
115 //===----------------------------------------------------------------------===//
116 // ALU32 +
117 //===----------------------------------------------------------------------===//
118
119 class T_ALU32_3op_not<string mnemonic, bits<3> MajOp, bits<3> MinOp,
120                       bit OpsRev>
121   : T_ALU32_3op<mnemonic, MajOp, MinOp, OpsRev, 0> {
122   let AsmString = "$Rd = "#mnemonic#"($Rs, ~$Rt)";
123 }
124
125 let BaseOpcode = "andn_rr", CextOpcode = "andn" in
126 def A4_andn    : T_ALU32_3op_not<"and", 0b001, 0b100, 1>;
127 let BaseOpcode = "orn_rr", CextOpcode = "orn" in
128 def A4_orn     : T_ALU32_3op_not<"or",  0b001, 0b101, 1>;
129
130 let CextOpcode = "rcmp.eq" in
131 def A4_rcmpeq  : T_ALU32_3op<"cmp.eq",  0b011, 0b010, 0, 1>;
132 let CextOpcode = "!rcmp.eq" in
133 def A4_rcmpneq : T_ALU32_3op<"!cmp.eq", 0b011, 0b011, 0, 1>;
134
135 def C4_cmpneq  : T_ALU32_3op_cmp<"!cmp.eq",  0b00, 1, 1>;
136 def C4_cmplte  : T_ALU32_3op_cmp<"!cmp.gt",  0b10, 1, 0>;
137 def C4_cmplteu : T_ALU32_3op_cmp<"!cmp.gtu", 0b11, 1, 0>;
138
139 // Pats for instruction selection.
140
141 // A class to embed the usual comparison patfrags within a zext to i32.
142 // The seteq/setne frags use "lhs" and "rhs" as operands, so use the same
143 // names, or else the frag's "body" won't match the operands.
144 class CmpInReg<PatFrag Op>
145   : PatFrag<(ops node:$lhs, node:$rhs),(i32 (zext (i1 Op.Fragment)))>;
146
147 def: T_cmp32_rr_pat<A4_rcmpeq,  CmpInReg<seteq>, i32>;
148 def: T_cmp32_rr_pat<A4_rcmpneq, CmpInReg<setne>, i32>;
149
150 def: T_cmp32_rr_pat<C4_cmpneq,  setne,  i1>;
151
152 class T_CMP_rrbh<string mnemonic, bits<3> MinOp, bit IsComm>
153   : SInst<(outs PredRegs:$Pd), (ins IntRegs:$Rs, IntRegs:$Rt),
154     "$Pd = "#mnemonic#"($Rs, $Rt)", [], "", S_3op_tc_2early_SLOT23>,
155     ImmRegRel {
156   let validSubTargets = HasV4SubT;
157   let InputType = "reg";
158   let CextOpcode = mnemonic;
159   let isCompare = 1;
160   let isCommutable = IsComm;
161   let hasSideEffects = 0;
162
163   bits<2> Pd;
164   bits<5> Rs;
165   bits<5> Rt;
166
167   let IClass = 0b1100;
168   let Inst{27-21} = 0b0111110;
169   let Inst{20-16} = Rs;
170   let Inst{12-8} = Rt;
171   let Inst{7-5} = MinOp;
172   let Inst{1-0} = Pd;
173 }
174
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>;
181
182 class T_CMP_ribh<string mnemonic, bits<2> MajOp, bit IsHalf, bit IsComm,
183                  Operand ImmType, bit IsImmExt, bit IsImmSigned, int ImmBits>
184   : ALU64Inst<(outs PredRegs:$Pd), (ins IntRegs:$Rs, ImmType:$Imm),
185     "$Pd = "#mnemonic#"($Rs, #$Imm)", [], "", ALU64_tc_2early_SLOT23>,
186     ImmRegRel {
187   let validSubTargets = HasV4SubT;
188   let InputType = "imm";
189   let CextOpcode = mnemonic;
190   let isCompare = 1;
191   let isCommutable = IsComm;
192   let hasSideEffects = 0;
193   let isExtendable = IsImmExt;
194   let opExtendable = !if (IsImmExt, 2, 0);
195   let isExtentSigned = IsImmSigned;
196   let opExtentBits = ImmBits;
197
198   bits<2> Pd;
199   bits<5> Rs;
200   bits<8> Imm;
201
202   let IClass = 0b1101;
203   let Inst{27-24} = 0b1101;
204   let Inst{22-21} = MajOp;
205   let Inst{20-16} = Rs;
206   let Inst{12-5} = Imm;
207   let Inst{4} = 0b0;
208   let Inst{3} = IsHalf;
209   let Inst{1-0} = Pd;
210 }
211
212 def A4_cmpbeqi  : T_CMP_ribh<"cmpb.eq",  0b00, 0, 1, u8Imm, 0, 0, 8>;
213 def A4_cmpbgti  : T_CMP_ribh<"cmpb.gt",  0b01, 0, 0, s8Imm, 0, 1, 8>;
214 def A4_cmpbgtui : T_CMP_ribh<"cmpb.gtu", 0b10, 0, 0, u7Ext, 1, 0, 7>;
215 def A4_cmpheqi  : T_CMP_ribh<"cmph.eq",  0b00, 1, 1, s8Ext, 1, 1, 8>;
216 def A4_cmphgti  : T_CMP_ribh<"cmph.gt",  0b01, 1, 0, s8Ext, 1, 1, 8>;
217 def A4_cmphgtui : T_CMP_ribh<"cmph.gtu", 0b10, 1, 0, u7Ext, 1, 0, 7>;
218
219 class T_RCMP_EQ_ri<string mnemonic, bit IsNeg>
220   : ALU32_ri<(outs IntRegs:$Rd), (ins IntRegs:$Rs, s8Ext:$s8),
221     "$Rd = "#mnemonic#"($Rs, #$s8)", [], "", ALU32_2op_tc_1_SLOT0123>,
222     ImmRegRel {
223   let validSubTargets = HasV4SubT;
224   let InputType = "imm";
225   let CextOpcode = !if (IsNeg, "!rcmp.eq", "rcmp.eq");
226   let isExtendable = 1;
227   let opExtendable = 2;
228   let isExtentSigned = 1;
229   let opExtentBits = 8;
230   let hasNewValue = 1;
231
232   bits<5> Rd;
233   bits<5> Rs;
234   bits<8> s8;
235
236   let IClass = 0b0111;
237   let Inst{27-24} = 0b0011;
238   let Inst{22} = 0b1;
239   let Inst{21} = IsNeg;
240   let Inst{20-16} = Rs;
241   let Inst{13} = 0b1;
242   let Inst{12-5} = s8;
243   let Inst{4-0} = Rd;
244 }
245
246 def A4_rcmpeqi  : T_RCMP_EQ_ri<"cmp.eq",  0>;
247 def A4_rcmpneqi : T_RCMP_EQ_ri<"!cmp.eq", 1>;
248
249 def: Pat<(i32 (zext (i1 (seteq (i32 IntRegs:$Rs), s8ExtPred:$s8)))),
250          (A4_rcmpeqi IntRegs:$Rs, s8ExtPred:$s8)>;
251 def: Pat<(i32 (zext (i1 (setne (i32 IntRegs:$Rs), s8ExtPred:$s8)))),
252          (A4_rcmpneqi IntRegs:$Rs, s8ExtPred:$s8)>;
253
254 // Preserve the S2_tstbit_r generation
255 def: Pat<(i32 (zext (i1 (setne (i32 (and (i32 (shl 1, (i32 IntRegs:$src2))),
256                                          (i32 IntRegs:$src1))), 0)))),
257          (C2_muxii (S2_tstbit_r IntRegs:$src1, IntRegs:$src2), 1, 0)>;
258
259
260 //===----------------------------------------------------------------------===//
261 // ALU32 -
262 //===----------------------------------------------------------------------===//
263
264
265 //===----------------------------------------------------------------------===//
266 // ALU32/PERM +
267 //===----------------------------------------------------------------------===//
268
269 // Combine a word and an immediate into a register pair.
270 let hasSideEffects = 0, isExtentSigned = 1, isExtendable = 1,
271     opExtentBits = 8 in
272 class T_Combine1 <bits<2> MajOp, dag ins, string AsmStr>
273   : ALU32Inst <(outs DoubleRegs:$Rdd), ins, AsmStr> {
274     bits<5> Rdd;
275     bits<5> Rs;
276     bits<8> s8;
277
278     let IClass      = 0b0111;
279     let Inst{27-24} = 0b0011;
280     let Inst{22-21} = MajOp;
281     let Inst{20-16} = Rs;
282     let Inst{13}    = 0b1;
283     let Inst{12-5}  = s8;
284     let Inst{4-0}   = Rdd;
285   }
286
287 let opExtendable = 2 in
288 def A4_combineri : T_Combine1<0b00, (ins IntRegs:$Rs, s8Ext:$s8),
289                                     "$Rdd = combine($Rs, #$s8)">;
290
291 let opExtendable = 1 in
292 def A4_combineir : T_Combine1<0b01, (ins s8Ext:$s8, IntRegs:$Rs),
293                                     "$Rdd = combine(#$s8, $Rs)">;
294
295 def HexagonWrapperCombineRI_V4 :
296   SDNode<"HexagonISD::WrapperCombineRI_V4", SDTHexagonI64I32I32>;
297 def HexagonWrapperCombineIR_V4 :
298   SDNode<"HexagonISD::WrapperCombineIR_V4", SDTHexagonI64I32I32>;
299
300 def : Pat <(HexagonWrapperCombineRI_V4 IntRegs:$r, s8ExtPred:$i),
301            (A4_combineri IntRegs:$r, s8ExtPred:$i)>,
302           Requires<[HasV4T]>;
303
304 def : Pat <(HexagonWrapperCombineIR_V4 s8ExtPred:$i, IntRegs:$r),
305            (A4_combineir s8ExtPred:$i, IntRegs:$r)>,
306           Requires<[HasV4T]>;
307
308 // A4_combineii: Set two small immediates.
309 let hasSideEffects = 0, isExtendable = 1, opExtentBits = 6, opExtendable = 2 in
310 def A4_combineii: ALU32Inst<(outs DoubleRegs:$Rdd), (ins s8Imm:$s8, u6Ext:$U6),
311   "$Rdd = combine(#$s8, #$U6)"> {
312     bits<5> Rdd;
313     bits<8> s8;
314     bits<6> U6;
315
316     let IClass = 0b0111;
317     let Inst{27-23} = 0b11001;
318     let Inst{20-16} = U6{5-1};
319     let Inst{13}    = U6{0};
320     let Inst{12-5}  = s8;
321     let Inst{4-0}   = Rdd;
322   }
323
324 //===----------------------------------------------------------------------===//
325 // ALU32/PERM -
326 //===----------------------------------------------------------------------===//
327
328 //===----------------------------------------------------------------------===//
329 // LD +
330 //===----------------------------------------------------------------------===//
331
332 def Zext64: OutPatFrag<(ops node:$Rs),
333   (i64 (A4_combineir 0, (i32 $Rs)))>;
334 def Sext64: OutPatFrag<(ops node:$Rs),
335   (i64 (A2_sxtw (i32 $Rs)))>;
336
337 // Patterns to generate indexed loads with different forms of the address:
338 // - frameindex,
339 // - base + offset,
340 // - base (without offset).
341 multiclass Loadxm_pat<PatFrag Load, ValueType VT, PatFrag ValueMod,
342                       PatLeaf ImmPred, InstHexagon MI> {
343   def: Pat<(VT (Load AddrFI:$fi)),
344            (VT (ValueMod (MI AddrFI:$fi, 0)))>;
345   def: Pat<(VT (Load (add IntRegs:$Rs, ImmPred:$Off))),
346            (VT (ValueMod (MI IntRegs:$Rs, imm:$Off)))>;
347   def: Pat<(VT (Load (i32 IntRegs:$Rs))),
348            (VT (ValueMod (MI IntRegs:$Rs, 0)))>;
349 }
350
351 defm: Loadxm_pat<extloadi1,   i64, Zext64, s11_0ExtPred, L2_loadrub_io>;
352 defm: Loadxm_pat<extloadi8,   i64, Zext64, s11_0ExtPred, L2_loadrub_io>;
353 defm: Loadxm_pat<extloadi16,  i64, Zext64, s11_1ExtPred, L2_loadruh_io>;
354 defm: Loadxm_pat<zextloadi1,  i64, Zext64, s11_0ExtPred, L2_loadrub_io>;
355 defm: Loadxm_pat<zextloadi8,  i64, Zext64, s11_0ExtPred, L2_loadrub_io>;
356 defm: Loadxm_pat<zextloadi16, i64, Zext64, s11_1ExtPred, L2_loadruh_io>;
357 defm: Loadxm_pat<sextloadi8,  i64, Sext64, s11_0ExtPred, L2_loadrb_io>;
358 defm: Loadxm_pat<sextloadi16, i64, Sext64, s11_1ExtPred, L2_loadrh_io>;
359
360 // Map Rdd = anyext(Rs) -> Rdd = combine(#0, Rs).
361 def: Pat<(i64 (anyext (i32 IntRegs:$src1))), (Zext64 IntRegs:$src1)>;
362
363 //===----------------------------------------------------------------------===//
364 // Template class for load instructions with Absolute set addressing mode.
365 //===----------------------------------------------------------------------===//
366 let isExtended = 1, opExtendable = 2, opExtentBits = 6, addrMode = AbsoluteSet,
367     hasSideEffects = 0 in
368 class T_LD_abs_set<string mnemonic, RegisterClass RC, bits<4>MajOp>:
369             LDInst<(outs RC:$dst1, IntRegs:$dst2),
370             (ins u6Ext:$addr),
371             "$dst1 = "#mnemonic#"($dst2 = #$addr)",
372             []> {
373   bits<7> name;
374   bits<5> dst1;
375   bits<5> dst2;
376   bits<6> addr;
377
378   let IClass = 0b1001;
379   let Inst{27-25} = 0b101;
380   let Inst{24-21} = MajOp;
381   let Inst{13-12} = 0b01;
382   let Inst{4-0}   = dst1;
383   let Inst{20-16} = dst2;
384   let Inst{11-8}  = addr{5-2};
385   let Inst{6-5}   = addr{1-0};
386 }
387
388 let accessSize = ByteAccess, hasNewValue = 1 in {
389   def L4_loadrb_ap   : T_LD_abs_set <"memb",   IntRegs, 0b1000>;
390   def L4_loadrub_ap  : T_LD_abs_set <"memub",  IntRegs, 0b1001>;
391 }
392
393 let accessSize = HalfWordAccess, hasNewValue = 1 in {
394   def L4_loadrh_ap  : T_LD_abs_set <"memh",  IntRegs, 0b1010>;
395   def L4_loadruh_ap : T_LD_abs_set <"memuh", IntRegs, 0b1011>;
396 }
397
398 let accessSize = WordAccess, hasNewValue = 1 in
399   def L4_loadri_ap : T_LD_abs_set <"memw", IntRegs, 0b1100>;
400
401 let accessSize = DoubleWordAccess in
402 def L4_loadrd_ap : T_LD_abs_set <"memd", DoubleRegs, 0b1110>;
403 // Load - Indirect with long offset
404 let InputType = "imm", addrMode = BaseLongOffset, isExtended = 1,
405 opExtentBits = 6, opExtendable = 3 in
406 class T_LoadAbsReg <string mnemonic, string CextOp, RegisterClass RC,
407                     bits<4> MajOp>
408   : LDInst <(outs RC:$dst), (ins IntRegs:$src1, u2Imm:$src2, u6Ext:$src3),
409   "$dst = "#mnemonic#"($src1<<#$src2 + #$src3)",
410   [] >, ImmRegShl {
411     bits<5> dst;
412     bits<5> src1;
413     bits<2> src2;
414     bits<6> src3;
415     let CextOpcode = CextOp;
416     let hasNewValue = !if (!eq(!cast<string>(RC), "DoubleRegs"), 0, 1);
417
418     let IClass = 0b1001;
419     let Inst{27-25} = 0b110;
420     let Inst{24-21} = MajOp;
421     let Inst{20-16} = src1;
422     let Inst{13}    = src2{1};
423     let Inst{12}    = 0b1;
424     let Inst{11-8}  = src3{5-2};
425     let Inst{7}     = src2{0};
426     let Inst{6-5}   = src3{1-0};
427     let Inst{4-0}   = dst;
428   }
429
430 let accessSize = ByteAccess in {
431   def L4_loadrb_ur  : T_LoadAbsReg<"memb",  "LDrib", IntRegs, 0b1000>;
432   def L4_loadrub_ur : T_LoadAbsReg<"memub", "LDriub", IntRegs, 0b1001>;
433   def L4_loadalignb_ur : T_LoadAbsReg<"memb_fifo", "LDrib_fifo",
434                                       DoubleRegs, 0b0100>;
435 }
436
437 let accessSize = HalfWordAccess in {
438   def L4_loadrh_ur   : T_LoadAbsReg<"memh",   "LDrih",    IntRegs, 0b1010>;
439   def L4_loadruh_ur  : T_LoadAbsReg<"memuh",  "LDriuh",   IntRegs, 0b1011>;
440   def L4_loadbsw2_ur : T_LoadAbsReg<"membh",  "LDribh2",  IntRegs, 0b0001>;
441   def L4_loadbzw2_ur : T_LoadAbsReg<"memubh", "LDriubh2", IntRegs, 0b0011>;
442   def L4_loadalignh_ur : T_LoadAbsReg<"memh_fifo", "LDrih_fifo",
443                                       DoubleRegs, 0b0010>;
444 }
445
446 let accessSize = WordAccess in {
447   def L4_loadri_ur   : T_LoadAbsReg<"memw", "LDriw", IntRegs, 0b1100>;
448   def L4_loadbsw4_ur : T_LoadAbsReg<"membh", "LDribh4", DoubleRegs, 0b0111>;
449   def L4_loadbzw4_ur : T_LoadAbsReg<"memubh", "LDriubh4", DoubleRegs, 0b0101>;
450 }
451
452 let accessSize = DoubleWordAccess in
453 def L4_loadrd_ur  : T_LoadAbsReg<"memd", "LDrid", DoubleRegs, 0b1110>;
454
455
456 multiclass T_LoadAbsReg_Pat <PatFrag ldOp, InstHexagon MI, ValueType VT = i32> {
457   def  : Pat <(VT (ldOp (add (shl IntRegs:$src1, u2ImmPred:$src2),
458                              (HexagonCONST32 tglobaladdr:$src3)))),
459               (MI IntRegs:$src1, u2ImmPred:$src2, tglobaladdr:$src3)>;
460
461   def  : Pat <(VT (ldOp (add IntRegs:$src1,
462                              (HexagonCONST32 tglobaladdr:$src2)))),
463               (MI IntRegs:$src1, 0, tglobaladdr:$src2)>;
464 }
465
466 let AddedComplexity  = 60 in {
467 defm : T_LoadAbsReg_Pat <sextloadi8, L4_loadrb_ur>;
468 defm : T_LoadAbsReg_Pat <zextloadi8, L4_loadrub_ur>;
469 defm : T_LoadAbsReg_Pat <extloadi8,  L4_loadrub_ur>;
470
471 defm : T_LoadAbsReg_Pat <sextloadi16, L4_loadrh_ur>;
472 defm : T_LoadAbsReg_Pat <zextloadi16, L4_loadruh_ur>;
473 defm : T_LoadAbsReg_Pat <extloadi16,  L4_loadruh_ur>;
474
475 defm : T_LoadAbsReg_Pat <load, L4_loadri_ur>;
476 defm : T_LoadAbsReg_Pat <load, L4_loadrd_ur, i64>;
477 }
478
479 //===----------------------------------------------------------------------===//
480 // Template classes for the non-predicated load instructions with
481 // base + register offset addressing mode
482 //===----------------------------------------------------------------------===//
483 class T_load_rr <string mnemonic, RegisterClass RC, bits<3> MajOp>:
484    LDInst<(outs RC:$dst), (ins IntRegs:$src1, IntRegs:$src2, u2Imm:$u2),
485   "$dst = "#mnemonic#"($src1 + $src2<<#$u2)",
486   [], "", V4LDST_tc_ld_SLOT01>, ImmRegShl, AddrModeRel {
487     bits<5> dst;
488     bits<5> src1;
489     bits<5> src2;
490     bits<2> u2;
491
492     let IClass = 0b0011;
493
494     let Inst{27-24} = 0b1010;
495     let Inst{23-21} = MajOp;
496     let Inst{20-16} = src1;
497     let Inst{12-8}  = src2;
498     let Inst{13}    = u2{1};
499     let Inst{7}     = u2{0};
500     let Inst{4-0}   = dst;
501   }
502
503 //===----------------------------------------------------------------------===//
504 // Template classes for the predicated load instructions with
505 // base + register offset addressing mode
506 //===----------------------------------------------------------------------===//
507 let isPredicated =  1 in
508 class T_pload_rr <string mnemonic, RegisterClass RC, bits<3> MajOp,
509                   bit isNot, bit isPredNew>:
510    LDInst <(outs RC:$dst),
511            (ins PredRegs:$src1, IntRegs:$src2, IntRegs:$src3, u2Imm:$u2),
512   !if(isNot, "if (!$src1", "if ($src1")#!if(isPredNew, ".new) ",
513   ") ")#"$dst = "#mnemonic#"($src2+$src3<<#$u2)",
514   [], "", V4LDST_tc_ld_SLOT01>, AddrModeRel {
515     bits<5> dst;
516     bits<2> src1;
517     bits<5> src2;
518     bits<5> src3;
519     bits<2> u2;
520
521     let isPredicatedFalse = isNot;
522     let isPredicatedNew = isPredNew;
523
524     let IClass = 0b0011;
525
526     let Inst{27-26} = 0b00;
527     let Inst{25}    = isPredNew;
528     let Inst{24}    = isNot;
529     let Inst{23-21} = MajOp;
530     let Inst{20-16} = src2;
531     let Inst{12-8}  = src3;
532     let Inst{13}    = u2{1};
533     let Inst{7}     = u2{0};
534     let Inst{6-5}   = src1;
535     let Inst{4-0}   = dst;
536   }
537
538 //===----------------------------------------------------------------------===//
539 // multiclass for load instructions with base + register offset
540 // addressing mode
541 //===----------------------------------------------------------------------===//
542 let hasSideEffects = 0, addrMode = BaseRegOffset in
543 multiclass ld_idxd_shl <string mnemonic, string CextOp, RegisterClass RC,
544                         bits<3> MajOp > {
545   let CextOpcode = CextOp, BaseOpcode = CextOp#_indexed_shl,
546       InputType = "reg" in {
547     let isPredicable = 1 in
548     def L4_#NAME#_rr : T_load_rr <mnemonic, RC, MajOp>;
549
550     // Predicated
551     def L4_p#NAME#t_rr : T_pload_rr <mnemonic, RC, MajOp, 0, 0>;
552     def L4_p#NAME#f_rr : T_pload_rr <mnemonic, RC, MajOp, 1, 0>;
553
554     // Predicated new
555     def L4_p#NAME#tnew_rr : T_pload_rr <mnemonic, RC, MajOp, 0, 1>;
556     def L4_p#NAME#fnew_rr : T_pload_rr <mnemonic, RC, MajOp, 1, 1>;
557   }
558 }
559
560 let hasNewValue = 1, accessSize = ByteAccess in {
561   defm loadrb  : ld_idxd_shl<"memb", "LDrib", IntRegs, 0b000>;
562   defm loadrub : ld_idxd_shl<"memub", "LDriub", IntRegs, 0b001>;
563 }
564
565 let hasNewValue = 1, accessSize = HalfWordAccess in {
566   defm loadrh  : ld_idxd_shl<"memh", "LDrih", IntRegs, 0b010>;
567   defm loadruh : ld_idxd_shl<"memuh", "LDriuh", IntRegs, 0b011>;
568 }
569
570 let hasNewValue = 1, accessSize = WordAccess in
571 defm loadri : ld_idxd_shl<"memw", "LDriw", IntRegs, 0b100>;
572
573 let accessSize = DoubleWordAccess in
574 defm loadrd  : ld_idxd_shl<"memd", "LDrid", DoubleRegs, 0b110>;
575
576 // 'def pats' for load instructions with base + register offset and non-zero
577 // immediate value. Immediate value is used to left-shift the second
578 // register operand.
579 class Loadxs_pat<PatFrag Load, ValueType VT, InstHexagon MI>
580   : Pat<(VT (Load (add (i32 IntRegs:$Rs),
581                        (i32 (shl (i32 IntRegs:$Rt), u2ImmPred:$u2))))),
582         (VT (MI IntRegs:$Rs, IntRegs:$Rt, imm:$u2))>;
583
584 let AddedComplexity = 40 in {
585   def: Loadxs_pat<extloadi8,   i32, L4_loadrub_rr>;
586   def: Loadxs_pat<zextloadi8,  i32, L4_loadrub_rr>;
587   def: Loadxs_pat<sextloadi8,  i32, L4_loadrb_rr>;
588   def: Loadxs_pat<extloadi16,  i32, L4_loadruh_rr>;
589   def: Loadxs_pat<zextloadi16, i32, L4_loadruh_rr>;
590   def: Loadxs_pat<sextloadi16, i32, L4_loadrh_rr>;
591   def: Loadxs_pat<load,        i32, L4_loadri_rr>;
592   def: Loadxs_pat<load,        i64, L4_loadrd_rr>;
593 }
594
595 // 'def pats' for load instruction base + register offset and
596 // zero immediate value.
597 class Loadxs_simple_pat<PatFrag Load, ValueType VT, InstHexagon MI>
598   : Pat<(VT (Load (add (i32 IntRegs:$Rs), (i32 IntRegs:$Rt)))),
599         (VT (MI IntRegs:$Rs, IntRegs:$Rt, 0))>;
600
601 let AddedComplexity = 20 in {
602   def: Loadxs_simple_pat<extloadi8,   i32, L4_loadrub_rr>;
603   def: Loadxs_simple_pat<zextloadi8,  i32, L4_loadrub_rr>;
604   def: Loadxs_simple_pat<sextloadi8,  i32, L4_loadrb_rr>;
605   def: Loadxs_simple_pat<extloadi16,  i32, L4_loadruh_rr>;
606   def: Loadxs_simple_pat<zextloadi16, i32, L4_loadruh_rr>;
607   def: Loadxs_simple_pat<sextloadi16, i32, L4_loadrh_rr>;
608   def: Loadxs_simple_pat<load,        i32, L4_loadri_rr>;
609   def: Loadxs_simple_pat<load,        i64, L4_loadrd_rr>;
610 }
611
612 // zext i1->i64
613 def: Pat<(i64 (zext (i1 PredRegs:$src1))),
614          (Zext64 (C2_muxii PredRegs:$src1, 1, 0))>;
615
616 // zext i32->i64
617 def: Pat<(i64 (zext (i32 IntRegs:$src1))),
618          (Zext64 IntRegs:$src1)>;
619
620 // zext i32->i64
621 def:  Pat <(i64 (zextloadi32 ADDRriS11_2:$src1)),
622       (i64 (A4_combineir 0, (L2_loadri_io AddrFI:$src1, 0)))>,
623       Requires<[HasV4T]>;
624
625 let AddedComplexity = 100 in
626 def:  Pat <(i64 (zextloadi32 (i32 (add IntRegs:$src1, s11_2ExtPred:$offset)))),
627       (i64 (A4_combineir 0, (L2_loadri_io IntRegs:$src1,
628                                   s11_2ExtPred:$offset)))>,
629       Requires<[HasV4T]>;
630
631 // anyext i32->i64
632 def:  Pat <(i64 (extloadi32 ADDRriS11_2:$src1)),
633       (i64 (A4_combineir 0, (L2_loadri_io AddrFI:$src1, 0)))>,
634       Requires<[HasV4T]>;
635
636 let AddedComplexity = 100 in
637 def:  Pat <(i64 (extloadi32 (i32 (add IntRegs:$src1, s11_2ExtPred:$offset)))),
638       (i64 (A4_combineir 0, (L2_loadri_io IntRegs:$src1,
639                                   s11_2ExtPred:$offset)))>,
640       Requires<[HasV4T]>;
641
642
643
644 //===----------------------------------------------------------------------===//
645 // LD -
646 //===----------------------------------------------------------------------===//
647
648 //===----------------------------------------------------------------------===//
649 // ST +
650 //===----------------------------------------------------------------------===//
651 ///
652 //===----------------------------------------------------------------------===//
653 // Template class for store instructions with Absolute set addressing mode.
654 //===----------------------------------------------------------------------===//
655 let isExtended = 1, opExtendable = 1, opExtentBits = 6,
656     addrMode = AbsoluteSet, isNVStorable = 1 in
657 class T_ST_absset <string mnemonic, string BaseOp, RegisterClass RC,
658                    bits<3> MajOp, MemAccessSize AccessSz, bit isHalf = 0>
659   : STInst<(outs IntRegs:$dst),
660            (ins u6Ext:$addr, RC:$src),
661     mnemonic#"($dst = #$addr) = $src"#!if(isHalf, ".h","")>, NewValueRel {
662     bits<5> dst;
663     bits<6> addr;
664     bits<5> src;
665     let accessSize = AccessSz;
666     let BaseOpcode = BaseOp#"_AbsSet";
667
668     let IClass = 0b1010;
669
670     let Inst{27-24} = 0b1011;
671     let Inst{23-21} = MajOp;
672     let Inst{20-16} = dst;
673     let Inst{13}    = 0b0;
674     let Inst{12-8}  = src;
675     let Inst{7}     = 0b1;
676     let Inst{5-0}   = addr;
677   }
678
679 def S4_storerb_ap : T_ST_absset <"memb", "STrib", IntRegs, 0b000, ByteAccess>;
680 def S4_storerh_ap : T_ST_absset <"memh", "STrih", IntRegs, 0b010,
681                                  HalfWordAccess>;
682 def S4_storeri_ap : T_ST_absset <"memw", "STriw", IntRegs, 0b100, WordAccess>;
683
684 let isNVStorable = 0 in {
685   def S4_storerf_ap : T_ST_absset <"memh", "STrif", IntRegs,
686                                    0b011, HalfWordAccess, 1>;
687   def S4_storerd_ap : T_ST_absset <"memd", "STrid", DoubleRegs,
688                                    0b110, DoubleWordAccess>;
689 }
690
691 let opExtendable = 1, isNewValue = 1, isNVStore = 1, opNewValue = 2,
692 isExtended = 1, opExtentBits= 6 in
693 class T_ST_absset_nv <string mnemonic, string BaseOp, bits<2> MajOp,
694                       MemAccessSize AccessSz >
695   : NVInst <(outs IntRegs:$dst),
696             (ins u6Ext:$addr, IntRegs:$src),
697     mnemonic#"($dst = #$addr) = $src.new">, NewValueRel {
698     bits<5> dst;
699     bits<6> addr;
700     bits<3> src;
701     let accessSize = AccessSz;
702     let BaseOpcode = BaseOp#"_AbsSet";
703
704     let IClass = 0b1010;
705
706     let Inst{27-21} = 0b1011101;
707     let Inst{20-16} = dst;
708     let Inst{13-11} = 0b000;
709     let Inst{12-11} = MajOp;
710     let Inst{10-8}  = src;
711     let Inst{7}     = 0b1;
712     let Inst{5-0}   = addr;
713   }
714
715 let mayStore = 1, addrMode = AbsoluteSet in {
716   def S4_storerbnew_ap : T_ST_absset_nv <"memb", "STrib", 0b00, ByteAccess>;
717   def S4_storerhnew_ap : T_ST_absset_nv <"memh", "STrih", 0b01, HalfWordAccess>;
718   def S4_storerinew_ap : T_ST_absset_nv <"memw", "STriw", 0b10, WordAccess>;
719 }
720
721 let isExtended = 1, opExtendable = 2, opExtentBits = 6, InputType = "imm",
722 addrMode = BaseLongOffset, AddedComplexity = 40 in
723 class T_StoreAbsReg <string mnemonic, string CextOp, RegisterClass RC,
724                      bits<3> MajOp, MemAccessSize AccessSz, bit isHalf = 0>
725   : STInst<(outs),
726            (ins IntRegs:$src1, u2Imm:$src2, u6Ext:$src3, RC:$src4),
727    mnemonic#"($src1<<#$src2 + #$src3) = $src4"#!if(isHalf, ".h",""),
728    []>, ImmRegShl, NewValueRel {
729
730     bits<5> src1;
731     bits<2> src2;
732     bits<6> src3;
733     bits<5> src4;
734
735     let accessSize = AccessSz;
736     let CextOpcode = CextOp;
737     let BaseOpcode = CextOp#"_shl";
738     let IClass = 0b1010;
739
740     let Inst{27-24} =0b1101;
741     let Inst{23-21} = MajOp;
742     let Inst{20-16} = src1;
743     let Inst{13}    = src2{1};
744     let Inst{12-8}  = src4;
745     let Inst{7}     = 0b1;
746     let Inst{6}     = src2{0};
747     let Inst{5-0}   = src3;
748 }
749
750 def S4_storerb_ur : T_StoreAbsReg <"memb", "STrib", IntRegs, 0b000, ByteAccess>;
751 def S4_storerh_ur : T_StoreAbsReg <"memh", "STrih", IntRegs, 0b010,
752                                    HalfWordAccess>;
753 def S4_storerf_ur : T_StoreAbsReg <"memh", "STrif", IntRegs, 0b011,
754                                    HalfWordAccess, 1>;
755 def S4_storeri_ur : T_StoreAbsReg <"memw", "STriw", IntRegs, 0b100, WordAccess>;
756 def S4_storerd_ur : T_StoreAbsReg <"memd", "STrid", DoubleRegs, 0b110,
757                                    DoubleWordAccess>;
758
759 let AddedComplexity = 40 in
760 multiclass T_StoreAbsReg_Pats <InstHexagon MI, RegisterClass RC, ValueType VT,
761                            PatFrag stOp> {
762  def : Pat<(stOp (VT RC:$src4),
763                  (add (shl (i32 IntRegs:$src1), u2ImmPred:$src2),
764                       u0AlwaysExtPred:$src3)),
765           (MI IntRegs:$src1, u2ImmPred:$src2, u0AlwaysExtPred:$src3, RC:$src4)>;
766
767  def : Pat<(stOp (VT RC:$src4),
768                  (add (shl IntRegs:$src1, u2ImmPred:$src2),
769                       (HexagonCONST32 tglobaladdr:$src3))),
770            (MI IntRegs:$src1, u2ImmPred:$src2, tglobaladdr:$src3, RC:$src4)>;
771
772  def : Pat<(stOp (VT RC:$src4),
773                  (add IntRegs:$src1, (HexagonCONST32 tglobaladdr:$src3))),
774            (MI IntRegs:$src1, 0, tglobaladdr:$src3, RC:$src4)>;
775 }
776
777 defm : T_StoreAbsReg_Pats <S4_storerd_ur, DoubleRegs, i64, store>;
778 defm : T_StoreAbsReg_Pats <S4_storeri_ur, IntRegs, i32, store>;
779 defm : T_StoreAbsReg_Pats <S4_storerb_ur, IntRegs, i32, truncstorei8>;
780 defm : T_StoreAbsReg_Pats <S4_storerh_ur, IntRegs, i32, truncstorei16>;
781
782 let mayStore = 1, isNVStore = 1, isExtended = 1, addrMode = BaseLongOffset,
783     opExtentBits = 6, isNewValue = 1, opNewValue = 3, opExtendable = 2 in
784 class T_StoreAbsRegNV <string mnemonic, string CextOp, bits<2> MajOp,
785                        MemAccessSize AccessSz>
786   : NVInst <(outs ),
787             (ins IntRegs:$src1, u2Imm:$src2, u6Ext:$src3, IntRegs:$src4),
788   mnemonic#"($src1<<#$src2 + #$src3) = $src4.new">, NewValueRel {
789     bits<5> src1;
790     bits<2> src2;
791     bits<6> src3;
792     bits<3> src4;
793
794     let CextOpcode  = CextOp;
795     let BaseOpcode  = CextOp#"_shl";
796     let IClass      = 0b1010;
797
798     let Inst{27-21} = 0b1101101;
799     let Inst{12-11} = 0b00;
800     let Inst{7}     = 0b1;
801     let Inst{20-16} = src1;
802     let Inst{13}    = src2{1};
803     let Inst{12-11} = MajOp;
804     let Inst{10-8}  = src4;
805     let Inst{6}     = src2{0};
806     let Inst{5-0}   = src3;
807   }
808
809 def S4_storerbnew_ur : T_StoreAbsRegNV <"memb", "STrib", 0b00, ByteAccess>;
810 def S4_storerhnew_ur : T_StoreAbsRegNV <"memh", "STrih", 0b01, HalfWordAccess>;
811 def S4_storerinew_ur : T_StoreAbsRegNV <"memw", "STriw", 0b10, WordAccess>;
812
813 //===----------------------------------------------------------------------===//
814 // Template classes for the non-predicated store instructions with
815 // base + register offset addressing mode
816 //===----------------------------------------------------------------------===//
817 let isPredicable = 1 in
818 class T_store_rr <string mnemonic, RegisterClass RC, bits<3> MajOp, bit isH>
819   : STInst < (outs ), (ins IntRegs:$Rs, IntRegs:$Ru, u2Imm:$u2, RC:$Rt),
820   mnemonic#"($Rs + $Ru<<#$u2) = $Rt"#!if(isH, ".h",""),
821   [],"",V4LDST_tc_st_SLOT01>, ImmRegShl, AddrModeRel {
822
823     bits<5> Rs;
824     bits<5> Ru;
825     bits<2> u2;
826     bits<5> Rt;
827
828     let IClass = 0b0011;
829
830     let Inst{27-24} = 0b1011;
831     let Inst{23-21} = MajOp;
832     let Inst{20-16} = Rs;
833     let Inst{12-8}  = Ru;
834     let Inst{13}    = u2{1};
835     let Inst{7}     = u2{0};
836     let Inst{4-0}   = Rt;
837   }
838
839 //===----------------------------------------------------------------------===//
840 // Template classes for the predicated store instructions with
841 // base + register offset addressing mode
842 //===----------------------------------------------------------------------===//
843 let isPredicated = 1 in
844 class T_pstore_rr <string mnemonic, RegisterClass RC, bits<3> MajOp,
845                    bit isNot, bit isPredNew, bit isH>
846   : STInst <(outs),
847             (ins PredRegs:$Pv, IntRegs:$Rs, IntRegs:$Ru, u2Imm:$u2, RC:$Rt),
848
849   !if(isNot, "if (!$Pv", "if ($Pv")#!if(isPredNew, ".new) ",
850   ") ")#mnemonic#"($Rs+$Ru<<#$u2) = $Rt"#!if(isH, ".h",""),
851   [], "", V4LDST_tc_st_SLOT01> , AddrModeRel{
852     bits<2> Pv;
853     bits<5> Rs;
854     bits<5> Ru;
855     bits<2> u2;
856     bits<5> Rt;
857
858     let isPredicatedFalse = isNot;
859     let isPredicatedNew = isPredNew;
860
861     let IClass = 0b0011;
862
863     let Inst{27-26} = 0b01;
864     let Inst{25}    = isPredNew;
865     let Inst{24}    = isNot;
866     let Inst{23-21} = MajOp;
867     let Inst{20-16} = Rs;
868     let Inst{12-8}  = Ru;
869     let Inst{13}    = u2{1};
870     let Inst{7}     = u2{0};
871     let Inst{6-5}   = Pv;
872     let Inst{4-0}   = Rt;
873   }
874
875 //===----------------------------------------------------------------------===//
876 // Template classes for the new-value store instructions with
877 // base + register offset addressing mode
878 //===----------------------------------------------------------------------===//
879 let isPredicable = 1, isNewValue = 1, opNewValue = 3 in
880 class T_store_new_rr <string mnemonic, bits<2> MajOp> :
881   NVInst < (outs ), (ins IntRegs:$Rs, IntRegs:$Ru, u2Imm:$u2, IntRegs:$Nt),
882   mnemonic#"($Rs + $Ru<<#$u2) = $Nt.new",
883   [],"",V4LDST_tc_st_SLOT0>, ImmRegShl, AddrModeRel {
884
885     bits<5> Rs;
886     bits<5> Ru;
887     bits<2> u2;
888     bits<3> Nt;
889
890     let IClass = 0b0011;
891
892     let Inst{27-21} = 0b1011101;
893     let Inst{20-16} = Rs;
894     let Inst{12-8}  = Ru;
895     let Inst{13}    = u2{1};
896     let Inst{7}     = u2{0};
897     let Inst{4-3}   = MajOp;
898     let Inst{2-0}   = Nt;
899   }
900
901 //===----------------------------------------------------------------------===//
902 // Template classes for the predicated new-value store instructions with
903 // base + register offset addressing mode
904 //===----------------------------------------------------------------------===//
905 let isPredicated = 1, isNewValue = 1, opNewValue = 4 in
906 class T_pstore_new_rr <string mnemonic, bits<2> MajOp, bit isNot, bit isPredNew>
907   : NVInst<(outs),
908            (ins PredRegs:$Pv, IntRegs:$Rs, IntRegs:$Ru, u2Imm:$u2, IntRegs:$Nt),
909    !if(isNot, "if (!$Pv", "if ($Pv")#!if(isPredNew, ".new) ",
910    ") ")#mnemonic#"($Rs+$Ru<<#$u2) = $Nt.new",
911    [], "", V4LDST_tc_st_SLOT0>, AddrModeRel {
912     bits<2> Pv;
913     bits<5> Rs;
914     bits<5> Ru;
915     bits<2> u2;
916     bits<3> Nt;
917
918     let isPredicatedFalse = isNot;
919     let isPredicatedNew = isPredNew;
920
921     let IClass = 0b0011;
922     let Inst{27-26} = 0b01;
923     let Inst{25}    = isPredNew;
924     let Inst{24}    = isNot;
925     let Inst{23-21} = 0b101;
926     let Inst{20-16} = Rs;
927     let Inst{12-8}  = Ru;
928     let Inst{13}    = u2{1};
929     let Inst{7}     = u2{0};
930     let Inst{6-5}   = Pv;
931     let Inst{4-3}   = MajOp;
932     let Inst{2-0}   = Nt;
933   }
934
935 //===----------------------------------------------------------------------===//
936 // multiclass for store instructions with base + register offset addressing
937 // mode
938 //===----------------------------------------------------------------------===//
939 let isNVStorable = 1 in
940 multiclass ST_Idxd_shl<string mnemonic, string CextOp, RegisterClass RC,
941                        bits<3> MajOp, bit isH = 0> {
942   let CextOpcode = CextOp, BaseOpcode = CextOp#_indexed_shl in {
943     def S4_#NAME#_rr : T_store_rr <mnemonic, RC, MajOp, isH>;
944
945     // Predicated
946     def S4_p#NAME#t_rr : T_pstore_rr <mnemonic, RC, MajOp, 0, 0, isH>;
947     def S4_p#NAME#f_rr : T_pstore_rr <mnemonic, RC, MajOp, 1, 0, isH>;
948
949     // Predicated new
950     def S4_p#NAME#tnew_rr : T_pstore_rr <mnemonic, RC, MajOp, 0, 1, isH>;
951     def S4_p#NAME#fnew_rr : T_pstore_rr <mnemonic, RC, MajOp, 1, 1, isH>;
952   }
953 }
954
955 //===----------------------------------------------------------------------===//
956 // multiclass for new-value store instructions with base + register offset
957 // addressing mode.
958 //===----------------------------------------------------------------------===//
959 let mayStore = 1, isNVStore = 1 in
960 multiclass ST_Idxd_shl_nv <string mnemonic, string CextOp, RegisterClass RC,
961                            bits<2> MajOp> {
962   let CextOpcode = CextOp, BaseOpcode = CextOp#_indexed_shl in {
963     def S4_#NAME#new_rr : T_store_new_rr<mnemonic, MajOp>;
964
965     // Predicated
966     def S4_p#NAME#newt_rr : T_pstore_new_rr <mnemonic, MajOp, 0, 0>;
967     def S4_p#NAME#newf_rr : T_pstore_new_rr <mnemonic, MajOp, 1, 0>;
968
969     // Predicated new
970     def S4_p#NAME#newtnew_rr : T_pstore_new_rr <mnemonic, MajOp, 0, 1>;
971     def S4_p#NAME#newfnew_rr : T_pstore_new_rr <mnemonic, MajOp, 1, 1>;
972   }
973 }
974
975 let addrMode = BaseRegOffset, InputType = "reg", hasSideEffects = 0 in {
976   let accessSize = ByteAccess in
977   defm storerb: ST_Idxd_shl<"memb", "STrib", IntRegs, 0b000>,
978                 ST_Idxd_shl_nv<"memb", "STrib", IntRegs, 0b00>;
979
980   let accessSize = HalfWordAccess in
981   defm storerh: ST_Idxd_shl<"memh", "STrih", IntRegs, 0b010>,
982                 ST_Idxd_shl_nv<"memh", "STrih", IntRegs, 0b01>;
983
984   let accessSize = WordAccess in
985   defm storeri: ST_Idxd_shl<"memw", "STriw", IntRegs, 0b100>,
986                 ST_Idxd_shl_nv<"memw", "STriw", IntRegs, 0b10>;
987
988   let isNVStorable = 0, accessSize = DoubleWordAccess in
989   defm storerd: ST_Idxd_shl<"memd", "STrid", DoubleRegs, 0b110>;
990
991   let isNVStorable = 0, accessSize = HalfWordAccess in
992   defm storerf: ST_Idxd_shl<"memh", "STrif", IntRegs, 0b011, 1>;
993 }
994
995 class Storexs_pat<PatFrag Store, PatFrag Value, InstHexagon MI>
996   : Pat<(Store Value:$Ru, (add (i32 IntRegs:$Rs),
997                                (i32 (shl (i32 IntRegs:$Rt), u2ImmPred:$u2)))),
998         (MI IntRegs:$Rs, IntRegs:$Rt, imm:$u2, Value:$Ru)>;
999
1000 let AddedComplexity = 40 in {
1001   def: Storexs_pat<truncstorei8,  I32, S4_storerb_rr>;
1002   def: Storexs_pat<truncstorei16, I32, S4_storerh_rr>;
1003   def: Storexs_pat<store,         I32, S4_storeri_rr>;
1004   def: Storexs_pat<store,         I64, S4_storerd_rr>;
1005 }
1006
1007 // memd(Rx++#s4:3)=Rtt
1008 // memd(Rx++#s4:3:circ(Mu))=Rtt
1009 // memd(Rx++I:circ(Mu))=Rtt
1010 // memd(Rx++Mu)=Rtt
1011 // memd(Rx++Mu:brev)=Rtt
1012 // memd(gp+#u16:3)=Rtt
1013
1014 // Store doubleword conditionally.
1015 // if ([!]Pv[.new]) memd(#u6)=Rtt
1016 // TODO: needs to be implemented.
1017
1018 //===----------------------------------------------------------------------===//
1019 // Template class
1020 //===----------------------------------------------------------------------===//
1021 let isPredicable = 1, isExtendable = 1, isExtentSigned = 1, opExtentBits = 8,
1022     opExtendable = 2 in
1023 class T_StoreImm <string mnemonic, Operand OffsetOp, bits<2> MajOp >
1024   : STInst <(outs ), (ins IntRegs:$Rs, OffsetOp:$offset, s8Ext:$S8),
1025   mnemonic#"($Rs+#$offset)=#$S8",
1026   [], "", V4LDST_tc_st_SLOT01>,
1027   ImmRegRel, PredNewRel {
1028     bits<5> Rs;
1029     bits<8> S8;
1030     bits<8> offset;
1031     bits<6> offsetBits;
1032
1033     string OffsetOpStr = !cast<string>(OffsetOp);
1034     let offsetBits = !if (!eq(OffsetOpStr, "u6_2Imm"), offset{7-2},
1035                      !if (!eq(OffsetOpStr, "u6_1Imm"), offset{6-1},
1036                                          /* u6_0Imm */ offset{5-0}));
1037
1038     let IClass = 0b0011;
1039
1040     let Inst{27-25} = 0b110;
1041     let Inst{22-21} = MajOp;
1042     let Inst{20-16} = Rs;
1043     let Inst{12-7}  = offsetBits;
1044     let Inst{13}    = S8{7};
1045     let Inst{6-0}   = S8{6-0};
1046   }
1047
1048 let isPredicated = 1, isExtendable = 1, isExtentSigned = 1, opExtentBits = 6,
1049     opExtendable = 3 in
1050 class T_StoreImm_pred <string mnemonic, Operand OffsetOp, bits<2> MajOp,
1051                        bit isPredNot, bit isPredNew >
1052   : STInst <(outs ),
1053             (ins PredRegs:$Pv, IntRegs:$Rs, OffsetOp:$offset, s6Ext:$S6),
1054   !if(isPredNot, "if (!$Pv", "if ($Pv")#!if(isPredNew, ".new) ",
1055   ") ")#mnemonic#"($Rs+#$offset)=#$S6",
1056   [], "", V4LDST_tc_st_SLOT01>,
1057   ImmRegRel, PredNewRel {
1058     bits<2> Pv;
1059     bits<5> Rs;
1060     bits<6> S6;
1061     bits<8> offset;
1062     bits<6> offsetBits;
1063
1064     string OffsetOpStr = !cast<string>(OffsetOp);
1065     let offsetBits = !if (!eq(OffsetOpStr, "u6_2Imm"), offset{7-2},
1066                      !if (!eq(OffsetOpStr, "u6_1Imm"), offset{6-1},
1067                                          /* u6_0Imm */ offset{5-0}));
1068     let isPredicatedNew = isPredNew;
1069     let isPredicatedFalse = isPredNot;
1070
1071     let IClass = 0b0011;
1072
1073     let Inst{27-25} = 0b100;
1074     let Inst{24}    = isPredNew;
1075     let Inst{23}    = isPredNot;
1076     let Inst{22-21} = MajOp;
1077     let Inst{20-16} = Rs;
1078     let Inst{13}    = S6{5};
1079     let Inst{12-7}  = offsetBits;
1080     let Inst{6-5}   = Pv;
1081     let Inst{4-0}   = S6{4-0};
1082   }
1083
1084
1085 //===----------------------------------------------------------------------===//
1086 // multiclass for store instructions with base + immediate offset
1087 // addressing mode and immediate stored value.
1088 // mem[bhw](Rx++#s4:3)=#s8
1089 // if ([!]Pv[.new]) mem[bhw](Rx++#s4:3)=#s6
1090 //===----------------------------------------------------------------------===//
1091
1092 multiclass ST_Imm_Pred <string mnemonic, Operand OffsetOp, bits<2> MajOp,
1093                         bit PredNot> {
1094   def _io    : T_StoreImm_pred <mnemonic, OffsetOp, MajOp, PredNot, 0>;
1095   // Predicate new
1096   def new_io : T_StoreImm_pred <mnemonic, OffsetOp, MajOp, PredNot, 1>;
1097 }
1098
1099 multiclass ST_Imm <string mnemonic, string CextOp, Operand OffsetOp,
1100                    bits<2> MajOp> {
1101   let CextOpcode = CextOp, BaseOpcode = CextOp#_imm in {
1102     def _io : T_StoreImm <mnemonic, OffsetOp, MajOp>;
1103
1104     defm t : ST_Imm_Pred <mnemonic, OffsetOp, MajOp, 0>;
1105     defm f : ST_Imm_Pred <mnemonic, OffsetOp, MajOp, 1>;
1106   }
1107 }
1108
1109 let hasSideEffects = 0, validSubTargets = HasV4SubT, addrMode = BaseImmOffset,
1110     InputType = "imm" in {
1111   let accessSize = ByteAccess in
1112   defm S4_storeirb : ST_Imm<"memb", "STrib", u6_0Imm, 0b00>;
1113
1114   let accessSize = HalfWordAccess in
1115   defm S4_storeirh : ST_Imm<"memh", "STrih", u6_1Imm, 0b01>;
1116
1117   let accessSize = WordAccess in
1118   defm S4_storeiri : ST_Imm<"memw", "STriw", u6_2Imm, 0b10>;
1119 }
1120
1121 let Predicates = [HasV4T], AddedComplexity = 10 in {
1122 def: Pat<(truncstorei8 s8ExtPred:$src3, (add IntRegs:$src1, u6_0ImmPred:$src2)),
1123             (S4_storeirb_io IntRegs:$src1, u6_0ImmPred:$src2, s8ExtPred:$src3)>;
1124
1125 def: Pat<(truncstorei16 s8ExtPred:$src3, (add IntRegs:$src1,
1126                                               u6_1ImmPred:$src2)),
1127             (S4_storeirh_io IntRegs:$src1, u6_1ImmPred:$src2, s8ExtPred:$src3)>;
1128
1129 def: Pat<(store s8ExtPred:$src3, (add IntRegs:$src1, u6_2ImmPred:$src2)),
1130             (S4_storeiri_io IntRegs:$src1, u6_2ImmPred:$src2, s8ExtPred:$src3)>;
1131 }
1132
1133 let AddedComplexity = 6 in
1134 def : Pat <(truncstorei8 s8ExtPred:$src2, (i32 IntRegs:$src1)),
1135            (S4_storeirb_io IntRegs:$src1, 0, s8ExtPred:$src2)>,
1136            Requires<[HasV4T]>;
1137
1138 // memb(Rx++#s4:0:circ(Mu))=Rt
1139 // memb(Rx++I:circ(Mu))=Rt
1140 // memb(Rx++Mu)=Rt
1141 // memb(Rx++Mu:brev)=Rt
1142 // memb(gp+#u16:0)=Rt
1143
1144
1145 // Store halfword.
1146 // TODO: needs to be implemented
1147 // memh(Re=#U6)=Rt.H
1148 // memh(Rs+#s11:1)=Rt.H
1149 let AddedComplexity = 6 in
1150 def : Pat <(truncstorei16 s8ExtPred:$src2, (i32 IntRegs:$src1)),
1151            (S4_storeirh_io IntRegs:$src1, 0, s8ExtPred:$src2)>,
1152            Requires<[HasV4T]>;
1153
1154 // memh(Rs+Ru<<#u2)=Rt.H
1155 // TODO: needs to be implemented.
1156
1157 // memh(Ru<<#u2+#U6)=Rt.H
1158 // memh(Rx++#s4:1:circ(Mu))=Rt.H
1159 // memh(Rx++#s4:1:circ(Mu))=Rt
1160 // memh(Rx++I:circ(Mu))=Rt.H
1161 // memh(Rx++I:circ(Mu))=Rt
1162 // memh(Rx++Mu)=Rt.H
1163 // memh(Rx++Mu)=Rt
1164 // memh(Rx++Mu:brev)=Rt.H
1165 // memh(Rx++Mu:brev)=Rt
1166 // memh(gp+#u16:1)=Rt
1167 // if ([!]Pv[.new]) memh(#u6)=Rt.H
1168 // if ([!]Pv[.new]) memh(#u6)=Rt
1169
1170
1171 // if ([!]Pv[.new]) memh(Rs+#u6:1)=Rt.H
1172 // TODO: needs to be implemented.
1173
1174 // if ([!]Pv[.new]) memh(Rx++#s4:1)=Rt.H
1175 // TODO: Needs to be implemented.
1176
1177 // Store word.
1178 // memw(Re=#U6)=Rt
1179 // TODO: Needs to be implemented.
1180
1181 let AddedComplexity = 6 in
1182 def : Pat <(store s8ExtPred:$src2, (i32 IntRegs:$src1)),
1183            (S4_storeiri_io IntRegs:$src1, 0, s8ExtPred:$src2)>,
1184            Requires<[HasV4T]>;
1185
1186 // memw(Rx++#s4:2)=Rt
1187 // memw(Rx++#s4:2:circ(Mu))=Rt
1188 // memw(Rx++I:circ(Mu))=Rt
1189 // memw(Rx++Mu)=Rt
1190 // memw(Rx++Mu:brev)=Rt
1191
1192 //===----------------------------------------------------------------------===
1193 // ST -
1194 //===----------------------------------------------------------------------===
1195
1196
1197 //===----------------------------------------------------------------------===//
1198 // NV/ST +
1199 //===----------------------------------------------------------------------===//
1200
1201 let opNewValue = 2, opExtendable = 1, isExtentSigned = 1, isPredicable = 1 in
1202 class T_store_io_nv <string mnemonic, RegisterClass RC,
1203                     Operand ImmOp, bits<2>MajOp>
1204   : NVInst_V4 <(outs),
1205                (ins IntRegs:$src1, ImmOp:$src2, RC:$src3),
1206   mnemonic#"($src1+#$src2) = $src3.new",
1207   [],"",ST_tc_st_SLOT0> {
1208     bits<5> src1;
1209     bits<13> src2; // Actual address offset
1210     bits<3> src3;
1211     bits<11> offsetBits; // Represents offset encoding
1212
1213     let opExtentBits = !if (!eq(mnemonic, "memb"), 11,
1214                        !if (!eq(mnemonic, "memh"), 12,
1215                        !if (!eq(mnemonic, "memw"), 13, 0)));
1216
1217     let opExtentAlign = !if (!eq(mnemonic, "memb"), 0,
1218                         !if (!eq(mnemonic, "memh"), 1,
1219                         !if (!eq(mnemonic, "memw"), 2, 0)));
1220
1221     let offsetBits = !if (!eq(mnemonic, "memb"),  src2{10-0},
1222                      !if (!eq(mnemonic, "memh"),  src2{11-1},
1223                      !if (!eq(mnemonic, "memw"),  src2{12-2}, 0)));
1224
1225     let IClass = 0b1010;
1226
1227     let Inst{27} = 0b0;
1228     let Inst{26-25} = offsetBits{10-9};
1229     let Inst{24-21} = 0b1101;
1230     let Inst{20-16} = src1;
1231     let Inst{13} = offsetBits{8};
1232     let Inst{12-11} = MajOp;
1233     let Inst{10-8} = src3;
1234     let Inst{7-0} = offsetBits{7-0};
1235   }
1236
1237 let opExtendable = 2, opNewValue = 3, isPredicated = 1 in
1238 class T_pstore_io_nv <string mnemonic, RegisterClass RC, Operand predImmOp,
1239                          bits<2>MajOp, bit PredNot, bit isPredNew>
1240   : NVInst_V4 <(outs),
1241                (ins PredRegs:$src1, IntRegs:$src2, predImmOp:$src3, RC:$src4),
1242   !if(PredNot, "if (!$src1", "if ($src1")#!if(isPredNew, ".new) ",
1243   ") ")#mnemonic#"($src2+#$src3) = $src4.new",
1244   [],"",V2LDST_tc_st_SLOT0> {
1245     bits<2> src1;
1246     bits<5> src2;
1247     bits<9> src3;
1248     bits<3> src4;
1249     bits<6> offsetBits; // Represents offset encoding
1250
1251     let isPredicatedNew = isPredNew;
1252     let isPredicatedFalse = PredNot;
1253     let opExtentBits = !if (!eq(mnemonic, "memb"), 6,
1254                        !if (!eq(mnemonic, "memh"), 7,
1255                        !if (!eq(mnemonic, "memw"), 8, 0)));
1256
1257     let opExtentAlign = !if (!eq(mnemonic, "memb"), 0,
1258                         !if (!eq(mnemonic, "memh"), 1,
1259                         !if (!eq(mnemonic, "memw"), 2, 0)));
1260
1261     let offsetBits = !if (!eq(mnemonic, "memb"), src3{5-0},
1262                      !if (!eq(mnemonic, "memh"), src3{6-1},
1263                      !if (!eq(mnemonic, "memw"), src3{7-2}, 0)));
1264
1265     let IClass = 0b0100;
1266
1267     let Inst{27}    = 0b0;
1268     let Inst{26}    = PredNot;
1269     let Inst{25}    = isPredNew;
1270     let Inst{24-21} = 0b0101;
1271     let Inst{20-16} = src2;
1272     let Inst{13}    = offsetBits{5};
1273     let Inst{12-11} = MajOp;
1274     let Inst{10-8}  = src4;
1275     let Inst{7-3}   = offsetBits{4-0};
1276     let Inst{2}     = 0b0;
1277     let Inst{1-0}   = src1;
1278   }
1279
1280 // multiclass for new-value store instructions with base + immediate offset.
1281 //
1282 let mayStore = 1, isNVStore = 1, isNewValue = 1, hasSideEffects = 0,
1283     isExtendable = 1 in
1284 multiclass ST_Idxd_nv<string mnemonic, string CextOp, RegisterClass RC,
1285                    Operand ImmOp, Operand predImmOp, bits<2> MajOp> {
1286
1287   let CextOpcode = CextOp, BaseOpcode = CextOp#_indexed in {
1288     def S2_#NAME#new_io : T_store_io_nv <mnemonic, RC, ImmOp, MajOp>;
1289     // Predicated
1290     def S2_p#NAME#newt_io :T_pstore_io_nv <mnemonic, RC, predImmOp, MajOp, 0, 0>;
1291     def S2_p#NAME#newf_io :T_pstore_io_nv <mnemonic, RC, predImmOp, MajOp, 1, 0>;
1292     // Predicated new
1293     def S4_p#NAME#newtnew_io :T_pstore_io_nv <mnemonic, RC, predImmOp,
1294                                               MajOp, 0, 1>;
1295     def S4_p#NAME#newfnew_io :T_pstore_io_nv <mnemonic, RC, predImmOp,
1296                                               MajOp, 1, 1>;
1297   }
1298 }
1299
1300 let addrMode = BaseImmOffset, InputType = "imm" in {
1301   let accessSize = ByteAccess in
1302   defm storerb: ST_Idxd_nv<"memb", "STrib", IntRegs, s11_0Ext,
1303                            u6_0Ext, 0b00>, AddrModeRel;
1304
1305   let accessSize = HalfWordAccess, opExtentAlign = 1 in
1306   defm storerh: ST_Idxd_nv<"memh", "STrih", IntRegs, s11_1Ext,
1307                            u6_1Ext, 0b01>, AddrModeRel;
1308
1309   let accessSize = WordAccess, opExtentAlign = 2 in
1310   defm storeri: ST_Idxd_nv<"memw", "STriw", IntRegs, s11_2Ext,
1311                            u6_2Ext, 0b10>, AddrModeRel;
1312 }
1313
1314 //===----------------------------------------------------------------------===//
1315 // Post increment loads with register offset.
1316 //===----------------------------------------------------------------------===//
1317
1318 let hasNewValue = 1 in
1319 def L2_loadbsw2_pr : T_load_pr <"membh", IntRegs, 0b0001, HalfWordAccess>;
1320
1321 def L2_loadbsw4_pr : T_load_pr <"membh", DoubleRegs, 0b0111, WordAccess>;
1322
1323 //===----------------------------------------------------------------------===//
1324 // Template class for non-predicated post increment .new stores
1325 // mem[bhwd](Rx++#s4:[0123])=Nt.new
1326 //===----------------------------------------------------------------------===//
1327 let isPredicable = 1, hasSideEffects = 0, validSubTargets = HasV4SubT,
1328     addrMode = PostInc, isNVStore = 1, isNewValue = 1, opNewValue = 3 in
1329 class T_StorePI_nv <string mnemonic, Operand ImmOp, bits<2> MajOp >
1330   : NVInstPI_V4 <(outs IntRegs:$_dst_),
1331                  (ins IntRegs:$src1, ImmOp:$offset, IntRegs:$src2),
1332   mnemonic#"($src1++#$offset) = $src2.new",
1333   [], "$src1 = $_dst_">,
1334   AddrModeRel {
1335     bits<5> src1;
1336     bits<3> src2;
1337     bits<7> offset;
1338     bits<4> offsetBits;
1339
1340     string ImmOpStr = !cast<string>(ImmOp);
1341     let offsetBits = !if (!eq(ImmOpStr, "s4_2Imm"), offset{5-2},
1342                      !if (!eq(ImmOpStr, "s4_1Imm"), offset{4-1},
1343                                       /* s4_0Imm */ offset{3-0}));
1344     let IClass = 0b1010;
1345
1346     let Inst{27-21} = 0b1011101;
1347     let Inst{20-16} = src1;
1348     let Inst{13} = 0b0;
1349     let Inst{12-11} = MajOp;
1350     let Inst{10-8} = src2;
1351     let Inst{7} = 0b0;
1352     let Inst{6-3} = offsetBits;
1353     let Inst{1} = 0b0;
1354   }
1355
1356 //===----------------------------------------------------------------------===//
1357 // Template class for predicated post increment .new stores
1358 // if([!]Pv[.new]) mem[bhwd](Rx++#s4:[0123])=Nt.new
1359 //===----------------------------------------------------------------------===//
1360 let isPredicated = 1, hasSideEffects = 0, validSubTargets = HasV4SubT,
1361     addrMode = PostInc, isNVStore = 1, isNewValue = 1, opNewValue = 4 in
1362 class T_StorePI_nv_pred <string mnemonic, Operand ImmOp,
1363                          bits<2> MajOp, bit isPredNot, bit isPredNew >
1364   : NVInstPI_V4 <(outs IntRegs:$_dst_),
1365                  (ins PredRegs:$src1, IntRegs:$src2,
1366                       ImmOp:$offset, IntRegs:$src3),
1367   !if(isPredNot, "if (!$src1", "if ($src1")#!if(isPredNew, ".new) ",
1368   ") ")#mnemonic#"($src2++#$offset) = $src3.new",
1369   [], "$src2 = $_dst_">,
1370   AddrModeRel {
1371     bits<2> src1;
1372     bits<5> src2;
1373     bits<3> src3;
1374     bits<7> offset;
1375     bits<4> offsetBits;
1376
1377     string ImmOpStr = !cast<string>(ImmOp);
1378     let offsetBits = !if (!eq(ImmOpStr, "s4_2Imm"), offset{5-2},
1379                      !if (!eq(ImmOpStr, "s4_1Imm"), offset{4-1},
1380                                       /* s4_0Imm */ offset{3-0}));
1381     let isPredicatedNew = isPredNew;
1382     let isPredicatedFalse = isPredNot;
1383
1384     let IClass = 0b1010;
1385
1386     let Inst{27-21} = 0b1011101;
1387     let Inst{20-16} = src2;
1388     let Inst{13} = 0b1;
1389     let Inst{12-11} = MajOp;
1390     let Inst{10-8} = src3;
1391     let Inst{7} = isPredNew;
1392     let Inst{6-3} = offsetBits;
1393     let Inst{2} = isPredNot;
1394     let Inst{1-0} = src1;
1395   }
1396
1397 multiclass ST_PostInc_Pred_nv<string mnemonic, Operand ImmOp,
1398                               bits<2> MajOp, bit PredNot> {
1399   def _pi : T_StorePI_nv_pred <mnemonic, ImmOp, MajOp, PredNot, 0>;
1400
1401   // Predicate new
1402   def new_pi : T_StorePI_nv_pred <mnemonic, ImmOp, MajOp, PredNot, 1>;
1403 }
1404
1405 multiclass ST_PostInc_nv<string mnemonic, string BaseOp, Operand ImmOp,
1406                          bits<2> MajOp> {
1407   let BaseOpcode = "POST_"#BaseOp in {
1408     def S2_#NAME#_pi : T_StorePI_nv <mnemonic, ImmOp, MajOp>;
1409
1410     // Predicated
1411     defm S2_p#NAME#t : ST_PostInc_Pred_nv <mnemonic, ImmOp, MajOp, 0>;
1412     defm S2_p#NAME#f : ST_PostInc_Pred_nv <mnemonic, ImmOp, MajOp, 1>;
1413   }
1414 }
1415
1416 let accessSize = ByteAccess in
1417 defm storerbnew: ST_PostInc_nv <"memb", "STrib", s4_0Imm, 0b00>;
1418
1419 let accessSize = HalfWordAccess in
1420 defm storerhnew: ST_PostInc_nv <"memh", "STrih", s4_1Imm, 0b01>;
1421
1422 let accessSize = WordAccess in
1423 defm storerinew: ST_PostInc_nv <"memw", "STriw", s4_2Imm, 0b10>;
1424
1425 //===----------------------------------------------------------------------===//
1426 // Template class for post increment .new stores with register offset
1427 //===----------------------------------------------------------------------===//
1428 let isNewValue = 1, mayStore = 1, isNVStore = 1, opNewValue = 3 in
1429 class T_StorePI_RegNV <string mnemonic, bits<2> MajOp, MemAccessSize AccessSz>
1430   : NVInstPI_V4 <(outs IntRegs:$_dst_),
1431                  (ins IntRegs:$src1, ModRegs:$src2, IntRegs:$src3),
1432   #mnemonic#"($src1++$src2) = $src3.new",
1433   [], "$src1 = $_dst_"> {
1434     bits<5> src1;
1435     bits<1> src2;
1436     bits<3> src3;
1437     let accessSize = AccessSz;
1438
1439     let IClass = 0b1010;
1440
1441     let Inst{27-21} = 0b1101101;
1442     let Inst{20-16} = src1;
1443     let Inst{13}    = src2;
1444     let Inst{12-11} = MajOp;
1445     let Inst{10-8}  = src3;
1446     let Inst{7}     = 0b0;
1447   }
1448
1449 def S2_storerbnew_pr : T_StorePI_RegNV<"memb", 0b00, ByteAccess>;
1450 def S2_storerhnew_pr : T_StorePI_RegNV<"memh", 0b01, HalfWordAccess>;
1451 def S2_storerinew_pr : T_StorePI_RegNV<"memw", 0b10, WordAccess>;
1452
1453 // memb(Rx++#s4:0:circ(Mu))=Nt.new
1454 // memb(Rx++I:circ(Mu))=Nt.new
1455 // memb(Rx++Mu)=Nt.new
1456 // memb(Rx++Mu:brev)=Nt.new
1457 // memh(Rx++#s4:1:circ(Mu))=Nt.new
1458 // memh(Rx++I:circ(Mu))=Nt.new
1459 // memh(Rx++Mu)=Nt.new
1460 // memh(Rx++Mu:brev)=Nt.new
1461
1462 // memw(Rx++#s4:2:circ(Mu))=Nt.new
1463 // memw(Rx++I:circ(Mu))=Nt.new
1464 // memw(Rx++Mu)=Nt.new
1465 // memw(Rx++Mu:brev)=Nt.new
1466
1467 //===----------------------------------------------------------------------===//
1468 // NV/ST -
1469 //===----------------------------------------------------------------------===//
1470
1471 //===----------------------------------------------------------------------===//
1472 // NV/J +
1473 //===----------------------------------------------------------------------===//
1474
1475 //===----------------------------------------------------------------------===//
1476 // multiclass/template class for the new-value compare jumps with the register
1477 // operands.
1478 //===----------------------------------------------------------------------===//
1479
1480 let isExtendable = 1, opExtendable = 2, isExtentSigned = 1, opExtentBits = 11,
1481     opExtentAlign = 2 in
1482 class NVJrr_template<string mnemonic, bits<3> majOp, bit NvOpNum,
1483                       bit isNegCond, bit isTak>
1484   : NVInst_V4<(outs),
1485     (ins IntRegs:$src1, IntRegs:$src2, brtarget:$offset),
1486     "if ("#!if(isNegCond, "!","")#mnemonic#
1487     "($src1"#!if(!eq(NvOpNum, 0),".new, ",", ")#
1488     "$src2"#!if(!eq(NvOpNum, 1),".new))","))")#" jump:"
1489     #!if(isTak, "t","nt")#" $offset", []> {
1490
1491       bits<5> src1;
1492       bits<5> src2;
1493       bits<3> Ns;    // New-Value Operand
1494       bits<5> RegOp; // Non-New-Value Operand
1495       bits<11> offset;
1496
1497       let isTaken = isTak;
1498       let isPredicatedFalse = isNegCond;
1499       let opNewValue{0} = NvOpNum;
1500
1501       let Ns = !if(!eq(NvOpNum, 0), src1{2-0}, src2{2-0});
1502       let RegOp = !if(!eq(NvOpNum, 0), src2, src1);
1503
1504       let IClass = 0b0010;
1505       let Inst{26} = 0b0;
1506       let Inst{25-23} = majOp;
1507       let Inst{22} = isNegCond;
1508       let Inst{18-16} = Ns;
1509       let Inst{13} = isTak;
1510       let Inst{12-8} = RegOp;
1511       let Inst{21-20} = offset{10-9};
1512       let Inst{7-1} = offset{8-2};
1513 }
1514
1515
1516 multiclass NVJrr_cond<string mnemonic, bits<3> majOp, bit NvOpNum,
1517                        bit isNegCond> {
1518   // Branch not taken:
1519   def _nt_V4: NVJrr_template<mnemonic, majOp, NvOpNum, isNegCond, 0>;
1520   // Branch taken:
1521   def _t_V4: NVJrr_template<mnemonic, majOp, NvOpNum, isNegCond, 1>;
1522 }
1523
1524 // NvOpNum = 0 -> First Operand is a new-value Register
1525 // NvOpNum = 1 -> Second Operand is a new-value Register
1526
1527 multiclass NVJrr_base<string mnemonic, string BaseOp, bits<3> majOp,
1528                        bit NvOpNum> {
1529   let BaseOpcode = BaseOp#_NVJ in {
1530     defm _t_Jumpnv : NVJrr_cond<mnemonic, majOp, NvOpNum, 0>; // True cond
1531     defm _f_Jumpnv : NVJrr_cond<mnemonic, majOp, NvOpNum, 1>; // False cond
1532   }
1533 }
1534
1535 // if ([!]cmp.eq(Ns.new,Rt)) jump:[n]t #r9:2
1536 // if ([!]cmp.gt(Ns.new,Rt)) jump:[n]t #r9:2
1537 // if ([!]cmp.gtu(Ns.new,Rt)) jump:[n]t #r9:2
1538 // if ([!]cmp.gt(Rt,Ns.new)) jump:[n]t #r9:2
1539 // if ([!]cmp.gtu(Rt,Ns.new)) jump:[n]t #r9:2
1540
1541 let isPredicated = 1, isBranch = 1, isNewValue = 1, isTerminator = 1,
1542     Defs = [PC], hasSideEffects = 0, validSubTargets = HasV4SubT in {
1543   defm CMPEQrr  : NVJrr_base<"cmp.eq",  "CMPEQ",  0b000, 0>, PredRel;
1544   defm CMPGTrr  : NVJrr_base<"cmp.gt",  "CMPGT",  0b001, 0>, PredRel;
1545   defm CMPGTUrr : NVJrr_base<"cmp.gtu", "CMPGTU", 0b010, 0>, PredRel;
1546   defm CMPLTrr  : NVJrr_base<"cmp.gt",  "CMPLT",  0b011, 1>, PredRel;
1547   defm CMPLTUrr : NVJrr_base<"cmp.gtu", "CMPLTU", 0b100, 1>, PredRel;
1548 }
1549
1550 //===----------------------------------------------------------------------===//
1551 // multiclass/template class for the new-value compare jumps instruction
1552 // with a register and an unsigned immediate (U5) operand.
1553 //===----------------------------------------------------------------------===//
1554
1555 let isExtendable = 1, opExtendable = 2, isExtentSigned = 1, opExtentBits = 11,
1556     opExtentAlign = 2 in
1557 class NVJri_template<string mnemonic, bits<3> majOp, bit isNegCond,
1558                          bit isTak>
1559   : NVInst_V4<(outs),
1560     (ins IntRegs:$src1, u5Imm:$src2, brtarget:$offset),
1561     "if ("#!if(isNegCond, "!","")#mnemonic#"($src1.new, #$src2)) jump:"
1562     #!if(isTak, "t","nt")#" $offset", []> {
1563
1564       let isTaken = isTak;
1565       let isPredicatedFalse = isNegCond;
1566       let isTaken = isTak;
1567
1568       bits<3> src1;
1569       bits<5> src2;
1570       bits<11> offset;
1571
1572       let IClass = 0b0010;
1573       let Inst{26} = 0b1;
1574       let Inst{25-23} = majOp;
1575       let Inst{22} = isNegCond;
1576       let Inst{18-16} = src1;
1577       let Inst{13} = isTak;
1578       let Inst{12-8} = src2;
1579       let Inst{21-20} = offset{10-9};
1580       let Inst{7-1} = offset{8-2};
1581 }
1582
1583 multiclass NVJri_cond<string mnemonic, bits<3> majOp, bit isNegCond> {
1584   // Branch not taken:
1585   def _nt_V4: NVJri_template<mnemonic, majOp, isNegCond, 0>;
1586   // Branch taken:
1587   def _t_V4: NVJri_template<mnemonic, majOp, isNegCond, 1>;
1588 }
1589
1590 multiclass NVJri_base<string mnemonic, string BaseOp, bits<3> majOp> {
1591   let BaseOpcode = BaseOp#_NVJri in {
1592     defm _t_Jumpnv : NVJri_cond<mnemonic, majOp, 0>; // True Cond
1593     defm _f_Jumpnv : NVJri_cond<mnemonic, majOp, 1>; // False cond
1594   }
1595 }
1596
1597 // if ([!]cmp.eq(Ns.new,#U5)) jump:[n]t #r9:2
1598 // if ([!]cmp.gt(Ns.new,#U5)) jump:[n]t #r9:2
1599 // if ([!]cmp.gtu(Ns.new,#U5)) jump:[n]t #r9:2
1600
1601 let isPredicated = 1, isBranch = 1, isNewValue = 1, isTerminator = 1,
1602     Defs = [PC], hasSideEffects = 0, validSubTargets = HasV4SubT in {
1603   defm CMPEQri  : NVJri_base<"cmp.eq", "CMPEQ", 0b000>, PredRel;
1604   defm CMPGTri  : NVJri_base<"cmp.gt", "CMPGT", 0b001>, PredRel;
1605   defm CMPGTUri : NVJri_base<"cmp.gtu", "CMPGTU", 0b010>, PredRel;
1606 }
1607
1608 //===----------------------------------------------------------------------===//
1609 // multiclass/template class for the new-value compare jumps instruction
1610 // with a register and an hardcoded 0/-1 immediate value.
1611 //===----------------------------------------------------------------------===//
1612
1613 let isExtendable = 1, opExtendable = 1, isExtentSigned = 1, opExtentBits = 11,
1614     opExtentAlign = 2 in
1615 class NVJ_ConstImm_template<string mnemonic, bits<3> majOp, string ImmVal,
1616                             bit isNegCond, bit isTak>
1617   : NVInst_V4<(outs),
1618     (ins IntRegs:$src1, brtarget:$offset),
1619     "if ("#!if(isNegCond, "!","")#mnemonic
1620     #"($src1.new, #"#ImmVal#")) jump:"
1621     #!if(isTak, "t","nt")#" $offset", []> {
1622
1623       let isTaken = isTak;
1624       let isPredicatedFalse = isNegCond;
1625       let isTaken = isTak;
1626
1627       bits<3> src1;
1628       bits<11> offset;
1629       let IClass = 0b0010;
1630       let Inst{26} = 0b1;
1631       let Inst{25-23} = majOp;
1632       let Inst{22} = isNegCond;
1633       let Inst{18-16} = src1;
1634       let Inst{13} = isTak;
1635       let Inst{21-20} = offset{10-9};
1636       let Inst{7-1} = offset{8-2};
1637 }
1638
1639 multiclass NVJ_ConstImm_cond<string mnemonic, bits<3> majOp, string ImmVal,
1640                              bit isNegCond> {
1641   // Branch not taken:
1642   def _nt_V4: NVJ_ConstImm_template<mnemonic, majOp, ImmVal, isNegCond, 0>;
1643   // Branch taken:
1644   def _t_V4: NVJ_ConstImm_template<mnemonic, majOp, ImmVal, isNegCond, 1>;
1645 }
1646
1647 multiclass NVJ_ConstImm_base<string mnemonic, string BaseOp, bits<3> majOp,
1648                              string ImmVal> {
1649   let BaseOpcode = BaseOp#_NVJ_ConstImm in {
1650     defm _t_Jumpnv : NVJ_ConstImm_cond<mnemonic, majOp, ImmVal, 0>; // True
1651     defm _f_Jumpnv : NVJ_ConstImm_cond<mnemonic, majOp, ImmVal, 1>; // False
1652   }
1653 }
1654
1655 // if ([!]tstbit(Ns.new,#0)) jump:[n]t #r9:2
1656 // if ([!]cmp.eq(Ns.new,#-1)) jump:[n]t #r9:2
1657 // if ([!]cmp.gt(Ns.new,#-1)) jump:[n]t #r9:2
1658
1659 let isPredicated = 1, isBranch = 1, isNewValue = 1, isTerminator=1,
1660     Defs = [PC], hasSideEffects = 0 in {
1661   defm TSTBIT0  : NVJ_ConstImm_base<"tstbit", "TSTBIT", 0b011, "0">, PredRel;
1662   defm CMPEQn1  : NVJ_ConstImm_base<"cmp.eq", "CMPEQ",  0b100, "-1">, PredRel;
1663   defm CMPGTn1  : NVJ_ConstImm_base<"cmp.gt", "CMPGT",  0b101, "-1">, PredRel;
1664 }
1665
1666 // J4_hintjumpr: Hint indirect conditional jump.
1667 let isBranch = 1, isIndirectBranch = 1, hasSideEffects = 0 in
1668 def J4_hintjumpr: JRInst <
1669   (outs),
1670   (ins IntRegs:$Rs),
1671   "hintjr($Rs)"> {
1672     bits<5> Rs;
1673     let IClass = 0b0101;
1674     let Inst{27-21} = 0b0010101;
1675     let Inst{20-16} = Rs;
1676   }
1677
1678 //===----------------------------------------------------------------------===//
1679 // NV/J -
1680 //===----------------------------------------------------------------------===//
1681
1682 //===----------------------------------------------------------------------===//
1683 // CR +
1684 //===----------------------------------------------------------------------===//
1685
1686 // PC-relative add
1687 let hasNewValue = 1, isExtendable = 1, opExtendable = 1,
1688     isExtentSigned = 0, opExtentBits = 6, hasSideEffects = 0,
1689     Uses = [PC], validSubTargets = HasV4SubT in
1690 def C4_addipc : CRInst <(outs IntRegs:$Rd), (ins u6Ext:$u6),
1691   "$Rd = add(pc, #$u6)", [], "", CR_tc_2_SLOT3 > {
1692     bits<5> Rd;
1693     bits<6> u6;
1694
1695     let IClass = 0b0110;
1696     let Inst{27-16} = 0b101001001001;
1697     let Inst{12-7} = u6;
1698     let Inst{4-0} = Rd;
1699   }
1700
1701
1702
1703 let hasSideEffects = 0 in
1704 class T_LOGICAL_3OP<string MnOp1, string MnOp2, bits<2> OpBits, bit IsNeg>
1705     : CRInst<(outs PredRegs:$Pd),
1706              (ins PredRegs:$Ps, PredRegs:$Pt, PredRegs:$Pu),
1707              "$Pd = " # MnOp1 # "($Ps, " # MnOp2 # "($Pt, " #
1708                    !if (IsNeg,"!","") # "$Pu))",
1709              [], "", CR_tc_2early_SLOT23> {
1710   bits<2> Pd;
1711   bits<2> Ps;
1712   bits<2> Pt;
1713   bits<2> Pu;
1714
1715   let IClass = 0b0110;
1716   let Inst{27-24} = 0b1011;
1717   let Inst{23} = IsNeg;
1718   let Inst{22-21} = OpBits;
1719   let Inst{20} = 0b1;
1720   let Inst{17-16} = Ps;
1721   let Inst{13} = 0b0;
1722   let Inst{9-8} = Pt;
1723   let Inst{7-6} = Pu;
1724   let Inst{1-0} = Pd;
1725 }
1726
1727 def C4_and_and  : T_LOGICAL_3OP<"and", "and", 0b00, 0>;
1728 def C4_and_or   : T_LOGICAL_3OP<"and", "or",  0b01, 0>;
1729 def C4_or_and   : T_LOGICAL_3OP<"or",  "and", 0b10, 0>;
1730 def C4_or_or    : T_LOGICAL_3OP<"or",  "or",  0b11, 0>;
1731 def C4_and_andn : T_LOGICAL_3OP<"and", "and", 0b00, 1>;
1732 def C4_and_orn  : T_LOGICAL_3OP<"and", "or",  0b01, 1>;
1733 def C4_or_andn  : T_LOGICAL_3OP<"or",  "and", 0b10, 1>;
1734 def C4_or_orn   : T_LOGICAL_3OP<"or",  "or",  0b11, 1>;
1735
1736 //===----------------------------------------------------------------------===//
1737 // CR -
1738 //===----------------------------------------------------------------------===//
1739
1740 //===----------------------------------------------------------------------===//
1741 // XTYPE/ALU +
1742 //===----------------------------------------------------------------------===//
1743
1744 // Logical with-not instructions.
1745 let validSubTargets = HasV4SubT in {
1746   def A4_andnp : T_ALU64_logical<"and", 0b001, 1, 0, 1>;
1747   def A4_ornp  : T_ALU64_logical<"or",  0b011, 1, 0, 1>;
1748 }
1749
1750 let hasNewValue = 1, hasSideEffects = 0 in
1751 def S4_parity: ALU64Inst<(outs IntRegs:$Rd), (ins IntRegs:$Rs, IntRegs:$Rt),
1752       "$Rd = parity($Rs, $Rt)", [], "", ALU64_tc_2_SLOT23> {
1753   bits<5> Rd;
1754   bits<5> Rs;
1755   bits<5> Rt;
1756
1757   let IClass = 0b1101;
1758   let Inst{27-21} = 0b0101111;
1759   let Inst{20-16} = Rs;
1760   let Inst{12-8} = Rt;
1761   let Inst{4-0} = Rd;
1762 }
1763 //  Add and accumulate.
1764 //  Rd=add(Rs,add(Ru,#s6))
1765 let isExtentSigned = 1, hasNewValue = 1, isExtendable = 1, opExtentBits = 6,
1766     opExtendable = 3 in
1767 def S4_addaddi : ALU64Inst <(outs IntRegs:$Rd),
1768                             (ins IntRegs:$Rs, IntRegs:$Ru, s6Ext:$s6),
1769   "$Rd = add($Rs, add($Ru, #$s6))" ,
1770   [(set (i32 IntRegs:$Rd), (add (i32 IntRegs:$Rs),
1771                            (add (i32 IntRegs:$Ru), s6_16ExtPred:$s6)))],
1772   "", ALU64_tc_2_SLOT23> {
1773     bits<5> Rd;
1774     bits<5> Rs;
1775     bits<5> Ru;
1776     bits<6> s6;
1777
1778     let IClass = 0b1101;
1779
1780     let Inst{27-23} = 0b10110;
1781     let Inst{22-21} = s6{5-4};
1782     let Inst{20-16} = Rs;
1783     let Inst{13}    = s6{3};
1784     let Inst{12-8}  = Rd;
1785     let Inst{7-5}   = s6{2-0};
1786     let Inst{4-0}   = Ru;
1787   }
1788
1789 let isExtentSigned = 1, hasSideEffects = 0, hasNewValue = 1, isExtendable = 1,
1790     opExtentBits = 6, opExtendable = 2 in
1791 def S4_subaddi: ALU64Inst <(outs IntRegs:$Rd),
1792                            (ins IntRegs:$Rs, s6Ext:$s6, IntRegs:$Ru),
1793   "$Rd = add($Rs, sub(#$s6, $Ru))",
1794   [], "", ALU64_tc_2_SLOT23> {
1795     bits<5> Rd;
1796     bits<5> Rs;
1797     bits<6> s6;
1798     bits<5> Ru;
1799
1800     let IClass = 0b1101;
1801
1802     let Inst{27-23} = 0b10111;
1803     let Inst{22-21} = s6{5-4};
1804     let Inst{20-16} = Rs;
1805     let Inst{13}    = s6{3};
1806     let Inst{12-8}  = Rd;
1807     let Inst{7-5}   = s6{2-0};
1808     let Inst{4-0}   = Ru;
1809   }
1810   
1811 // Extract bitfield
1812 // Rdd=extract(Rss,#u6,#U6)
1813 // Rdd=extract(Rss,Rtt)
1814 // Rd=extract(Rs,Rtt)
1815 // Rd=extract(Rs,#u5,#U5)
1816
1817 def S4_extractp_rp : T_S3op_64 < "extract",  0b11, 0b100, 0>;
1818 def S4_extractp    : T_S2op_extract <"extract",  0b1010, DoubleRegs, u6Imm>;
1819
1820 let hasNewValue = 1 in {
1821   def S4_extract_rp : T_S3op_extract<"extract",  0b01>;
1822   def S4_extract    : T_S2op_extract <"extract",  0b1101, IntRegs, u5Imm>;
1823 }
1824
1825 // Complex add/sub halfwords/words
1826 let Defs = [USR_OVF] in {
1827   def S4_vxaddsubh : T_S3op_64 < "vxaddsubh", 0b01, 0b100, 0, 1>;
1828   def S4_vxaddsubw : T_S3op_64 < "vxaddsubw", 0b01, 0b000, 0, 1>;
1829   def S4_vxsubaddh : T_S3op_64 < "vxsubaddh", 0b01, 0b110, 0, 1>;
1830   def S4_vxsubaddw : T_S3op_64 < "vxsubaddw", 0b01, 0b010, 0, 1>;
1831 }
1832
1833 let Defs = [USR_OVF] in {
1834   def S4_vxaddsubhr : T_S3op_64 < "vxaddsubh", 0b11, 0b000, 0, 1, 1, 1>;
1835   def S4_vxsubaddhr : T_S3op_64 < "vxsubaddh", 0b11, 0b010, 0, 1, 1, 1>;
1836 }
1837
1838 let Itinerary = M_tc_3x_SLOT23, Defs = [USR_OVF] in {
1839   def M4_mac_up_s1_sat: T_MType_acc_rr<"+= mpy", 0b011, 0b000, 0, [], 0, 1, 1>;
1840   def M4_nac_up_s1_sat: T_MType_acc_rr<"-= mpy", 0b011, 0b001, 0, [], 0, 1, 1>;
1841 }
1842
1843 // Logical xor with xor accumulation.
1844 // Rxx^=xor(Rss,Rtt)
1845 let hasSideEffects = 0 in
1846 def M4_xor_xacc
1847   : SInst <(outs DoubleRegs:$Rxx),
1848            (ins DoubleRegs:$dst2, DoubleRegs:$Rss, DoubleRegs:$Rtt),
1849   "$Rxx ^= xor($Rss, $Rtt)",
1850   [(set (i64 DoubleRegs:$Rxx),
1851    (xor (i64 DoubleRegs:$dst2), (xor (i64 DoubleRegs:$Rss),
1852                                      (i64 DoubleRegs:$Rtt))))],
1853   "$dst2 = $Rxx", S_3op_tc_1_SLOT23> {
1854     bits<5> Rxx;
1855     bits<5> Rss;
1856     bits<5> Rtt;
1857
1858     let IClass = 0b1100;
1859
1860     let Inst{27-23} = 0b10101;
1861     let Inst{20-16} = Rss;
1862     let Inst{12-8}  = Rtt;
1863     let Inst{4-0}   = Rxx;
1864   }
1865
1866 // Rotate and reduce bytes
1867 // Rdd=vrcrotate(Rss,Rt,#u2)
1868 let hasSideEffects = 0 in
1869 def S4_vrcrotate
1870   : SInst <(outs DoubleRegs:$Rdd),
1871            (ins DoubleRegs:$Rss, IntRegs:$Rt, u2Imm:$u2),
1872   "$Rdd = vrcrotate($Rss, $Rt, #$u2)",
1873   [], "", S_3op_tc_3x_SLOT23> {
1874     bits<5> Rdd;
1875     bits<5> Rss;
1876     bits<5> Rt;
1877     bits<2> u2;
1878
1879     let IClass = 0b1100;
1880
1881     let Inst{27-22} = 0b001111;
1882     let Inst{20-16} = Rss;
1883     let Inst{13}    = u2{1};
1884     let Inst{12-8}  = Rt;
1885     let Inst{7-6}   = 0b11;
1886     let Inst{5}     = u2{0};
1887     let Inst{4-0}   = Rdd;
1888   }
1889
1890 // Rotate and reduce bytes with accumulation
1891 // Rxx+=vrcrotate(Rss,Rt,#u2)
1892 let hasSideEffects = 0 in
1893 def S4_vrcrotate_acc
1894   : SInst <(outs DoubleRegs:$Rxx),
1895            (ins DoubleRegs:$dst2, DoubleRegs:$Rss, IntRegs:$Rt, u2Imm:$u2),
1896   "$Rxx += vrcrotate($Rss, $Rt, #$u2)", [],
1897   "$dst2 = $Rxx", S_3op_tc_3x_SLOT23> {
1898     bits<5> Rxx;
1899     bits<5> Rss;
1900     bits<5> Rt;
1901     bits<2> u2;
1902
1903     let IClass = 0b1100;
1904
1905     let Inst{27-21} = 0b1011101;
1906     let Inst{20-16} = Rss;
1907     let Inst{13}    = u2{1};
1908     let Inst{12-8}  = Rt;
1909     let Inst{5}     = u2{0};
1910     let Inst{4-0}   = Rxx;
1911   }
1912
1913
1914 // Vector reduce conditional negate halfwords
1915 let hasSideEffects = 0 in
1916 def S2_vrcnegh
1917   : SInst <(outs DoubleRegs:$Rxx),
1918            (ins DoubleRegs:$dst2, DoubleRegs:$Rss, IntRegs:$Rt),
1919   "$Rxx += vrcnegh($Rss, $Rt)", [],
1920   "$dst2 = $Rxx", S_3op_tc_3x_SLOT23> {
1921     bits<5> Rxx;
1922     bits<5> Rss;
1923     bits<5> Rt;
1924
1925     let IClass = 0b1100;
1926
1927     let Inst{27-21} = 0b1011001;
1928     let Inst{20-16} = Rss;
1929     let Inst{13}    = 0b1;
1930     let Inst{12-8}  = Rt;
1931     let Inst{7-5}   = 0b111;
1932     let Inst{4-0}   = Rxx;
1933   }
1934
1935 // Split bitfield
1936 def A4_bitspliti : T_S2op_2_di <"bitsplit", 0b110, 0b100>;
1937
1938 // Arithmetic/Convergent round
1939 def A4_cround_ri : T_S2op_2_ii <"cround", 0b111, 0b000>;
1940
1941 def A4_round_ri  : T_S2op_2_ii <"round", 0b111, 0b100>;
1942
1943 let Defs = [USR_OVF] in
1944 def A4_round_ri_sat : T_S2op_2_ii <"round", 0b111, 0b110, 1>;
1945
1946 // Logical-logical words.
1947 // Compound or-and -- Rx=or(Ru,and(Rx,#s10))
1948 let isExtentSigned = 1, hasNewValue = 1, isExtendable = 1, opExtentBits = 10,
1949     opExtendable = 3 in
1950 def S4_or_andix:
1951   ALU64Inst<(outs IntRegs:$Rx),
1952             (ins IntRegs:$Ru, IntRegs:$_src_, s10Ext:$s10),
1953   "$Rx = or($Ru, and($_src_, #$s10))" ,
1954   [(set (i32 IntRegs:$Rx),
1955         (or (i32 IntRegs:$Ru), (and (i32 IntRegs:$_src_), s10ExtPred:$s10)))] ,
1956   "$_src_ = $Rx", ALU64_tc_2_SLOT23> {
1957     bits<5> Rx;
1958     bits<5> Ru;
1959     bits<10> s10;
1960
1961     let IClass = 0b1101;
1962
1963     let Inst{27-22} = 0b101001;
1964     let Inst{20-16} = Rx;
1965     let Inst{21}    = s10{9};
1966     let Inst{13-5}  = s10{8-0};
1967     let Inst{4-0}   = Ru;
1968   }
1969
1970 // Miscellaneous ALU64 instructions.
1971 //
1972 let hasNewValue = 1, hasSideEffects = 0 in
1973 def A4_modwrapu: ALU64Inst<(outs IntRegs:$Rd), (ins IntRegs:$Rs, IntRegs:$Rt),
1974       "$Rd = modwrap($Rs, $Rt)", [], "", ALU64_tc_2_SLOT23> {
1975   bits<5> Rd;
1976   bits<5> Rs;
1977   bits<5> Rt;
1978
1979   let IClass = 0b1101;
1980   let Inst{27-21} = 0b0011111;
1981   let Inst{20-16} = Rs;
1982   let Inst{12-8} = Rt;
1983   let Inst{7-5} = 0b111;
1984   let Inst{4-0} = Rd;
1985 }
1986
1987 let hasSideEffects = 0 in
1988 def A4_bitsplit: ALU64Inst<(outs DoubleRegs:$Rd),
1989       (ins IntRegs:$Rs, IntRegs:$Rt),
1990       "$Rd = bitsplit($Rs, $Rt)", [], "", ALU64_tc_1_SLOT23> {
1991   bits<5> Rd;
1992   bits<5> Rs;
1993   bits<5> Rt;
1994
1995   let IClass = 0b1101;
1996   let Inst{27-24} = 0b0100;
1997   let Inst{21} = 0b1;
1998   let Inst{20-16} = Rs;
1999   let Inst{12-8} = Rt;
2000   let Inst{4-0} = Rd;
2001 }
2002
2003 // Rx[&|]=xor(Rs,Rt)
2004 def M4_or_xor   : T_MType_acc_rr < "|= xor", 0b110, 0b001, 0>;
2005 def M4_and_xor  : T_MType_acc_rr < "&= xor", 0b010, 0b010, 0>;
2006
2007 // Rx[&|^]=or(Rs,Rt)
2008 def M4_xor_or   : T_MType_acc_rr < "^= or",  0b110, 0b011, 0>;
2009
2010 let CextOpcode = "ORr_ORr" in
2011 def M4_or_or    : T_MType_acc_rr < "|= or",  0b110, 0b000, 0>;
2012 def M4_and_or   : T_MType_acc_rr < "&= or",  0b010, 0b001, 0>;
2013
2014 // Rx[&|^]=and(Rs,Rt)
2015 def M4_xor_and  : T_MType_acc_rr < "^= and", 0b110, 0b010, 0>;
2016
2017 let CextOpcode = "ORr_ANDr" in
2018 def M4_or_and   : T_MType_acc_rr < "|= and", 0b010, 0b011, 0>;
2019 def M4_and_and  : T_MType_acc_rr < "&= and", 0b010, 0b000, 0>;
2020
2021 // Rx[&|^]=and(Rs,~Rt)
2022 def M4_xor_andn : T_MType_acc_rr < "^= and", 0b001, 0b010, 0, [], 1>;
2023 def M4_or_andn  : T_MType_acc_rr < "|= and", 0b001, 0b000, 0, [], 1>;
2024 def M4_and_andn : T_MType_acc_rr < "&= and", 0b001, 0b001, 0, [], 1>;
2025
2026 // Compound or-or and or-and
2027 let isExtentSigned = 1, InputType = "imm", hasNewValue = 1, isExtendable = 1,
2028     opExtentBits = 10, opExtendable = 3 in
2029 class T_CompOR <string mnemonic, bits<2> MajOp, SDNode OpNode>
2030   : MInst_acc <(outs IntRegs:$Rx),
2031                (ins IntRegs:$src1, IntRegs:$Rs, s10Ext:$s10),
2032   "$Rx |= "#mnemonic#"($Rs, #$s10)",
2033   [(set (i32 IntRegs:$Rx), (or (i32 IntRegs:$src1),
2034                            (OpNode (i32 IntRegs:$Rs), s10ExtPred:$s10)))],
2035   "$src1 = $Rx", ALU64_tc_2_SLOT23>, ImmRegRel {
2036     bits<5> Rx;
2037     bits<5> Rs;
2038     bits<10> s10;
2039
2040     let IClass = 0b1101;
2041
2042     let Inst{27-24} = 0b1010;
2043     let Inst{23-22} = MajOp;
2044     let Inst{20-16} = Rs;
2045     let Inst{21}    = s10{9};
2046     let Inst{13-5}  = s10{8-0};
2047     let Inst{4-0}   = Rx;
2048   }
2049
2050 let CextOpcode = "ORr_ANDr" in
2051 def S4_or_andi : T_CompOR <"and", 0b00, and>;
2052
2053 let CextOpcode = "ORr_ORr" in
2054 def S4_or_ori : T_CompOR <"or", 0b10, or>;
2055
2056 //    Modulo wrap
2057 //        Rd=modwrap(Rs,Rt)
2058 //    Round
2059 //        Rd=cround(Rs,#u5)
2060 //        Rd=cround(Rs,Rt)
2061 //        Rd=round(Rs,#u5)[:sat]
2062 //        Rd=round(Rs,Rt)[:sat]
2063 //    Vector reduce add unsigned halfwords
2064 //        Rd=vraddh(Rss,Rtt)
2065 //    Vector add bytes
2066 //        Rdd=vaddb(Rss,Rtt)
2067 //    Vector conditional negate
2068 //        Rdd=vcnegh(Rss,Rt)
2069 //        Rxx+=vrcnegh(Rss,Rt)
2070 //    Vector maximum bytes
2071 //        Rdd=vmaxb(Rtt,Rss)
2072 //    Vector reduce maximum halfwords
2073 //        Rxx=vrmaxh(Rss,Ru)
2074 //        Rxx=vrmaxuh(Rss,Ru)
2075 //    Vector reduce maximum words
2076 //        Rxx=vrmaxuw(Rss,Ru)
2077 //        Rxx=vrmaxw(Rss,Ru)
2078 //    Vector minimum bytes
2079 //        Rdd=vminb(Rtt,Rss)
2080 //    Vector reduce minimum halfwords
2081 //        Rxx=vrminh(Rss,Ru)
2082 //        Rxx=vrminuh(Rss,Ru)
2083 //    Vector reduce minimum words
2084 //        Rxx=vrminuw(Rss,Ru)
2085 //        Rxx=vrminw(Rss,Ru)
2086 //    Vector subtract bytes
2087 //        Rdd=vsubb(Rss,Rtt)
2088
2089 //===----------------------------------------------------------------------===//
2090 // XTYPE/ALU -
2091 //===----------------------------------------------------------------------===//
2092
2093 //===----------------------------------------------------------------------===//
2094 // XTYPE/BIT +
2095 //===----------------------------------------------------------------------===//
2096
2097 // Bit reverse
2098 def S2_brevp : T_S2op_3 <"brev", 0b11, 0b110>;
2099
2100 // Bit count
2101 def S2_ct0p : T_COUNT_LEADING_64<"ct0", 0b111, 0b010>;
2102 def S2_ct1p : T_COUNT_LEADING_64<"ct1", 0b111, 0b100>;
2103 def S4_clbpnorm : T_COUNT_LEADING_64<"normamt", 0b011, 0b000>;
2104
2105 def: Pat<(i32 (trunc (cttz (i64 DoubleRegs:$Rss)))),
2106          (S2_ct0p (i64 DoubleRegs:$Rss))>;
2107 def: Pat<(i32 (trunc (cttz (not (i64 DoubleRegs:$Rss))))),
2108          (S2_ct1p (i64 DoubleRegs:$Rss))>;
2109
2110 let hasSideEffects = 0, hasNewValue = 1 in
2111 def S4_clbaddi : SInst<(outs IntRegs:$Rd), (ins IntRegs:$Rs, s6Imm:$s6),
2112     "$Rd = add(clb($Rs), #$s6)", [], "", S_2op_tc_2_SLOT23> {
2113   bits<5> Rs;
2114   bits<5> Rd;
2115   bits<6> s6;
2116   let IClass = 0b1000;
2117   let Inst{27-24} = 0b1100;
2118   let Inst{23-21} = 0b001;
2119   let Inst{20-16} = Rs;
2120   let Inst{13-8} = s6;
2121   let Inst{7-5} = 0b000;
2122   let Inst{4-0} = Rd;
2123 }
2124
2125 let hasSideEffects = 0, hasNewValue = 1 in
2126 def S4_clbpaddi : SInst<(outs IntRegs:$Rd), (ins DoubleRegs:$Rs, s6Imm:$s6),
2127     "$Rd = add(clb($Rs), #$s6)", [], "", S_2op_tc_2_SLOT23> {
2128   bits<5> Rs;
2129   bits<5> Rd;
2130   bits<6> s6;
2131   let IClass = 0b1000;
2132   let Inst{27-24} = 0b1000;
2133   let Inst{23-21} = 0b011;
2134   let Inst{20-16} = Rs;
2135   let Inst{13-8} = s6;
2136   let Inst{7-5} = 0b010;
2137   let Inst{4-0} = Rd;
2138 }
2139
2140
2141 // Bit test/set/clear
2142 def S4_ntstbit_i : T_TEST_BIT_IMM<"!tstbit", 0b001>;
2143 def S4_ntstbit_r : T_TEST_BIT_REG<"!tstbit", 1>;
2144
2145 let AddedComplexity = 20 in {   // Complexity greater than cmp reg-imm.
2146   def: Pat<(i1 (seteq (and (shl 1, u5ImmPred:$u5), (i32 IntRegs:$Rs)), 0)),
2147            (S4_ntstbit_i (i32 IntRegs:$Rs), u5ImmPred:$u5)>;
2148   def: Pat<(i1 (seteq (and (shl 1, (i32 IntRegs:$Rt)), (i32 IntRegs:$Rs)), 0)),
2149            (S4_ntstbit_r (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))>;
2150 }
2151
2152 // Add extra complexity to prefer these instructions over bitsset/bitsclr.
2153 // The reason is that tstbit/ntstbit can be folded into a compound instruction:
2154 //   if ([!]tstbit(...)) jump ...
2155 let AddedComplexity = 100 in
2156 def: Pat<(i1 (setne (and (i32 IntRegs:$Rs), (i32 Set5ImmPred:$u5)), (i32 0))),
2157          (S2_tstbit_i (i32 IntRegs:$Rs), (BITPOS32 Set5ImmPred:$u5))>;
2158
2159 let AddedComplexity = 100 in
2160 def: Pat<(i1 (seteq (and (i32 IntRegs:$Rs), (i32 Set5ImmPred:$u5)), (i32 0))),
2161          (S4_ntstbit_i (i32 IntRegs:$Rs), (BITPOS32 Set5ImmPred:$u5))>;
2162
2163 def C4_nbitsset  : T_TEST_BITS_REG<"!bitsset", 0b01, 1>;
2164 def C4_nbitsclr  : T_TEST_BITS_REG<"!bitsclr", 0b10, 1>;
2165 def C4_nbitsclri : T_TEST_BITS_IMM<"!bitsclr", 0b10, 1>;
2166
2167 // Do not increase complexity of these patterns. In the DAG, "cmp i8" may be
2168 // represented as a compare against "value & 0xFF", which is an exact match
2169 // for cmpb (same for cmph). The patterns below do not contain any additional
2170 // complexity that would make them preferable, and if they were actually used
2171 // instead of cmpb/cmph, they would result in a compare against register that
2172 // is loaded with the byte/half mask (i.e. 0xFF or 0xFFFF).
2173 def: Pat<(i1 (setne (and I32:$Rs, u6ImmPred:$u6), 0)),
2174          (C4_nbitsclri I32:$Rs, u6ImmPred:$u6)>;
2175 def: Pat<(i1 (setne (and I32:$Rs, I32:$Rt), 0)),
2176          (C4_nbitsclr I32:$Rs, I32:$Rt)>;
2177 def: Pat<(i1 (setne (and I32:$Rs, I32:$Rt), I32:$Rt)),
2178          (C4_nbitsset I32:$Rs, I32:$Rt)>;
2179
2180 //===----------------------------------------------------------------------===//
2181 // XTYPE/BIT -
2182 //===----------------------------------------------------------------------===//
2183
2184 //===----------------------------------------------------------------------===//
2185 // XTYPE/MPY +
2186 //===----------------------------------------------------------------------===//
2187
2188 // Rd=add(#u6,mpyi(Rs,#U6)) -- Multiply by immed and add immed.
2189
2190 let hasNewValue = 1, isExtendable = 1, opExtentBits = 6, opExtendable = 1 in
2191 def M4_mpyri_addi : MInst<(outs IntRegs:$Rd),
2192   (ins u6Ext:$u6, IntRegs:$Rs, u6Imm:$U6),
2193   "$Rd = add(#$u6, mpyi($Rs, #$U6))" ,
2194   [(set (i32 IntRegs:$Rd),
2195         (add (mul (i32 IntRegs:$Rs), u6ImmPred:$U6),
2196              u6ExtPred:$u6))] ,"",ALU64_tc_3x_SLOT23> {
2197     bits<5> Rd;
2198     bits<6> u6;
2199     bits<5> Rs;
2200     bits<6> U6;
2201
2202     let IClass = 0b1101;
2203
2204     let Inst{27-24} = 0b1000;
2205     let Inst{23}    = U6{5};
2206     let Inst{22-21} = u6{5-4};
2207     let Inst{20-16} = Rs;
2208     let Inst{13}    = u6{3};
2209     let Inst{12-8}  = Rd;
2210     let Inst{7-5}   = u6{2-0};
2211     let Inst{4-0}   = U6{4-0};
2212   }
2213
2214 // Rd=add(#u6,mpyi(Rs,Rt))
2215 let CextOpcode = "ADD_MPY", InputType = "imm", hasNewValue = 1,
2216     isExtendable = 1, opExtentBits = 6, opExtendable = 1 in
2217 def M4_mpyrr_addi : MInst <(outs IntRegs:$Rd),
2218   (ins u6Ext:$u6, IntRegs:$Rs, IntRegs:$Rt),
2219   "$Rd = add(#$u6, mpyi($Rs, $Rt))" ,
2220   [(set (i32 IntRegs:$Rd),
2221         (add (mul (i32 IntRegs:$Rs), (i32 IntRegs:$Rt)), u6ExtPred:$u6))],
2222   "", ALU64_tc_3x_SLOT23>, ImmRegRel {
2223     bits<5> Rd;
2224     bits<6> u6;
2225     bits<5> Rs;
2226     bits<5> Rt;
2227
2228     let IClass = 0b1101;
2229
2230     let Inst{27-23} = 0b01110;
2231     let Inst{22-21} = u6{5-4};
2232     let Inst{20-16} = Rs;
2233     let Inst{13}    = u6{3};
2234     let Inst{12-8}  = Rt;
2235     let Inst{7-5}   = u6{2-0};
2236     let Inst{4-0}   = Rd;
2237   }
2238
2239 let hasNewValue = 1 in
2240 class T_AddMpy <bit MajOp, PatLeaf ImmPred, dag ins>
2241   : ALU64Inst <(outs IntRegs:$dst), ins,
2242   "$dst = add($src1, mpyi("#!if(MajOp,"$src3, #$src2))",
2243                                       "#$src2, $src3))"),
2244   [(set (i32 IntRegs:$dst),
2245         (add (i32 IntRegs:$src1), (mul (i32 IntRegs:$src3), ImmPred:$src2)))],
2246   "", ALU64_tc_3x_SLOT23> {
2247     bits<5> dst;
2248     bits<5> src1;
2249     bits<8> src2;
2250     bits<5> src3;
2251
2252     let IClass = 0b1101;
2253
2254     bits<6> ImmValue = !if(MajOp, src2{5-0}, src2{7-2});
2255
2256     let Inst{27-24} = 0b1111;
2257     let Inst{23}    = MajOp;
2258     let Inst{22-21} = ImmValue{5-4};
2259     let Inst{20-16} = src3;
2260     let Inst{13}    = ImmValue{3};
2261     let Inst{12-8}  = dst;
2262     let Inst{7-5}   = ImmValue{2-0};
2263     let Inst{4-0}   = src1;
2264   }
2265
2266 def M4_mpyri_addr_u2 : T_AddMpy<0b0, u6_2ImmPred,
2267                        (ins IntRegs:$src1, u6_2Imm:$src2, IntRegs:$src3)>;
2268
2269 let isExtendable = 1, opExtentBits = 6, opExtendable = 3,
2270     CextOpcode = "ADD_MPY", InputType = "imm" in
2271 def M4_mpyri_addr : T_AddMpy<0b1, u6ExtPred,
2272                     (ins IntRegs:$src1, IntRegs:$src3, u6Ext:$src2)>, ImmRegRel;
2273
2274 // Rx=add(Ru,mpyi(Rx,Rs))
2275 let validSubTargets = HasV4SubT, CextOpcode = "ADD_MPY", InputType = "reg",
2276     hasNewValue = 1 in
2277 def M4_mpyrr_addr: MInst_acc <(outs IntRegs:$Rx),
2278                               (ins IntRegs:$Ru, IntRegs:$_src_, IntRegs:$Rs),
2279   "$Rx = add($Ru, mpyi($_src_, $Rs))",
2280   [(set (i32 IntRegs:$Rx), (add (i32 IntRegs:$Ru),
2281                            (mul (i32 IntRegs:$_src_), (i32 IntRegs:$Rs))))],
2282   "$_src_ = $Rx", M_tc_3x_SLOT23>, ImmRegRel {
2283     bits<5> Rx;
2284     bits<5> Ru;
2285     bits<5> Rs;
2286
2287     let IClass = 0b1110;
2288
2289     let Inst{27-21} = 0b0011000;
2290     let Inst{12-8} = Rx;
2291     let Inst{4-0} = Ru;
2292     let Inst{20-16} = Rs;
2293   }
2294
2295 // Rd=add(##,mpyi(Rs,#U6))
2296 def : Pat <(add (mul (i32 IntRegs:$src2), u6ImmPred:$src3),
2297                      (HexagonCONST32 tglobaladdr:$src1)),
2298            (i32 (M4_mpyri_addi tglobaladdr:$src1, IntRegs:$src2,
2299                                u6ImmPred:$src3))>;
2300
2301 // Rd=add(##,mpyi(Rs,Rt))
2302 def : Pat <(add (mul (i32 IntRegs:$src2), (i32 IntRegs:$src3)),
2303                      (HexagonCONST32 tglobaladdr:$src1)),
2304            (i32 (M4_mpyrr_addi tglobaladdr:$src1, IntRegs:$src2,
2305                                IntRegs:$src3))>;
2306
2307 // Vector reduce multiply word by signed half (32x16)
2308 //Rdd=vrmpyweh(Rss,Rtt)[:<<1]
2309 def M4_vrmpyeh_s0 : T_M2_vmpy<"vrmpyweh", 0b010, 0b100, 0, 0, 0>;
2310 def M4_vrmpyeh_s1 : T_M2_vmpy<"vrmpyweh", 0b110, 0b100, 1, 0, 0>;
2311
2312 //Rdd=vrmpywoh(Rss,Rtt)[:<<1]
2313 def M4_vrmpyoh_s0 : T_M2_vmpy<"vrmpywoh", 0b001, 0b010, 0, 0, 0>;
2314 def M4_vrmpyoh_s1 : T_M2_vmpy<"vrmpywoh", 0b101, 0b010, 1, 0, 0>;
2315
2316 //Rdd+=vrmpyweh(Rss,Rtt)[:<<1]
2317 def M4_vrmpyeh_acc_s0: T_M2_vmpy_acc<"vrmpyweh", 0b001, 0b110, 0, 0>;
2318 def M4_vrmpyeh_acc_s1: T_M2_vmpy_acc<"vrmpyweh", 0b101, 0b110, 1, 0>;
2319
2320 //Rdd=vrmpywoh(Rss,Rtt)[:<<1]
2321 def M4_vrmpyoh_acc_s0: T_M2_vmpy_acc<"vrmpywoh", 0b011, 0b110, 0, 0>;
2322 def M4_vrmpyoh_acc_s1: T_M2_vmpy_acc<"vrmpywoh", 0b111, 0b110, 1, 0>;
2323
2324 // Vector multiply halfwords, signed by unsigned
2325 // Rdd=vmpyhsu(Rs,Rt)[:<<]:sat
2326 def M2_vmpy2su_s0 : T_XTYPE_mpy64 < "vmpyhsu", 0b000, 0b111, 1, 0, 0>;
2327 def M2_vmpy2su_s1 : T_XTYPE_mpy64 < "vmpyhsu", 0b100, 0b111, 1, 1, 0>;
2328
2329 // Rxx+=vmpyhsu(Rs,Rt)[:<<1]:sat
2330 def M2_vmac2su_s0 : T_XTYPE_mpy64_acc < "vmpyhsu", "+", 0b011, 0b101, 1, 0, 0>;
2331 def M2_vmac2su_s1 : T_XTYPE_mpy64_acc < "vmpyhsu", "+", 0b111, 0b101, 1, 1, 0>;
2332
2333 // Vector polynomial multiply halfwords
2334 // Rdd=vpmpyh(Rs,Rt)
2335 def M4_vpmpyh : T_XTYPE_mpy64 < "vpmpyh", 0b110, 0b111, 0, 0, 0>;
2336
2337 // Rxx^=vpmpyh(Rs,Rt)
2338 def M4_vpmpyh_acc : T_XTYPE_mpy64_acc < "vpmpyh", "^", 0b101, 0b111, 0, 0, 0>;
2339
2340 // Polynomial multiply words
2341 // Rdd=pmpyw(Rs,Rt)
2342 def M4_pmpyw : T_XTYPE_mpy64 < "pmpyw", 0b010, 0b111, 0, 0, 0>;
2343
2344 // Rxx^=pmpyw(Rs,Rt)
2345 def M4_pmpyw_acc  : T_XTYPE_mpy64_acc < "pmpyw", "^", 0b001, 0b111, 0, 0, 0>;
2346
2347 //===----------------------------------------------------------------------===//
2348 // XTYPE/MPY -
2349 //===----------------------------------------------------------------------===//
2350
2351
2352 //===----------------------------------------------------------------------===//
2353 // ALU64/Vector compare
2354 //===----------------------------------------------------------------------===//
2355 //===----------------------------------------------------------------------===//
2356 // Template class for vector compare
2357 //===----------------------------------------------------------------------===//
2358
2359 let hasSideEffects = 0 in
2360 class T_vcmpImm <string Str, bits<2> cmpOp, bits<2> minOp, Operand ImmOprnd>
2361   : ALU64_rr <(outs PredRegs:$Pd),
2362               (ins DoubleRegs:$Rss, ImmOprnd:$Imm),
2363   "$Pd = "#Str#"($Rss, #$Imm)",
2364   [], "", ALU64_tc_2early_SLOT23> {
2365     bits<2> Pd;
2366     bits<5> Rss;
2367     bits<32> Imm;
2368     bits<8> ImmBits;
2369     let ImmBits{6-0} = Imm{6-0};
2370     let ImmBits{7} = !if (!eq(cmpOp,0b10), 0b0, Imm{7}); // 0 for vcmp[bhw].gtu
2371
2372     let IClass = 0b1101;
2373
2374     let Inst{27-24} = 0b1100;
2375     let Inst{22-21} = cmpOp;
2376     let Inst{20-16} = Rss;
2377     let Inst{12-5} = ImmBits;
2378     let Inst{4-3} = minOp;
2379     let Inst{1-0} = Pd;
2380   }
2381
2382 // Vector compare bytes
2383 def A4_vcmpbgt   : T_vcmp <"vcmpb.gt", 0b1010>;
2384 def: T_vcmp_pat<A4_vcmpbgt, setgt, v8i8>;
2385
2386 let AsmString = "$Pd = any8(vcmpb.eq($Rss, $Rtt))" in
2387 def A4_vcmpbeq_any : T_vcmp <"any8(vcmpb.gt", 0b1000>;
2388
2389 def A4_vcmpbeqi  : T_vcmpImm <"vcmpb.eq",  0b00, 0b00, u8Imm>;
2390 def A4_vcmpbgti  : T_vcmpImm <"vcmpb.gt",  0b01, 0b00, s8Imm>;
2391 def A4_vcmpbgtui : T_vcmpImm <"vcmpb.gtu", 0b10, 0b00, u7Imm>;
2392
2393 // Vector compare halfwords
2394 def A4_vcmpheqi  : T_vcmpImm <"vcmph.eq",  0b00, 0b01, s8Imm>;
2395 def A4_vcmphgti  : T_vcmpImm <"vcmph.gt",  0b01, 0b01, s8Imm>;
2396 def A4_vcmphgtui : T_vcmpImm <"vcmph.gtu", 0b10, 0b01, u7Imm>;
2397
2398 // Vector compare words
2399 def A4_vcmpweqi  : T_vcmpImm <"vcmpw.eq",  0b00, 0b10, s8Imm>;
2400 def A4_vcmpwgti  : T_vcmpImm <"vcmpw.gt",  0b01, 0b10, s8Imm>;
2401 def A4_vcmpwgtui : T_vcmpImm <"vcmpw.gtu", 0b10, 0b10, u7Imm>;
2402
2403 //===----------------------------------------------------------------------===//
2404 // XTYPE/SHIFT +
2405 //===----------------------------------------------------------------------===//
2406 // Shift by immediate and accumulate/logical.
2407 // Rx=add(#u8,asl(Rx,#U5))  Rx=add(#u8,lsr(Rx,#U5))
2408 // Rx=sub(#u8,asl(Rx,#U5))  Rx=sub(#u8,lsr(Rx,#U5))
2409 // Rx=and(#u8,asl(Rx,#U5))  Rx=and(#u8,lsr(Rx,#U5))
2410 // Rx=or(#u8,asl(Rx,#U5))   Rx=or(#u8,lsr(Rx,#U5))
2411 let isExtendable = 1, opExtendable = 1, isExtentSigned = 0, opExtentBits = 8,
2412     hasNewValue = 1, opNewValue = 0, validSubTargets = HasV4SubT in
2413 class T_S4_ShiftOperate<string MnOp, string MnSh, SDNode Op, SDNode Sh,
2414                         bit asl_lsr, bits<2> MajOp, InstrItinClass Itin>
2415   : MInst_acc<(outs IntRegs:$Rd), (ins u8Ext:$u8, IntRegs:$Rx, u5Imm:$U5),
2416       "$Rd = "#MnOp#"(#$u8, "#MnSh#"($Rx, #$U5))",
2417       [(set (i32 IntRegs:$Rd),
2418             (Op (Sh I32:$Rx, u5ImmPred:$U5), u8ExtPred:$u8))],
2419       "$Rd = $Rx", Itin> {
2420
2421   bits<5> Rd;
2422   bits<8> u8;
2423   bits<5> Rx;
2424   bits<5> U5;
2425
2426   let IClass = 0b1101;
2427   let Inst{27-24} = 0b1110;
2428   let Inst{23-21} = u8{7-5};
2429   let Inst{20-16} = Rd;
2430   let Inst{13} = u8{4};
2431   let Inst{12-8} = U5;
2432   let Inst{7-5} = u8{3-1};
2433   let Inst{4} = asl_lsr;
2434   let Inst{3} = u8{0};
2435   let Inst{2-1} = MajOp;
2436 }
2437
2438 multiclass T_ShiftOperate<string mnemonic, SDNode Op, bits<2> MajOp,
2439                           InstrItinClass Itin> {
2440   def _asl_ri : T_S4_ShiftOperate<mnemonic, "asl", Op, shl, 0, MajOp, Itin>;
2441   def _lsr_ri : T_S4_ShiftOperate<mnemonic, "lsr", Op, srl, 1, MajOp, Itin>;
2442 }
2443
2444 let AddedComplexity = 200 in {
2445   defm S4_addi : T_ShiftOperate<"add", add, 0b10, ALU64_tc_2_SLOT23>;
2446   defm S4_andi : T_ShiftOperate<"and", and, 0b00, ALU64_tc_2_SLOT23>;
2447 }
2448
2449 let AddedComplexity = 30 in
2450 defm S4_ori  : T_ShiftOperate<"or",  or,  0b01, ALU64_tc_1_SLOT23>;
2451
2452 defm S4_subi : T_ShiftOperate<"sub", sub, 0b11, ALU64_tc_1_SLOT23>;
2453
2454 // Vector conditional negate
2455 // Rdd=vcnegh(Rss,Rt)
2456 let Defs = [USR_OVF], Itinerary = S_3op_tc_2_SLOT23 in
2457 def S2_vcnegh   : T_S3op_shiftVect < "vcnegh",   0b11, 0b01>;
2458
2459 // Rd=[cround|round](Rs,Rt)
2460 let hasNewValue = 1, Itinerary = S_3op_tc_2_SLOT23 in {
2461   def A4_cround_rr    : T_S3op_3 < "cround", IntRegs, 0b11, 0b00>;
2462   def A4_round_rr     : T_S3op_3 < "round", IntRegs, 0b11, 0b10>;
2463 }
2464
2465 // Rd=round(Rs,Rt):sat
2466 let hasNewValue = 1, Defs = [USR_OVF], Itinerary = S_3op_tc_2_SLOT23 in
2467 def A4_round_rr_sat : T_S3op_3 < "round", IntRegs, 0b11, 0b11, 1>;
2468
2469 // Rd=[cmpyiwh|cmpyrwh](Rss,Rt):<<1:rnd:sat
2470 let Defs = [USR_OVF], Itinerary = S_3op_tc_3x_SLOT23 in {
2471   def M4_cmpyi_wh     : T_S3op_8<"cmpyiwh", 0b100, 1, 1, 1>;
2472   def M4_cmpyr_wh     : T_S3op_8<"cmpyrwh", 0b110, 1, 1, 1>;
2473 }
2474
2475 // Rdd=[add|sub](Rss,Rtt,Px):carry
2476 let isPredicateLate = 1, hasSideEffects = 0 in
2477 class T_S3op_carry <string mnemonic, bits<3> MajOp>
2478   : SInst < (outs DoubleRegs:$Rdd, PredRegs:$Px),
2479             (ins DoubleRegs:$Rss, DoubleRegs:$Rtt, PredRegs:$Pu),
2480   "$Rdd = "#mnemonic#"($Rss, $Rtt, $Pu):carry",
2481   [], "$Px = $Pu", S_3op_tc_1_SLOT23 > {
2482     bits<5> Rdd;
2483     bits<5> Rss;
2484     bits<5> Rtt;
2485     bits<2> Pu;
2486
2487     let IClass = 0b1100;
2488
2489     let Inst{27-24} = 0b0010;
2490     let Inst{23-21} = MajOp;
2491     let Inst{20-16} = Rss;
2492     let Inst{12-8}  = Rtt;
2493     let Inst{6-5}   = Pu;
2494     let Inst{4-0}   = Rdd;
2495   }
2496
2497 def A4_addp_c : T_S3op_carry < "add", 0b110 >;
2498 def A4_subp_c : T_S3op_carry < "sub", 0b111 >;
2499
2500 let Itinerary = S_3op_tc_3_SLOT23, hasSideEffects = 0 in
2501 class T_S3op_6 <string mnemonic, bits<3> MinOp, bit isUnsigned>
2502   : SInst <(outs DoubleRegs:$Rxx),
2503            (ins DoubleRegs:$dst2, DoubleRegs:$Rss, IntRegs:$Ru),
2504   "$Rxx = "#mnemonic#"($Rss, $Ru)" ,
2505   [] , "$dst2 = $Rxx"> {
2506     bits<5> Rxx;
2507     bits<5> Rss;
2508     bits<5> Ru;
2509
2510     let IClass = 0b1100;
2511
2512     let Inst{27-21} = 0b1011001;
2513     let Inst{20-16} = Rss;
2514     let Inst{13}    = isUnsigned;
2515     let Inst{12-8}  = Rxx;
2516     let Inst{7-5}   = MinOp;
2517     let Inst{4-0}   = Ru;
2518   }
2519
2520 // Vector reduce maximum halfwords
2521 // Rxx=vrmax[u]h(Rss,Ru)
2522 def A4_vrmaxh  : T_S3op_6 < "vrmaxh",  0b001, 0>;
2523 def A4_vrmaxuh : T_S3op_6 < "vrmaxuh", 0b001, 1>;
2524
2525 // Vector reduce maximum words
2526 // Rxx=vrmax[u]w(Rss,Ru)
2527 def A4_vrmaxw  : T_S3op_6 < "vrmaxw",  0b010, 0>;
2528 def A4_vrmaxuw : T_S3op_6 < "vrmaxuw", 0b010, 1>;
2529
2530 // Vector reduce minimum halfwords
2531 // Rxx=vrmin[u]h(Rss,Ru)
2532 def A4_vrminh  : T_S3op_6 < "vrminh",  0b101, 0>;
2533 def A4_vrminuh : T_S3op_6 < "vrminuh", 0b101, 1>;
2534
2535 // Vector reduce minimum words
2536 // Rxx=vrmin[u]w(Rss,Ru)
2537 def A4_vrminw  : T_S3op_6 < "vrminw",  0b110, 0>;
2538 def A4_vrminuw : T_S3op_6 < "vrminuw", 0b110, 1>;
2539
2540 // Shift an immediate left by register amount.
2541 let hasNewValue = 1, hasSideEffects = 0 in
2542 def S4_lsli: SInst <(outs IntRegs:$Rd), (ins s6Imm:$s6, IntRegs:$Rt),
2543   "$Rd = lsl(#$s6, $Rt)" ,
2544   [(set (i32 IntRegs:$Rd), (shl s6ImmPred:$s6,
2545                                  (i32 IntRegs:$Rt)))],
2546   "", S_3op_tc_1_SLOT23> {
2547     bits<5> Rd;
2548     bits<6> s6;
2549     bits<5> Rt;
2550
2551     let IClass = 0b1100;
2552
2553     let Inst{27-22} = 0b011010;
2554     let Inst{20-16} = s6{5-1};
2555     let Inst{12-8}  = Rt;
2556     let Inst{7-6}   = 0b11;
2557     let Inst{4-0}   = Rd;
2558     let Inst{5}     = s6{0};
2559   }
2560
2561 //===----------------------------------------------------------------------===//
2562 // XTYPE/SHIFT -
2563 //===----------------------------------------------------------------------===//
2564
2565 //===----------------------------------------------------------------------===//
2566 // MEMOP: Word, Half, Byte
2567 //===----------------------------------------------------------------------===//
2568
2569 def MEMOPIMM : SDNodeXForm<imm, [{
2570   // Call the transformation function XformM5ToU5Imm to get the negative
2571   // immediate's positive counterpart.
2572   int32_t imm = N->getSExtValue();
2573   return XformM5ToU5Imm(imm);
2574 }]>;
2575
2576 def MEMOPIMM_HALF : SDNodeXForm<imm, [{
2577   // -1 .. -31 represented as 65535..65515
2578   // assigning to a short restores our desired signed value.
2579   // Call the transformation function XformM5ToU5Imm to get the negative
2580   // immediate's positive counterpart.
2581   int16_t imm = N->getSExtValue();
2582   return XformM5ToU5Imm(imm);
2583 }]>;
2584
2585 def MEMOPIMM_BYTE : SDNodeXForm<imm, [{
2586   // -1 .. -31 represented as 255..235
2587   // assigning to a char restores our desired signed value.
2588   // Call the transformation function XformM5ToU5Imm to get the negative
2589   // immediate's positive counterpart.
2590   int8_t imm = N->getSExtValue();
2591   return XformM5ToU5Imm(imm);
2592 }]>;
2593
2594 def SETMEMIMM : SDNodeXForm<imm, [{
2595    // Return the bit position we will set [0-31].
2596    // As an SDNode.
2597    int32_t imm = N->getSExtValue();
2598    return XformMskToBitPosU5Imm(imm);
2599 }]>;
2600
2601 def CLRMEMIMM : SDNodeXForm<imm, [{
2602    // Return the bit position we will clear [0-31].
2603    // As an SDNode.
2604    // we bit negate the value first
2605    int32_t imm = ~(N->getSExtValue());
2606    return XformMskToBitPosU5Imm(imm);
2607 }]>;
2608
2609 def SETMEMIMM_SHORT : SDNodeXForm<imm, [{
2610    // Return the bit position we will set [0-15].
2611    // As an SDNode.
2612    int16_t imm = N->getSExtValue();
2613    return XformMskToBitPosU4Imm(imm);
2614 }]>;
2615
2616 def CLRMEMIMM_SHORT : SDNodeXForm<imm, [{
2617    // Return the bit position we will clear [0-15].
2618    // As an SDNode.
2619    // we bit negate the value first
2620    int16_t imm = ~(N->getSExtValue());
2621    return XformMskToBitPosU4Imm(imm);
2622 }]>;
2623
2624 def SETMEMIMM_BYTE : SDNodeXForm<imm, [{
2625    // Return the bit position we will set [0-7].
2626    // As an SDNode.
2627    int8_t imm =  N->getSExtValue();
2628    return XformMskToBitPosU3Imm(imm);
2629 }]>;
2630
2631 def CLRMEMIMM_BYTE : SDNodeXForm<imm, [{
2632    // Return the bit position we will clear [0-7].
2633    // As an SDNode.
2634    // we bit negate the value first
2635    int8_t imm = ~(N->getSExtValue());
2636    return XformMskToBitPosU3Imm(imm);
2637 }]>;
2638
2639 //===----------------------------------------------------------------------===//
2640 // Template class for MemOp instructions with the register value.
2641 //===----------------------------------------------------------------------===//
2642 class MemOp_rr_base <string opc, bits<2> opcBits, Operand ImmOp,
2643                      string memOp, bits<2> memOpBits> :
2644       MEMInst_V4<(outs),
2645                  (ins IntRegs:$base, ImmOp:$offset, IntRegs:$delta),
2646                  opc#"($base+#$offset)"#memOp#"$delta",
2647                  []>,
2648                  Requires<[UseMEMOP]> {
2649
2650     bits<5> base;
2651     bits<5> delta;
2652     bits<32> offset;
2653     bits<6> offsetBits; // memb - u6:0 , memh - u6:1, memw - u6:2
2654
2655     let offsetBits = !if (!eq(opcBits, 0b00), offset{5-0},
2656                      !if (!eq(opcBits, 0b01), offset{6-1},
2657                      !if (!eq(opcBits, 0b10), offset{7-2},0)));
2658
2659     let opExtentAlign = opcBits;
2660     let IClass = 0b0011;
2661     let Inst{27-24} = 0b1110;
2662     let Inst{22-21} = opcBits;
2663     let Inst{20-16} = base;
2664     let Inst{13} = 0b0;
2665     let Inst{12-7} = offsetBits;
2666     let Inst{6-5} = memOpBits;
2667     let Inst{4-0} = delta;
2668 }
2669
2670 //===----------------------------------------------------------------------===//
2671 // Template class for MemOp instructions with the immediate value.
2672 //===----------------------------------------------------------------------===//
2673 class MemOp_ri_base <string opc, bits<2> opcBits, Operand ImmOp,
2674                      string memOp, bits<2> memOpBits> :
2675       MEMInst_V4 <(outs),
2676                   (ins IntRegs:$base, ImmOp:$offset, u5Imm:$delta),
2677                   opc#"($base+#$offset)"#memOp#"#$delta"
2678                   #!if(memOpBits{1},")", ""), // clrbit, setbit - include ')'
2679                   []>,
2680                   Requires<[UseMEMOP]> {
2681
2682     bits<5> base;
2683     bits<5> delta;
2684     bits<32> offset;
2685     bits<6> offsetBits; // memb - u6:0 , memh - u6:1, memw - u6:2
2686
2687     let offsetBits = !if (!eq(opcBits, 0b00), offset{5-0},
2688                      !if (!eq(opcBits, 0b01), offset{6-1},
2689                      !if (!eq(opcBits, 0b10), offset{7-2},0)));
2690
2691     let opExtentAlign = opcBits;
2692     let IClass = 0b0011;
2693     let Inst{27-24} = 0b1111;
2694     let Inst{22-21} = opcBits;
2695     let Inst{20-16} = base;
2696     let Inst{13} = 0b0;
2697     let Inst{12-7} = offsetBits;
2698     let Inst{6-5} = memOpBits;
2699     let Inst{4-0} = delta;
2700 }
2701
2702 // multiclass to define MemOp instructions with register operand.
2703 multiclass MemOp_rr<string opc, bits<2> opcBits, Operand ImmOp> {
2704   def L4_add#NAME : MemOp_rr_base <opc, opcBits, ImmOp, " += ", 0b00>; // add
2705   def L4_sub#NAME : MemOp_rr_base <opc, opcBits, ImmOp, " -= ", 0b01>; // sub
2706   def L4_and#NAME : MemOp_rr_base <opc, opcBits, ImmOp, " &= ", 0b10>; // and
2707   def L4_or#NAME  : MemOp_rr_base <opc, opcBits, ImmOp, " |= ", 0b11>; // or
2708 }
2709
2710 // multiclass to define MemOp instructions with immediate Operand.
2711 multiclass MemOp_ri<string opc, bits<2> opcBits, Operand ImmOp> {
2712   def L4_iadd#NAME : MemOp_ri_base <opc, opcBits, ImmOp, " += ", 0b00 >;
2713   def L4_isub#NAME : MemOp_ri_base <opc, opcBits, ImmOp, " -= ", 0b01 >;
2714   def L4_iand#NAME : MemOp_ri_base<opc, opcBits, ImmOp, " = clrbit(", 0b10>;
2715   def L4_ior#NAME : MemOp_ri_base<opc, opcBits, ImmOp, " = setbit(", 0b11>;
2716 }
2717
2718 multiclass MemOp_base <string opc, bits<2> opcBits, Operand ImmOp> {
2719   defm _#NAME : MemOp_rr <opc, opcBits, ImmOp>;
2720   defm _#NAME : MemOp_ri <opc, opcBits, ImmOp>;
2721 }
2722
2723 // Define MemOp instructions.
2724 let isExtendable = 1, opExtendable = 1, isExtentSigned = 0,
2725     validSubTargets =HasV4SubT in {
2726   let opExtentBits = 6, accessSize = ByteAccess in
2727   defm memopb_io : MemOp_base <"memb", 0b00, u6_0Ext>;
2728
2729   let opExtentBits = 7, accessSize = HalfWordAccess in
2730   defm memoph_io : MemOp_base <"memh", 0b01, u6_1Ext>;
2731
2732   let opExtentBits = 8, accessSize = WordAccess in
2733   defm memopw_io : MemOp_base <"memw", 0b10, u6_2Ext>;
2734 }
2735
2736 //===----------------------------------------------------------------------===//
2737 // Multiclass to define 'Def Pats' for ALU operations on the memory
2738 // Here value used for the ALU operation is an immediate value.
2739 // mem[bh](Rs+#0) += #U5
2740 // mem[bh](Rs+#u6) += #U5
2741 //===----------------------------------------------------------------------===//
2742
2743 multiclass MemOpi_u5Pats <PatFrag ldOp, PatFrag stOp, PatLeaf ExtPred,
2744                           InstHexagon MI, SDNode OpNode> {
2745   let AddedComplexity = 180 in
2746   def : Pat < (stOp (OpNode (ldOp IntRegs:$addr), u5ImmPred:$addend),
2747                     IntRegs:$addr),
2748               (MI IntRegs:$addr, #0, u5ImmPred:$addend )>;
2749
2750   let AddedComplexity = 190 in
2751   def : Pat <(stOp (OpNode (ldOp (add IntRegs:$base, ExtPred:$offset)),
2752                      u5ImmPred:$addend),
2753              (add IntRegs:$base, ExtPred:$offset)),
2754        (MI IntRegs:$base, ExtPred:$offset, u5ImmPred:$addend)>;
2755 }
2756
2757 multiclass MemOpi_u5ALUOp<PatFrag ldOp, PatFrag stOp, PatLeaf ExtPred,
2758                           InstHexagon addMI, InstHexagon subMI> {
2759   defm : MemOpi_u5Pats<ldOp, stOp, ExtPred, addMI, add>;
2760   defm : MemOpi_u5Pats<ldOp, stOp, ExtPred, subMI, sub>;
2761 }
2762
2763 multiclass MemOpi_u5ExtType<PatFrag ldOpByte, PatFrag ldOpHalf > {
2764   // Half Word
2765   defm : MemOpi_u5ALUOp <ldOpHalf, truncstorei16, u6_1ExtPred,
2766                          L4_iadd_memoph_io, L4_isub_memoph_io>;
2767   // Byte
2768   defm : MemOpi_u5ALUOp <ldOpByte, truncstorei8, u6ExtPred,
2769                          L4_iadd_memopb_io, L4_isub_memopb_io>;
2770 }
2771
2772 let Predicates = [HasV4T, UseMEMOP] in {
2773   defm : MemOpi_u5ExtType<zextloadi8, zextloadi16>; // zero extend
2774   defm : MemOpi_u5ExtType<sextloadi8, sextloadi16>; // sign extend
2775   defm : MemOpi_u5ExtType<extloadi8,  extloadi16>;  // any extend
2776
2777   // Word
2778   defm : MemOpi_u5ALUOp <load, store, u6_2ExtPred, L4_iadd_memopw_io,
2779                          L4_isub_memopw_io>;
2780 }
2781
2782 //===----------------------------------------------------------------------===//
2783 // multiclass to define 'Def Pats' for ALU operations on the memory.
2784 // Here value used for the ALU operation is a negative value.
2785 // mem[bh](Rs+#0) += #m5
2786 // mem[bh](Rs+#u6) += #m5
2787 //===----------------------------------------------------------------------===//
2788
2789 multiclass MemOpi_m5Pats <PatFrag ldOp, PatFrag stOp, PatLeaf extPred,
2790                           PatLeaf immPred, ComplexPattern addrPred,
2791                           SDNodeXForm xformFunc, InstHexagon MI> {
2792   let AddedComplexity = 190 in
2793   def : Pat <(stOp (add (ldOp IntRegs:$addr), immPred:$subend),
2794                    IntRegs:$addr),
2795              (MI IntRegs:$addr, #0, (xformFunc immPred:$subend) )>;
2796
2797   let AddedComplexity = 195 in
2798   def : Pat<(stOp (add (ldOp (add IntRegs:$base, extPred:$offset)),
2799                        immPred:$subend),
2800                   (add IntRegs:$base, extPred:$offset)),
2801             (MI IntRegs:$base, extPred:$offset, (xformFunc immPred:$subend))>;
2802 }
2803
2804 multiclass MemOpi_m5ExtType<PatFrag ldOpByte, PatFrag ldOpHalf > {
2805   // Half Word
2806   defm : MemOpi_m5Pats <ldOpHalf, truncstorei16, u6_1ExtPred, m5HImmPred,
2807                         ADDRriU6_1, MEMOPIMM_HALF, L4_isub_memoph_io>;
2808   // Byte
2809   defm : MemOpi_m5Pats <ldOpByte, truncstorei8, u6ExtPred, m5BImmPred,
2810                         ADDRriU6_0, MEMOPIMM_BYTE, L4_isub_memopb_io>;
2811 }
2812
2813 let Predicates = [HasV4T, UseMEMOP] in {
2814   defm : MemOpi_m5ExtType<zextloadi8, zextloadi16>; // zero extend
2815   defm : MemOpi_m5ExtType<sextloadi8, sextloadi16>; // sign extend
2816   defm : MemOpi_m5ExtType<extloadi8,  extloadi16>;  // any extend
2817
2818   // Word
2819   defm : MemOpi_m5Pats <load, store, u6_2ExtPred, m5ImmPred,
2820                           ADDRriU6_2, MEMOPIMM, L4_isub_memopw_io>;
2821 }
2822
2823 //===----------------------------------------------------------------------===//
2824 // Multiclass to define 'def Pats' for bit operations on the memory.
2825 // mem[bhw](Rs+#0) = [clrbit|setbit](#U5)
2826 // mem[bhw](Rs+#u6) = [clrbit|setbit](#U5)
2827 //===----------------------------------------------------------------------===//
2828
2829 multiclass MemOpi_bitPats <PatFrag ldOp, PatFrag stOp, PatLeaf immPred,
2830                      PatLeaf extPred, ComplexPattern addrPred,
2831                      SDNodeXForm xformFunc, InstHexagon MI, SDNode OpNode> {
2832
2833   // mem[bhw](Rs+#u6:[012]) = [clrbit|setbit](#U5)
2834   let AddedComplexity = 250 in
2835   def : Pat<(stOp (OpNode (ldOp (add IntRegs:$base, extPred:$offset)),
2836                           immPred:$bitend),
2837                   (add IntRegs:$base, extPred:$offset)),
2838             (MI IntRegs:$base, extPred:$offset, (xformFunc immPred:$bitend))>;
2839
2840   // mem[bhw](Rs+#0) = [clrbit|setbit](#U5)
2841   let AddedComplexity = 225 in
2842   def : Pat <(stOp (OpNode (ldOp (addrPred IntRegs:$addr, extPred:$offset)),
2843                            immPred:$bitend),
2844                    (addrPred (i32 IntRegs:$addr), extPred:$offset)),
2845              (MI IntRegs:$addr, extPred:$offset, (xformFunc immPred:$bitend))>;
2846 }
2847
2848 multiclass MemOpi_bitExtType<PatFrag ldOpByte, PatFrag ldOpHalf > {
2849   // Byte - clrbit
2850   defm : MemOpi_bitPats<ldOpByte, truncstorei8, Clr3ImmPred, u6ExtPred,
2851                        ADDRriU6_0, CLRMEMIMM_BYTE, L4_iand_memopb_io, and>;
2852   // Byte - setbit
2853   defm : MemOpi_bitPats<ldOpByte, truncstorei8, Set3ImmPred,  u6ExtPred,
2854                        ADDRriU6_0, SETMEMIMM_BYTE, L4_ior_memopb_io, or>;
2855   // Half Word - clrbit
2856   defm : MemOpi_bitPats<ldOpHalf, truncstorei16, Clr4ImmPred, u6_1ExtPred,
2857                        ADDRriU6_1, CLRMEMIMM_SHORT, L4_iand_memoph_io, and>;
2858   // Half Word - setbit
2859   defm : MemOpi_bitPats<ldOpHalf, truncstorei16, Set4ImmPred, u6_1ExtPred,
2860                        ADDRriU6_1, SETMEMIMM_SHORT, L4_ior_memoph_io, or>;
2861 }
2862
2863 let Predicates = [HasV4T, UseMEMOP] in {
2864   // mem[bh](Rs+#0) = [clrbit|setbit](#U5)
2865   // mem[bh](Rs+#u6:[01]) = [clrbit|setbit](#U5)
2866   defm : MemOpi_bitExtType<zextloadi8, zextloadi16>; // zero extend
2867   defm : MemOpi_bitExtType<sextloadi8, sextloadi16>; // sign extend
2868   defm : MemOpi_bitExtType<extloadi8,  extloadi16>;  // any extend
2869
2870   // memw(Rs+#0) = [clrbit|setbit](#U5)
2871   // memw(Rs+#u6:2) = [clrbit|setbit](#U5)
2872   defm : MemOpi_bitPats<load, store, Clr5ImmPred, u6_2ExtPred, ADDRriU6_2,
2873                        CLRMEMIMM, L4_iand_memopw_io, and>;
2874   defm : MemOpi_bitPats<load, store, Set5ImmPred, u6_2ExtPred, ADDRriU6_2,
2875                        SETMEMIMM, L4_ior_memopw_io, or>;
2876 }
2877
2878 //===----------------------------------------------------------------------===//
2879 // Multiclass to define 'def Pats' for ALU operations on the memory
2880 // where addend is a register.
2881 // mem[bhw](Rs+#0) [+-&|]= Rt
2882 // mem[bhw](Rs+#U6:[012]) [+-&|]= Rt
2883 //===----------------------------------------------------------------------===//
2884
2885 multiclass MemOpr_Pats <PatFrag ldOp, PatFrag stOp, ComplexPattern addrPred,
2886                      PatLeaf extPred, InstHexagon MI, SDNode OpNode> {
2887   let AddedComplexity = 141 in
2888   // mem[bhw](Rs+#0) [+-&|]= Rt
2889   def : Pat <(stOp (OpNode (ldOp (addrPred IntRegs:$addr, extPred:$offset)),
2890                            (i32 IntRegs:$addend)),
2891                    (addrPred (i32 IntRegs:$addr), extPred:$offset)),
2892              (MI IntRegs:$addr, extPred:$offset, (i32 IntRegs:$addend) )>;
2893
2894   // mem[bhw](Rs+#U6:[012]) [+-&|]= Rt
2895   let AddedComplexity = 150 in
2896   def : Pat <(stOp (OpNode (ldOp (add IntRegs:$base, extPred:$offset)),
2897                            (i32 IntRegs:$orend)),
2898                    (add IntRegs:$base, extPred:$offset)),
2899              (MI IntRegs:$base, extPred:$offset, (i32 IntRegs:$orend) )>;
2900 }
2901
2902 multiclass MemOPr_ALUOp<PatFrag ldOp, PatFrag stOp,
2903                         ComplexPattern addrPred, PatLeaf extPred,
2904                         InstHexagon addMI, InstHexagon subMI,
2905                         InstHexagon andMI, InstHexagon orMI > {
2906
2907   defm : MemOpr_Pats <ldOp, stOp, addrPred, extPred, addMI, add>;
2908   defm : MemOpr_Pats <ldOp, stOp, addrPred, extPred, subMI, sub>;
2909   defm : MemOpr_Pats <ldOp, stOp, addrPred, extPred, andMI, and>;
2910   defm : MemOpr_Pats <ldOp, stOp, addrPred, extPred, orMI,  or>;
2911 }
2912
2913 multiclass MemOPr_ExtType<PatFrag ldOpByte, PatFrag ldOpHalf > {
2914   // Half Word
2915   defm : MemOPr_ALUOp <ldOpHalf, truncstorei16, ADDRriU6_1, u6_1ExtPred,
2916                        L4_add_memoph_io, L4_sub_memoph_io,
2917                        L4_and_memoph_io, L4_or_memoph_io>;
2918   // Byte
2919   defm : MemOPr_ALUOp <ldOpByte, truncstorei8, ADDRriU6_0, u6ExtPred,
2920                        L4_add_memopb_io, L4_sub_memopb_io,
2921                        L4_and_memopb_io, L4_or_memopb_io>;
2922 }
2923
2924 // Define 'def Pats' for MemOps with register addend.
2925 let Predicates = [HasV4T, UseMEMOP] in {
2926   // Byte, Half Word
2927   defm : MemOPr_ExtType<zextloadi8, zextloadi16>; // zero extend
2928   defm : MemOPr_ExtType<sextloadi8, sextloadi16>; // sign extend
2929   defm : MemOPr_ExtType<extloadi8,  extloadi16>;  // any extend
2930   // Word
2931   defm : MemOPr_ALUOp <load, store, ADDRriU6_2, u6_2ExtPred, L4_add_memopw_io,
2932                        L4_sub_memopw_io, L4_and_memopw_io, L4_or_memopw_io >;
2933 }
2934
2935 //===----------------------------------------------------------------------===//
2936 // XTYPE/PRED +
2937 //===----------------------------------------------------------------------===//
2938
2939 // Hexagon V4 only supports these flavors of byte/half compare instructions:
2940 // EQ/GT/GTU. Other flavors like GE/GEU/LT/LTU/LE/LEU are not supported by
2941 // hardware. However, compiler can still implement these patterns through
2942 // appropriate patterns combinations based on current implemented patterns.
2943 // The implemented patterns are: EQ/GT/GTU.
2944 // Missing patterns are: GE/GEU/LT/LTU/LE/LEU.
2945
2946 // Following instruction is not being extended as it results into the
2947 // incorrect code for negative numbers.
2948 // Pd=cmpb.eq(Rs,#u8)
2949
2950 // p=!cmp.eq(r1,#s10)
2951 def C4_cmpneqi  : T_CMP <"cmp.eq",  0b00, 1, s10Ext>;
2952 def C4_cmpltei  : T_CMP <"cmp.gt",  0b01, 1, s10Ext>;
2953 def C4_cmplteui : T_CMP <"cmp.gtu", 0b10, 1, u9Ext>;
2954
2955 def : T_CMP_pat <C4_cmpneqi,  setne,  s10ExtPred>;
2956 def : T_CMP_pat <C4_cmpltei,  setle,  s10ExtPred>;
2957 def : T_CMP_pat <C4_cmplteui, setule, u9ImmPred>;
2958
2959 // rs <= rt -> !(rs > rt).
2960 /*
2961 def: Pat<(i1 (setle (i32 IntRegs:$src1), s10ExtPred:$src2)),
2962          (C2_not (C2_cmpgti IntRegs:$src1, s10ExtPred:$src2))>;
2963 //         (C4_cmpltei IntRegs:$src1, s10ExtPred:$src2)>;
2964 */
2965 // Map cmplt(Rs, Imm) -> !cmpgt(Rs, Imm-1).
2966 def: Pat<(i1 (setlt (i32 IntRegs:$src1), s8ExtPred:$src2)),
2967          (C4_cmpltei IntRegs:$src1, (DEC_CONST_SIGNED s8ExtPred:$src2))>;
2968
2969 // rs != rt -> !(rs == rt).
2970 def: Pat<(i1 (setne (i32 IntRegs:$src1), s10ExtPred:$src2)),
2971          (C4_cmpneqi IntRegs:$src1, s10ExtPred:$src2)>;
2972
2973 // SDNode for converting immediate C to C-1.
2974 def DEC_CONST_BYTE : SDNodeXForm<imm, [{
2975    // Return the byte immediate const-1 as an SDNode.
2976    int32_t imm = N->getSExtValue();
2977    return XformU7ToU7M1Imm(imm);
2978 }]>;
2979
2980 // For the sequence
2981 //   zext( seteq ( and(Rs, 255), u8))
2982 // Generate
2983 //   Pd=cmpb.eq(Rs, #u8)
2984 //   if (Pd.new) Rd=#1
2985 //   if (!Pd.new) Rd=#0
2986 def : Pat <(i32 (zext (i1 (seteq (i32 (and (i32 IntRegs:$Rs), 255)),
2987                                            u8ExtPred:$u8)))),
2988            (i32 (TFR_condset_ii (i1 (A4_cmpbeqi (i32 IntRegs:$Rs),
2989                                                  (u8ExtPred:$u8))),
2990                                 1, 0))>,
2991            Requires<[HasV4T]>;
2992
2993 // For the sequence
2994 //   zext( setne ( and(Rs, 255), u8))
2995 // Generate
2996 //   Pd=cmpb.eq(Rs, #u8)
2997 //   if (Pd.new) Rd=#0
2998 //   if (!Pd.new) Rd=#1
2999 def : Pat <(i32 (zext (i1 (setne (i32 (and (i32 IntRegs:$Rs), 255)),
3000                                            u8ExtPred:$u8)))),
3001            (i32 (TFR_condset_ii (i1 (A4_cmpbeqi (i32 IntRegs:$Rs),
3002                                                  (u8ExtPred:$u8))),
3003                                 0, 1))>,
3004            Requires<[HasV4T]>;
3005
3006 // For the sequence
3007 //   zext( seteq (Rs, and(Rt, 255)))
3008 // Generate
3009 //   Pd=cmpb.eq(Rs, Rt)
3010 //   if (Pd.new) Rd=#1
3011 //   if (!Pd.new) Rd=#0
3012 def : Pat <(i32 (zext (i1 (seteq (i32 IntRegs:$Rt),
3013                                  (i32 (and (i32 IntRegs:$Rs), 255)))))),
3014            (i32 (TFR_condset_ii (i1 (A4_cmpbeq (i32 IntRegs:$Rs),
3015                                                       (i32 IntRegs:$Rt))),
3016                                 1, 0))>,
3017            Requires<[HasV4T]>;
3018
3019 // For the sequence
3020 //   zext( setne (Rs, and(Rt, 255)))
3021 // Generate
3022 //   Pd=cmpb.eq(Rs, Rt)
3023 //   if (Pd.new) Rd=#0
3024 //   if (!Pd.new) Rd=#1
3025 def : Pat <(i32 (zext (i1 (setne (i32 IntRegs:$Rt),
3026                                  (i32 (and (i32 IntRegs:$Rs), 255)))))),
3027            (i32 (TFR_condset_ii (i1 (A4_cmpbeq (i32 IntRegs:$Rs),
3028                                                       (i32 IntRegs:$Rt))),
3029                                 0, 1))>,
3030            Requires<[HasV4T]>;
3031
3032 // For the sequence
3033 //   zext( setugt ( and(Rs, 255), u8))
3034 // Generate
3035 //   Pd=cmpb.gtu(Rs, #u8)
3036 //   if (Pd.new) Rd=#1
3037 //   if (!Pd.new) Rd=#0
3038 def : Pat <(i32 (zext (i1 (setugt (i32 (and (i32 IntRegs:$Rs), 255)),
3039                                             u8ExtPred:$u8)))),
3040            (i32 (TFR_condset_ii (i1 (A4_cmpbgtui (i32 IntRegs:$Rs),
3041                                                   (u8ExtPred:$u8))),
3042                                 1, 0))>,
3043            Requires<[HasV4T]>;
3044
3045 // For the sequence
3046 //   zext( setugt ( and(Rs, 254), u8))
3047 // Generate
3048 //   Pd=cmpb.gtu(Rs, #u8)
3049 //   if (Pd.new) Rd=#1
3050 //   if (!Pd.new) Rd=#0
3051 def : Pat <(i32 (zext (i1 (setugt (i32 (and (i32 IntRegs:$Rs), 254)),
3052                                             u8ExtPred:$u8)))),
3053            (i32 (TFR_condset_ii (i1 (A4_cmpbgtui (i32 IntRegs:$Rs),
3054                                                   (u8ExtPred:$u8))),
3055                                 1, 0))>,
3056            Requires<[HasV4T]>;
3057
3058 // For the sequence
3059 //   zext( setult ( Rs, Rt))
3060 // Generate
3061 //   Pd=cmp.ltu(Rs, Rt)
3062 //   if (Pd.new) Rd=#1
3063 //   if (!Pd.new) Rd=#0
3064 // cmp.ltu(Rs, Rt) -> cmp.gtu(Rt, Rs)
3065 def : Pat <(i32 (zext (i1 (setult (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))))),
3066            (i32 (TFR_condset_ii (i1 (C2_cmpgtu (i32 IntRegs:$Rt),
3067                                               (i32 IntRegs:$Rs))),
3068                                 1, 0))>,
3069            Requires<[HasV4T]>;
3070
3071 // For the sequence
3072 //   zext( setlt ( Rs, Rt))
3073 // Generate
3074 //   Pd=cmp.lt(Rs, Rt)
3075 //   if (Pd.new) Rd=#1
3076 //   if (!Pd.new) Rd=#0
3077 // cmp.lt(Rs, Rt) -> cmp.gt(Rt, Rs)
3078 def : Pat <(i32 (zext (i1 (setlt (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))))),
3079            (i32 (TFR_condset_ii (i1 (C2_cmpgt (i32 IntRegs:$Rt),
3080                                              (i32 IntRegs:$Rs))),
3081                                 1, 0))>,
3082            Requires<[HasV4T]>;
3083
3084 // For the sequence
3085 //   zext( setugt ( Rs, Rt))
3086 // Generate
3087 //   Pd=cmp.gtu(Rs, Rt)
3088 //   if (Pd.new) Rd=#1
3089 //   if (!Pd.new) Rd=#0
3090 def : Pat <(i32 (zext (i1 (setugt (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))))),
3091            (i32 (TFR_condset_ii (i1 (C2_cmpgtu (i32 IntRegs:$Rs),
3092                                               (i32 IntRegs:$Rt))),
3093                                 1, 0))>,
3094            Requires<[HasV4T]>;
3095
3096 // This pattern interefers with coremark performance, not implementing at this
3097 // time.
3098 // For the sequence
3099 //   zext( setgt ( Rs, Rt))
3100 // Generate
3101 //   Pd=cmp.gt(Rs, Rt)
3102 //   if (Pd.new) Rd=#1
3103 //   if (!Pd.new) Rd=#0
3104
3105 // For the sequence
3106 //   zext( setuge ( Rs, Rt))
3107 // Generate
3108 //   Pd=cmp.ltu(Rs, Rt)
3109 //   if (Pd.new) Rd=#0
3110 //   if (!Pd.new) Rd=#1
3111 // cmp.ltu(Rs, Rt) -> cmp.gtu(Rt, Rs)
3112 def : Pat <(i32 (zext (i1 (setuge (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))))),
3113            (i32 (TFR_condset_ii (i1 (C2_cmpgtu (i32 IntRegs:$Rt),
3114                                               (i32 IntRegs:$Rs))),
3115                                 0, 1))>,
3116            Requires<[HasV4T]>;
3117
3118 // For the sequence
3119 //   zext( setge ( Rs, Rt))
3120 // Generate
3121 //   Pd=cmp.lt(Rs, Rt)
3122 //   if (Pd.new) Rd=#0
3123 //   if (!Pd.new) Rd=#1
3124 // cmp.lt(Rs, Rt) -> cmp.gt(Rt, Rs)
3125 def : Pat <(i32 (zext (i1 (setge (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))))),
3126            (i32 (TFR_condset_ii (i1 (C2_cmpgt (i32 IntRegs:$Rt),
3127                                              (i32 IntRegs:$Rs))),
3128                                 0, 1))>,
3129            Requires<[HasV4T]>;
3130
3131 // For the sequence
3132 //   zext( setule ( Rs, Rt))
3133 // Generate
3134 //   Pd=cmp.gtu(Rs, Rt)
3135 //   if (Pd.new) Rd=#0
3136 //   if (!Pd.new) Rd=#1
3137 def : Pat <(i32 (zext (i1 (setule (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))))),
3138            (i32 (TFR_condset_ii (i1 (C2_cmpgtu (i32 IntRegs:$Rs),
3139                                               (i32 IntRegs:$Rt))),
3140                                 0, 1))>,
3141            Requires<[HasV4T]>;
3142
3143 // For the sequence
3144 //   zext( setle ( Rs, Rt))
3145 // Generate
3146 //   Pd=cmp.gt(Rs, Rt)
3147 //   if (Pd.new) Rd=#0
3148 //   if (!Pd.new) Rd=#1
3149 def : Pat <(i32 (zext (i1 (setle (i32 IntRegs:$Rs), (i32 IntRegs:$Rt))))),
3150            (i32 (TFR_condset_ii (i1 (C2_cmpgt (i32 IntRegs:$Rs),
3151                                              (i32 IntRegs:$Rt))),
3152                                 0, 1))>,
3153            Requires<[HasV4T]>;
3154
3155 // For the sequence
3156 //   zext( setult ( and(Rs, 255), u8))
3157 // Use the isdigit transformation below
3158
3159 // Generate code of the form 'mux_ii(cmpbgtu(Rdd, C-1),0,1)'
3160 // for C code of the form r = ((c>='0') & (c<='9')) ? 1 : 0;.
3161 // The isdigit transformation relies on two 'clever' aspects:
3162 // 1) The data type is unsigned which allows us to eliminate a zero test after
3163 //    biasing the expression by 48. We are depending on the representation of
3164 //    the unsigned types, and semantics.
3165 // 2) The front end has converted <= 9 into < 10 on entry to LLVM
3166 //
3167 // For the C code:
3168 //   retval = ((c>='0') & (c<='9')) ? 1 : 0;
3169 // The code is transformed upstream of llvm into
3170 //   retval = (c-48) < 10 ? 1 : 0;
3171 let AddedComplexity = 139 in
3172 def : Pat <(i32 (zext (i1 (setult (i32 (and (i32 IntRegs:$src1), 255)),
3173                                   u7StrictPosImmPred:$src2)))),
3174   (i32 (C2_muxii (i1 (A4_cmpbgtui (i32 IntRegs:$src1),
3175                                  (DEC_CONST_BYTE u7StrictPosImmPred:$src2))),
3176                    0, 1))>,
3177                    Requires<[HasV4T]>;
3178
3179 //===----------------------------------------------------------------------===//
3180 // XTYPE/PRED -
3181 //===----------------------------------------------------------------------===//
3182
3183 //===----------------------------------------------------------------------===//
3184 // Multiclass for DeallocReturn
3185 //===----------------------------------------------------------------------===//
3186 class L4_RETURN<string mnemonic, bit isNot, bit isPredNew, bit isTak>
3187   : LD0Inst<(outs), (ins PredRegs:$src),
3188   !if(isNot, "if (!$src", "if ($src")#
3189   !if(isPredNew, ".new) ", ") ")#mnemonic#
3190   !if(isPredNew, #!if(isTak,":t", ":nt"),""),
3191   [], "", LD_tc_3or4stall_SLOT0> {
3192
3193     bits<2> src;
3194     let BaseOpcode = "L4_RETURN";
3195     let isPredicatedFalse = isNot;
3196     let isPredicatedNew = isPredNew;
3197     let isTaken = isTak;
3198     let IClass = 0b1001;
3199
3200     let Inst{27-16} = 0b011000011110;
3201
3202     let Inst{13} = isNot;
3203     let Inst{12} = isTak;
3204     let Inst{11} = isPredNew;
3205     let Inst{10} = 0b0;
3206     let Inst{9-8} = src;
3207     let Inst{4-0} = 0b11110;
3208   }
3209
3210 // Produce all predicated forms, p, !p, p.new, !p.new, :t, :nt
3211 multiclass L4_RETURN_PRED<string mnemonic, bit PredNot> {
3212   let isPredicated = 1 in {
3213     def _#NAME# : L4_RETURN <mnemonic, PredNot, 0, 1>;
3214     def _#NAME#new_pnt : L4_RETURN <mnemonic, PredNot, 1, 0>;
3215     def _#NAME#new_pt : L4_RETURN <mnemonic, PredNot, 1, 1>;
3216   }
3217 }
3218
3219 multiclass LD_MISC_L4_RETURN<string mnemonic> {
3220   let isBarrier = 1, isPredicable = 1 in
3221     def NAME : LD0Inst <(outs), (ins), mnemonic, [], "",
3222                         LD_tc_3or4stall_SLOT0> {
3223       let BaseOpcode = "L4_RETURN";
3224       let IClass = 0b1001;
3225       let Inst{27-16} = 0b011000011110;
3226       let Inst{13-10} = 0b0000;
3227       let Inst{4-0} = 0b11110;
3228     }
3229   defm t : L4_RETURN_PRED<mnemonic, 0 >;
3230   defm f : L4_RETURN_PRED<mnemonic, 1 >;
3231 }
3232
3233 let isReturn = 1, isTerminator = 1,
3234     Defs = [R29, R30, R31, PC], Uses = [R30], hasSideEffects = 0,
3235     validSubTargets = HasV4SubT in
3236 defm L4_return: LD_MISC_L4_RETURN <"dealloc_return">, PredNewRel;
3237
3238 // Restore registers and dealloc return function call.
3239 let isCall = 1, isBarrier = 1, isReturn = 1, isTerminator = 1,
3240   Defs = [R29, R30, R31, PC], isAsmParserOnly = 1 in {
3241 let validSubTargets = HasV4SubT in
3242   def RESTORE_DEALLOC_RET_JMP_V4 : JInst<(outs),
3243                                    (ins calltarget:$dst),
3244              "jump $dst",
3245              []>,
3246              Requires<[HasV4T]>;
3247 }
3248
3249 // Restore registers and dealloc frame before a tail call.
3250 let isCall = 1, isBarrier = 1, isAsmParserOnly = 1,
3251   Defs = [R29, R30, R31, PC] in {
3252 let validSubTargets = HasV4SubT in
3253   def RESTORE_DEALLOC_BEFORE_TAILCALL_V4 : JInst<(outs),
3254                                            (ins calltarget:$dst),
3255              "call $dst",
3256              []>,
3257              Requires<[HasV4T]>;
3258 }
3259
3260 // Save registers function call.
3261 let isCall = 1, isBarrier = 1, isAsmParserOnly = 1,
3262   Uses = [R29, R31] in {
3263   def SAVE_REGISTERS_CALL_V4 : JInst<(outs),
3264                                (ins calltarget:$dst),
3265              "call $dst // Save_calle_saved_registers",
3266              []>,
3267              Requires<[HasV4T]>;
3268 }
3269
3270 //===----------------------------------------------------------------------===//
3271 // Template class for non predicated store instructions with
3272 // GP-Relative or absolute addressing.
3273 //===----------------------------------------------------------------------===//
3274 let hasSideEffects = 0, isPredicable = 1, isNVStorable = 1 in
3275 class T_StoreAbsGP <string mnemonic, RegisterClass RC, Operand ImmOp,
3276                     bits<2>MajOp, Operand AddrOp, bit isAbs, bit isHalf>
3277   : STInst<(outs), (ins AddrOp:$addr, RC:$src),
3278   mnemonic # !if(isAbs, "(##", "(#")#"$addr) = $src"#!if(isHalf, ".h",""),
3279   [], "", V2LDST_tc_st_SLOT01> {
3280     bits<19> addr;
3281     bits<5> src;
3282     bits<16> offsetBits;
3283
3284     string ImmOpStr = !cast<string>(ImmOp);
3285     let offsetBits = !if (!eq(ImmOpStr, "u16_3Imm"), addr{18-3},
3286                      !if (!eq(ImmOpStr, "u16_2Imm"), addr{17-2},
3287                      !if (!eq(ImmOpStr, "u16_1Imm"), addr{16-1},
3288                                       /* u16_0Imm */ addr{15-0})));
3289     let IClass = 0b0100;
3290     let Inst{27} = 1;
3291     let Inst{26-25} = offsetBits{15-14};
3292     let Inst{24}    = 0b0;
3293     let Inst{23-22} = MajOp;
3294     let Inst{21}    = isHalf;
3295     let Inst{20-16} = offsetBits{13-9};
3296     let Inst{13}    = offsetBits{8};
3297     let Inst{12-8}  = src;
3298     let Inst{7-0}   = offsetBits{7-0};
3299   }
3300
3301 //===----------------------------------------------------------------------===//
3302 // Template class for predicated store instructions with
3303 // GP-Relative or absolute addressing.
3304 //===----------------------------------------------------------------------===//
3305 let hasSideEffects = 0, isPredicated = 1, isNVStorable = 1, opExtentBits = 6,
3306     opExtendable = 1 in
3307 class T_StoreAbs_Pred <string mnemonic, RegisterClass RC, bits<2> MajOp,
3308                        bit isHalf, bit isNot, bit isNew>
3309   : STInst<(outs), (ins PredRegs:$src1, u6Ext:$absaddr, RC: $src2),
3310   !if(isNot, "if (!$src1", "if ($src1")#!if(isNew, ".new) ",
3311   ") ")#mnemonic#"(#$absaddr) = $src2"#!if(isHalf, ".h",""),
3312   [], "", ST_tc_st_SLOT01>, AddrModeRel {
3313     bits<2> src1;
3314     bits<6> absaddr;
3315     bits<5> src2;
3316
3317     let isPredicatedNew = isNew;
3318     let isPredicatedFalse = isNot;
3319
3320     let IClass = 0b1010;
3321
3322     let Inst{27-24} = 0b1111;
3323     let Inst{23-22} = MajOp;
3324     let Inst{21}    = isHalf;
3325     let Inst{17-16} = absaddr{5-4};
3326     let Inst{13}    = isNew;
3327     let Inst{12-8}  = src2;
3328     let Inst{7}     = 0b1;
3329     let Inst{6-3}   = absaddr{3-0};
3330     let Inst{2}     = isNot;
3331     let Inst{1-0}   = src1;
3332   }
3333
3334 //===----------------------------------------------------------------------===//
3335 // Template class for predicated store instructions with absolute addressing.
3336 //===----------------------------------------------------------------------===//
3337 class T_StoreAbs <string mnemonic, RegisterClass RC, Operand ImmOp,
3338                  bits<2> MajOp, bit isHalf>
3339   : T_StoreAbsGP <mnemonic, RC, ImmOp, MajOp, u0AlwaysExt, 1, isHalf>,
3340                   AddrModeRel {
3341   string ImmOpStr = !cast<string>(ImmOp);
3342   let opExtentBits = !if (!eq(ImmOpStr, "u16_3Imm"), 19,
3343                      !if (!eq(ImmOpStr, "u16_2Imm"), 18,
3344                      !if (!eq(ImmOpStr, "u16_1Imm"), 17,
3345                                       /* u16_0Imm */ 16)));
3346
3347   let opExtentAlign = !if (!eq(ImmOpStr, "u16_3Imm"), 3,
3348                       !if (!eq(ImmOpStr, "u16_2Imm"), 2,
3349                       !if (!eq(ImmOpStr, "u16_1Imm"), 1,
3350                                        /* u16_0Imm */ 0)));
3351 }
3352
3353 //===----------------------------------------------------------------------===//
3354 // Multiclass for store instructions with absolute addressing.
3355 //===----------------------------------------------------------------------===//
3356 let validSubTargets = HasV4SubT, addrMode = Absolute, isExtended = 1 in
3357 multiclass ST_Abs<string mnemonic, string CextOp, RegisterClass RC,
3358                   Operand ImmOp, bits<2> MajOp, bit isHalf = 0> {
3359   let CextOpcode = CextOp, BaseOpcode = CextOp#_abs in {
3360     let opExtendable = 0, isPredicable = 1 in
3361     def S2_#NAME#abs : T_StoreAbs <mnemonic, RC, ImmOp, MajOp, isHalf>;
3362
3363     // Predicated
3364     def S4_p#NAME#t_abs : T_StoreAbs_Pred<mnemonic, RC, MajOp, isHalf, 0, 0>;
3365     def S4_p#NAME#f_abs : T_StoreAbs_Pred<mnemonic, RC, MajOp, isHalf, 1, 0>;
3366
3367     // .new Predicated
3368     def S4_p#NAME#tnew_abs : T_StoreAbs_Pred<mnemonic, RC, MajOp, isHalf, 0, 1>;
3369     def S4_p#NAME#fnew_abs : T_StoreAbs_Pred<mnemonic, RC, MajOp, isHalf, 1, 1>;
3370   }
3371 }
3372
3373 //===----------------------------------------------------------------------===//
3374 // Template class for non predicated new-value store instructions with
3375 // GP-Relative or absolute addressing.
3376 //===----------------------------------------------------------------------===//
3377 let hasSideEffects = 0, isPredicable = 1, mayStore = 1, isNVStore = 1,
3378     isNewValue = 1, opNewValue = 1 in
3379 class T_StoreAbsGP_NV <string mnemonic, Operand ImmOp, bits<2>MajOp, bit isAbs>
3380   : NVInst_V4<(outs), (ins u0AlwaysExt:$addr, IntRegs:$src),
3381   mnemonic # !if(isAbs, "(##", "(#")#"$addr) = $src.new",
3382   [], "", V2LDST_tc_st_SLOT0> {
3383     bits<19> addr;
3384     bits<3> src;
3385     bits<16> offsetBits;
3386
3387     string ImmOpStr = !cast<string>(ImmOp);
3388     let offsetBits = !if (!eq(ImmOpStr, "u16_3Imm"), addr{18-3},
3389                      !if (!eq(ImmOpStr, "u16_2Imm"), addr{17-2},
3390                      !if (!eq(ImmOpStr, "u16_1Imm"), addr{16-1},
3391                                       /* u16_0Imm */ addr{15-0})));
3392     let IClass = 0b0100;
3393
3394     let Inst{27} = 1;
3395     let Inst{26-25} = offsetBits{15-14};
3396     let Inst{24-21} = 0b0101;
3397     let Inst{20-16} = offsetBits{13-9};
3398     let Inst{13}    = offsetBits{8};
3399     let Inst{12-11} = MajOp;
3400     let Inst{10-8}  = src;
3401     let Inst{7-0}   = offsetBits{7-0};
3402   }
3403
3404 //===----------------------------------------------------------------------===//
3405 // Template class for predicated new-value store instructions with
3406 // absolute addressing.
3407 //===----------------------------------------------------------------------===//
3408 let hasSideEffects = 0, isPredicated = 1, mayStore = 1, isNVStore = 1,
3409     isNewValue = 1, opNewValue = 2, opExtentBits = 6, opExtendable = 1 in
3410 class T_StoreAbs_NV_Pred <string mnemonic, bits<2> MajOp, bit isNot, bit isNew>
3411   : NVInst_V4<(outs), (ins PredRegs:$src1, u6Ext:$absaddr, IntRegs:$src2),
3412   !if(isNot, "if (!$src1", "if ($src1")#!if(isNew, ".new) ",
3413   ") ")#mnemonic#"(#$absaddr) = $src2.new",
3414   [], "", ST_tc_st_SLOT0>, AddrModeRel {
3415     bits<2> src1;
3416     bits<6> absaddr;
3417     bits<3> src2;
3418
3419     let isPredicatedNew = isNew;
3420     let isPredicatedFalse = isNot;
3421
3422     let IClass = 0b1010;
3423
3424     let Inst{27-24} = 0b1111;
3425     let Inst{23-21} = 0b101;
3426     let Inst{17-16} = absaddr{5-4};
3427     let Inst{13}    = isNew;
3428     let Inst{12-11} = MajOp;
3429     let Inst{10-8}  = src2;
3430     let Inst{7}     = 0b1;
3431     let Inst{6-3}   = absaddr{3-0};
3432     let Inst{2}     = isNot;
3433     let Inst{1-0}   = src1;
3434 }
3435
3436 //===----------------------------------------------------------------------===//
3437 // Template class for non-predicated new-value store instructions with
3438 // absolute addressing.
3439 //===----------------------------------------------------------------------===//
3440 class T_StoreAbs_NV <string mnemonic, Operand ImmOp, bits<2> MajOp>
3441   : T_StoreAbsGP_NV <mnemonic, ImmOp, MajOp, 1>, AddrModeRel {
3442
3443   string ImmOpStr = !cast<string>(ImmOp);
3444   let opExtentBits = !if (!eq(ImmOpStr, "u16_3Imm"), 19,
3445                      !if (!eq(ImmOpStr, "u16_2Imm"), 18,
3446                      !if (!eq(ImmOpStr, "u16_1Imm"), 17,
3447                                       /* u16_0Imm */ 16)));
3448
3449   let opExtentAlign = !if (!eq(ImmOpStr, "u16_3Imm"), 3,
3450                       !if (!eq(ImmOpStr, "u16_2Imm"), 2,
3451                       !if (!eq(ImmOpStr, "u16_1Imm"), 1,
3452                                        /* u16_0Imm */ 0)));
3453 }
3454
3455 //===----------------------------------------------------------------------===//
3456 // Multiclass for new-value store instructions with absolute addressing.
3457 //===----------------------------------------------------------------------===//
3458 let validSubTargets = HasV4SubT, addrMode = Absolute, isExtended = 1  in
3459 multiclass ST_Abs_NV <string mnemonic, string CextOp, Operand ImmOp,
3460                    bits<2> MajOp> {
3461   let CextOpcode = CextOp, BaseOpcode = CextOp#_abs in {
3462     let opExtendable = 0, isPredicable = 1 in
3463     def S2_#NAME#newabs : T_StoreAbs_NV <mnemonic, ImmOp, MajOp>;
3464
3465     // Predicated
3466     def S4_p#NAME#newt_abs  : T_StoreAbs_NV_Pred <mnemonic, MajOp, 0, 0>;
3467     def S4_p#NAME#newf_abs  : T_StoreAbs_NV_Pred <mnemonic, MajOp, 1, 0>;
3468
3469     // .new Predicated
3470     def S4_p#NAME#newtnew_abs : T_StoreAbs_NV_Pred <mnemonic, MajOp, 0, 1>;
3471     def S4_p#NAME#newfnew_abs : T_StoreAbs_NV_Pred <mnemonic, MajOp, 1, 1>;
3472   }
3473 }
3474
3475 //===----------------------------------------------------------------------===//
3476 // Stores with absolute addressing
3477 //===----------------------------------------------------------------------===//
3478 let accessSize = ByteAccess in
3479 defm storerb : ST_Abs    <"memb", "STrib", IntRegs, u16_0Imm, 0b00>,
3480                ST_Abs_NV <"memb", "STrib", u16_0Imm, 0b00>;
3481
3482 let accessSize = HalfWordAccess in
3483 defm storerh : ST_Abs    <"memh", "STrih", IntRegs, u16_1Imm, 0b01>,
3484                ST_Abs_NV <"memh", "STrih", u16_1Imm, 0b01>;
3485
3486 let accessSize = WordAccess in
3487 defm storeri : ST_Abs    <"memw", "STriw", IntRegs, u16_2Imm, 0b10>,
3488                ST_Abs_NV <"memw", "STriw", u16_2Imm, 0b10>;
3489
3490 let isNVStorable = 0, accessSize = DoubleWordAccess in
3491 defm storerd : ST_Abs <"memd", "STrid", DoubleRegs, u16_3Imm, 0b11>;
3492
3493 let isNVStorable = 0, accessSize = HalfWordAccess in
3494 defm storerf : ST_Abs <"memh", "STrif", IntRegs, u16_1Imm, 0b01, 1>;
3495
3496 //===----------------------------------------------------------------------===//
3497 // GP-relative stores.
3498 // mem[bhwd](#global)=Rt
3499 // Once predicated, these instructions map to absolute addressing mode.
3500 // if ([!]Pv[.new]) mem[bhwd](##global)=Rt
3501 //===----------------------------------------------------------------------===//
3502
3503 let validSubTargets = HasV4SubT, isAsmParserOnly = 1 in
3504 class T_StoreGP <string mnemonic, string BaseOp, RegisterClass RC,
3505                  Operand ImmOp, bits<2> MajOp, bit isHalf = 0>
3506   : T_StoreAbsGP <mnemonic, RC, ImmOp, MajOp, globaladdress, 0, isHalf> {
3507     // Set BaseOpcode same as absolute addressing instructions so that
3508     // non-predicated GP-Rel instructions can have relate with predicated
3509     // Absolute instruction.
3510     let BaseOpcode = BaseOp#_abs;
3511   }
3512
3513 let validSubTargets = HasV4SubT, isAsmParserOnly = 1 in
3514 multiclass ST_GP <string mnemonic, string BaseOp, Operand ImmOp,
3515                   bits<2> MajOp, bit isHalf = 0> {
3516   // Set BaseOpcode same as absolute addressing instructions so that
3517   // non-predicated GP-Rel instructions can have relate with predicated
3518   // Absolute instruction.
3519   let BaseOpcode = BaseOp#_abs in {
3520     def NAME#gp : T_StoreAbsGP <mnemonic, IntRegs, ImmOp, MajOp,
3521                                 globaladdress, 0, isHalf>;
3522     // New-value store
3523     def NAME#newgp : T_StoreAbsGP_NV <mnemonic, ImmOp, MajOp, 0> ;
3524   }
3525 }
3526
3527 let accessSize = ByteAccess in
3528 defm S2_storerb : ST_GP<"memb", "STrib", u16_0Imm, 0b00>, NewValueRel;
3529
3530 let accessSize = HalfWordAccess in
3531 defm S2_storerh : ST_GP<"memh", "STrih", u16_1Imm, 0b01>, NewValueRel;
3532
3533 let accessSize = WordAccess in
3534 defm S2_storeri : ST_GP<"memw", "STriw", u16_2Imm, 0b10>, NewValueRel;
3535
3536 let isNVStorable = 0, accessSize = DoubleWordAccess in
3537 def S2_storerdgp : T_StoreGP <"memd", "STrid", DoubleRegs,
3538                               u16_3Imm, 0b11>, PredNewRel;
3539
3540 let isNVStorable = 0, accessSize = HalfWordAccess in
3541 def S2_storerfgp : T_StoreGP <"memh", "STrif", IntRegs,
3542                               u16_1Imm, 0b01, 1>, PredNewRel;
3543
3544 class Loada_pat<PatFrag Load, ValueType VT, PatFrag Addr, InstHexagon MI>
3545   : Pat<(VT (Load Addr:$addr)), (MI Addr:$addr)>;
3546
3547 class Loadam_pat<PatFrag Load, ValueType VT, PatFrag Addr, PatFrag ValueMod,
3548                  InstHexagon MI>
3549   : Pat<(VT (Load Addr:$addr)), (ValueMod (MI Addr:$addr))>;
3550
3551 class Storea_pat<PatFrag Store, PatFrag Value, PatFrag Addr, InstHexagon MI>
3552   : Pat<(Store Value:$val, Addr:$addr), (MI Addr:$addr, Value:$val)>;
3553
3554 class Stoream_pat<PatFrag Store, PatFrag Value, PatFrag Addr, PatFrag ValueMod,
3555                   InstHexagon MI>
3556   : Pat<(Store Value:$val, Addr:$addr),
3557         (MI Addr:$addr, (ValueMod Value:$val))>;
3558
3559 def: Storea_pat<SwapSt<atomic_store_8>,  I32, addrgp, S2_storerbgp>;
3560 def: Storea_pat<SwapSt<atomic_store_16>, I32, addrgp, S2_storerhgp>;
3561 def: Storea_pat<SwapSt<atomic_store_32>, I32, addrgp, S2_storerigp>;
3562 def: Storea_pat<SwapSt<atomic_store_64>, I64, addrgp, S2_storerdgp>;
3563
3564 let AddedComplexity = 100 in {
3565   def: Storea_pat<truncstorei8,  I32, addrgp, S2_storerbgp>;
3566   def: Storea_pat<truncstorei16, I32, addrgp, S2_storerhgp>;
3567   def: Storea_pat<store,         I32, addrgp, S2_storerigp>;
3568   def: Storea_pat<store,         I64, addrgp, S2_storerdgp>;
3569
3570   // Map from "i1 = constant<-1>; memw(CONST32(#foo)) = i1"
3571   //       to "r0 = 1; memw(#foo) = r0"
3572   let AddedComplexity = 100 in
3573   def: Pat<(store (i1 -1), (HexagonCONST32_GP tglobaladdr:$global)),
3574            (S2_storerbgp tglobaladdr:$global, (A2_tfrsi 1))>;
3575 }
3576
3577 //===----------------------------------------------------------------------===//
3578 // Template class for non predicated load instructions with
3579 // absolute addressing mode.
3580 //===----------------------------------------------------------------------===//
3581 let isPredicable = 1, hasSideEffects = 0, validSubTargets = HasV4SubT in
3582 class T_LoadAbsGP <string mnemonic, RegisterClass RC, Operand ImmOp,
3583                    bits<3> MajOp, Operand AddrOp, bit isAbs>
3584   : LDInst <(outs RC:$dst), (ins AddrOp:$addr),
3585   "$dst = "#mnemonic# !if(isAbs, "(##", "(#")#"$addr)",
3586   [], "", V2LDST_tc_ld_SLOT01> {
3587     bits<5> dst;
3588     bits<19> addr;
3589     bits<16> offsetBits;
3590
3591     string ImmOpStr = !cast<string>(ImmOp);
3592     let offsetBits = !if (!eq(ImmOpStr, "u16_3Imm"), addr{18-3},
3593                      !if (!eq(ImmOpStr, "u16_2Imm"), addr{17-2},
3594                      !if (!eq(ImmOpStr, "u16_1Imm"), addr{16-1},
3595                                       /* u16_0Imm */ addr{15-0})));
3596
3597     let IClass = 0b0100;
3598
3599     let Inst{27}    = 0b1;
3600     let Inst{26-25} = offsetBits{15-14};
3601     let Inst{24}    = 0b1;
3602     let Inst{23-21} = MajOp;
3603     let Inst{20-16} = offsetBits{13-9};
3604     let Inst{13-5}  = offsetBits{8-0};
3605     let Inst{4-0}   = dst;
3606   }
3607
3608 class T_LoadAbs <string mnemonic, RegisterClass RC, Operand ImmOp,
3609                  bits<3> MajOp>
3610   : T_LoadAbsGP <mnemonic, RC, ImmOp, MajOp, u0AlwaysExt, 1>, AddrModeRel {
3611
3612     string ImmOpStr = !cast<string>(ImmOp);
3613     let opExtentBits = !if (!eq(ImmOpStr, "u16_3Imm"), 19,
3614                        !if (!eq(ImmOpStr, "u16_2Imm"), 18,
3615                        !if (!eq(ImmOpStr, "u16_1Imm"), 17,
3616                                         /* u16_0Imm */ 16)));
3617
3618     let opExtentAlign = !if (!eq(ImmOpStr, "u16_3Imm"), 3,
3619                         !if (!eq(ImmOpStr, "u16_2Imm"), 2,
3620                         !if (!eq(ImmOpStr, "u16_1Imm"), 1,
3621                                         /* u16_0Imm */ 0)));
3622   }
3623 //===----------------------------------------------------------------------===//
3624 // Template class for predicated load instructions with
3625 // absolute addressing mode.
3626 //===----------------------------------------------------------------------===//
3627 let isPredicated = 1, hasNewValue = 1, opExtentBits = 6, opExtendable = 2 in
3628 class T_LoadAbs_Pred <string mnemonic, RegisterClass RC, bits<3> MajOp,
3629                       bit isPredNot, bit isPredNew>
3630   : LDInst <(outs RC:$dst), (ins PredRegs:$src1, u6Ext:$absaddr),
3631   !if(isPredNot, "if (!$src1", "if ($src1")#!if(isPredNew, ".new) ",
3632   ") ")#"$dst = "#mnemonic#"(#$absaddr)">, AddrModeRel {
3633     bits<5> dst;
3634     bits<2> src1;
3635     bits<6> absaddr;
3636
3637     let isPredicatedNew = isPredNew;
3638     let isPredicatedFalse = isPredNot;
3639
3640     let IClass = 0b1001;
3641
3642     let Inst{27-24} = 0b1111;
3643     let Inst{23-21} = MajOp;
3644     let Inst{20-16} = absaddr{5-1};
3645     let Inst{13} = 0b1;
3646     let Inst{12} = isPredNew;
3647     let Inst{11} = isPredNot;
3648     let Inst{10-9} = src1;
3649     let Inst{8} = absaddr{0};
3650     let Inst{7} = 0b1;
3651     let Inst{4-0} = dst;
3652   }
3653
3654 //===----------------------------------------------------------------------===//
3655 // Multiclass for the load instructions with absolute addressing mode.
3656 //===----------------------------------------------------------------------===//
3657 multiclass LD_Abs_Pred<string mnemonic, RegisterClass RC, bits<3> MajOp,
3658                        bit PredNot> {
3659   def _abs : T_LoadAbs_Pred <mnemonic, RC, MajOp, PredNot, 0>;
3660   // Predicate new
3661   def new_abs : T_LoadAbs_Pred <mnemonic, RC, MajOp, PredNot, 1>;
3662 }
3663
3664 let addrMode = Absolute, isExtended = 1 in
3665 multiclass LD_Abs<string mnemonic, string CextOp, RegisterClass RC,
3666                   Operand ImmOp, bits<3> MajOp> {
3667   let CextOpcode = CextOp, BaseOpcode = CextOp#_abs in {
3668     let opExtendable = 1, isPredicable = 1 in
3669     def L4_#NAME#_abs: T_LoadAbs <mnemonic, RC, ImmOp, MajOp>;
3670
3671     // Predicated
3672     defm L4_p#NAME#t : LD_Abs_Pred<mnemonic, RC, MajOp, 0>;
3673     defm L4_p#NAME#f : LD_Abs_Pred<mnemonic, RC, MajOp, 1>;
3674   }
3675 }
3676
3677 let accessSize = ByteAccess, hasNewValue = 1 in {
3678   defm loadrb  : LD_Abs<"memb",  "LDrib",  IntRegs, u16_0Imm, 0b000>;
3679   defm loadrub : LD_Abs<"memub", "LDriub", IntRegs, u16_0Imm, 0b001>;
3680 }
3681
3682 let accessSize = HalfWordAccess, hasNewValue = 1 in {
3683   defm loadrh  : LD_Abs<"memh",  "LDrih",  IntRegs, u16_1Imm, 0b010>;
3684   defm loadruh : LD_Abs<"memuh", "LDriuh", IntRegs, u16_1Imm, 0b011>;
3685 }
3686
3687 let accessSize = WordAccess, hasNewValue = 1 in
3688 defm loadri  : LD_Abs<"memw",  "LDriw",  IntRegs, u16_2Imm, 0b100>;
3689
3690 let accessSize = DoubleWordAccess in
3691 defm loadrd  : LD_Abs<"memd",  "LDrid", DoubleRegs, u16_3Imm, 0b110>;
3692
3693 //===----------------------------------------------------------------------===//
3694 // multiclass for load instructions with GP-relative addressing mode.
3695 // Rx=mem[bhwd](##global)
3696 // Once predicated, these instructions map to absolute addressing mode.
3697 // if ([!]Pv[.new]) Rx=mem[bhwd](##global)
3698 //===----------------------------------------------------------------------===//
3699
3700 let isAsmParserOnly = 1 in
3701 class T_LoadGP <string mnemonic, string BaseOp, RegisterClass RC, Operand ImmOp,
3702                 bits<3> MajOp>
3703   : T_LoadAbsGP <mnemonic, RC, ImmOp, MajOp, globaladdress, 0>, PredNewRel {
3704     let BaseOpcode = BaseOp#_abs;
3705   }
3706
3707 let accessSize = ByteAccess, hasNewValue = 1 in {
3708   def L2_loadrbgp  : T_LoadGP<"memb",  "LDrib",  IntRegs, u16_0Imm, 0b000>;
3709   def L2_loadrubgp : T_LoadGP<"memub", "LDriub", IntRegs, u16_0Imm, 0b001>;
3710 }
3711
3712 let accessSize = HalfWordAccess, hasNewValue = 1 in {
3713   def L2_loadrhgp  : T_LoadGP<"memh",  "LDrih",  IntRegs, u16_1Imm, 0b010>;
3714   def L2_loadruhgp : T_LoadGP<"memuh", "LDriuh", IntRegs, u16_1Imm, 0b011>;
3715 }
3716
3717 let accessSize = WordAccess, hasNewValue = 1 in
3718 def L2_loadrigp  : T_LoadGP<"memw",  "LDriw",  IntRegs, u16_2Imm, 0b100>;
3719
3720 let accessSize = DoubleWordAccess in
3721 def L2_loadrdgp  : T_LoadGP<"memd", "LDrid", DoubleRegs, u16_3Imm, 0b110>;
3722
3723 def: Loada_pat<atomic_load_8,  i32, addrgp, L2_loadrubgp>;
3724 def: Loada_pat<atomic_load_16, i32, addrgp, L2_loadruhgp>;
3725 def: Loada_pat<atomic_load_32, i32, addrgp, L2_loadrigp>;
3726 def: Loada_pat<atomic_load_64, i64, addrgp, L2_loadrdgp>;
3727
3728 // Map from load(globaladdress) -> mem[u][bhwd](#foo)
3729 class LoadGP_pats <PatFrag ldOp, InstHexagon MI, ValueType VT = i32>
3730   : Pat <(VT (ldOp (HexagonCONST32_GP tglobaladdr:$global))),
3731          (VT (MI tglobaladdr:$global))>;
3732
3733 let AddedComplexity = 100 in {
3734   def: LoadGP_pats <extloadi8, L2_loadrbgp>;
3735   def: LoadGP_pats <sextloadi8, L2_loadrbgp>;
3736   def: LoadGP_pats <zextloadi8, L2_loadrubgp>;
3737   def: LoadGP_pats <extloadi16, L2_loadrhgp>;
3738   def: LoadGP_pats <sextloadi16, L2_loadrhgp>;
3739   def: LoadGP_pats <zextloadi16, L2_loadruhgp>;
3740   def: LoadGP_pats <load, L2_loadrigp>;
3741   def: LoadGP_pats <load, L2_loadrdgp, i64>;
3742 }
3743
3744 // When the Interprocedural Global Variable optimizer realizes that a certain
3745 // global variable takes only two constant values, it shrinks the global to
3746 // a boolean. Catch those loads here in the following 3 patterns.
3747 let AddedComplexity = 100 in {
3748   def: LoadGP_pats <extloadi1, L2_loadrubgp>;
3749   def: LoadGP_pats <zextloadi1, L2_loadrubgp>;
3750 }
3751
3752 def: Pat<(i64 (ctlz I64:$src1)), (Zext64 (S2_cl0p I64:$src1))>;
3753 def: Pat<(i64 (cttz I64:$src1)), (Zext64 (S2_ct0p I64:$src1))>;
3754
3755 let AddedComplexity  = 30 in {
3756   def: Storea_pat<truncstorei8,  I32, u0AlwaysExtPred, S2_storerbabs>;
3757   def: Storea_pat<truncstorei16, I32, u0AlwaysExtPred, S2_storerhabs>;
3758   def: Storea_pat<store,         I32, u0AlwaysExtPred, S2_storeriabs>;
3759 }
3760
3761 let AddedComplexity  = 30 in {
3762   def: Loada_pat<load,        i32, u0AlwaysExtPred, L4_loadri_abs>;
3763   def: Loada_pat<sextloadi8,  i32, u0AlwaysExtPred, L4_loadrb_abs>;
3764   def: Loada_pat<zextloadi8,  i32, u0AlwaysExtPred, L4_loadrub_abs>;
3765   def: Loada_pat<sextloadi16, i32, u0AlwaysExtPred, L4_loadrh_abs>;
3766   def: Loada_pat<zextloadi16, i32, u0AlwaysExtPred, L4_loadruh_abs>;
3767 }
3768
3769 // Indexed store word - global address.
3770 // memw(Rs+#u6:2)=#S8
3771 let AddedComplexity = 100 in
3772 def: Storex_add_pat<store, addrga, u6_2ImmPred, S4_storeiri_io>;
3773
3774 // Load from a global address that has only one use in the current basic block.
3775 let AddedComplexity = 100 in {
3776   def: Loada_pat<extloadi8,   i32, addrga, L4_loadrub_abs>;
3777   def: Loada_pat<sextloadi8,  i32, addrga, L4_loadrb_abs>;
3778   def: Loada_pat<zextloadi8,  i32, addrga, L4_loadrub_abs>;
3779
3780   def: Loada_pat<extloadi16,  i32, addrga, L4_loadruh_abs>;
3781   def: Loada_pat<sextloadi16, i32, addrga, L4_loadrh_abs>;
3782   def: Loada_pat<zextloadi16, i32, addrga, L4_loadruh_abs>;
3783
3784   def: Loada_pat<load,        i32, addrga, L4_loadri_abs>;
3785   def: Loada_pat<load,        i64, addrga, L4_loadrd_abs>;
3786 }
3787
3788 // Store to a global address that has only one use in the current basic block.
3789 let AddedComplexity = 100 in {
3790   def: Storea_pat<truncstorei8,  I32, addrga, S2_storerbabs>;
3791   def: Storea_pat<truncstorei16, I32, addrga, S2_storerhabs>;
3792   def: Storea_pat<store,         I32, addrga, S2_storeriabs>;
3793   def: Storea_pat<store,         I64, addrga, S2_storerdabs>;
3794
3795   def: Stoream_pat<truncstorei32, I64, addrga, LoReg, S2_storeriabs>;
3796 }
3797
3798 // Map from Pd = load(globaladdress) -> Rd = memb(globaladdress), Pd = Rd
3799 let AddedComplexity = 100 in
3800 def : Pat <(i1 (load (HexagonCONST32_GP tglobaladdr:$global))),
3801            (i1 (C2_tfrrp (i32 (L2_loadrbgp tglobaladdr:$global))))>;
3802
3803 // Transfer global address into a register
3804 let isExtended = 1, opExtendable = 1, AddedComplexity=50, isMoveImm = 1,
3805 isAsCheapAsAMove = 1, isReMaterializable = 1, validSubTargets = HasV4SubT,
3806 isCodeGenOnly = 1 in
3807 def TFRI_V4 : ALU32_ri<(outs IntRegs:$dst), (ins s16Ext:$src1),
3808            "$dst = #$src1",
3809            [(set IntRegs:$dst, (HexagonCONST32 tglobaladdr:$src1))]>,
3810            Requires<[HasV4T]>;
3811
3812 // Transfer a block address into a register
3813 def : Pat<(HexagonCONST32_GP tblockaddress:$src1),
3814           (TFRI_V4 tblockaddress:$src1)>,
3815           Requires<[HasV4T]>;
3816
3817 let AddedComplexity = 50, Predicates = [HasV4T] in
3818 def : Pat<(HexagonCONST32_GP tglobaladdr:$src1),
3819            (TFRI_V4 tglobaladdr:$src1)>,
3820            Requires<[HasV4T]>;
3821
3822 // i8/i16/i32 -> i64 loads
3823 // We need a complexity of 120 here to override preceding handling of
3824 // zextload.
3825 let AddedComplexity = 120 in {
3826   def: Loadam_pat<extloadi8,   i64, addrga, Zext64, L4_loadrub_abs>;
3827   def: Loadam_pat<sextloadi8,  i64, addrga, Sext64, L4_loadrb_abs>;
3828   def: Loadam_pat<zextloadi8,  i64, addrga, Zext64, L4_loadrub_abs>;
3829
3830   def: Loadam_pat<extloadi16,  i64, addrga, Zext64, L4_loadruh_abs>;
3831   def: Loadam_pat<sextloadi16, i64, addrga, Sext64, L4_loadrh_abs>;
3832   def: Loadam_pat<zextloadi16, i64, addrga, Zext64, L4_loadruh_abs>;
3833
3834   def: Loadam_pat<extloadi32,  i64, addrga, Zext64, L4_loadri_abs>;
3835   def: Loadam_pat<sextloadi32, i64, addrga, Sext64, L4_loadri_abs>;
3836   def: Loadam_pat<zextloadi32, i64, addrga, Zext64, L4_loadri_abs>;
3837
3838 let AddedComplexity = 100 in {
3839   def: Loada_pat<extloadi8,   i32, addrgp, L4_loadrub_abs>;
3840   def: Loada_pat<sextloadi8,  i32, addrgp, L4_loadrb_abs>;
3841   def: Loada_pat<zextloadi8,  i32, addrgp, L4_loadrub_abs>;
3842
3843   def: Loada_pat<extloadi16,  i32, addrgp, L4_loadruh_abs>;
3844   def: Loada_pat<sextloadi16, i32, addrgp, L4_loadrh_abs>;
3845   def: Loada_pat<zextloadi16, i32, addrgp, L4_loadruh_abs>;
3846
3847   def: Loada_pat<load,        i32, addrgp, L4_loadri_abs>;
3848   def: Loada_pat<load,        i64, addrgp, L4_loadrd_abs>;
3849 }
3850 }
3851 let AddedComplexity = 100 in {
3852   def: Storea_pat<truncstorei8,  I32, addrgp, S2_storerbabs>;
3853   def: Storea_pat<truncstorei16, I32, addrgp, S2_storerhabs>;
3854   def: Storea_pat<store,         I32, addrgp, S2_storeriabs>;
3855   def: Storea_pat<store,         I64, addrgp, S2_storerdabs>;
3856 }
3857
3858 def: Loada_pat<atomic_load_8,  i32, addrgp, L4_loadrub_abs>;
3859 def: Loada_pat<atomic_load_16, i32, addrgp, L4_loadruh_abs>;
3860 def: Loada_pat<atomic_load_32, i32, addrgp, L4_loadri_abs>;
3861 def: Loada_pat<atomic_load_64, i64, addrgp, L4_loadrd_abs>;
3862
3863 def: Storea_pat<SwapSt<atomic_store_8>,  I32, addrgp, S2_storerbabs>;
3864 def: Storea_pat<SwapSt<atomic_store_16>, I32, addrgp, S2_storerhabs>;
3865 def: Storea_pat<SwapSt<atomic_store_32>, I32, addrgp, S2_storeriabs>;
3866 def: Storea_pat<SwapSt<atomic_store_64>, I64, addrgp, S2_storerdabs>;
3867
3868 //===----------------------------------------------------------------------===//
3869 // :raw for of boundscheck:hi:lo insns
3870 //===----------------------------------------------------------------------===//
3871
3872 // A4_boundscheck_lo: Detect if a register is within bounds.
3873 let hasSideEffects = 0 in
3874 def A4_boundscheck_lo: ALU64Inst <
3875   (outs PredRegs:$Pd),
3876   (ins DoubleRegs:$Rss, DoubleRegs:$Rtt),
3877   "$Pd = boundscheck($Rss, $Rtt):raw:lo"> {
3878     bits<2> Pd;
3879     bits<5> Rss;
3880     bits<5> Rtt;
3881
3882     let IClass = 0b1101;
3883
3884     let Inst{27-23} = 0b00100;
3885     let Inst{13} = 0b1;
3886     let Inst{7-5} = 0b100;
3887     let Inst{1-0} = Pd;
3888     let Inst{20-16} = Rss;
3889     let Inst{12-8} = Rtt;
3890   }
3891
3892 // A4_boundscheck_hi: Detect if a register is within bounds.
3893 let hasSideEffects = 0 in
3894 def A4_boundscheck_hi: ALU64Inst <
3895   (outs PredRegs:$Pd),
3896   (ins DoubleRegs:$Rss, DoubleRegs:$Rtt),
3897   "$Pd = boundscheck($Rss, $Rtt):raw:hi"> {
3898     bits<2> Pd;
3899     bits<5> Rss;
3900     bits<5> Rtt;
3901
3902     let IClass = 0b1101;
3903
3904     let Inst{27-23} = 0b00100;
3905     let Inst{13} = 0b1;
3906     let Inst{7-5} = 0b101;
3907     let Inst{1-0} = Pd;
3908     let Inst{20-16} = Rss;
3909     let Inst{12-8} = Rtt;
3910   }
3911
3912 let hasSideEffects = 0, isAsmParserOnly = 1 in
3913 def A4_boundscheck : MInst <
3914   (outs PredRegs:$Pd), (ins IntRegs:$Rs, DoubleRegs:$Rtt),
3915   "$Pd=boundscheck($Rs,$Rtt)">;
3916
3917 // A4_tlbmatch: Detect if a VA/ASID matches a TLB entry.
3918 let isPredicateLate = 1, hasSideEffects = 0 in
3919 def A4_tlbmatch : ALU64Inst<(outs PredRegs:$Pd),
3920   (ins DoubleRegs:$Rs, IntRegs:$Rt),
3921   "$Pd = tlbmatch($Rs, $Rt)",
3922   [], "", ALU64_tc_2early_SLOT23> {
3923     bits<2> Pd;
3924     bits<5> Rs;
3925     bits<5> Rt;
3926
3927     let IClass = 0b1101;
3928     let Inst{27-23} = 0b00100;
3929     let Inst{20-16} = Rs;
3930     let Inst{13} = 0b1;
3931     let Inst{12-8} = Rt;
3932     let Inst{7-5} = 0b011;
3933     let Inst{1-0} = Pd;
3934   }
3935
3936 // We need custom lowering of ISD::PREFETCH into HexagonISD::DCFETCH
3937 // because the SDNode ISD::PREFETCH has properties MayLoad and MayStore.
3938 // We don't really want either one here.
3939 def SDTHexagonDCFETCH : SDTypeProfile<0, 2, [SDTCisPtrTy<0>,SDTCisInt<1>]>;
3940 def HexagonDCFETCH : SDNode<"HexagonISD::DCFETCH", SDTHexagonDCFETCH,
3941                             [SDNPHasChain]>;
3942
3943 // Use LD0Inst for dcfetch, but set "mayLoad" to 0 because this doesn't
3944 // really do a load.
3945 let hasSideEffects = 1, mayLoad = 0 in
3946 def Y2_dcfetchbo : LD0Inst<(outs), (ins IntRegs:$Rs, u11_3Imm:$u11_3),
3947       "dcfetch($Rs + #$u11_3)",
3948       [(HexagonDCFETCH IntRegs:$Rs, u11_3ImmPred:$u11_3)],
3949       "", LD_tc_ld_SLOT0> {
3950   bits<5> Rs;
3951   bits<14> u11_3;
3952
3953   let IClass = 0b1001;
3954   let Inst{27-21} = 0b0100000;
3955   let Inst{20-16} = Rs;
3956   let Inst{13} = 0b0;
3957   let Inst{10-0} = u11_3{13-3};
3958 }
3959
3960 //===----------------------------------------------------------------------===//
3961 // Compound instructions
3962 //===----------------------------------------------------------------------===//
3963
3964 let isBranch = 1, hasSideEffects = 0, isExtentSigned = 1,
3965     isPredicated = 1, isPredicatedNew = 1, isExtendable = 1,
3966     opExtentBits = 11, opExtentAlign = 2, opExtendable = 1,
3967     isTerminator = 1, validSubTargets = HasV4SubT in
3968 class CJInst_tstbit_R0<string px, bit np, string tnt>
3969   : InstHexagon<(outs), (ins IntRegs:$Rs, brtarget:$r9_2),
3970   ""#px#" = tstbit($Rs, #0); if ("
3971     #!if(np, "!","")#""#px#".new) jump:"#tnt#" $r9_2",
3972   [], "", COMPOUND, TypeCOMPOUND> {
3973   bits<4> Rs;
3974   bits<11> r9_2;
3975
3976   // np: !p[01]
3977   let isPredicatedFalse = np;
3978   // tnt: Taken/Not Taken
3979   let isBrTaken = !if (!eq(tnt, "t"), "true", "false");
3980   let isTaken   = !if (!eq(tnt, "t"), 1, 0);
3981
3982   let IClass = 0b0001;
3983   let Inst{27-26} = 0b00;
3984   let Inst{25} = !if (!eq(px, "!p1"), 1,
3985                  !if (!eq(px,  "p1"), 1, 0));
3986   let Inst{24-23} = 0b11;
3987   let Inst{22} = np;
3988   let Inst{21-20} = r9_2{10-9};
3989   let Inst{19-16} = Rs;
3990   let Inst{13} = !if (!eq(tnt, "t"), 1, 0);
3991   let Inst{9-8} = 0b11;
3992   let Inst{7-1} = r9_2{8-2};
3993 }
3994
3995 let Defs = [PC, P0], Uses = [P0] in {
3996   def J4_tstbit0_tp0_jump_nt : CJInst_tstbit_R0<"p0", 0, "nt">;
3997   def J4_tstbit0_tp0_jump_t : CJInst_tstbit_R0<"p0", 0, "t">;
3998   def J4_tstbit0_fp0_jump_nt : CJInst_tstbit_R0<"p0", 1, "nt">;
3999   def J4_tstbit0_fp0_jump_t : CJInst_tstbit_R0<"p0", 1, "t">;
4000 }
4001
4002 let Defs = [PC, P1], Uses = [P1] in {
4003   def J4_tstbit0_tp1_jump_nt : CJInst_tstbit_R0<"p1", 0, "nt">;
4004   def J4_tstbit0_tp1_jump_t : CJInst_tstbit_R0<"p1", 0, "t">;
4005   def J4_tstbit0_fp1_jump_nt : CJInst_tstbit_R0<"p1", 1, "nt">;
4006   def J4_tstbit0_fp1_jump_t : CJInst_tstbit_R0<"p1", 1, "t">;
4007 }
4008
4009
4010 let isBranch = 1, hasSideEffects = 0,
4011     isExtentSigned = 1, isPredicated = 1, isPredicatedNew = 1,
4012     isExtendable = 1, opExtentBits = 11, opExtentAlign = 2,
4013     opExtendable = 2, isTerminator = 1, validSubTargets = HasV4SubT in
4014 class CJInst_RR<string px, string op, bit np, string tnt>
4015   : InstHexagon<(outs), (ins IntRegs:$Rs, IntRegs:$Rt, brtarget:$r9_2),
4016   ""#px#" = cmp."#op#"($Rs, $Rt); if ("
4017    #!if(np, "!","")#""#px#".new) jump:"#tnt#" $r9_2",
4018   [], "", COMPOUND, TypeCOMPOUND> {
4019   bits<4> Rs;
4020   bits<4> Rt;
4021   bits<11> r9_2;
4022
4023   // np: !p[01]
4024   let isPredicatedFalse = np;
4025   // tnt: Taken/Not Taken
4026   let isBrTaken = !if (!eq(tnt, "t"), "true", "false");
4027   let isTaken   = !if (!eq(tnt, "t"), 1, 0);
4028
4029   let IClass = 0b0001;
4030   let Inst{27-23} = !if (!eq(op, "eq"),  0b01000,
4031                     !if (!eq(op, "gt"),  0b01001,
4032                     !if (!eq(op, "gtu"), 0b01010, 0)));
4033   let Inst{22} = np;
4034   let Inst{21-20} = r9_2{10-9};
4035   let Inst{19-16} = Rs;
4036   let Inst{13} = !if (!eq(tnt, "t"), 1, 0);
4037   // px: Predicate reg 0/1
4038   let Inst{12} = !if (!eq(px, "!p1"), 1,
4039                  !if (!eq(px,  "p1"), 1, 0));
4040   let Inst{11-8} = Rt;
4041   let Inst{7-1} = r9_2{8-2};
4042 }
4043
4044 // P[10] taken/not taken.
4045 multiclass T_tnt_CJInst_RR<string op, bit np> {
4046   let Defs = [PC, P0], Uses = [P0] in {
4047     def NAME#p0_jump_nt : CJInst_RR<"p0", op, np, "nt">;
4048     def NAME#p0_jump_t : CJInst_RR<"p0", op, np, "t">;
4049   }
4050   let Defs = [PC, P1], Uses = [P1] in {
4051     def NAME#p1_jump_nt : CJInst_RR<"p1", op, np, "nt">;
4052     def NAME#p1_jump_t : CJInst_RR<"p1", op, np, "t">;
4053   }
4054 }
4055 // Predicate / !Predicate
4056 multiclass T_pnp_CJInst_RR<string op>{
4057   defm J4_cmp#NAME#_t : T_tnt_CJInst_RR<op, 0>;
4058   defm J4_cmp#NAME#_f : T_tnt_CJInst_RR<op, 1>;
4059 }
4060 // TypeCJ Instructions compare RR and jump
4061 defm eq : T_pnp_CJInst_RR<"eq">;
4062 defm gt : T_pnp_CJInst_RR<"gt">;
4063 defm gtu : T_pnp_CJInst_RR<"gtu">;
4064
4065 let isBranch = 1, hasSideEffects = 0, isExtentSigned = 1,
4066     isPredicated = 1, isPredicatedNew = 1, isExtendable = 1, opExtentBits = 11,
4067     opExtentAlign = 2, opExtendable = 2, isTerminator = 1,
4068     validSubTargets = HasV4SubT in
4069 class CJInst_RU5<string px, string op, bit np, string tnt>
4070   : InstHexagon<(outs), (ins IntRegs:$Rs, u5Imm:$U5, brtarget:$r9_2),
4071   ""#px#" = cmp."#op#"($Rs, #$U5); if ("
4072     #!if(np, "!","")#""#px#".new) jump:"#tnt#" $r9_2",
4073   [], "", COMPOUND, TypeCOMPOUND> {
4074   bits<4> Rs;
4075   bits<5> U5;
4076   bits<11> r9_2;
4077
4078   // np: !p[01]
4079   let isPredicatedFalse = np;
4080   // tnt: Taken/Not Taken
4081   let isBrTaken = !if (!eq(tnt, "t"), "true", "false");
4082   let isTaken   = !if (!eq(tnt, "t"), 1, 0);
4083
4084   let IClass = 0b0001;
4085   let Inst{27-26} = 0b00;
4086   // px: Predicate reg 0/1
4087   let Inst{25} = !if (!eq(px, "!p1"), 1,
4088                  !if (!eq(px,  "p1"), 1, 0));
4089   let Inst{24-23} = !if (!eq(op, "eq"),  0b00,
4090                     !if (!eq(op, "gt"),  0b01,
4091                     !if (!eq(op, "gtu"), 0b10, 0)));
4092   let Inst{22} = np;
4093   let Inst{21-20} = r9_2{10-9};
4094   let Inst{19-16} = Rs;
4095   let Inst{13} = !if (!eq(tnt, "t"), 1, 0);
4096   let Inst{12-8} = U5;
4097   let Inst{7-1} = r9_2{8-2};
4098 }
4099 // P[10] taken/not taken.
4100 multiclass T_tnt_CJInst_RU5<string op, bit np> {
4101   let Defs = [PC, P0], Uses = [P0] in {
4102     def NAME#p0_jump_nt : CJInst_RU5<"p0", op, np, "nt">;
4103     def NAME#p0_jump_t : CJInst_RU5<"p0", op, np, "t">;
4104   }
4105   let Defs = [PC, P1], Uses = [P1] in {
4106     def NAME#p1_jump_nt : CJInst_RU5<"p1", op, np, "nt">;
4107     def NAME#p1_jump_t : CJInst_RU5<"p1", op, np, "t">;
4108   }
4109 }
4110 // Predicate / !Predicate
4111 multiclass T_pnp_CJInst_RU5<string op>{
4112   defm J4_cmp#NAME#i_t : T_tnt_CJInst_RU5<op, 0>;
4113   defm J4_cmp#NAME#i_f : T_tnt_CJInst_RU5<op, 1>;
4114 }
4115 // TypeCJ Instructions compare RI and jump
4116 defm eq : T_pnp_CJInst_RU5<"eq">;
4117 defm gt : T_pnp_CJInst_RU5<"gt">;
4118 defm gtu : T_pnp_CJInst_RU5<"gtu">;
4119
4120 let isBranch = 1, hasSideEffects = 0, isExtentSigned = 1,
4121     isPredicated = 1, isPredicatedFalse = 1, isPredicatedNew = 1,
4122     isExtendable = 1, opExtentBits = 11, opExtentAlign = 2, opExtendable = 1,
4123     isTerminator = 1, validSubTargets = HasV4SubT in
4124 class CJInst_Rn1<string px, string op, bit np, string tnt>
4125   : InstHexagon<(outs), (ins IntRegs:$Rs, brtarget:$r9_2),
4126   ""#px#" = cmp."#op#"($Rs,#-1); if ("
4127   #!if(np, "!","")#""#px#".new) jump:"#tnt#" $r9_2",
4128   [], "", COMPOUND, TypeCOMPOUND> {
4129   bits<4> Rs;
4130   bits<11> r9_2;
4131
4132   // np: !p[01]
4133   let isPredicatedFalse = np;
4134   // tnt: Taken/Not Taken
4135   let isBrTaken = !if (!eq(tnt, "t"), "true", "false");
4136   let isTaken   = !if (!eq(tnt, "t"), 1, 0);
4137
4138   let IClass = 0b0001;
4139   let Inst{27-26} = 0b00;
4140   let Inst{25} = !if (!eq(px, "!p1"), 1,
4141                  !if (!eq(px,  "p1"), 1, 0));
4142
4143   let Inst{24-23} = 0b11;
4144   let Inst{22} = np;
4145   let Inst{21-20} = r9_2{10-9};
4146   let Inst{19-16} = Rs;
4147   let Inst{13} = !if (!eq(tnt, "t"), 1, 0);
4148   let Inst{9-8} = !if (!eq(op, "eq"),  0b00,
4149                   !if (!eq(op, "gt"),  0b01, 0));
4150   let Inst{7-1} = r9_2{8-2};
4151 }
4152
4153 // P[10] taken/not taken.
4154 multiclass T_tnt_CJInst_Rn1<string op, bit np> {
4155   let Defs = [PC, P0], Uses = [P0] in {
4156     def NAME#p0_jump_nt : CJInst_Rn1<"p0", op, np, "nt">;
4157     def NAME#p0_jump_t : CJInst_Rn1<"p0", op, np, "t">;
4158   }
4159   let Defs = [PC, P1], Uses = [P1] in {
4160     def NAME#p1_jump_nt : CJInst_Rn1<"p1", op, np, "nt">;
4161     def NAME#p1_jump_t : CJInst_Rn1<"p1", op, np, "t">;
4162   }
4163 }
4164 // Predicate / !Predicate
4165 multiclass T_pnp_CJInst_Rn1<string op>{
4166   defm J4_cmp#NAME#n1_t : T_tnt_CJInst_Rn1<op, 0>;
4167   defm J4_cmp#NAME#n1_f : T_tnt_CJInst_Rn1<op, 1>;
4168 }
4169 // TypeCJ Instructions compare -1 and jump
4170 defm eq : T_pnp_CJInst_Rn1<"eq">;
4171 defm gt : T_pnp_CJInst_Rn1<"gt">;
4172
4173 // J4_jumpseti: Direct unconditional jump and set register to immediate.
4174 let Defs = [PC], isBranch = 1, hasSideEffects = 0, hasNewValue = 1,
4175     isExtentSigned = 1, opNewValue = 0, isExtendable = 1, opExtentBits = 11,
4176     opExtentAlign = 2, opExtendable = 2, validSubTargets = HasV4SubT in
4177 def J4_jumpseti: CJInst <
4178   (outs IntRegs:$Rd),
4179   (ins u6Imm:$U6, brtarget:$r9_2),
4180   "$Rd = #$U6 ; jump $r9_2"> {
4181     bits<4> Rd;
4182     bits<6> U6;
4183     bits<11> r9_2;
4184
4185     let IClass = 0b0001;
4186     let Inst{27-24} = 0b0110;
4187     let Inst{21-20} = r9_2{10-9};
4188     let Inst{19-16} = Rd;
4189     let Inst{13-8} = U6;
4190     let Inst{7-1} = r9_2{8-2};
4191   }
4192
4193 // J4_jumpsetr: Direct unconditional jump and transfer register.
4194 let Defs = [PC], isBranch = 1, hasSideEffects = 0, hasNewValue = 1,
4195     isExtentSigned = 1, opNewValue = 0, isExtendable = 1, opExtentBits = 11,
4196     opExtentAlign = 2, opExtendable = 2, validSubTargets = HasV4SubT in
4197 def J4_jumpsetr: CJInst <
4198   (outs IntRegs:$Rd),
4199   (ins IntRegs:$Rs, brtarget:$r9_2),
4200   "$Rd = $Rs ; jump $r9_2"> {
4201     bits<4> Rd;
4202     bits<4> Rs;
4203     bits<11> r9_2;
4204
4205     let IClass = 0b0001;
4206     let Inst{27-24} = 0b0111;
4207     let Inst{21-20} = r9_2{10-9};
4208     let Inst{11-8} = Rd;
4209     let Inst{19-16} = Rs;
4210     let Inst{7-1} = r9_2{8-2};
4211   }