[Sparc] Add support for flush instruction.
[oota-llvm.git] / lib / Target / Sparc / SparcInstrInfo.td
1 //===-- SparcInstrInfo.td - Target Description for Sparc Target -----------===//
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 Sparc instructions in TableGen format.
11 //
12 //===----------------------------------------------------------------------===//
13
14 //===----------------------------------------------------------------------===//
15 // Instruction format superclass
16 //===----------------------------------------------------------------------===//
17
18 include "SparcInstrFormats.td"
19
20 //===----------------------------------------------------------------------===//
21 // Feature predicates.
22 //===----------------------------------------------------------------------===//
23
24 // True when generating 32-bit code.
25 def Is32Bit : Predicate<"!Subtarget->is64Bit()">;
26
27 // True when generating 64-bit code. This also implies HasV9.
28 def Is64Bit : Predicate<"Subtarget->is64Bit()">;
29
30 // HasV9 - This predicate is true when the target processor supports V9
31 // instructions.  Note that the machine may be running in 32-bit mode.
32 def HasV9   : Predicate<"Subtarget->isV9()">,
33               AssemblerPredicate<"FeatureV9">;
34
35 // HasNoV9 - This predicate is true when the target doesn't have V9
36 // instructions.  Use of this is just a hack for the isel not having proper
37 // costs for V8 instructions that are more expensive than their V9 ones.
38 def HasNoV9 : Predicate<"!Subtarget->isV9()">;
39
40 // HasVIS - This is true when the target processor has VIS extensions.
41 def HasVIS : Predicate<"Subtarget->isVIS()">,
42              AssemblerPredicate<"FeatureVIS">;
43 def HasVIS2 : Predicate<"Subtarget->isVIS2()">,
44              AssemblerPredicate<"FeatureVIS2">;
45 def HasVIS3 : Predicate<"Subtarget->isVIS3()">,
46              AssemblerPredicate<"FeatureVIS3">;
47
48 // HasHardQuad - This is true when the target processor supports quad floating
49 // point instructions.
50 def HasHardQuad : Predicate<"Subtarget->hasHardQuad()">;
51
52 // UseDeprecatedInsts - This predicate is true when the target processor is a
53 // V8, or when it is V9 but the V8 deprecated instructions are efficient enough
54 // to use when appropriate.  In either of these cases, the instruction selector
55 // will pick deprecated instructions.
56 def UseDeprecatedInsts : Predicate<"Subtarget->useDeprecatedV8Instructions()">;
57
58 //===----------------------------------------------------------------------===//
59 // Instruction Pattern Stuff
60 //===----------------------------------------------------------------------===//
61
62 def simm11  : PatLeaf<(imm), [{ return isInt<11>(N->getSExtValue()); }]>;
63
64 def simm13  : PatLeaf<(imm), [{ return isInt<13>(N->getSExtValue()); }]>;
65
66 def LO10 : SDNodeXForm<imm, [{
67   return CurDAG->getTargetConstant((unsigned)N->getZExtValue() & 1023, SDLoc(N),
68                                    MVT::i32);
69 }]>;
70
71 def HI22 : SDNodeXForm<imm, [{
72   // Transformation function: shift the immediate value down into the low bits.
73   return CurDAG->getTargetConstant((unsigned)N->getZExtValue() >> 10, SDLoc(N),
74                                    MVT::i32);
75 }]>;
76
77 def SETHIimm : PatLeaf<(imm), [{
78   return isShiftedUInt<22, 10>(N->getZExtValue());
79 }], HI22>;
80
81 // Addressing modes.
82 def ADDRrr : ComplexPattern<iPTR, 2, "SelectADDRrr", [], []>;
83 def ADDRri : ComplexPattern<iPTR, 2, "SelectADDRri", [frameindex], []>;
84
85 // Address operands
86 def SparcMEMrrAsmOperand : AsmOperandClass {
87   let Name = "MEMrr";
88   let ParserMethod = "parseMEMOperand";
89 }
90
91 def SparcMEMriAsmOperand : AsmOperandClass {
92   let Name = "MEMri";
93   let ParserMethod = "parseMEMOperand";
94 }
95
96 def MEMrr : Operand<iPTR> {
97   let PrintMethod = "printMemOperand";
98   let MIOperandInfo = (ops ptr_rc, ptr_rc);
99   let ParserMatchClass = SparcMEMrrAsmOperand;
100 }
101 def MEMri : Operand<iPTR> {
102   let PrintMethod = "printMemOperand";
103   let MIOperandInfo = (ops ptr_rc, i32imm);
104   let ParserMatchClass = SparcMEMriAsmOperand;
105 }
106
107 def TLSSym : Operand<iPTR>;
108
109 // Branch targets have OtherVT type.
110 def brtarget : Operand<OtherVT> {
111   let EncoderMethod = "getBranchTargetOpValue";
112 }
113
114 def bprtarget : Operand<OtherVT> {
115   let EncoderMethod = "getBranchPredTargetOpValue";
116 }
117
118 def bprtarget16 : Operand<OtherVT> {
119   let EncoderMethod = "getBranchOnRegTargetOpValue";
120 }
121
122 def calltarget : Operand<i32> {
123   let EncoderMethod = "getCallTargetOpValue";
124   let DecoderMethod = "DecodeCall";
125 }
126
127 def simm13Op : Operand<i32> {
128   let DecoderMethod = "DecodeSIMM13";
129 }
130
131 // Operand for printing out a condition code.
132 let PrintMethod = "printCCOperand" in
133   def CCOp : Operand<i32>;
134
135 def SDTSPcmpicc :
136 SDTypeProfile<0, 2, [SDTCisInt<0>, SDTCisSameAs<0, 1>]>;
137 def SDTSPcmpfcc :
138 SDTypeProfile<0, 2, [SDTCisFP<0>, SDTCisSameAs<0, 1>]>;
139 def SDTSPbrcc :
140 SDTypeProfile<0, 2, [SDTCisVT<0, OtherVT>, SDTCisVT<1, i32>]>;
141 def SDTSPselectcc :
142 SDTypeProfile<1, 3, [SDTCisSameAs<0, 1>, SDTCisSameAs<1, 2>, SDTCisVT<3, i32>]>;
143 def SDTSPFTOI :
144 SDTypeProfile<1, 1, [SDTCisVT<0, f32>, SDTCisFP<1>]>;
145 def SDTSPITOF :
146 SDTypeProfile<1, 1, [SDTCisFP<0>, SDTCisVT<1, f32>]>;
147 def SDTSPFTOX :
148 SDTypeProfile<1, 1, [SDTCisVT<0, f64>, SDTCisFP<1>]>;
149 def SDTSPXTOF :
150 SDTypeProfile<1, 1, [SDTCisFP<0>, SDTCisVT<1, f64>]>;
151
152 def SDTSPtlsadd :
153 SDTypeProfile<1, 3, [SDTCisInt<0>, SDTCisSameAs<0, 1>, SDTCisPtrTy<2>]>;
154 def SDTSPtlsld :
155 SDTypeProfile<1, 2, [SDTCisPtrTy<0>, SDTCisPtrTy<1>]>;
156
157 def SPcmpicc : SDNode<"SPISD::CMPICC", SDTSPcmpicc, [SDNPOutGlue]>;
158 def SPcmpfcc : SDNode<"SPISD::CMPFCC", SDTSPcmpfcc, [SDNPOutGlue]>;
159 def SPbricc : SDNode<"SPISD::BRICC", SDTSPbrcc, [SDNPHasChain, SDNPInGlue]>;
160 def SPbrxcc : SDNode<"SPISD::BRXCC", SDTSPbrcc, [SDNPHasChain, SDNPInGlue]>;
161 def SPbrfcc : SDNode<"SPISD::BRFCC", SDTSPbrcc, [SDNPHasChain, SDNPInGlue]>;
162
163 def SPhi    : SDNode<"SPISD::Hi", SDTIntUnaryOp>;
164 def SPlo    : SDNode<"SPISD::Lo", SDTIntUnaryOp>;
165
166 def SPftoi  : SDNode<"SPISD::FTOI", SDTSPFTOI>;
167 def SPitof  : SDNode<"SPISD::ITOF", SDTSPITOF>;
168 def SPftox  : SDNode<"SPISD::FTOX", SDTSPFTOX>;
169 def SPxtof  : SDNode<"SPISD::XTOF", SDTSPXTOF>;
170
171 def SPselecticc : SDNode<"SPISD::SELECT_ICC", SDTSPselectcc, [SDNPInGlue]>;
172 def SPselectxcc : SDNode<"SPISD::SELECT_XCC", SDTSPselectcc, [SDNPInGlue]>;
173 def SPselectfcc : SDNode<"SPISD::SELECT_FCC", SDTSPselectcc, [SDNPInGlue]>;
174
175 //  These are target-independent nodes, but have target-specific formats.
176 def SDT_SPCallSeqStart : SDCallSeqStart<[ SDTCisVT<0, i32> ]>;
177 def SDT_SPCallSeqEnd   : SDCallSeqEnd<[ SDTCisVT<0, i32>,
178                                         SDTCisVT<1, i32> ]>;
179
180 def callseq_start : SDNode<"ISD::CALLSEQ_START", SDT_SPCallSeqStart,
181                            [SDNPHasChain, SDNPOutGlue]>;
182 def callseq_end   : SDNode<"ISD::CALLSEQ_END",   SDT_SPCallSeqEnd,
183                            [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue]>;
184
185 def SDT_SPCall    : SDTypeProfile<0, -1, [SDTCisVT<0, i32>]>;
186 def call          : SDNode<"SPISD::CALL", SDT_SPCall,
187                            [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
188                             SDNPVariadic]>;
189
190 def SDT_SPRet     : SDTypeProfile<0, 1, [SDTCisVT<0, i32>]>;
191 def retflag       : SDNode<"SPISD::RET_FLAG", SDT_SPRet,
192                            [SDNPHasChain, SDNPOptInGlue, SDNPVariadic]>;
193
194 def flushw        : SDNode<"SPISD::FLUSHW", SDTNone,
195                            [SDNPHasChain, SDNPSideEffect, SDNPMayStore]>;
196
197 def tlsadd        : SDNode<"SPISD::TLS_ADD", SDTSPtlsadd>;
198 def tlsld         : SDNode<"SPISD::TLS_LD",  SDTSPtlsld>;
199 def tlscall       : SDNode<"SPISD::TLS_CALL", SDT_SPCall,
200                             [SDNPHasChain, SDNPOptInGlue, SDNPOutGlue,
201                              SDNPVariadic]>;
202
203 def getPCX        : Operand<iPTR> {
204   let PrintMethod = "printGetPCX";
205 }
206
207 //===----------------------------------------------------------------------===//
208 // SPARC Flag Conditions
209 //===----------------------------------------------------------------------===//
210
211 // Note that these values must be kept in sync with the CCOp::CondCode enum
212 // values.
213 class ICC_VAL<int N> : PatLeaf<(i32 N)>;
214 def ICC_NE  : ICC_VAL< 9>;  // Not Equal
215 def ICC_E   : ICC_VAL< 1>;  // Equal
216 def ICC_G   : ICC_VAL<10>;  // Greater
217 def ICC_LE  : ICC_VAL< 2>;  // Less or Equal
218 def ICC_GE  : ICC_VAL<11>;  // Greater or Equal
219 def ICC_L   : ICC_VAL< 3>;  // Less
220 def ICC_GU  : ICC_VAL<12>;  // Greater Unsigned
221 def ICC_LEU : ICC_VAL< 4>;  // Less or Equal Unsigned
222 def ICC_CC  : ICC_VAL<13>;  // Carry Clear/Great or Equal Unsigned
223 def ICC_CS  : ICC_VAL< 5>;  // Carry Set/Less Unsigned
224 def ICC_POS : ICC_VAL<14>;  // Positive
225 def ICC_NEG : ICC_VAL< 6>;  // Negative
226 def ICC_VC  : ICC_VAL<15>;  // Overflow Clear
227 def ICC_VS  : ICC_VAL< 7>;  // Overflow Set
228
229 class FCC_VAL<int N> : PatLeaf<(i32 N)>;
230 def FCC_U   : FCC_VAL<23>;  // Unordered
231 def FCC_G   : FCC_VAL<22>;  // Greater
232 def FCC_UG  : FCC_VAL<21>;  // Unordered or Greater
233 def FCC_L   : FCC_VAL<20>;  // Less
234 def FCC_UL  : FCC_VAL<19>;  // Unordered or Less
235 def FCC_LG  : FCC_VAL<18>;  // Less or Greater
236 def FCC_NE  : FCC_VAL<17>;  // Not Equal
237 def FCC_E   : FCC_VAL<25>;  // Equal
238 def FCC_UE  : FCC_VAL<24>;  // Unordered or Equal
239 def FCC_GE  : FCC_VAL<25>;  // Greater or Equal
240 def FCC_UGE : FCC_VAL<26>;  // Unordered or Greater or Equal
241 def FCC_LE  : FCC_VAL<27>;  // Less or Equal
242 def FCC_ULE : FCC_VAL<28>;  // Unordered or Less or Equal
243 def FCC_O   : FCC_VAL<29>;  // Ordered
244
245 //===----------------------------------------------------------------------===//
246 // Instruction Class Templates
247 //===----------------------------------------------------------------------===//
248
249 /// F3_12 multiclass - Define a normal F3_1/F3_2 pattern in one shot.
250 multiclass F3_12<string OpcStr, bits<6> Op3Val, SDNode OpNode,
251                  RegisterClass RC, ValueType Ty, Operand immOp> {
252   def rr  : F3_1<2, Op3Val,
253                  (outs RC:$rd), (ins RC:$rs1, RC:$rs2),
254                  !strconcat(OpcStr, " $rs1, $rs2, $rd"),
255                  [(set Ty:$rd, (OpNode Ty:$rs1, Ty:$rs2))]>;
256   def ri  : F3_2<2, Op3Val,
257                  (outs RC:$rd), (ins RC:$rs1, immOp:$simm13),
258                  !strconcat(OpcStr, " $rs1, $simm13, $rd"),
259                  [(set Ty:$rd, (OpNode Ty:$rs1, (Ty simm13:$simm13)))]>;
260 }
261
262 /// F3_12np multiclass - Define a normal F3_1/F3_2 pattern in one shot, with no
263 /// pattern.
264 multiclass F3_12np<string OpcStr, bits<6> Op3Val> {
265   def rr  : F3_1<2, Op3Val,
266                  (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2),
267                  !strconcat(OpcStr, " $rs1, $rs2, $rd"), []>;
268   def ri  : F3_2<2, Op3Val,
269                  (outs IntRegs:$rd), (ins IntRegs:$rs1, simm13Op:$simm13),
270                  !strconcat(OpcStr, " $rs1, $simm13, $rd"), []>;
271 }
272
273 // Load multiclass - Define both Reg+Reg/Reg+Imm patterns in one shot.
274 multiclass Load<string OpcStr, bits<6> Op3Val, SDPatternOperator OpNode,
275            RegisterClass RC, ValueType Ty> {
276   def rr  : F3_1<3, Op3Val,
277                  (outs RC:$dst), (ins MEMrr:$addr),
278                  !strconcat(OpcStr, " [$addr], $dst"),
279                  [(set Ty:$dst, (OpNode ADDRrr:$addr))]>;
280   def ri  : F3_2<3, Op3Val,
281                  (outs RC:$dst), (ins MEMri:$addr),
282                  !strconcat(OpcStr, " [$addr], $dst"),
283                  [(set Ty:$dst, (OpNode ADDRri:$addr))]>;
284 }
285
286 // LoadA multiclass - As above, but also define alternate address space variant
287 multiclass LoadA<string OpcStr, bits<6> Op3Val, bits<6> LoadAOp3Val,
288                  SDPatternOperator OpNode, RegisterClass RC, ValueType Ty> :
289              Load<OpcStr, Op3Val, OpNode, RC, Ty> {
290   // TODO: The LD*Arr instructions are currently asm only; hooking up
291   // CodeGen's address spaces to use these is a future task.
292   def Arr  : F3_1_asi<3, LoadAOp3Val, (outs RC:$dst), (ins MEMrr:$addr, i8imm:$asi),
293                 !strconcat(OpcStr, "a [$addr] $asi, $dst"),
294                 []>;
295 }
296
297 // Store multiclass - Define both Reg+Reg/Reg+Imm patterns in one shot.
298 multiclass Store<string OpcStr, bits<6> Op3Val, SDPatternOperator OpNode,
299            RegisterClass RC, ValueType Ty> {
300   def rr  : F3_1<3, Op3Val,
301                  (outs), (ins MEMrr:$addr, RC:$rd),
302                  !strconcat(OpcStr, " $rd, [$addr]"),
303                  [(OpNode Ty:$rd, ADDRrr:$addr)]>;
304   def ri  : F3_2<3, Op3Val,
305                  (outs), (ins MEMri:$addr, RC:$rd),
306                  !strconcat(OpcStr, " $rd, [$addr]"),
307                  [(OpNode Ty:$rd, ADDRri:$addr)]>;
308 }
309
310 multiclass StoreA<string OpcStr, bits<6> Op3Val, bits<6> StoreAOp3Val,
311                   SDPatternOperator OpNode, RegisterClass RC, ValueType Ty> :
312              Store<OpcStr, Op3Val, OpNode, RC, Ty> {
313   // TODO: The ST*Arr instructions are currently asm only; hooking up
314   // CodeGen's address spaces to use these is a future task.
315   def Arr  : F3_1_asi<3, StoreAOp3Val, (outs), (ins MEMrr:$addr, RC:$rd, i8imm:$asi),
316                   !strconcat(OpcStr, "a $rd, [$addr] $asi"),
317                   []>;
318 }
319
320 //===----------------------------------------------------------------------===//
321 // Instructions
322 //===----------------------------------------------------------------------===//
323
324 // Pseudo instructions.
325 class Pseudo<dag outs, dag ins, string asmstr, list<dag> pattern>
326    : InstSP<outs, ins, asmstr, pattern> {
327   let isCodeGenOnly = 1;
328   let isPseudo = 1;
329 }
330
331 // GETPCX for PIC
332 let Defs = [O7] in {
333   def GETPCX : Pseudo<(outs getPCX:$getpcseq), (ins), "$getpcseq", [] >;
334 }
335
336 let Defs = [O6], Uses = [O6] in {
337 def ADJCALLSTACKDOWN : Pseudo<(outs), (ins i32imm:$amt),
338                                "!ADJCALLSTACKDOWN $amt",
339                                [(callseq_start timm:$amt)]>;
340 def ADJCALLSTACKUP : Pseudo<(outs), (ins i32imm:$amt1, i32imm:$amt2),
341                             "!ADJCALLSTACKUP $amt1",
342                             [(callseq_end timm:$amt1, timm:$amt2)]>;
343 }
344
345 let hasSideEffects = 1, mayStore = 1 in {
346   let rd = 0, rs1 = 0, rs2 = 0 in
347     def FLUSHW : F3_1<0b10, 0b101011, (outs), (ins),
348                       "flushw",
349                       [(flushw)]>, Requires<[HasV9]>;
350   let rd = 0, rs1 = 1, simm13 = 3 in
351     def TA3 : F3_2<0b10, 0b111010, (outs), (ins),
352                    "ta 3",
353                    [(flushw)]>;
354 }
355
356 // SELECT_CC_* - Used to implement the SELECT_CC DAG operation.  Expanded after
357 // instruction selection into a branch sequence.  This has to handle all
358 // permutations of selection between i32/f32/f64 on ICC and FCC.
359 // Expanded after instruction selection.
360 let Uses = [ICC], usesCustomInserter = 1 in {
361   def SELECT_CC_Int_ICC
362    : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, i32imm:$Cond),
363             "; SELECT_CC_Int_ICC PSEUDO!",
364             [(set i32:$dst, (SPselecticc i32:$T, i32:$F, imm:$Cond))]>;
365   def SELECT_CC_FP_ICC
366    : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, i32imm:$Cond),
367             "; SELECT_CC_FP_ICC PSEUDO!",
368             [(set f32:$dst, (SPselecticc f32:$T, f32:$F, imm:$Cond))]>;
369
370   def SELECT_CC_DFP_ICC
371    : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, i32imm:$Cond),
372             "; SELECT_CC_DFP_ICC PSEUDO!",
373             [(set f64:$dst, (SPselecticc f64:$T, f64:$F, imm:$Cond))]>;
374
375   def SELECT_CC_QFP_ICC
376    : Pseudo<(outs QFPRegs:$dst), (ins QFPRegs:$T, QFPRegs:$F, i32imm:$Cond),
377             "; SELECT_CC_QFP_ICC PSEUDO!",
378             [(set f128:$dst, (SPselecticc f128:$T, f128:$F, imm:$Cond))]>;
379 }
380
381 let usesCustomInserter = 1, Uses = [FCC0] in {
382
383   def SELECT_CC_Int_FCC
384    : Pseudo<(outs IntRegs:$dst), (ins IntRegs:$T, IntRegs:$F, i32imm:$Cond),
385             "; SELECT_CC_Int_FCC PSEUDO!",
386             [(set i32:$dst, (SPselectfcc i32:$T, i32:$F, imm:$Cond))]>;
387
388   def SELECT_CC_FP_FCC
389    : Pseudo<(outs FPRegs:$dst), (ins FPRegs:$T, FPRegs:$F, i32imm:$Cond),
390             "; SELECT_CC_FP_FCC PSEUDO!",
391             [(set f32:$dst, (SPselectfcc f32:$T, f32:$F, imm:$Cond))]>;
392   def SELECT_CC_DFP_FCC
393    : Pseudo<(outs DFPRegs:$dst), (ins DFPRegs:$T, DFPRegs:$F, i32imm:$Cond),
394             "; SELECT_CC_DFP_FCC PSEUDO!",
395             [(set f64:$dst, (SPselectfcc f64:$T, f64:$F, imm:$Cond))]>;
396   def SELECT_CC_QFP_FCC
397    : Pseudo<(outs QFPRegs:$dst), (ins QFPRegs:$T, QFPRegs:$F, i32imm:$Cond),
398             "; SELECT_CC_QFP_FCC PSEUDO!",
399             [(set f128:$dst, (SPselectfcc f128:$T, f128:$F, imm:$Cond))]>;
400 }
401
402 // Section B.1 - Load Integer Instructions, p. 90
403 let DecoderMethod = "DecodeLoadInt" in {
404   defm LDSB : LoadA<"ldsb", 0b001001, 0b011001, sextloadi8,  IntRegs, i32>;
405   defm LDSH : LoadA<"ldsh", 0b001010, 0b011010, sextloadi16, IntRegs, i32>;
406   defm LDUB : LoadA<"ldub", 0b000001, 0b010001, zextloadi8,  IntRegs, i32>;
407   defm LDUH : LoadA<"lduh", 0b000010, 0b010010, zextloadi16, IntRegs, i32>;
408   defm LD   : LoadA<"ld",   0b000000, 0b010000, load,        IntRegs, i32>;
409 }
410
411 // Section B.2 - Load Floating-point Instructions, p. 92
412 let DecoderMethod = "DecodeLoadFP" in
413   defm LDF   : Load<"ld",  0b100000, load, FPRegs,  f32>;
414 let DecoderMethod = "DecodeLoadDFP" in
415   defm LDDF  : Load<"ldd", 0b100011, load, DFPRegs, f64>;
416 let DecoderMethod = "DecodeLoadQFP" in
417   defm LDQF  : Load<"ldq", 0b100010, load, QFPRegs, f128>,
418                Requires<[HasV9, HasHardQuad]>;
419
420 // Section B.4 - Store Integer Instructions, p. 95
421 let DecoderMethod = "DecodeStoreInt" in {
422   defm STB   : StoreA<"stb", 0b000101, 0b010101, truncstorei8,  IntRegs, i32>;
423   defm STH   : StoreA<"sth", 0b000110, 0b010110, truncstorei16, IntRegs, i32>;
424   defm ST    : StoreA<"st",  0b000100, 0b010100, store,         IntRegs, i32>;
425 }
426
427 // Section B.5 - Store Floating-point Instructions, p. 97
428 let DecoderMethod = "DecodeStoreFP" in
429   defm STF   : Store<"st",  0b100100, store,         FPRegs,  f32>;
430 let DecoderMethod = "DecodeStoreDFP" in
431   defm STDF  : Store<"std", 0b100111, store,         DFPRegs, f64>;
432 let DecoderMethod = "DecodeStoreQFP" in
433   defm STQF  : Store<"stq", 0b100110, store,         QFPRegs, f128>,
434                Requires<[HasV9, HasHardQuad]>;
435
436 // Section B.8 - SWAP Register with Memory Instruction
437 // (Atomic swap)
438 let Constraints = "$val = $dst", DecoderMethod = "DecodeSWAP" in {
439   def SWAPrr : F3_1<3, 0b001111,
440                  (outs IntRegs:$dst), (ins MEMrr:$addr, IntRegs:$val),
441                  "swap [$addr], $dst",
442                  [(set i32:$dst, (atomic_swap_32 ADDRrr:$addr, i32:$val))]>;
443   def SWAPri : F3_2<3, 0b001111,
444                  (outs IntRegs:$dst), (ins MEMri:$addr, IntRegs:$val),
445                  "swap [$addr], $dst",
446                  [(set i32:$dst, (atomic_swap_32 ADDRri:$addr, i32:$val))]>;
447   def SWAPArr : F3_1_asi<3, 0b011111,
448                  (outs IntRegs:$dst), (ins MEMrr:$addr, i8imm:$asi, IntRegs:$val),
449                  "swapa [$addr] $asi, $dst",
450                  [/*FIXME: pattern?*/]>;
451 }
452
453
454 // Section B.9 - SETHI Instruction, p. 104
455 def SETHIi: F2_1<0b100,
456                  (outs IntRegs:$rd), (ins i32imm:$imm22),
457                  "sethi $imm22, $rd",
458                  [(set i32:$rd, SETHIimm:$imm22)]>;
459
460 // Section B.10 - NOP Instruction, p. 105
461 // (It's a special case of SETHI)
462 let rd = 0, imm22 = 0 in
463   def NOP : F2_1<0b100, (outs), (ins), "nop", []>;
464
465 // Section B.11 - Logical Instructions, p. 106
466 defm AND    : F3_12<"and", 0b000001, and, IntRegs, i32, simm13Op>;
467
468 def ANDNrr  : F3_1<2, 0b000101,
469                    (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2),
470                    "andn $rs1, $rs2, $rd",
471                    [(set i32:$rd, (and i32:$rs1, (not i32:$rs2)))]>;
472 def ANDNri  : F3_2<2, 0b000101,
473                    (outs IntRegs:$rd), (ins IntRegs:$rs1, simm13Op:$simm13),
474                    "andn $rs1, $simm13, $rd", []>;
475
476 defm OR     : F3_12<"or", 0b000010, or, IntRegs, i32, simm13Op>;
477
478 def ORNrr   : F3_1<2, 0b000110,
479                    (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2),
480                    "orn $rs1, $rs2, $rd",
481                    [(set i32:$rd, (or i32:$rs1, (not i32:$rs2)))]>;
482 def ORNri   : F3_2<2, 0b000110,
483                    (outs IntRegs:$rd), (ins IntRegs:$rs1, simm13Op:$simm13),
484                    "orn $rs1, $simm13, $rd", []>;
485 defm XOR    : F3_12<"xor", 0b000011, xor, IntRegs, i32, simm13Op>;
486
487 def XNORrr  : F3_1<2, 0b000111,
488                    (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2),
489                    "xnor $rs1, $rs2, $rd",
490                    [(set i32:$rd, (not (xor i32:$rs1, i32:$rs2)))]>;
491 def XNORri  : F3_2<2, 0b000111,
492                    (outs IntRegs:$rd), (ins IntRegs:$rs1, simm13Op:$simm13),
493                    "xnor $rs1, $simm13, $rd", []>;
494
495 let Defs = [ICC] in {
496   defm ANDCC  : F3_12np<"andcc",  0b010001>;
497   defm ANDNCC : F3_12np<"andncc", 0b010101>;
498   defm ORCC   : F3_12np<"orcc",   0b010010>;
499   defm ORNCC  : F3_12np<"orncc",  0b010110>;
500   defm XORCC  : F3_12np<"xorcc",  0b010011>;
501   defm XNORCC : F3_12np<"xnorcc", 0b010111>;
502 }
503
504 // Section B.12 - Shift Instructions, p. 107
505 defm SLL : F3_12<"sll", 0b100101, shl, IntRegs, i32, simm13Op>;
506 defm SRL : F3_12<"srl", 0b100110, srl, IntRegs, i32, simm13Op>;
507 defm SRA : F3_12<"sra", 0b100111, sra, IntRegs, i32, simm13Op>;
508
509 // Section B.13 - Add Instructions, p. 108
510 defm ADD   : F3_12<"add", 0b000000, add, IntRegs, i32, simm13Op>;
511
512 // "LEA" forms of add (patterns to make tblgen happy)
513 let Predicates = [Is32Bit], isCodeGenOnly = 1 in
514   def LEA_ADDri   : F3_2<2, 0b000000,
515                      (outs IntRegs:$dst), (ins MEMri:$addr),
516                      "add ${addr:arith}, $dst",
517                      [(set iPTR:$dst, ADDRri:$addr)]>;
518
519 let Defs = [ICC] in
520   defm ADDCC  : F3_12<"addcc", 0b010000, addc, IntRegs, i32, simm13Op>;
521
522 let Uses = [ICC] in
523   defm ADDC   : F3_12np<"addx", 0b001000>;
524
525 let Uses = [ICC], Defs = [ICC] in
526   defm ADDE  : F3_12<"addxcc", 0b011000, adde, IntRegs, i32, simm13Op>;
527
528 // Section B.15 - Subtract Instructions, p. 110
529 defm SUB    : F3_12  <"sub"  , 0b000100, sub, IntRegs, i32, simm13Op>;
530 let Uses = [ICC], Defs = [ICC] in
531   defm SUBE   : F3_12  <"subxcc" , 0b011100, sube, IntRegs, i32, simm13Op>;
532
533 let Defs = [ICC] in
534   defm SUBCC  : F3_12  <"subcc", 0b010100, subc, IntRegs, i32, simm13Op>;
535
536 let Uses = [ICC] in
537   defm SUBC   : F3_12np <"subx", 0b001100>;
538
539 let Defs = [ICC], rd = 0 in {
540   def CMPrr   : F3_1<2, 0b010100,
541                      (outs), (ins IntRegs:$rs1, IntRegs:$rs2),
542                      "cmp $rs1, $rs2",
543                      [(SPcmpicc i32:$rs1, i32:$rs2)]>;
544   def CMPri   : F3_2<2, 0b010100,
545                      (outs), (ins IntRegs:$rs1, simm13Op:$simm13),
546                      "cmp $rs1, $simm13",
547                      [(SPcmpicc i32:$rs1, (i32 simm13:$simm13))]>;
548 }
549
550 // Section B.18 - Multiply Instructions, p. 113
551 let Defs = [Y] in {
552   defm UMUL : F3_12np<"umul", 0b001010>;
553   defm SMUL : F3_12  <"smul", 0b001011, mul, IntRegs, i32, simm13Op>;
554 }
555
556 let Defs = [Y, ICC] in {
557   defm UMULCC : F3_12np<"umulcc", 0b011010>;
558   defm SMULCC : F3_12np<"smulcc", 0b011011>;
559 }
560
561 // Section B.19 - Divide Instructions, p. 115
562 let Defs = [Y] in {
563   defm UDIV : F3_12np<"udiv", 0b001110>;
564   defm SDIV : F3_12np<"sdiv", 0b001111>;
565 }
566
567 let Defs = [Y, ICC] in {
568   defm UDIVCC : F3_12np<"udivcc", 0b011110>;
569   defm SDIVCC : F3_12np<"sdivcc", 0b011111>;
570 }
571
572 // Section B.20 - SAVE and RESTORE, p. 117
573 defm SAVE    : F3_12np<"save"   , 0b111100>;
574 defm RESTORE : F3_12np<"restore", 0b111101>;
575
576 // Section B.21 - Branch on Integer Condition Codes Instructions, p. 119
577
578 // unconditional branch class.
579 class BranchAlways<dag ins, string asmstr, list<dag> pattern>
580   : F2_2<0b010, 0, (outs), ins, asmstr, pattern> {
581   let isBranch     = 1;
582   let isTerminator = 1;
583   let hasDelaySlot = 1;
584   let isBarrier    = 1;
585 }
586
587 let cond = 8 in
588   def BA : BranchAlways<(ins brtarget:$imm22), "ba $imm22", [(br bb:$imm22)]>;
589
590
591 let isBranch = 1, isTerminator = 1, hasDelaySlot = 1 in {
592
593 // conditional branch class:
594 class BranchSP<dag ins, string asmstr, list<dag> pattern>
595  : F2_2<0b010, 0, (outs), ins, asmstr, pattern>;
596
597 // conditional branch with annul class:
598 class BranchSPA<dag ins, string asmstr, list<dag> pattern>
599  : F2_2<0b010, 1, (outs), ins, asmstr, pattern>;
600
601 // Conditional branch class on %icc|%xcc with predication:
602 multiclass IPredBranch<string regstr, list<dag> CCPattern> {
603   def CC    : F2_3<0b001, 0, 1, (outs), (ins bprtarget:$imm19, CCOp:$cond),
604                   !strconcat("b$cond ", !strconcat(regstr, ", $imm19")),
605                    CCPattern>;
606   def CCA   : F2_3<0b001, 1, 1, (outs), (ins bprtarget:$imm19, CCOp:$cond),
607                   !strconcat("b$cond,a ", !strconcat(regstr, ", $imm19")),
608                    []>;
609   def CCNT  : F2_3<0b001, 0, 0, (outs), (ins bprtarget:$imm19, CCOp:$cond),
610                    !strconcat("b$cond,pn ", !strconcat(regstr, ", $imm19")),
611                    []>;
612   def CCANT : F2_3<0b001, 1, 0, (outs), (ins bprtarget:$imm19, CCOp:$cond),
613                    !strconcat("b$cond,a,pn ", !strconcat(regstr, ", $imm19")),
614                    []>;
615 }
616
617 } // let isBranch = 1, isTerminator = 1, hasDelaySlot = 1
618
619
620 // Indirect branch instructions.
621 let isTerminator = 1, isBarrier = 1,  hasDelaySlot = 1, isBranch =1,
622      isIndirectBranch = 1, rd = 0, isCodeGenOnly = 1 in {
623   def BINDrr  : F3_1<2, 0b111000,
624                    (outs), (ins MEMrr:$ptr),
625                    "jmp $ptr",
626                    [(brind ADDRrr:$ptr)]>;
627   def BINDri  : F3_2<2, 0b111000,
628                    (outs), (ins MEMri:$ptr),
629                    "jmp $ptr",
630                    [(brind ADDRri:$ptr)]>;
631 }
632
633 let Uses = [ICC] in {
634   def BCOND : BranchSP<(ins brtarget:$imm22, CCOp:$cond),
635                          "b$cond $imm22",
636                         [(SPbricc bb:$imm22, imm:$cond)]>;
637   def BCONDA : BranchSPA<(ins brtarget:$imm22, CCOp:$cond),
638                          "b$cond,a $imm22", []>;
639
640   let Predicates = [HasV9], cc = 0b00 in
641     defm BPI : IPredBranch<"%icc", []>;
642 }
643
644 // Section B.22 - Branch on Floating-point Condition Codes Instructions, p. 121
645
646 let isBranch = 1, isTerminator = 1, hasDelaySlot = 1 in {
647
648 // floating-point conditional branch class:
649 class FPBranchSP<dag ins, string asmstr, list<dag> pattern>
650  : F2_2<0b110, 0, (outs), ins, asmstr, pattern>;
651
652 // floating-point conditional branch with annul class:
653 class FPBranchSPA<dag ins, string asmstr, list<dag> pattern>
654  : F2_2<0b110, 1, (outs), ins, asmstr, pattern>;
655
656 // Conditional branch class on %fcc0-%fcc3 with predication:
657 multiclass FPredBranch {
658   def CC    : F2_3<0b101, 0, 1, (outs), (ins bprtarget:$imm19, CCOp:$cond,
659                                          FCCRegs:$cc),
660                   "fb$cond $cc, $imm19", []>;
661   def CCA   : F2_3<0b101, 1, 1, (outs), (ins bprtarget:$imm19, CCOp:$cond,
662                                          FCCRegs:$cc),
663                   "fb$cond,a $cc, $imm19", []>;
664   def CCNT  : F2_3<0b101, 0, 0, (outs), (ins bprtarget:$imm19, CCOp:$cond,
665                                          FCCRegs:$cc),
666                   "fb$cond,pn $cc, $imm19", []>;
667   def CCANT : F2_3<0b101, 1, 0, (outs), (ins bprtarget:$imm19, CCOp:$cond,
668                                          FCCRegs:$cc),
669                   "fb$cond,a,pn $cc, $imm19", []>;
670 }
671 } // let isBranch = 1, isTerminator = 1, hasDelaySlot = 1
672
673 let Uses = [FCC0] in {
674   def FBCOND  : FPBranchSP<(ins brtarget:$imm22, CCOp:$cond),
675                               "fb$cond $imm22",
676                               [(SPbrfcc bb:$imm22, imm:$cond)]>;
677   def FBCONDA : FPBranchSPA<(ins brtarget:$imm22, CCOp:$cond),
678                              "fb$cond,a $imm22", []>;
679 }
680
681 let Predicates = [HasV9] in
682   defm BPF : FPredBranch;
683
684
685 // Section B.24 - Call and Link Instruction, p. 125
686 // This is the only Format 1 instruction
687 let Uses = [O6],
688     hasDelaySlot = 1, isCall = 1 in {
689   def CALL : InstSP<(outs), (ins calltarget:$disp, variable_ops),
690                     "call $disp", []> {
691     bits<30> disp;
692     let op = 1;
693     let Inst{29-0} = disp;
694   }
695
696   // indirect calls: special cases of JMPL.
697   let isCodeGenOnly = 1, rd = 15 in {
698     def CALLrr : F3_1<2, 0b111000,
699                       (outs), (ins MEMrr:$ptr, variable_ops),
700                       "call $ptr",
701                       [(call ADDRrr:$ptr)]>;
702     def CALLri : F3_2<2, 0b111000,
703                       (outs), (ins MEMri:$ptr, variable_ops),
704                       "call $ptr",
705                       [(call ADDRri:$ptr)]>;
706   }
707 }
708
709 // Section B.25 - Jump and Link Instruction
710
711 // JMPL Instruction.
712 let isTerminator = 1, hasDelaySlot = 1, isBarrier = 1,
713     DecoderMethod = "DecodeJMPL" in {
714   def JMPLrr: F3_1<2, 0b111000, (outs IntRegs:$dst), (ins MEMrr:$addr),
715                   "jmpl $addr, $dst", []>;
716   def JMPLri: F3_2<2, 0b111000, (outs IntRegs:$dst), (ins MEMri:$addr),
717                   "jmpl $addr, $dst", []>;
718 }
719
720 // Section A.3 - Synthetic Instructions, p. 85
721 // special cases of JMPL:
722 let isReturn = 1, isTerminator = 1, hasDelaySlot = 1, isBarrier = 1,
723     isCodeGenOnly = 1 in {
724   let rd = 0, rs1 = 15 in
725     def RETL: F3_2<2, 0b111000, (outs), (ins i32imm:$val),
726                    "jmp %o7+$val", [(retflag simm13:$val)]>;
727
728   let rd = 0, rs1 = 31 in
729     def RET: F3_2<2, 0b111000, (outs), (ins i32imm:$val),
730                   "jmp %i7+$val", []>;
731 }
732
733 // Section B.26 - Return from Trap Instruction
734 let isReturn = 1, isTerminator = 1, hasDelaySlot = 1,
735      isBarrier = 1, rd = 0, DecoderMethod = "DecodeReturn" in {
736   def RETTrr : F3_1<2, 0b111001, (outs), (ins MEMrr:$addr),
737                        "rett $addr", []>;
738   def RETTri : F3_2<2, 0b111001, (outs), (ins MEMri:$addr),
739                        "rett $addr", []>;
740 }
741
742
743 // Section B.27 - Trap on Integer Condition Codes Instruction
744 multiclass TRAP<string regStr> {
745   def rr : TRAPSPrr<0b111010, (outs), (ins IntRegs:$rs1, IntRegs:$rs2,
746                                        CCOp:$cond),
747               !strconcat(!strconcat("t$cond ", regStr), ", $rs1 + $rs2"), []>;
748   def ri : TRAPSPri<0b111010, (outs), (ins IntRegs:$rs1, i32imm:$imm,
749                                       CCOp:$cond),
750               !strconcat(!strconcat("t$cond ", regStr), ", $rs1 + $imm"), []>;
751 }
752
753 let hasSideEffects = 1, Uses = [ICC], cc = 0b00 in
754   defm TICC : TRAP<"%icc">;
755
756 let isBarrier = 1, isTerminator = 1, rd = 0b01000, rs1 = 0, simm13 = 5 in
757   def TA5 : F3_2<0b10, 0b111010, (outs), (ins), "ta 5", [(trap)]>;
758
759 // Section B.28 - Read State Register Instructions
760 let rs2 = 0 in
761   def RDASR : F3_1<2, 0b101000,
762                  (outs IntRegs:$rd), (ins ASRRegs:$rs1),
763                  "rd $rs1, $rd", []>;
764
765 // PSR, WIM, and TBR don't exist on the SparcV9, only the V8.
766 let Predicates = [HasNoV9] in {
767   let rs2 = 0, rs1 = 0, Uses=[PSR] in
768     def RDPSR : F3_1<2, 0b101001,
769                      (outs IntRegs:$rd), (ins),
770                      "rd %psr, $rd", []>;
771
772   let rs2 = 0, rs1 = 0, Uses=[WIM] in
773     def RDWIM : F3_1<2, 0b101010,
774                      (outs IntRegs:$rd), (ins),
775                      "rd %wim, $rd", []>;
776
777   let rs2 = 0, rs1 = 0, Uses=[TBR] in
778     def RDTBR : F3_1<2, 0b101011,
779                      (outs IntRegs:$rd), (ins),
780                      "rd %tbr, $rd", []>;
781 }
782
783 // Section B.29 - Write State Register Instructions
784 def WRASRrr : F3_1<2, 0b110000,
785                  (outs ASRRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2),
786                  "wr $rs1, $rs2, $rd", []>;
787 def WRASRri : F3_2<2, 0b110000,
788                  (outs ASRRegs:$rd), (ins IntRegs:$rs1, simm13Op:$simm13),
789                  "wr $rs1, $simm13, $rd", []>;
790
791 // PSR, WIM, and TBR don't exist on the SparcV9, only the V8.
792 let Predicates = [HasNoV9] in {
793   let Defs = [PSR], rd=0 in {
794     def WRPSRrr : F3_1<2, 0b110001,
795                      (outs), (ins IntRegs:$rs1, IntRegs:$rs2),
796                      "wr $rs1, $rs2, %psr", []>;
797     def WRPSRri : F3_2<2, 0b110001,
798                      (outs), (ins IntRegs:$rs1, simm13Op:$simm13),
799                      "wr $rs1, $simm13, %psr", []>;
800   }
801
802   let Defs = [WIM], rd=0 in {
803     def WRWIMrr : F3_1<2, 0b110010,
804                      (outs), (ins IntRegs:$rs1, IntRegs:$rs2),
805                      "wr $rs1, $rs2, %wim", []>;
806     def WRWIMri : F3_2<2, 0b110010,
807                      (outs), (ins IntRegs:$rs1, simm13Op:$simm13),
808                      "wr $rs1, $simm13, %wim", []>;
809   }
810
811   let Defs = [TBR], rd=0 in {
812     def WRTBRrr : F3_1<2, 0b110011,
813                      (outs), (ins IntRegs:$rs1, IntRegs:$rs2),
814                      "wr $rs1, $rs2, %tbr", []>;
815     def WRTBRri : F3_2<2, 0b110011,
816                      (outs), (ins IntRegs:$rs1, simm13Op:$simm13),
817                      "wr $rs1, $simm13, %tbr", []>;
818   }
819 }
820
821 // Section B.30 - STBAR Instruction
822 let hasSideEffects = 1, rd = 0, rs1 = 0b01111, rs2 = 0 in
823   def STBAR : F3_1<2, 0b101000, (outs), (ins), "stbar", []>;
824
825
826 // Section B.31 - Unimplmented Instruction
827 let rd = 0 in
828   def UNIMP : F2_1<0b000, (outs), (ins i32imm:$imm22),
829                   "unimp $imm22", []>;
830
831 // Section B.32 - Flush Instruction Memory
832 let rd = 0 in {
833   def FLUSHrr : F3_1<2, 0b111011, (outs), (ins MEMrr:$addr),
834                        "flush $addr", []>;
835   def FLUSHri : F3_2<2, 0b111011, (outs), (ins MEMri:$addr),
836                        "flush $addr", []>;
837
838   // The no-arg FLUSH is only here for the benefit of the InstAlias
839   // "flush", which cannot seem to use FLUSHrr, due to the inability
840   // to construct a MEMrr with fixed G0 registers.
841   let rs1 = 0, rs2 = 0 in
842     def FLUSH   : F3_1<2, 0b111011, (outs), (ins), "flush %g0", []>;
843 }
844
845 // Section B.33 - Floating-point Operate (FPop) Instructions
846
847 // Convert Integer to Floating-point Instructions, p. 141
848 def FITOS : F3_3u<2, 0b110100, 0b011000100,
849                  (outs FPRegs:$rd), (ins FPRegs:$rs2),
850                  "fitos $rs2, $rd",
851                  [(set FPRegs:$rd, (SPitof FPRegs:$rs2))]>;
852 def FITOD : F3_3u<2, 0b110100, 0b011001000,
853                  (outs DFPRegs:$rd), (ins FPRegs:$rs2),
854                  "fitod $rs2, $rd",
855                  [(set DFPRegs:$rd, (SPitof FPRegs:$rs2))]>;
856 def FITOQ : F3_3u<2, 0b110100, 0b011001100,
857                  (outs QFPRegs:$rd), (ins FPRegs:$rs2),
858                  "fitoq $rs2, $rd",
859                  [(set QFPRegs:$rd, (SPitof FPRegs:$rs2))]>,
860                  Requires<[HasHardQuad]>;
861
862 // Convert Floating-point to Integer Instructions, p. 142
863 def FSTOI : F3_3u<2, 0b110100, 0b011010001,
864                  (outs FPRegs:$rd), (ins FPRegs:$rs2),
865                  "fstoi $rs2, $rd",
866                  [(set FPRegs:$rd, (SPftoi FPRegs:$rs2))]>;
867 def FDTOI : F3_3u<2, 0b110100, 0b011010010,
868                  (outs FPRegs:$rd), (ins DFPRegs:$rs2),
869                  "fdtoi $rs2, $rd",
870                  [(set FPRegs:$rd, (SPftoi DFPRegs:$rs2))]>;
871 def FQTOI : F3_3u<2, 0b110100, 0b011010011,
872                  (outs FPRegs:$rd), (ins QFPRegs:$rs2),
873                  "fqtoi $rs2, $rd",
874                  [(set FPRegs:$rd, (SPftoi QFPRegs:$rs2))]>,
875                  Requires<[HasHardQuad]>;
876
877 // Convert between Floating-point Formats Instructions, p. 143
878 def FSTOD : F3_3u<2, 0b110100, 0b011001001,
879                  (outs DFPRegs:$rd), (ins FPRegs:$rs2),
880                  "fstod $rs2, $rd",
881                  [(set f64:$rd, (fextend f32:$rs2))]>;
882 def FSTOQ : F3_3u<2, 0b110100, 0b011001101,
883                  (outs QFPRegs:$rd), (ins FPRegs:$rs2),
884                  "fstoq $rs2, $rd",
885                  [(set f128:$rd, (fextend f32:$rs2))]>,
886                  Requires<[HasHardQuad]>;
887 def FDTOS : F3_3u<2, 0b110100, 0b011000110,
888                  (outs FPRegs:$rd), (ins DFPRegs:$rs2),
889                  "fdtos $rs2, $rd",
890                  [(set f32:$rd, (fround f64:$rs2))]>;
891 def FDTOQ : F3_3u<2, 0b110100, 0b011001110,
892                  (outs QFPRegs:$rd), (ins DFPRegs:$rs2),
893                  "fdtoq $rs2, $rd",
894                  [(set f128:$rd, (fextend f64:$rs2))]>,
895                  Requires<[HasHardQuad]>;
896 def FQTOS : F3_3u<2, 0b110100, 0b011000111,
897                  (outs FPRegs:$rd), (ins QFPRegs:$rs2),
898                  "fqtos $rs2, $rd",
899                  [(set f32:$rd, (fround f128:$rs2))]>,
900                  Requires<[HasHardQuad]>;
901 def FQTOD : F3_3u<2, 0b110100, 0b011001011,
902                  (outs DFPRegs:$rd), (ins QFPRegs:$rs2),
903                  "fqtod $rs2, $rd",
904                  [(set f64:$rd, (fround f128:$rs2))]>,
905                  Requires<[HasHardQuad]>;
906
907 // Floating-point Move Instructions, p. 144
908 def FMOVS : F3_3u<2, 0b110100, 0b000000001,
909                  (outs FPRegs:$rd), (ins FPRegs:$rs2),
910                  "fmovs $rs2, $rd", []>;
911 def FNEGS : F3_3u<2, 0b110100, 0b000000101,
912                  (outs FPRegs:$rd), (ins FPRegs:$rs2),
913                  "fnegs $rs2, $rd",
914                  [(set f32:$rd, (fneg f32:$rs2))]>;
915 def FABSS : F3_3u<2, 0b110100, 0b000001001,
916                  (outs FPRegs:$rd), (ins FPRegs:$rs2),
917                  "fabss $rs2, $rd",
918                  [(set f32:$rd, (fabs f32:$rs2))]>;
919
920
921 // Floating-point Square Root Instructions, p.145
922 def FSQRTS : F3_3u<2, 0b110100, 0b000101001,
923                   (outs FPRegs:$rd), (ins FPRegs:$rs2),
924                   "fsqrts $rs2, $rd",
925                   [(set f32:$rd, (fsqrt f32:$rs2))]>;
926 def FSQRTD : F3_3u<2, 0b110100, 0b000101010,
927                   (outs DFPRegs:$rd), (ins DFPRegs:$rs2),
928                   "fsqrtd $rs2, $rd",
929                   [(set f64:$rd, (fsqrt f64:$rs2))]>;
930 def FSQRTQ : F3_3u<2, 0b110100, 0b000101011,
931                   (outs QFPRegs:$rd), (ins QFPRegs:$rs2),
932                   "fsqrtq $rs2, $rd",
933                   [(set f128:$rd, (fsqrt f128:$rs2))]>,
934                   Requires<[HasHardQuad]>;
935
936
937
938 // Floating-point Add and Subtract Instructions, p. 146
939 def FADDS  : F3_3<2, 0b110100, 0b001000001,
940                   (outs FPRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
941                   "fadds $rs1, $rs2, $rd",
942                   [(set f32:$rd, (fadd f32:$rs1, f32:$rs2))]>;
943 def FADDD  : F3_3<2, 0b110100, 0b001000010,
944                   (outs DFPRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
945                   "faddd $rs1, $rs2, $rd",
946                   [(set f64:$rd, (fadd f64:$rs1, f64:$rs2))]>;
947 def FADDQ  : F3_3<2, 0b110100, 0b001000011,
948                   (outs QFPRegs:$rd), (ins QFPRegs:$rs1, QFPRegs:$rs2),
949                   "faddq $rs1, $rs2, $rd",
950                   [(set f128:$rd, (fadd f128:$rs1, f128:$rs2))]>,
951                   Requires<[HasHardQuad]>;
952
953 def FSUBS  : F3_3<2, 0b110100, 0b001000101,
954                   (outs FPRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
955                   "fsubs $rs1, $rs2, $rd",
956                   [(set f32:$rd, (fsub f32:$rs1, f32:$rs2))]>;
957 def FSUBD  : F3_3<2, 0b110100, 0b001000110,
958                   (outs DFPRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
959                   "fsubd $rs1, $rs2, $rd",
960                   [(set f64:$rd, (fsub f64:$rs1, f64:$rs2))]>;
961 def FSUBQ  : F3_3<2, 0b110100, 0b001000111,
962                   (outs QFPRegs:$rd), (ins QFPRegs:$rs1, QFPRegs:$rs2),
963                   "fsubq $rs1, $rs2, $rd",
964                   [(set f128:$rd, (fsub f128:$rs1, f128:$rs2))]>,
965                   Requires<[HasHardQuad]>;
966
967
968 // Floating-point Multiply and Divide Instructions, p. 147
969 def FMULS  : F3_3<2, 0b110100, 0b001001001,
970                   (outs FPRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
971                   "fmuls $rs1, $rs2, $rd",
972                   [(set f32:$rd, (fmul f32:$rs1, f32:$rs2))]>;
973 def FMULD  : F3_3<2, 0b110100, 0b001001010,
974                   (outs DFPRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
975                   "fmuld $rs1, $rs2, $rd",
976                   [(set f64:$rd, (fmul f64:$rs1, f64:$rs2))]>;
977 def FMULQ  : F3_3<2, 0b110100, 0b001001011,
978                   (outs QFPRegs:$rd), (ins QFPRegs:$rs1, QFPRegs:$rs2),
979                   "fmulq $rs1, $rs2, $rd",
980                   [(set f128:$rd, (fmul f128:$rs1, f128:$rs2))]>,
981                   Requires<[HasHardQuad]>;
982
983 def FSMULD : F3_3<2, 0b110100, 0b001101001,
984                   (outs DFPRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
985                   "fsmuld $rs1, $rs2, $rd",
986                   [(set f64:$rd, (fmul (fextend f32:$rs1),
987                                         (fextend f32:$rs2)))]>;
988 def FDMULQ : F3_3<2, 0b110100, 0b001101110,
989                   (outs QFPRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
990                   "fdmulq $rs1, $rs2, $rd",
991                   [(set f128:$rd, (fmul (fextend f64:$rs1),
992                                          (fextend f64:$rs2)))]>,
993                   Requires<[HasHardQuad]>;
994
995 def FDIVS  : F3_3<2, 0b110100, 0b001001101,
996                  (outs FPRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
997                  "fdivs $rs1, $rs2, $rd",
998                  [(set f32:$rd, (fdiv f32:$rs1, f32:$rs2))]>;
999 def FDIVD  : F3_3<2, 0b110100, 0b001001110,
1000                  (outs DFPRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
1001                  "fdivd $rs1, $rs2, $rd",
1002                  [(set f64:$rd, (fdiv f64:$rs1, f64:$rs2))]>;
1003 def FDIVQ  : F3_3<2, 0b110100, 0b001001111,
1004                  (outs QFPRegs:$rd), (ins QFPRegs:$rs1, QFPRegs:$rs2),
1005                  "fdivq $rs1, $rs2, $rd",
1006                  [(set f128:$rd, (fdiv f128:$rs1, f128:$rs2))]>,
1007                  Requires<[HasHardQuad]>;
1008
1009 // Floating-point Compare Instructions, p. 148
1010 // Note: the 2nd template arg is different for these guys.
1011 // Note 2: the result of a FCMP is not available until the 2nd cycle
1012 // after the instr is retired, but there is no interlock in Sparc V8.
1013 // This behavior is modeled with a forced noop after the instruction in
1014 // DelaySlotFiller.
1015
1016 let Defs = [FCC0], rd = 0, isCodeGenOnly = 1 in {
1017   def FCMPS  : F3_3c<2, 0b110101, 0b001010001,
1018                    (outs), (ins FPRegs:$rs1, FPRegs:$rs2),
1019                    "fcmps $rs1, $rs2",
1020                    [(SPcmpfcc f32:$rs1, f32:$rs2)]>;
1021   def FCMPD  : F3_3c<2, 0b110101, 0b001010010,
1022                    (outs), (ins DFPRegs:$rs1, DFPRegs:$rs2),
1023                    "fcmpd $rs1, $rs2",
1024                    [(SPcmpfcc f64:$rs1, f64:$rs2)]>;
1025   def FCMPQ  : F3_3c<2, 0b110101, 0b001010011,
1026                    (outs), (ins QFPRegs:$rs1, QFPRegs:$rs2),
1027                    "fcmpq $rs1, $rs2",
1028                    [(SPcmpfcc f128:$rs1, f128:$rs2)]>,
1029                    Requires<[HasHardQuad]>;
1030 }
1031
1032 //===----------------------------------------------------------------------===//
1033 // Instructions for Thread Local Storage(TLS).
1034 //===----------------------------------------------------------------------===//
1035 let isCodeGenOnly = 1, isAsmParserOnly = 1 in {
1036 def TLS_ADDrr : F3_1<2, 0b000000,
1037                     (outs IntRegs:$rd),
1038                     (ins IntRegs:$rs1, IntRegs:$rs2, TLSSym:$sym),
1039                     "add $rs1, $rs2, $rd, $sym",
1040                     [(set i32:$rd,
1041                         (tlsadd i32:$rs1, i32:$rs2, tglobaltlsaddr:$sym))]>;
1042
1043 let mayLoad = 1 in
1044   def TLS_LDrr : F3_1<3, 0b000000,
1045                       (outs IntRegs:$dst), (ins MEMrr:$addr, TLSSym:$sym),
1046                       "ld [$addr], $dst, $sym",
1047                       [(set i32:$dst,
1048                           (tlsld ADDRrr:$addr, tglobaltlsaddr:$sym))]>;
1049
1050 let Uses = [O6], isCall = 1, hasDelaySlot = 1 in
1051   def TLS_CALL : InstSP<(outs),
1052                         (ins calltarget:$disp, TLSSym:$sym, variable_ops),
1053                         "call $disp, $sym",
1054                         [(tlscall texternalsym:$disp, tglobaltlsaddr:$sym)]> {
1055   bits<30> disp;
1056   let op = 1;
1057   let Inst{29-0} = disp;
1058 }
1059 }
1060
1061 //===----------------------------------------------------------------------===//
1062 // V9 Instructions
1063 //===----------------------------------------------------------------------===//
1064
1065 // V9 Conditional Moves.
1066 let Predicates = [HasV9], Constraints = "$f = $rd" in {
1067   // Move Integer Register on Condition (MOVcc) p. 194 of the V9 manual.
1068   let Uses = [ICC], intcc = 1, cc = 0b00 in {
1069     def MOVICCrr
1070       : F4_1<0b101100, (outs IntRegs:$rd),
1071              (ins IntRegs:$rs2, IntRegs:$f, CCOp:$cond),
1072              "mov$cond %icc, $rs2, $rd",
1073              [(set i32:$rd, (SPselecticc i32:$rs2, i32:$f, imm:$cond))]>;
1074
1075     def MOVICCri
1076       : F4_2<0b101100, (outs IntRegs:$rd),
1077              (ins i32imm:$simm11, IntRegs:$f, CCOp:$cond),
1078              "mov$cond %icc, $simm11, $rd",
1079              [(set i32:$rd,
1080                     (SPselecticc simm11:$simm11, i32:$f, imm:$cond))]>;
1081   }
1082
1083   let Uses = [FCC0], intcc = 0, cc = 0b00 in {
1084     def MOVFCCrr
1085       : F4_1<0b101100, (outs IntRegs:$rd),
1086              (ins IntRegs:$rs2, IntRegs:$f, CCOp:$cond),
1087              "mov$cond %fcc0, $rs2, $rd",
1088              [(set i32:$rd, (SPselectfcc i32:$rs2, i32:$f, imm:$cond))]>;
1089     def MOVFCCri
1090       : F4_2<0b101100, (outs IntRegs:$rd),
1091              (ins i32imm:$simm11, IntRegs:$f, CCOp:$cond),
1092              "mov$cond %fcc0, $simm11, $rd",
1093              [(set i32:$rd,
1094                     (SPselectfcc simm11:$simm11, i32:$f, imm:$cond))]>;
1095   }
1096
1097   let Uses = [ICC], intcc = 1, opf_cc = 0b00 in {
1098     def FMOVS_ICC
1099       : F4_3<0b110101, 0b000001, (outs FPRegs:$rd),
1100              (ins FPRegs:$rs2, FPRegs:$f, CCOp:$cond),
1101              "fmovs$cond %icc, $rs2, $rd",
1102              [(set f32:$rd, (SPselecticc f32:$rs2, f32:$f, imm:$cond))]>;
1103     def FMOVD_ICC
1104       : F4_3<0b110101, 0b000010, (outs DFPRegs:$rd),
1105                (ins DFPRegs:$rs2, DFPRegs:$f, CCOp:$cond),
1106                "fmovd$cond %icc, $rs2, $rd",
1107                [(set f64:$rd, (SPselecticc f64:$rs2, f64:$f, imm:$cond))]>;
1108     def FMOVQ_ICC
1109       : F4_3<0b110101, 0b000011, (outs QFPRegs:$rd),
1110                (ins QFPRegs:$rs2, QFPRegs:$f, CCOp:$cond),
1111                "fmovq$cond %icc, $rs2, $rd",
1112                [(set f128:$rd, (SPselecticc f128:$rs2, f128:$f, imm:$cond))]>,
1113                Requires<[HasHardQuad]>;
1114   }
1115
1116   let Uses = [FCC0], intcc = 0, opf_cc = 0b00 in {
1117     def FMOVS_FCC
1118       : F4_3<0b110101, 0b000001, (outs FPRegs:$rd),
1119              (ins FPRegs:$rs2, FPRegs:$f, CCOp:$cond),
1120              "fmovs$cond %fcc0, $rs2, $rd",
1121              [(set f32:$rd, (SPselectfcc f32:$rs2, f32:$f, imm:$cond))]>;
1122     def FMOVD_FCC
1123       : F4_3<0b110101, 0b000010, (outs DFPRegs:$rd),
1124              (ins DFPRegs:$rs2, DFPRegs:$f, CCOp:$cond),
1125              "fmovd$cond %fcc0, $rs2, $rd",
1126              [(set f64:$rd, (SPselectfcc f64:$rs2, f64:$f, imm:$cond))]>;
1127     def FMOVQ_FCC
1128       : F4_3<0b110101, 0b000011, (outs QFPRegs:$rd),
1129              (ins QFPRegs:$rs2, QFPRegs:$f, CCOp:$cond),
1130              "fmovq$cond %fcc0, $rs2, $rd",
1131              [(set f128:$rd, (SPselectfcc f128:$rs2, f128:$f, imm:$cond))]>,
1132              Requires<[HasHardQuad]>;
1133   }
1134
1135 }
1136
1137 // Floating-Point Move Instructions, p. 164 of the V9 manual.
1138 let Predicates = [HasV9] in {
1139   def FMOVD : F3_3u<2, 0b110100, 0b000000010,
1140                    (outs DFPRegs:$rd), (ins DFPRegs:$rs2),
1141                    "fmovd $rs2, $rd", []>;
1142   def FMOVQ : F3_3u<2, 0b110100, 0b000000011,
1143                    (outs QFPRegs:$rd), (ins QFPRegs:$rs2),
1144                    "fmovq $rs2, $rd", []>,
1145                    Requires<[HasHardQuad]>;
1146   def FNEGD : F3_3u<2, 0b110100, 0b000000110,
1147                    (outs DFPRegs:$rd), (ins DFPRegs:$rs2),
1148                    "fnegd $rs2, $rd",
1149                    [(set f64:$rd, (fneg f64:$rs2))]>;
1150   def FNEGQ : F3_3u<2, 0b110100, 0b000000111,
1151                    (outs QFPRegs:$rd), (ins QFPRegs:$rs2),
1152                    "fnegq $rs2, $rd",
1153                    [(set f128:$rd, (fneg f128:$rs2))]>,
1154                    Requires<[HasHardQuad]>;
1155   def FABSD : F3_3u<2, 0b110100, 0b000001010,
1156                    (outs DFPRegs:$rd), (ins DFPRegs:$rs2),
1157                    "fabsd $rs2, $rd",
1158                    [(set f64:$rd, (fabs f64:$rs2))]>;
1159   def FABSQ : F3_3u<2, 0b110100, 0b000001011,
1160                    (outs QFPRegs:$rd), (ins QFPRegs:$rs2),
1161                    "fabsq $rs2, $rd",
1162                    [(set f128:$rd, (fabs f128:$rs2))]>,
1163                    Requires<[HasHardQuad]>;
1164 }
1165
1166 // Floating-point compare instruction with %fcc0-%fcc3.
1167 def V9FCMPS  : F3_3c<2, 0b110101, 0b001010001,
1168                (outs FCCRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
1169                "fcmps $rd, $rs1, $rs2", []>;
1170 def V9FCMPD  : F3_3c<2, 0b110101, 0b001010010,
1171                 (outs FCCRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
1172                 "fcmpd $rd, $rs1, $rs2", []>;
1173 def V9FCMPQ  : F3_3c<2, 0b110101, 0b001010011,
1174                 (outs FCCRegs:$rd), (ins QFPRegs:$rs1, QFPRegs:$rs2),
1175                 "fcmpq $rd, $rs1, $rs2", []>,
1176                  Requires<[HasHardQuad]>;
1177
1178 let hasSideEffects = 1 in {
1179   def V9FCMPES  : F3_3c<2, 0b110101, 0b001010101,
1180                    (outs FCCRegs:$rd), (ins FPRegs:$rs1, FPRegs:$rs2),
1181                    "fcmpes $rd, $rs1, $rs2", []>;
1182   def V9FCMPED  : F3_3c<2, 0b110101, 0b001010110,
1183                    (outs FCCRegs:$rd), (ins DFPRegs:$rs1, DFPRegs:$rs2),
1184                    "fcmped $rd, $rs1, $rs2", []>;
1185   def V9FCMPEQ  : F3_3c<2, 0b110101, 0b001010111,
1186                    (outs FCCRegs:$rd), (ins QFPRegs:$rs1, QFPRegs:$rs2),
1187                    "fcmpeq $rd, $rs1, $rs2", []>,
1188                    Requires<[HasHardQuad]>;
1189 }
1190
1191 // Floating point conditional move instrucitons with %fcc0-%fcc3.
1192 let Predicates = [HasV9] in {
1193   let Constraints = "$f = $rd", intcc = 0 in {
1194     def V9MOVFCCrr
1195       : F4_1<0b101100, (outs IntRegs:$rd),
1196              (ins FCCRegs:$cc, IntRegs:$rs2, IntRegs:$f, CCOp:$cond),
1197              "mov$cond $cc, $rs2, $rd", []>;
1198     def V9MOVFCCri
1199       : F4_2<0b101100, (outs IntRegs:$rd),
1200              (ins FCCRegs:$cc, i32imm:$simm11, IntRegs:$f, CCOp:$cond),
1201              "mov$cond $cc, $simm11, $rd", []>;
1202     def V9FMOVS_FCC
1203       : F4_3<0b110101, 0b000001, (outs FPRegs:$rd),
1204              (ins FCCRegs:$opf_cc, FPRegs:$rs2, FPRegs:$f, CCOp:$cond),
1205              "fmovs$cond $opf_cc, $rs2, $rd", []>;
1206     def V9FMOVD_FCC
1207       : F4_3<0b110101, 0b000010, (outs DFPRegs:$rd),
1208              (ins FCCRegs:$opf_cc, DFPRegs:$rs2, DFPRegs:$f, CCOp:$cond),
1209              "fmovd$cond $opf_cc, $rs2, $rd", []>;
1210     def V9FMOVQ_FCC
1211       : F4_3<0b110101, 0b000011, (outs QFPRegs:$rd),
1212              (ins FCCRegs:$opf_cc, QFPRegs:$rs2, QFPRegs:$f, CCOp:$cond),
1213              "fmovq$cond $opf_cc, $rs2, $rd", []>,
1214              Requires<[HasHardQuad]>;
1215   } // Constraints = "$f = $rd", ...
1216 } // let Predicates = [hasV9]
1217
1218
1219 // POPCrr - This does a ctpop of a 64-bit register.  As such, we have to clear
1220 // the top 32-bits before using it.  To do this clearing, we use a SRLri X,0.
1221 let rs1 = 0 in
1222   def POPCrr : F3_1<2, 0b101110,
1223                     (outs IntRegs:$dst), (ins IntRegs:$src),
1224                     "popc $src, $dst", []>, Requires<[HasV9]>;
1225 def : Pat<(ctpop i32:$src),
1226           (POPCrr (SRLri $src, 0))>;
1227
1228 let Predicates = [HasV9], hasSideEffects = 1, rd = 0, rs1 = 0b01111 in
1229  def MEMBARi : F3_2<2, 0b101000, (outs), (ins simm13Op:$simm13),
1230                     "membar $simm13", []>;
1231
1232 // TODO: Should add a CASArr variant. In fact, the CAS instruction,
1233 // unlike other instructions, only comes in a form which requires an
1234 // ASI be provided. The ASI value hardcoded here is ASI_PRIMARY, the
1235 // default unprivileged ASI for SparcV9.  (Also of note: some modern
1236 // SparcV8 implementations provide CASA as an extension, but require
1237 // the use of SparcV8's default ASI, 0xA ("User Data") instead.)
1238 let Predicates = [HasV9], Constraints = "$swap = $rd", asi = 0b10000000 in
1239   def CASrr: F3_1_asi<3, 0b111100,
1240                 (outs IntRegs:$rd), (ins IntRegs:$rs1, IntRegs:$rs2,
1241                                      IntRegs:$swap),
1242                  "cas [$rs1], $rs2, $rd",
1243                  [(set i32:$rd,
1244                      (atomic_cmp_swap iPTR:$rs1, i32:$rs2, i32:$swap))]>;
1245
1246 let Defs = [ICC] in {
1247 defm TADDCC   : F3_12np<"taddcc",   0b100000>;
1248 defm TSUBCC   : F3_12np<"tsubcc",   0b100001>;
1249
1250 let hasSideEffects = 1 in {
1251   defm TADDCCTV : F3_12np<"taddcctv", 0b100010>;
1252   defm TSUBCCTV : F3_12np<"tsubcctv", 0b100011>;
1253 }
1254 }
1255
1256 //===----------------------------------------------------------------------===//
1257 // Non-Instruction Patterns
1258 //===----------------------------------------------------------------------===//
1259
1260 // Small immediates.
1261 def : Pat<(i32 simm13:$val),
1262           (ORri (i32 G0), imm:$val)>;
1263 // Arbitrary immediates.
1264 def : Pat<(i32 imm:$val),
1265           (ORri (SETHIi (HI22 imm:$val)), (LO10 imm:$val))>;
1266
1267
1268 // Global addresses, constant pool entries
1269 let Predicates = [Is32Bit] in {
1270
1271 def : Pat<(SPhi tglobaladdr:$in), (SETHIi tglobaladdr:$in)>;
1272 def : Pat<(SPlo tglobaladdr:$in), (ORri (i32 G0), tglobaladdr:$in)>;
1273 def : Pat<(SPhi tconstpool:$in), (SETHIi tconstpool:$in)>;
1274 def : Pat<(SPlo tconstpool:$in), (ORri (i32 G0), tconstpool:$in)>;
1275
1276 // GlobalTLS addresses
1277 def : Pat<(SPhi tglobaltlsaddr:$in), (SETHIi tglobaltlsaddr:$in)>;
1278 def : Pat<(SPlo tglobaltlsaddr:$in), (ORri (i32 G0), tglobaltlsaddr:$in)>;
1279 def : Pat<(add (SPhi tglobaltlsaddr:$in1), (SPlo tglobaltlsaddr:$in2)),
1280           (ADDri (SETHIi tglobaltlsaddr:$in1), (tglobaltlsaddr:$in2))>;
1281 def : Pat<(xor (SPhi tglobaltlsaddr:$in1), (SPlo tglobaltlsaddr:$in2)),
1282           (XORri (SETHIi tglobaltlsaddr:$in1), (tglobaltlsaddr:$in2))>;
1283
1284 // Blockaddress
1285 def : Pat<(SPhi tblockaddress:$in), (SETHIi tblockaddress:$in)>;
1286 def : Pat<(SPlo tblockaddress:$in), (ORri (i32 G0), tblockaddress:$in)>;
1287
1288 // Add reg, lo.  This is used when taking the addr of a global/constpool entry.
1289 def : Pat<(add iPTR:$r, (SPlo tglobaladdr:$in)), (ADDri $r, tglobaladdr:$in)>;
1290 def : Pat<(add iPTR:$r, (SPlo tconstpool:$in)),  (ADDri $r, tconstpool:$in)>;
1291 def : Pat<(add iPTR:$r, (SPlo tblockaddress:$in)),
1292                         (ADDri $r, tblockaddress:$in)>;
1293 }
1294
1295 // Calls:
1296 def : Pat<(call tglobaladdr:$dst),
1297           (CALL tglobaladdr:$dst)>;
1298 def : Pat<(call texternalsym:$dst),
1299           (CALL texternalsym:$dst)>;
1300
1301 // Map integer extload's to zextloads.
1302 def : Pat<(i32 (extloadi1 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
1303 def : Pat<(i32 (extloadi1 ADDRri:$src)), (LDUBri ADDRri:$src)>;
1304 def : Pat<(i32 (extloadi8 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
1305 def : Pat<(i32 (extloadi8 ADDRri:$src)), (LDUBri ADDRri:$src)>;
1306 def : Pat<(i32 (extloadi16 ADDRrr:$src)), (LDUHrr ADDRrr:$src)>;
1307 def : Pat<(i32 (extloadi16 ADDRri:$src)), (LDUHri ADDRri:$src)>;
1308
1309 // zextload bool -> zextload byte
1310 def : Pat<(i32 (zextloadi1 ADDRrr:$src)), (LDUBrr ADDRrr:$src)>;
1311 def : Pat<(i32 (zextloadi1 ADDRri:$src)), (LDUBri ADDRri:$src)>;
1312
1313 // store 0, addr -> store %g0, addr
1314 def : Pat<(store (i32 0), ADDRrr:$dst), (STrr ADDRrr:$dst, (i32 G0))>;
1315 def : Pat<(store (i32 0), ADDRri:$dst), (STri ADDRri:$dst, (i32 G0))>;
1316
1317 // store bar for all atomic_fence in V8.
1318 let Predicates = [HasNoV9] in
1319   def : Pat<(atomic_fence imm, imm), (STBAR)>;
1320
1321 // atomic_load_32 addr -> load addr
1322 def : Pat<(i32 (atomic_load ADDRrr:$src)), (LDrr ADDRrr:$src)>;
1323 def : Pat<(i32 (atomic_load ADDRri:$src)), (LDri ADDRri:$src)>;
1324
1325 // atomic_store_32 val, addr -> store val, addr
1326 def : Pat<(atomic_store ADDRrr:$dst, i32:$val), (STrr ADDRrr:$dst, $val)>;
1327 def : Pat<(atomic_store ADDRri:$dst, i32:$val), (STri ADDRri:$dst, $val)>;
1328
1329
1330 include "SparcInstr64Bit.td"
1331 include "SparcInstrVIS.td"
1332 include "SparcInstrAliases.td"