1 //===-- R600ISelLowering.cpp - R600 DAG Lowering Implementation -----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
11 /// \brief Custom DAG lowering for R600
13 //===----------------------------------------------------------------------===//
15 #include "R600ISelLowering.h"
16 #include "AMDGPUFrameLowering.h"
17 #include "AMDGPUIntrinsicInfo.h"
18 #include "AMDGPUSubtarget.h"
19 #include "R600Defines.h"
20 #include "R600FrameLowering.h"
21 #include "R600InstrInfo.h"
22 #include "R600MachineFunctionInfo.h"
23 #include "Utils/AMDGPUBaseInfo.h"
24 #include "llvm/ADT/APFloat.h"
25 #include "llvm/ADT/APInt.h"
26 #include "llvm/ADT/ArrayRef.h"
27 #include "llvm/ADT/DenseMap.h"
28 #include "llvm/ADT/SmallVector.h"
29 #include "llvm/CodeGen/CallingConvLower.h"
30 #include "llvm/CodeGen/DAGCombine.h"
31 #include "llvm/CodeGen/ISDOpcodes.h"
32 #include "llvm/CodeGen/MachineBasicBlock.h"
33 #include "llvm/CodeGen/MachineFunction.h"
34 #include "llvm/CodeGen/MachineInstr.h"
35 #include "llvm/CodeGen/MachineInstrBuilder.h"
36 #include "llvm/CodeGen/MachineMemOperand.h"
37 #include "llvm/CodeGen/MachineRegisterInfo.h"
38 #include "llvm/CodeGen/MachineValueType.h"
39 #include "llvm/CodeGen/SelectionDAG.h"
40 #include "llvm/IR/Constants.h"
41 #include "llvm/IR/DerivedTypes.h"
42 #include "llvm/Support/Casting.h"
43 #include "llvm/Support/Compiler.h"
44 #include "llvm/Support/ErrorHandling.h"
53 R600TargetLowering::R600TargetLowering(const TargetMachine &TM,
54 const R600Subtarget &STI)
55 : AMDGPUTargetLowering(TM, STI), Gen(STI.getGeneration()) {
56 addRegisterClass(MVT::f32, &AMDGPU::R600_Reg32RegClass);
57 addRegisterClass(MVT::i32, &AMDGPU::R600_Reg32RegClass);
58 addRegisterClass(MVT::v2f32, &AMDGPU::R600_Reg64RegClass);
59 addRegisterClass(MVT::v2i32, &AMDGPU::R600_Reg64RegClass);
60 addRegisterClass(MVT::v4f32, &AMDGPU::R600_Reg128RegClass);
61 addRegisterClass(MVT::v4i32, &AMDGPU::R600_Reg128RegClass);
63 computeRegisterProperties(STI.getRegisterInfo());
65 // Legalize loads and stores to the private address space.
66 setOperationAction(ISD::LOAD, MVT::i32, Custom);
67 setOperationAction(ISD::LOAD, MVT::v2i32, Custom);
68 setOperationAction(ISD::LOAD, MVT::v4i32, Custom);
70 // EXTLOAD should be the same as ZEXTLOAD. It is legal for some address
71 // spaces, so it is custom lowered to handle those where it isn't.
72 for (MVT VT : MVT::integer_valuetypes()) {
73 setLoadExtAction(ISD::SEXTLOAD, VT, MVT::i1, Promote);
74 setLoadExtAction(ISD::SEXTLOAD, VT, MVT::i8, Custom);
75 setLoadExtAction(ISD::SEXTLOAD, VT, MVT::i16, Custom);
77 setLoadExtAction(ISD::ZEXTLOAD, VT, MVT::i1, Promote);
78 setLoadExtAction(ISD::ZEXTLOAD, VT, MVT::i8, Custom);
79 setLoadExtAction(ISD::ZEXTLOAD, VT, MVT::i16, Custom);
81 setLoadExtAction(ISD::EXTLOAD, VT, MVT::i1, Promote);
82 setLoadExtAction(ISD::EXTLOAD, VT, MVT::i8, Custom);
83 setLoadExtAction(ISD::EXTLOAD, VT, MVT::i16, Custom);
86 // Workaround for LegalizeDAG asserting on expansion of i1 vector loads.
87 setLoadExtAction(ISD::EXTLOAD, MVT::v2i32, MVT::v2i1, Expand);
88 setLoadExtAction(ISD::SEXTLOAD, MVT::v2i32, MVT::v2i1, Expand);
89 setLoadExtAction(ISD::ZEXTLOAD, MVT::v2i32, MVT::v2i1, Expand);
91 setLoadExtAction(ISD::EXTLOAD, MVT::v4i32, MVT::v4i1, Expand);
92 setLoadExtAction(ISD::SEXTLOAD, MVT::v4i32, MVT::v4i1, Expand);
93 setLoadExtAction(ISD::ZEXTLOAD, MVT::v4i32, MVT::v4i1, Expand);
95 setOperationAction(ISD::STORE, MVT::i8, Custom);
96 setOperationAction(ISD::STORE, MVT::i32, Custom);
97 setOperationAction(ISD::STORE, MVT::v2i32, Custom);
98 setOperationAction(ISD::STORE, MVT::v4i32, Custom);
100 setTruncStoreAction(MVT::i32, MVT::i8, Custom);
101 setTruncStoreAction(MVT::i32, MVT::i16, Custom);
102 // We need to include these since trunc STORES to PRIVATE need
103 // special handling to accommodate RMW
104 setTruncStoreAction(MVT::v2i32, MVT::v2i16, Custom);
105 setTruncStoreAction(MVT::v4i32, MVT::v4i16, Custom);
106 setTruncStoreAction(MVT::v8i32, MVT::v8i16, Custom);
107 setTruncStoreAction(MVT::v16i32, MVT::v16i16, Custom);
108 setTruncStoreAction(MVT::v32i32, MVT::v32i16, Custom);
109 setTruncStoreAction(MVT::v2i32, MVT::v2i8, Custom);
110 setTruncStoreAction(MVT::v4i32, MVT::v4i8, Custom);
111 setTruncStoreAction(MVT::v8i32, MVT::v8i8, Custom);
112 setTruncStoreAction(MVT::v16i32, MVT::v16i8, Custom);
113 setTruncStoreAction(MVT::v32i32, MVT::v32i8, Custom);
115 // Workaround for LegalizeDAG asserting on expansion of i1 vector stores.
116 setTruncStoreAction(MVT::v2i32, MVT::v2i1, Expand);
117 setTruncStoreAction(MVT::v4i32, MVT::v4i1, Expand);
119 // Set condition code actions
120 setCondCodeAction(ISD::SETO, MVT::f32, Expand);
121 setCondCodeAction(ISD::SETUO, MVT::f32, Expand);
122 setCondCodeAction(ISD::SETLT, MVT::f32, Expand);
123 setCondCodeAction(ISD::SETLE, MVT::f32, Expand);
124 setCondCodeAction(ISD::SETOLT, MVT::f32, Expand);
125 setCondCodeAction(ISD::SETOLE, MVT::f32, Expand);
126 setCondCodeAction(ISD::SETONE, MVT::f32, Expand);
127 setCondCodeAction(ISD::SETUEQ, MVT::f32, Expand);
128 setCondCodeAction(ISD::SETUGE, MVT::f32, Expand);
129 setCondCodeAction(ISD::SETUGT, MVT::f32, Expand);
130 setCondCodeAction(ISD::SETULT, MVT::f32, Expand);
131 setCondCodeAction(ISD::SETULE, MVT::f32, Expand);
133 setCondCodeAction(ISD::SETLE, MVT::i32, Expand);
134 setCondCodeAction(ISD::SETLT, MVT::i32, Expand);
135 setCondCodeAction(ISD::SETULE, MVT::i32, Expand);
136 setCondCodeAction(ISD::SETULT, MVT::i32, Expand);
138 setOperationAction(ISD::FCOS, MVT::f32, Custom);
139 setOperationAction(ISD::FSIN, MVT::f32, Custom);
141 setOperationAction(ISD::SETCC, MVT::v4i32, Expand);
142 setOperationAction(ISD::SETCC, MVT::v2i32, Expand);
144 setOperationAction(ISD::BR_CC, MVT::i32, Expand);
145 setOperationAction(ISD::BR_CC, MVT::f32, Expand);
146 setOperationAction(ISD::BRCOND, MVT::Other, Custom);
148 setOperationAction(ISD::FSUB, MVT::f32, Expand);
150 setOperationAction(ISD::SELECT_CC, MVT::f32, Custom);
151 setOperationAction(ISD::SELECT_CC, MVT::i32, Custom);
153 setOperationAction(ISD::SETCC, MVT::i32, Expand);
154 setOperationAction(ISD::SETCC, MVT::f32, Expand);
155 setOperationAction(ISD::FP_TO_UINT, MVT::i1, Custom);
156 setOperationAction(ISD::FP_TO_SINT, MVT::i1, Custom);
157 setOperationAction(ISD::FP_TO_SINT, MVT::i64, Custom);
158 setOperationAction(ISD::FP_TO_UINT, MVT::i64, Custom);
160 setOperationAction(ISD::SELECT, MVT::i32, Expand);
161 setOperationAction(ISD::SELECT, MVT::f32, Expand);
162 setOperationAction(ISD::SELECT, MVT::v2i32, Expand);
163 setOperationAction(ISD::SELECT, MVT::v4i32, Expand);
165 // ADD, SUB overflow.
166 // TODO: turn these into Legal?
167 if (Subtarget->hasCARRY())
168 setOperationAction(ISD::UADDO, MVT::i32, Custom);
170 if (Subtarget->hasBORROW())
171 setOperationAction(ISD::USUBO, MVT::i32, Custom);
173 // Expand sign extension of vectors
174 if (!Subtarget->hasBFE())
175 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i1, Expand);
177 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::v2i1, Expand);
178 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::v4i1, Expand);
180 if (!Subtarget->hasBFE())
181 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i8, Expand);
182 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::v2i8, Expand);
183 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::v4i8, Expand);
185 if (!Subtarget->hasBFE())
186 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i16, Expand);
187 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::v2i16, Expand);
188 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::v4i16, Expand);
190 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::i32, Legal);
191 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::v2i32, Expand);
192 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::v4i32, Expand);
194 setOperationAction(ISD::SIGN_EXTEND_INREG, MVT::Other, Expand);
196 setOperationAction(ISD::FrameIndex, MVT::i32, Custom);
198 setOperationAction(ISD::EXTRACT_VECTOR_ELT, MVT::v2i32, Custom);
199 setOperationAction(ISD::EXTRACT_VECTOR_ELT, MVT::v2f32, Custom);
200 setOperationAction(ISD::EXTRACT_VECTOR_ELT, MVT::v4i32, Custom);
201 setOperationAction(ISD::EXTRACT_VECTOR_ELT, MVT::v4f32, Custom);
203 setOperationAction(ISD::INSERT_VECTOR_ELT, MVT::v2i32, Custom);
204 setOperationAction(ISD::INSERT_VECTOR_ELT, MVT::v2f32, Custom);
205 setOperationAction(ISD::INSERT_VECTOR_ELT, MVT::v4i32, Custom);
206 setOperationAction(ISD::INSERT_VECTOR_ELT, MVT::v4f32, Custom);
208 // We don't have 64-bit shifts. Thus we need either SHX i64 or SHX_PARTS i32
209 // to be Legal/Custom in order to avoid library calls.
210 setOperationAction(ISD::SHL_PARTS, MVT::i32, Custom);
211 setOperationAction(ISD::SRL_PARTS, MVT::i32, Custom);
212 setOperationAction(ISD::SRA_PARTS, MVT::i32, Custom);
214 setOperationAction(ISD::GlobalAddress, MVT::i32, Custom);
216 const MVT ScalarIntVTs[] = { MVT::i32, MVT::i64 };
217 for (MVT VT : ScalarIntVTs) {
218 setOperationAction(ISD::ADDC, VT, Expand);
219 setOperationAction(ISD::SUBC, VT, Expand);
220 setOperationAction(ISD::ADDE, VT, Expand);
221 setOperationAction(ISD::SUBE, VT, Expand);
224 // LLVM will expand these to atomic_cmp_swap(0)
225 // and atomic_swap, respectively.
226 setOperationAction(ISD::ATOMIC_LOAD, MVT::i32, Expand);
227 setOperationAction(ISD::ATOMIC_STORE, MVT::i32, Expand);
229 // We need to custom lower some of the intrinsics
230 setOperationAction(ISD::INTRINSIC_VOID, MVT::Other, Custom);
231 setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);
233 setSchedulingPreference(Sched::Source);
235 setTargetDAGCombine(ISD::FP_ROUND);
236 setTargetDAGCombine(ISD::FP_TO_SINT);
237 setTargetDAGCombine(ISD::EXTRACT_VECTOR_ELT);
238 setTargetDAGCombine(ISD::SELECT_CC);
239 setTargetDAGCombine(ISD::INSERT_VECTOR_ELT);
240 setTargetDAGCombine(ISD::LOAD);
243 const R600Subtarget *R600TargetLowering::getSubtarget() const {
244 return static_cast<const R600Subtarget *>(Subtarget);
247 static inline bool isEOP(MachineBasicBlock::iterator I) {
248 if (std::next(I) == I->getParent()->end())
250 return std::next(I)->getOpcode() == AMDGPU::RETURN;
254 R600TargetLowering::EmitInstrWithCustomInserter(MachineInstr &MI,
255 MachineBasicBlock *BB) const {
256 MachineFunction *MF = BB->getParent();
257 MachineRegisterInfo &MRI = MF->getRegInfo();
258 MachineBasicBlock::iterator I = MI;
259 const R600InstrInfo *TII = getSubtarget()->getInstrInfo();
261 switch (MI.getOpcode()) {
263 // Replace LDS_*_RET instruction that don't have any uses with the
264 // equivalent LDS_*_NORET instruction.
265 if (TII->isLDSRetInstr(MI.getOpcode())) {
266 int DstIdx = TII->getOperandIdx(MI.getOpcode(), AMDGPU::OpName::dst);
267 assert(DstIdx != -1);
268 MachineInstrBuilder NewMI;
269 // FIXME: getLDSNoRetOp method only handles LDS_1A1D LDS ops. Add
270 // LDS_1A2D support and remove this special case.
271 if (!MRI.use_empty(MI.getOperand(DstIdx).getReg()) ||
272 MI.getOpcode() == AMDGPU::LDS_CMPST_RET)
275 NewMI = BuildMI(*BB, I, BB->findDebugLoc(I),
276 TII->get(AMDGPU::getLDSNoRetOp(MI.getOpcode())));
277 for (unsigned i = 1, e = MI.getNumOperands(); i < e; ++i) {
278 NewMI.add(MI.getOperand(i));
281 return AMDGPUTargetLowering::EmitInstrWithCustomInserter(MI, BB);
284 case AMDGPU::CLAMP_R600: {
285 MachineInstr *NewMI = TII->buildDefaultInstruction(
286 *BB, I, AMDGPU::MOV, MI.getOperand(0).getReg(),
287 MI.getOperand(1).getReg());
288 TII->addFlag(*NewMI, 0, MO_FLAG_CLAMP);
292 case AMDGPU::FABS_R600: {
293 MachineInstr *NewMI = TII->buildDefaultInstruction(
294 *BB, I, AMDGPU::MOV, MI.getOperand(0).getReg(),
295 MI.getOperand(1).getReg());
296 TII->addFlag(*NewMI, 0, MO_FLAG_ABS);
300 case AMDGPU::FNEG_R600: {
301 MachineInstr *NewMI = TII->buildDefaultInstruction(
302 *BB, I, AMDGPU::MOV, MI.getOperand(0).getReg(),
303 MI.getOperand(1).getReg());
304 TII->addFlag(*NewMI, 0, MO_FLAG_NEG);
308 case AMDGPU::MASK_WRITE: {
309 unsigned maskedRegister = MI.getOperand(0).getReg();
310 assert(TargetRegisterInfo::isVirtualRegister(maskedRegister));
311 MachineInstr * defInstr = MRI.getVRegDef(maskedRegister);
312 TII->addFlag(*defInstr, 0, MO_FLAG_MASK);
316 case AMDGPU::MOV_IMM_F32:
317 TII->buildMovImm(*BB, I, MI.getOperand(0).getReg(), MI.getOperand(1)
324 case AMDGPU::MOV_IMM_I32:
325 TII->buildMovImm(*BB, I, MI.getOperand(0).getReg(),
326 MI.getOperand(1).getImm());
329 case AMDGPU::MOV_IMM_GLOBAL_ADDR: {
330 //TODO: Perhaps combine this instruction with the next if possible
331 auto MIB = TII->buildDefaultInstruction(
332 *BB, MI, AMDGPU::MOV, MI.getOperand(0).getReg(), AMDGPU::ALU_LITERAL_X);
333 int Idx = TII->getOperandIdx(*MIB, AMDGPU::OpName::literal);
334 //TODO: Ugh this is rather ugly
335 MIB->getOperand(Idx) = MI.getOperand(1);
339 case AMDGPU::CONST_COPY: {
340 MachineInstr *NewMI = TII->buildDefaultInstruction(
341 *BB, MI, AMDGPU::MOV, MI.getOperand(0).getReg(), AMDGPU::ALU_CONST);
342 TII->setImmOperand(*NewMI, AMDGPU::OpName::src0_sel,
343 MI.getOperand(1).getImm());
347 case AMDGPU::RAT_WRITE_CACHELESS_32_eg:
348 case AMDGPU::RAT_WRITE_CACHELESS_64_eg:
349 case AMDGPU::RAT_WRITE_CACHELESS_128_eg:
350 BuildMI(*BB, I, BB->findDebugLoc(I), TII->get(MI.getOpcode()))
351 .add(MI.getOperand(0))
352 .add(MI.getOperand(1))
353 .addImm(isEOP(I)); // Set End of program bit
356 case AMDGPU::RAT_STORE_TYPED_eg:
357 BuildMI(*BB, I, BB->findDebugLoc(I), TII->get(MI.getOpcode()))
358 .add(MI.getOperand(0))
359 .add(MI.getOperand(1))
360 .add(MI.getOperand(2))
361 .addImm(isEOP(I)); // Set End of program bit
365 BuildMI(*BB, I, BB->findDebugLoc(I), TII->get(AMDGPU::JUMP))
366 .add(MI.getOperand(0));
369 case AMDGPU::BRANCH_COND_f32: {
370 MachineInstr *NewMI =
371 BuildMI(*BB, I, BB->findDebugLoc(I), TII->get(AMDGPU::PRED_X),
372 AMDGPU::PREDICATE_BIT)
373 .add(MI.getOperand(1))
374 .addImm(AMDGPU::PRED_SETNE)
376 TII->addFlag(*NewMI, 0, MO_FLAG_PUSH);
377 BuildMI(*BB, I, BB->findDebugLoc(I), TII->get(AMDGPU::JUMP_COND))
378 .add(MI.getOperand(0))
379 .addReg(AMDGPU::PREDICATE_BIT, RegState::Kill);
383 case AMDGPU::BRANCH_COND_i32: {
384 MachineInstr *NewMI =
385 BuildMI(*BB, I, BB->findDebugLoc(I), TII->get(AMDGPU::PRED_X),
386 AMDGPU::PREDICATE_BIT)
387 .add(MI.getOperand(1))
388 .addImm(AMDGPU::PRED_SETNE_INT)
390 TII->addFlag(*NewMI, 0, MO_FLAG_PUSH);
391 BuildMI(*BB, I, BB->findDebugLoc(I), TII->get(AMDGPU::JUMP_COND))
392 .add(MI.getOperand(0))
393 .addReg(AMDGPU::PREDICATE_BIT, RegState::Kill);
397 case AMDGPU::EG_ExportSwz:
398 case AMDGPU::R600_ExportSwz: {
399 // Instruction is left unmodified if its not the last one of its type
400 bool isLastInstructionOfItsType = true;
401 unsigned InstExportType = MI.getOperand(1).getImm();
402 for (MachineBasicBlock::iterator NextExportInst = std::next(I),
403 EndBlock = BB->end(); NextExportInst != EndBlock;
404 NextExportInst = std::next(NextExportInst)) {
405 if (NextExportInst->getOpcode() == AMDGPU::EG_ExportSwz ||
406 NextExportInst->getOpcode() == AMDGPU::R600_ExportSwz) {
407 unsigned CurrentInstExportType = NextExportInst->getOperand(1)
409 if (CurrentInstExportType == InstExportType) {
410 isLastInstructionOfItsType = false;
416 if (!EOP && !isLastInstructionOfItsType)
418 unsigned CfInst = (MI.getOpcode() == AMDGPU::EG_ExportSwz) ? 84 : 40;
419 BuildMI(*BB, I, BB->findDebugLoc(I), TII->get(MI.getOpcode()))
420 .add(MI.getOperand(0))
421 .add(MI.getOperand(1))
422 .add(MI.getOperand(2))
423 .add(MI.getOperand(3))
424 .add(MI.getOperand(4))
425 .add(MI.getOperand(5))
426 .add(MI.getOperand(6))
431 case AMDGPU::RETURN: {
436 MI.eraseFromParent();
440 //===----------------------------------------------------------------------===//
441 // Custom DAG Lowering Operations
442 //===----------------------------------------------------------------------===//
444 SDValue R600TargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
445 MachineFunction &MF = DAG.getMachineFunction();
446 R600MachineFunctionInfo *MFI = MF.getInfo<R600MachineFunctionInfo>();
447 switch (Op.getOpcode()) {
448 default: return AMDGPUTargetLowering::LowerOperation(Op, DAG);
449 case ISD::EXTRACT_VECTOR_ELT: return LowerEXTRACT_VECTOR_ELT(Op, DAG);
450 case ISD::INSERT_VECTOR_ELT: return LowerINSERT_VECTOR_ELT(Op, DAG);
451 case ISD::SHL_PARTS: return LowerSHLParts(Op, DAG);
453 case ISD::SRL_PARTS: return LowerSRXParts(Op, DAG);
454 case ISD::UADDO: return LowerUADDSUBO(Op, DAG, ISD::ADD, AMDGPUISD::CARRY);
455 case ISD::USUBO: return LowerUADDSUBO(Op, DAG, ISD::SUB, AMDGPUISD::BORROW);
457 case ISD::FSIN: return LowerTrig(Op, DAG);
458 case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG);
459 case ISD::STORE: return LowerSTORE(Op, DAG);
461 SDValue Result = LowerLOAD(Op, DAG);
462 assert((!Result.getNode() ||
463 Result.getNode()->getNumValues() == 2) &&
464 "Load should return a value and a chain");
468 case ISD::BRCOND: return LowerBRCOND(Op, DAG);
469 case ISD::GlobalAddress: return LowerGlobalAddress(MFI, Op, DAG);
470 case ISD::FrameIndex: return lowerFrameIndex(Op, DAG);
471 case ISD::INTRINSIC_VOID: {
472 SDValue Chain = Op.getOperand(0);
473 unsigned IntrinsicID =
474 cast<ConstantSDNode>(Op.getOperand(1))->getZExtValue();
475 switch (IntrinsicID) {
476 case AMDGPUIntrinsic::r600_store_swizzle: {
478 const SDValue Args[8] = {
480 Op.getOperand(2), // Export Value
481 Op.getOperand(3), // ArrayBase
482 Op.getOperand(4), // Type
483 DAG.getConstant(0, DL, MVT::i32), // SWZ_X
484 DAG.getConstant(1, DL, MVT::i32), // SWZ_Y
485 DAG.getConstant(2, DL, MVT::i32), // SWZ_Z
486 DAG.getConstant(3, DL, MVT::i32) // SWZ_W
488 return DAG.getNode(AMDGPUISD::R600_EXPORT, DL, Op.getValueType(), Args);
491 // default for switch(IntrinsicID)
494 // break out of case ISD::INTRINSIC_VOID in switch(Op.getOpcode())
497 case ISD::INTRINSIC_WO_CHAIN: {
498 unsigned IntrinsicID =
499 cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
500 EVT VT = Op.getValueType();
502 switch (IntrinsicID) {
503 case AMDGPUIntrinsic::r600_tex:
504 case AMDGPUIntrinsic::r600_texc: {
506 switch (IntrinsicID) {
507 case AMDGPUIntrinsic::r600_tex:
510 case AMDGPUIntrinsic::r600_texc:
514 llvm_unreachable("unhandled texture operation");
517 SDValue TexArgs[19] = {
518 DAG.getConstant(TextureOp, DL, MVT::i32),
520 DAG.getConstant(0, DL, MVT::i32),
521 DAG.getConstant(1, DL, MVT::i32),
522 DAG.getConstant(2, DL, MVT::i32),
523 DAG.getConstant(3, DL, MVT::i32),
527 DAG.getConstant(0, DL, MVT::i32),
528 DAG.getConstant(1, DL, MVT::i32),
529 DAG.getConstant(2, DL, MVT::i32),
530 DAG.getConstant(3, DL, MVT::i32),
538 return DAG.getNode(AMDGPUISD::TEXTURE_FETCH, DL, MVT::v4f32, TexArgs);
540 case AMDGPUIntrinsic::r600_dot4: {
542 DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, Op.getOperand(1),
543 DAG.getConstant(0, DL, MVT::i32)),
544 DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, Op.getOperand(2),
545 DAG.getConstant(0, DL, MVT::i32)),
546 DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, Op.getOperand(1),
547 DAG.getConstant(1, DL, MVT::i32)),
548 DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, Op.getOperand(2),
549 DAG.getConstant(1, DL, MVT::i32)),
550 DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, Op.getOperand(1),
551 DAG.getConstant(2, DL, MVT::i32)),
552 DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, Op.getOperand(2),
553 DAG.getConstant(2, DL, MVT::i32)),
554 DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, Op.getOperand(1),
555 DAG.getConstant(3, DL, MVT::i32)),
556 DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::f32, Op.getOperand(2),
557 DAG.getConstant(3, DL, MVT::i32))
559 return DAG.getNode(AMDGPUISD::DOT4, DL, MVT::f32, Args);
562 case Intrinsic::r600_implicitarg_ptr: {
563 MVT PtrVT = getPointerTy(DAG.getDataLayout(), AMDGPUASI.PARAM_I_ADDRESS);
564 uint32_t ByteOffset = getImplicitParameterOffset(MFI, FIRST_IMPLICIT);
565 return DAG.getConstant(ByteOffset, DL, PtrVT);
567 case Intrinsic::r600_read_ngroups_x:
568 return LowerImplicitParameter(DAG, VT, DL, 0);
569 case Intrinsic::r600_read_ngroups_y:
570 return LowerImplicitParameter(DAG, VT, DL, 1);
571 case Intrinsic::r600_read_ngroups_z:
572 return LowerImplicitParameter(DAG, VT, DL, 2);
573 case Intrinsic::r600_read_global_size_x:
574 return LowerImplicitParameter(DAG, VT, DL, 3);
575 case Intrinsic::r600_read_global_size_y:
576 return LowerImplicitParameter(DAG, VT, DL, 4);
577 case Intrinsic::r600_read_global_size_z:
578 return LowerImplicitParameter(DAG, VT, DL, 5);
579 case Intrinsic::r600_read_local_size_x:
580 return LowerImplicitParameter(DAG, VT, DL, 6);
581 case Intrinsic::r600_read_local_size_y:
582 return LowerImplicitParameter(DAG, VT, DL, 7);
583 case Intrinsic::r600_read_local_size_z:
584 return LowerImplicitParameter(DAG, VT, DL, 8);
586 case Intrinsic::r600_read_tgid_x:
587 return CreateLiveInRegister(DAG, &AMDGPU::R600_TReg32RegClass,
589 case Intrinsic::r600_read_tgid_y:
590 return CreateLiveInRegister(DAG, &AMDGPU::R600_TReg32RegClass,
592 case Intrinsic::r600_read_tgid_z:
593 return CreateLiveInRegister(DAG, &AMDGPU::R600_TReg32RegClass,
595 case Intrinsic::r600_read_tidig_x:
596 return CreateLiveInRegister(DAG, &AMDGPU::R600_TReg32RegClass,
598 case Intrinsic::r600_read_tidig_y:
599 return CreateLiveInRegister(DAG, &AMDGPU::R600_TReg32RegClass,
601 case Intrinsic::r600_read_tidig_z:
602 return CreateLiveInRegister(DAG, &AMDGPU::R600_TReg32RegClass,
605 case Intrinsic::r600_recipsqrt_ieee:
606 return DAG.getNode(AMDGPUISD::RSQ, DL, VT, Op.getOperand(1));
608 case Intrinsic::r600_recipsqrt_clamped:
609 return DAG.getNode(AMDGPUISD::RSQ_CLAMP, DL, VT, Op.getOperand(1));
614 // break out of case ISD::INTRINSIC_WO_CHAIN in switch(Op.getOpcode())
617 } // end switch(Op.getOpcode())
621 void R600TargetLowering::ReplaceNodeResults(SDNode *N,
622 SmallVectorImpl<SDValue> &Results,
623 SelectionDAG &DAG) const {
624 switch (N->getOpcode()) {
626 AMDGPUTargetLowering::ReplaceNodeResults(N, Results, DAG);
628 case ISD::FP_TO_UINT:
629 if (N->getValueType(0) == MVT::i1) {
630 Results.push_back(lowerFP_TO_UINT(N->getOperand(0), DAG));
633 // Since we don't care about out of bounds values we can use FP_TO_SINT for
634 // uints too. The DAGLegalizer code for uint considers some extra cases
635 // which are not necessary here.
637 case ISD::FP_TO_SINT: {
638 if (N->getValueType(0) == MVT::i1) {
639 Results.push_back(lowerFP_TO_SINT(N->getOperand(0), DAG));
644 if (expandFP_TO_SINT(N, Result, DAG))
645 Results.push_back(Result);
649 SDValue Op = SDValue(N, 1);
650 SDValue RES = LowerSDIVREM(Op, DAG);
651 Results.push_back(RES);
652 Results.push_back(RES.getValue(1));
656 SDValue Op = SDValue(N, 0);
657 LowerUDIVREM64(Op, DAG, Results);
663 SDValue R600TargetLowering::vectorToVerticalVector(SelectionDAG &DAG,
664 SDValue Vector) const {
666 EVT VecVT = Vector.getValueType();
667 EVT EltVT = VecVT.getVectorElementType();
668 SmallVector<SDValue, 8> Args;
670 for (unsigned i = 0, e = VecVT.getVectorNumElements(); i != e; ++i) {
671 Args.push_back(DAG.getNode(
672 ISD::EXTRACT_VECTOR_ELT, DL, EltVT, Vector,
673 DAG.getConstant(i, DL, getVectorIdxTy(DAG.getDataLayout()))));
676 return DAG.getNode(AMDGPUISD::BUILD_VERTICAL_VECTOR, DL, VecVT, Args);
679 SDValue R600TargetLowering::LowerEXTRACT_VECTOR_ELT(SDValue Op,
680 SelectionDAG &DAG) const {
682 SDValue Vector = Op.getOperand(0);
683 SDValue Index = Op.getOperand(1);
685 if (isa<ConstantSDNode>(Index) ||
686 Vector.getOpcode() == AMDGPUISD::BUILD_VERTICAL_VECTOR)
689 Vector = vectorToVerticalVector(DAG, Vector);
690 return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, Op.getValueType(),
694 SDValue R600TargetLowering::LowerINSERT_VECTOR_ELT(SDValue Op,
695 SelectionDAG &DAG) const {
697 SDValue Vector = Op.getOperand(0);
698 SDValue Value = Op.getOperand(1);
699 SDValue Index = Op.getOperand(2);
701 if (isa<ConstantSDNode>(Index) ||
702 Vector.getOpcode() == AMDGPUISD::BUILD_VERTICAL_VECTOR)
705 Vector = vectorToVerticalVector(DAG, Vector);
706 SDValue Insert = DAG.getNode(ISD::INSERT_VECTOR_ELT, DL, Op.getValueType(),
707 Vector, Value, Index);
708 return vectorToVerticalVector(DAG, Insert);
711 SDValue R600TargetLowering::LowerGlobalAddress(AMDGPUMachineFunction *MFI,
713 SelectionDAG &DAG) const {
714 GlobalAddressSDNode *GSD = cast<GlobalAddressSDNode>(Op);
715 if (GSD->getAddressSpace() != AMDGPUASI.CONSTANT_ADDRESS)
716 return AMDGPUTargetLowering::LowerGlobalAddress(MFI, Op, DAG);
718 const DataLayout &DL = DAG.getDataLayout();
719 const GlobalValue *GV = GSD->getGlobal();
720 MVT ConstPtrVT = getPointerTy(DL, AMDGPUASI.CONSTANT_ADDRESS);
722 SDValue GA = DAG.getTargetGlobalAddress(GV, SDLoc(GSD), ConstPtrVT);
723 return DAG.getNode(AMDGPUISD::CONST_DATA_PTR, SDLoc(GSD), ConstPtrVT, GA);
726 SDValue R600TargetLowering::LowerTrig(SDValue Op, SelectionDAG &DAG) const {
727 // On hw >= R700, COS/SIN input must be between -1. and 1.
728 // Thus we lower them to TRIG ( FRACT ( x / 2Pi + 0.5) - 0.5)
729 EVT VT = Op.getValueType();
730 SDValue Arg = Op.getOperand(0);
733 // TODO: Should this propagate fast-math-flags?
734 SDValue FractPart = DAG.getNode(AMDGPUISD::FRACT, DL, VT,
735 DAG.getNode(ISD::FADD, DL, VT,
736 DAG.getNode(ISD::FMUL, DL, VT, Arg,
737 DAG.getConstantFP(0.15915494309, DL, MVT::f32)),
738 DAG.getConstantFP(0.5, DL, MVT::f32)));
740 switch (Op.getOpcode()) {
742 TrigNode = AMDGPUISD::COS_HW;
745 TrigNode = AMDGPUISD::SIN_HW;
748 llvm_unreachable("Wrong trig opcode");
750 SDValue TrigVal = DAG.getNode(TrigNode, DL, VT,
751 DAG.getNode(ISD::FADD, DL, VT, FractPart,
752 DAG.getConstantFP(-0.5, DL, MVT::f32)));
753 if (Gen >= R600Subtarget::R700)
755 // On R600 hw, COS/SIN input must be between -Pi and Pi.
756 return DAG.getNode(ISD::FMUL, DL, VT, TrigVal,
757 DAG.getConstantFP(3.14159265359, DL, MVT::f32));
760 SDValue R600TargetLowering::LowerSHLParts(SDValue Op, SelectionDAG &DAG) const {
762 EVT VT = Op.getValueType();
764 SDValue Lo = Op.getOperand(0);
765 SDValue Hi = Op.getOperand(1);
766 SDValue Shift = Op.getOperand(2);
767 SDValue Zero = DAG.getConstant(0, DL, VT);
768 SDValue One = DAG.getConstant(1, DL, VT);
770 SDValue Width = DAG.getConstant(VT.getSizeInBits(), DL, VT);
771 SDValue Width1 = DAG.getConstant(VT.getSizeInBits() - 1, DL, VT);
772 SDValue BigShift = DAG.getNode(ISD::SUB, DL, VT, Shift, Width);
773 SDValue CompShift = DAG.getNode(ISD::SUB, DL, VT, Width1, Shift);
775 // The dance around Width1 is necessary for 0 special case.
776 // Without it the CompShift might be 32, producing incorrect results in
777 // Overflow. So we do the shift in two steps, the alternative is to
778 // add a conditional to filter the special case.
780 SDValue Overflow = DAG.getNode(ISD::SRL, DL, VT, Lo, CompShift);
781 Overflow = DAG.getNode(ISD::SRL, DL, VT, Overflow, One);
783 SDValue HiSmall = DAG.getNode(ISD::SHL, DL, VT, Hi, Shift);
784 HiSmall = DAG.getNode(ISD::OR, DL, VT, HiSmall, Overflow);
785 SDValue LoSmall = DAG.getNode(ISD::SHL, DL, VT, Lo, Shift);
787 SDValue HiBig = DAG.getNode(ISD::SHL, DL, VT, Lo, BigShift);
788 SDValue LoBig = Zero;
790 Hi = DAG.getSelectCC(DL, Shift, Width, HiSmall, HiBig, ISD::SETULT);
791 Lo = DAG.getSelectCC(DL, Shift, Width, LoSmall, LoBig, ISD::SETULT);
793 return DAG.getNode(ISD::MERGE_VALUES, DL, DAG.getVTList(VT,VT), Lo, Hi);
796 SDValue R600TargetLowering::LowerSRXParts(SDValue Op, SelectionDAG &DAG) const {
798 EVT VT = Op.getValueType();
800 SDValue Lo = Op.getOperand(0);
801 SDValue Hi = Op.getOperand(1);
802 SDValue Shift = Op.getOperand(2);
803 SDValue Zero = DAG.getConstant(0, DL, VT);
804 SDValue One = DAG.getConstant(1, DL, VT);
806 const bool SRA = Op.getOpcode() == ISD::SRA_PARTS;
808 SDValue Width = DAG.getConstant(VT.getSizeInBits(), DL, VT);
809 SDValue Width1 = DAG.getConstant(VT.getSizeInBits() - 1, DL, VT);
810 SDValue BigShift = DAG.getNode(ISD::SUB, DL, VT, Shift, Width);
811 SDValue CompShift = DAG.getNode(ISD::SUB, DL, VT, Width1, Shift);
813 // The dance around Width1 is necessary for 0 special case.
814 // Without it the CompShift might be 32, producing incorrect results in
815 // Overflow. So we do the shift in two steps, the alternative is to
816 // add a conditional to filter the special case.
818 SDValue Overflow = DAG.getNode(ISD::SHL, DL, VT, Hi, CompShift);
819 Overflow = DAG.getNode(ISD::SHL, DL, VT, Overflow, One);
821 SDValue HiSmall = DAG.getNode(SRA ? ISD::SRA : ISD::SRL, DL, VT, Hi, Shift);
822 SDValue LoSmall = DAG.getNode(ISD::SRL, DL, VT, Lo, Shift);
823 LoSmall = DAG.getNode(ISD::OR, DL, VT, LoSmall, Overflow);
825 SDValue LoBig = DAG.getNode(SRA ? ISD::SRA : ISD::SRL, DL, VT, Hi, BigShift);
826 SDValue HiBig = SRA ? DAG.getNode(ISD::SRA, DL, VT, Hi, Width1) : Zero;
828 Hi = DAG.getSelectCC(DL, Shift, Width, HiSmall, HiBig, ISD::SETULT);
829 Lo = DAG.getSelectCC(DL, Shift, Width, LoSmall, LoBig, ISD::SETULT);
831 return DAG.getNode(ISD::MERGE_VALUES, DL, DAG.getVTList(VT,VT), Lo, Hi);
834 SDValue R600TargetLowering::LowerUADDSUBO(SDValue Op, SelectionDAG &DAG,
835 unsigned mainop, unsigned ovf) const {
837 EVT VT = Op.getValueType();
839 SDValue Lo = Op.getOperand(0);
840 SDValue Hi = Op.getOperand(1);
842 SDValue OVF = DAG.getNode(ovf, DL, VT, Lo, Hi);
844 OVF = DAG.getNode(ISD::SIGN_EXTEND_INREG, DL, VT, OVF,
845 DAG.getValueType(MVT::i1));
847 SDValue Res = DAG.getNode(mainop, DL, VT, Lo, Hi);
849 return DAG.getNode(ISD::MERGE_VALUES, DL, DAG.getVTList(VT, VT), Res, OVF);
852 SDValue R600TargetLowering::lowerFP_TO_UINT(SDValue Op, SelectionDAG &DAG) const {
858 Op, DAG.getConstantFP(1.0f, DL, MVT::f32),
859 DAG.getCondCode(ISD::SETEQ));
862 SDValue R600TargetLowering::lowerFP_TO_SINT(SDValue Op, SelectionDAG &DAG) const {
868 Op, DAG.getConstantFP(-1.0f, DL, MVT::f32),
869 DAG.getCondCode(ISD::SETEQ));
872 SDValue R600TargetLowering::LowerImplicitParameter(SelectionDAG &DAG, EVT VT,
874 unsigned DwordOffset) const {
875 unsigned ByteOffset = DwordOffset * 4;
876 PointerType * PtrType = PointerType::get(VT.getTypeForEVT(*DAG.getContext()),
877 AMDGPUASI.CONSTANT_BUFFER_0);
879 // We shouldn't be using an offset wider than 16-bits for implicit parameters.
880 assert(isInt<16>(ByteOffset));
882 return DAG.getLoad(VT, DL, DAG.getEntryNode(),
883 DAG.getConstant(ByteOffset, DL, MVT::i32), // PTR
884 MachinePointerInfo(ConstantPointerNull::get(PtrType)));
887 bool R600TargetLowering::isZero(SDValue Op) const {
888 if(ConstantSDNode *Cst = dyn_cast<ConstantSDNode>(Op)) {
889 return Cst->isNullValue();
890 } else if(ConstantFPSDNode *CstFP = dyn_cast<ConstantFPSDNode>(Op)){
891 return CstFP->isZero();
897 bool R600TargetLowering::isHWTrueValue(SDValue Op) const {
898 if (ConstantFPSDNode * CFP = dyn_cast<ConstantFPSDNode>(Op)) {
899 return CFP->isExactlyValue(1.0);
901 return isAllOnesConstant(Op);
904 bool R600TargetLowering::isHWFalseValue(SDValue Op) const {
905 if (ConstantFPSDNode * CFP = dyn_cast<ConstantFPSDNode>(Op)) {
906 return CFP->getValueAPF().isZero();
908 return isNullConstant(Op);
911 SDValue R600TargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const {
913 EVT VT = Op.getValueType();
915 SDValue LHS = Op.getOperand(0);
916 SDValue RHS = Op.getOperand(1);
917 SDValue True = Op.getOperand(2);
918 SDValue False = Op.getOperand(3);
919 SDValue CC = Op.getOperand(4);
922 if (VT == MVT::f32) {
923 DAGCombinerInfo DCI(DAG, AfterLegalizeVectorOps, true, nullptr);
924 SDValue MinMax = combineFMinMaxLegacy(DL, VT, LHS, RHS, True, False, CC, DCI);
929 // LHS and RHS are guaranteed to be the same value type
930 EVT CompareVT = LHS.getValueType();
932 // Check if we can lower this to a native operation.
934 // Try to lower to a SET* instruction:
936 // SET* can match the following patterns:
938 // select_cc f32, f32, -1, 0, cc_supported
939 // select_cc f32, f32, 1.0f, 0.0f, cc_supported
940 // select_cc i32, i32, -1, 0, cc_supported
943 // Move hardware True/False values to the correct operand.
944 ISD::CondCode CCOpcode = cast<CondCodeSDNode>(CC)->get();
945 ISD::CondCode InverseCC =
946 ISD::getSetCCInverse(CCOpcode, CompareVT == MVT::i32);
947 if (isHWTrueValue(False) && isHWFalseValue(True)) {
948 if (isCondCodeLegal(InverseCC, CompareVT.getSimpleVT())) {
949 std::swap(False, True);
950 CC = DAG.getCondCode(InverseCC);
952 ISD::CondCode SwapInvCC = ISD::getSetCCSwappedOperands(InverseCC);
953 if (isCondCodeLegal(SwapInvCC, CompareVT.getSimpleVT())) {
954 std::swap(False, True);
956 CC = DAG.getCondCode(SwapInvCC);
961 if (isHWTrueValue(True) && isHWFalseValue(False) &&
962 (CompareVT == VT || VT == MVT::i32)) {
963 // This can be matched by a SET* instruction.
964 return DAG.getNode(ISD::SELECT_CC, DL, VT, LHS, RHS, True, False, CC);
967 // Try to lower to a CND* instruction:
969 // CND* can match the following patterns:
971 // select_cc f32, 0.0, f32, f32, cc_supported
972 // select_cc f32, 0.0, i32, i32, cc_supported
973 // select_cc i32, 0, f32, f32, cc_supported
974 // select_cc i32, 0, i32, i32, cc_supported
977 // Try to move the zero value to the RHS
979 ISD::CondCode CCOpcode = cast<CondCodeSDNode>(CC)->get();
980 // Try swapping the operands
981 ISD::CondCode CCSwapped = ISD::getSetCCSwappedOperands(CCOpcode);
982 if (isCondCodeLegal(CCSwapped, CompareVT.getSimpleVT())) {
984 CC = DAG.getCondCode(CCSwapped);
986 // Try inverting the conditon and then swapping the operands
987 ISD::CondCode CCInv = ISD::getSetCCInverse(CCOpcode, CompareVT.isInteger());
988 CCSwapped = ISD::getSetCCSwappedOperands(CCInv);
989 if (isCondCodeLegal(CCSwapped, CompareVT.getSimpleVT())) {
990 std::swap(True, False);
992 CC = DAG.getCondCode(CCSwapped);
999 ISD::CondCode CCOpcode = cast<CondCodeSDNode>(CC)->get();
1000 if (CompareVT != VT) {
1001 // Bitcast True / False to the correct types. This will end up being
1002 // a nop, but it allows us to define only a single pattern in the
1003 // .TD files for each CND* instruction rather than having to have
1004 // one pattern for integer True/False and one for fp True/False
1005 True = DAG.getNode(ISD::BITCAST, DL, CompareVT, True);
1006 False = DAG.getNode(ISD::BITCAST, DL, CompareVT, False);
1013 CCOpcode = ISD::getSetCCInverse(CCOpcode, CompareVT == MVT::i32);
1021 SDValue SelectNode = DAG.getNode(ISD::SELECT_CC, DL, CompareVT,
1024 DAG.getCondCode(CCOpcode));
1025 return DAG.getNode(ISD::BITCAST, DL, VT, SelectNode);
1028 // If we make it this for it means we have no native instructions to handle
1029 // this SELECT_CC, so we must lower it.
1030 SDValue HWTrue, HWFalse;
1032 if (CompareVT == MVT::f32) {
1033 HWTrue = DAG.getConstantFP(1.0f, DL, CompareVT);
1034 HWFalse = DAG.getConstantFP(0.0f, DL, CompareVT);
1035 } else if (CompareVT == MVT::i32) {
1036 HWTrue = DAG.getConstant(-1, DL, CompareVT);
1037 HWFalse = DAG.getConstant(0, DL, CompareVT);
1040 llvm_unreachable("Unhandled value type in LowerSELECT_CC");
1043 // Lower this unsupported SELECT_CC into a combination of two supported
1044 // SELECT_CC operations.
1045 SDValue Cond = DAG.getNode(ISD::SELECT_CC, DL, CompareVT, LHS, RHS, HWTrue, HWFalse, CC);
1047 return DAG.getNode(ISD::SELECT_CC, DL, VT,
1050 DAG.getCondCode(ISD::SETNE));
1053 /// LLVM generates byte-addressed pointers. For indirect addressing, we need to
1054 /// convert these pointers to a register index. Each register holds
1055 /// 16 bytes, (4 x 32bit sub-register), but we need to take into account the
1056 /// \p StackWidth, which tells us how many of the 4 sub-registrers will be used
1057 /// for indirect addressing.
1058 SDValue R600TargetLowering::stackPtrToRegIndex(SDValue Ptr,
1059 unsigned StackWidth,
1060 SelectionDAG &DAG) const {
1062 switch(StackWidth) {
1072 default: llvm_unreachable("Invalid stack width");
1076 return DAG.getNode(ISD::SRL, DL, Ptr.getValueType(), Ptr,
1077 DAG.getConstant(SRLPad, DL, MVT::i32));
1080 void R600TargetLowering::getStackAddress(unsigned StackWidth,
1083 unsigned &PtrIncr) const {
1084 switch (StackWidth) {
1095 Channel = ElemIdx % 2;
1109 SDValue R600TargetLowering::lowerPrivateTruncStore(StoreSDNode *Store,
1110 SelectionDAG &DAG) const {
1112 //TODO: Who creates the i8 stores?
1113 assert(Store->isTruncatingStore()
1114 || Store->getValue().getValueType() == MVT::i8);
1115 assert(Store->getAddressSpace() == AMDGPUASI.PRIVATE_ADDRESS);
1118 if (Store->getMemoryVT() == MVT::i8) {
1119 assert(Store->getAlignment() >= 1);
1120 Mask = DAG.getConstant(0xff, DL, MVT::i32);
1121 } else if (Store->getMemoryVT() == MVT::i16) {
1122 assert(Store->getAlignment() >= 2);
1123 Mask = DAG.getConstant(0xffff, DL, MVT::i32);;
1125 llvm_unreachable("Unsupported private trunc store");
1128 SDValue OldChain = Store->getChain();
1129 bool VectorTrunc = (OldChain.getOpcode() == AMDGPUISD::DUMMY_CHAIN);
1131 SDValue Chain = VectorTrunc ? OldChain->getOperand(0) : OldChain;
1132 SDValue BasePtr = Store->getBasePtr();
1133 SDValue Offset = Store->getOffset();
1134 EVT MemVT = Store->getMemoryVT();
1136 SDValue LoadPtr = BasePtr;
1137 if (!Offset.isUndef()) {
1138 LoadPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, Offset);
1141 // Get dword location
1142 // TODO: this should be eliminated by the future SHR ptr, 2
1143 SDValue Ptr = DAG.getNode(ISD::AND, DL, MVT::i32, LoadPtr,
1144 DAG.getConstant(0xfffffffc, DL, MVT::i32));
1147 // TODO: can we be smarter about machine pointer info?
1148 SDValue Dst = DAG.getLoad(MVT::i32, DL, Chain, Ptr, MachinePointerInfo());
1150 Chain = Dst.getValue(1);
1152 // Get offset in dword
1153 SDValue ByteIdx = DAG.getNode(ISD::AND, DL, MVT::i32, LoadPtr,
1154 DAG.getConstant(0x3, DL, MVT::i32));
1156 // Convert byte offset to bit shift
1157 SDValue ShiftAmt = DAG.getNode(ISD::SHL, DL, MVT::i32, ByteIdx,
1158 DAG.getConstant(3, DL, MVT::i32));
1160 // TODO: Contrary to the name of the functiom,
1161 // it also handles sub i32 non-truncating stores (like i1)
1162 SDValue SExtValue = DAG.getNode(ISD::SIGN_EXTEND, DL, MVT::i32,
1165 // Mask the value to the right type
1166 SDValue MaskedValue = DAG.getZeroExtendInReg(SExtValue, DL, MemVT);
1168 // Shift the value in place
1169 SDValue ShiftedValue = DAG.getNode(ISD::SHL, DL, MVT::i32,
1170 MaskedValue, ShiftAmt);
1172 // Shift the mask in place
1173 SDValue DstMask = DAG.getNode(ISD::SHL, DL, MVT::i32, Mask, ShiftAmt);
1175 // Invert the mask. NOTE: if we had native ROL instructions we could
1176 // use inverted mask
1177 DstMask = DAG.getNOT(DL, DstMask, MVT::i32);
1179 // Cleanup the target bits
1180 Dst = DAG.getNode(ISD::AND, DL, MVT::i32, Dst, DstMask);
1183 SDValue Value = DAG.getNode(ISD::OR, DL, MVT::i32, Dst, ShiftedValue);
1186 // TODO: Can we be smarter about MachinePointerInfo?
1187 SDValue NewStore = DAG.getStore(Chain, DL, Value, Ptr, MachinePointerInfo());
1189 // If we are part of expanded vector, make our neighbors depend on this store
1191 // Make all other vector elements depend on this store
1192 Chain = DAG.getNode(AMDGPUISD::DUMMY_CHAIN, DL, MVT::Other, NewStore);
1193 DAG.ReplaceAllUsesOfValueWith(OldChain, Chain);
1198 SDValue R600TargetLowering::LowerSTORE(SDValue Op, SelectionDAG &DAG) const {
1199 StoreSDNode *StoreNode = cast<StoreSDNode>(Op);
1200 unsigned AS = StoreNode->getAddressSpace();
1202 SDValue Chain = StoreNode->getChain();
1203 SDValue Ptr = StoreNode->getBasePtr();
1204 SDValue Value = StoreNode->getValue();
1206 EVT VT = Value.getValueType();
1207 EVT MemVT = StoreNode->getMemoryVT();
1208 EVT PtrVT = Ptr.getValueType();
1212 // Neither LOCAL nor PRIVATE can do vectors at the moment
1213 if ((AS == AMDGPUASI.LOCAL_ADDRESS || AS == AMDGPUASI.PRIVATE_ADDRESS) &&
1215 if ((AS == AMDGPUASI.PRIVATE_ADDRESS) &&
1216 StoreNode->isTruncatingStore()) {
1217 // Add an extra level of chain to isolate this vector
1218 SDValue NewChain = DAG.getNode(AMDGPUISD::DUMMY_CHAIN, DL, MVT::Other, Chain);
1219 // TODO: can the chain be replaced without creating a new store?
1220 SDValue NewStore = DAG.getTruncStore(
1221 NewChain, DL, Value, Ptr, StoreNode->getPointerInfo(),
1222 MemVT, StoreNode->getAlignment(),
1223 StoreNode->getMemOperand()->getFlags(), StoreNode->getAAInfo());
1224 StoreNode = cast<StoreSDNode>(NewStore);
1227 return scalarizeVectorStore(StoreNode, DAG);
1230 unsigned Align = StoreNode->getAlignment();
1231 if (Align < MemVT.getStoreSize() &&
1232 !allowsMisalignedMemoryAccesses(MemVT, AS, Align, nullptr)) {
1233 return expandUnalignedStore(StoreNode, DAG);
1236 SDValue DWordAddr = DAG.getNode(ISD::SRL, DL, PtrVT, Ptr,
1237 DAG.getConstant(2, DL, PtrVT));
1239 if (AS == AMDGPUASI.GLOBAL_ADDRESS) {
1240 // It is beneficial to create MSKOR here instead of combiner to avoid
1241 // artificial dependencies introduced by RMW
1242 if (StoreNode->isTruncatingStore()) {
1243 assert(VT.bitsLE(MVT::i32));
1244 SDValue MaskConstant;
1245 if (MemVT == MVT::i8) {
1246 MaskConstant = DAG.getConstant(0xFF, DL, MVT::i32);
1248 assert(MemVT == MVT::i16);
1249 assert(StoreNode->getAlignment() >= 2);
1250 MaskConstant = DAG.getConstant(0xFFFF, DL, MVT::i32);
1253 SDValue ByteIndex = DAG.getNode(ISD::AND, DL, PtrVT, Ptr,
1254 DAG.getConstant(0x00000003, DL, PtrVT));
1255 SDValue BitShift = DAG.getNode(ISD::SHL, DL, VT, ByteIndex,
1256 DAG.getConstant(3, DL, VT));
1258 // Put the mask in correct place
1259 SDValue Mask = DAG.getNode(ISD::SHL, DL, VT, MaskConstant, BitShift);
1261 // Put the value bits in correct place
1262 SDValue TruncValue = DAG.getNode(ISD::AND, DL, VT, Value, MaskConstant);
1263 SDValue ShiftedValue = DAG.getNode(ISD::SHL, DL, VT, TruncValue, BitShift);
1265 // XXX: If we add a 64-bit ZW register class, then we could use a 2 x i32
1269 DAG.getConstant(0, DL, MVT::i32),
1270 DAG.getConstant(0, DL, MVT::i32),
1273 SDValue Input = DAG.getBuildVector(MVT::v4i32, DL, Src);
1274 SDValue Args[3] = { Chain, Input, DWordAddr };
1275 return DAG.getMemIntrinsicNode(AMDGPUISD::STORE_MSKOR, DL,
1276 Op->getVTList(), Args, MemVT,
1277 StoreNode->getMemOperand());
1278 } else if (Ptr->getOpcode() != AMDGPUISD::DWORDADDR && VT.bitsGE(MVT::i32)) {
1279 // Convert pointer from byte address to dword address.
1280 Ptr = DAG.getNode(AMDGPUISD::DWORDADDR, DL, PtrVT, DWordAddr);
1282 if (StoreNode->isTruncatingStore() || StoreNode->isIndexed()) {
1283 llvm_unreachable("Truncated and indexed stores not supported yet");
1285 Chain = DAG.getStore(Chain, DL, Value, Ptr, StoreNode->getMemOperand());
1291 // GLOBAL_ADDRESS has been handled above, LOCAL_ADDRESS allows all sizes
1292 if (AS != AMDGPUASI.PRIVATE_ADDRESS)
1295 if (MemVT.bitsLT(MVT::i32))
1296 return lowerPrivateTruncStore(StoreNode, DAG);
1298 // Standard i32+ store, tag it with DWORDADDR to note that the address
1300 if (Ptr.getOpcode() != AMDGPUISD::DWORDADDR) {
1301 Ptr = DAG.getNode(AMDGPUISD::DWORDADDR, DL, PtrVT, DWordAddr);
1302 return DAG.getStore(Chain, DL, Value, Ptr, StoreNode->getMemOperand());
1305 // Tagged i32+ stores will be matched by patterns
1309 // return (512 + (kc_bank << 12)
1311 ConstantAddressBlock(unsigned AddressSpace, AMDGPUAS AMDGPUASI) {
1312 switch (AddressSpace) {
1313 case AMDGPUASI.CONSTANT_BUFFER_0:
1315 case AMDGPUASI.CONSTANT_BUFFER_1:
1317 case AMDGPUASI.CONSTANT_BUFFER_2:
1318 return 512 + 4096 * 2;
1319 case AMDGPUASI.CONSTANT_BUFFER_3:
1320 return 512 + 4096 * 3;
1321 case AMDGPUASI.CONSTANT_BUFFER_4:
1322 return 512 + 4096 * 4;
1323 case AMDGPUASI.CONSTANT_BUFFER_5:
1324 return 512 + 4096 * 5;
1325 case AMDGPUASI.CONSTANT_BUFFER_6:
1326 return 512 + 4096 * 6;
1327 case AMDGPUASI.CONSTANT_BUFFER_7:
1328 return 512 + 4096 * 7;
1329 case AMDGPUASI.CONSTANT_BUFFER_8:
1330 return 512 + 4096 * 8;
1331 case AMDGPUASI.CONSTANT_BUFFER_9:
1332 return 512 + 4096 * 9;
1333 case AMDGPUASI.CONSTANT_BUFFER_10:
1334 return 512 + 4096 * 10;
1335 case AMDGPUASI.CONSTANT_BUFFER_11:
1336 return 512 + 4096 * 11;
1337 case AMDGPUASI.CONSTANT_BUFFER_12:
1338 return 512 + 4096 * 12;
1339 case AMDGPUASI.CONSTANT_BUFFER_13:
1340 return 512 + 4096 * 13;
1341 case AMDGPUASI.CONSTANT_BUFFER_14:
1342 return 512 + 4096 * 14;
1343 case AMDGPUASI.CONSTANT_BUFFER_15:
1344 return 512 + 4096 * 15;
1350 SDValue R600TargetLowering::lowerPrivateExtLoad(SDValue Op,
1351 SelectionDAG &DAG) const {
1353 LoadSDNode *Load = cast<LoadSDNode>(Op);
1354 ISD::LoadExtType ExtType = Load->getExtensionType();
1355 EVT MemVT = Load->getMemoryVT();
1356 assert(Load->getAlignment() >= MemVT.getStoreSize());
1358 SDValue BasePtr = Load->getBasePtr();
1359 SDValue Chain = Load->getChain();
1360 SDValue Offset = Load->getOffset();
1362 SDValue LoadPtr = BasePtr;
1363 if (!Offset.isUndef()) {
1364 LoadPtr = DAG.getNode(ISD::ADD, DL, MVT::i32, BasePtr, Offset);
1367 // Get dword location
1368 // NOTE: this should be eliminated by the future SHR ptr, 2
1369 SDValue Ptr = DAG.getNode(ISD::AND, DL, MVT::i32, LoadPtr,
1370 DAG.getConstant(0xfffffffc, DL, MVT::i32));
1373 // TODO: can we be smarter about machine pointer info?
1374 SDValue Read = DAG.getLoad(MVT::i32, DL, Chain, Ptr, MachinePointerInfo());
1376 // Get offset within the register.
1377 SDValue ByteIdx = DAG.getNode(ISD::AND, DL, MVT::i32,
1378 LoadPtr, DAG.getConstant(0x3, DL, MVT::i32));
1380 // Bit offset of target byte (byteIdx * 8).
1381 SDValue ShiftAmt = DAG.getNode(ISD::SHL, DL, MVT::i32, ByteIdx,
1382 DAG.getConstant(3, DL, MVT::i32));
1384 // Shift to the right.
1385 SDValue Ret = DAG.getNode(ISD::SRL, DL, MVT::i32, Read, ShiftAmt);
1387 // Eliminate the upper bits by setting them to ...
1388 EVT MemEltVT = MemVT.getScalarType();
1390 if (ExtType == ISD::SEXTLOAD) { // ... ones.
1391 SDValue MemEltVTNode = DAG.getValueType(MemEltVT);
1392 Ret = DAG.getNode(ISD::SIGN_EXTEND_INREG, DL, MVT::i32, Ret, MemEltVTNode);
1393 } else { // ... or zeros.
1394 Ret = DAG.getZeroExtendInReg(Ret, DL, MemEltVT);
1399 Read.getValue(1) // This should be our output chain
1402 return DAG.getMergeValues(Ops, DL);
1405 SDValue R600TargetLowering::LowerLOAD(SDValue Op, SelectionDAG &DAG) const {
1406 LoadSDNode *LoadNode = cast<LoadSDNode>(Op);
1407 unsigned AS = LoadNode->getAddressSpace();
1408 EVT MemVT = LoadNode->getMemoryVT();
1409 ISD::LoadExtType ExtType = LoadNode->getExtensionType();
1411 if (AS == AMDGPUASI.PRIVATE_ADDRESS &&
1412 ExtType != ISD::NON_EXTLOAD && MemVT.bitsLT(MVT::i32)) {
1413 return lowerPrivateExtLoad(Op, DAG);
1417 EVT VT = Op.getValueType();
1418 SDValue Chain = LoadNode->getChain();
1419 SDValue Ptr = LoadNode->getBasePtr();
1421 if ((LoadNode->getAddressSpace() == AMDGPUASI.LOCAL_ADDRESS ||
1422 LoadNode->getAddressSpace() == AMDGPUASI.PRIVATE_ADDRESS) &&
1424 return scalarizeVectorLoad(LoadNode, DAG);
1427 int ConstantBlock = ConstantAddressBlock(LoadNode->getAddressSpace(),
1429 if (ConstantBlock > -1 &&
1430 ((LoadNode->getExtensionType() == ISD::NON_EXTLOAD) ||
1431 (LoadNode->getExtensionType() == ISD::ZEXTLOAD))) {
1433 if (isa<ConstantExpr>(LoadNode->getMemOperand()->getValue()) ||
1434 isa<Constant>(LoadNode->getMemOperand()->getValue()) ||
1435 isa<ConstantSDNode>(Ptr)) {
1437 for (unsigned i = 0; i < 4; i++) {
1438 // We want Const position encoded with the following formula :
1439 // (((512 + (kc_bank << 12) + const_index) << 2) + chan)
1440 // const_index is Ptr computed by llvm using an alignment of 16.
1441 // Thus we add (((512 + (kc_bank << 12)) + chan ) * 4 here and
1442 // then div by 4 at the ISel step
1443 SDValue NewPtr = DAG.getNode(ISD::ADD, DL, Ptr.getValueType(), Ptr,
1444 DAG.getConstant(4 * i + ConstantBlock * 16, DL, MVT::i32));
1445 Slots[i] = DAG.getNode(AMDGPUISD::CONST_ADDRESS, DL, MVT::i32, NewPtr);
1447 EVT NewVT = MVT::v4i32;
1448 unsigned NumElements = 4;
1449 if (VT.isVector()) {
1451 NumElements = VT.getVectorNumElements();
1453 Result = DAG.getBuildVector(NewVT, DL, makeArrayRef(Slots, NumElements));
1455 // non-constant ptr can't be folded, keeps it as a v4f32 load
1456 Result = DAG.getNode(AMDGPUISD::CONST_ADDRESS, DL, MVT::v4i32,
1457 DAG.getNode(ISD::SRL, DL, MVT::i32, Ptr,
1458 DAG.getConstant(4, DL, MVT::i32)),
1459 DAG.getConstant(LoadNode->getAddressSpace() -
1460 AMDGPUASI.CONSTANT_BUFFER_0, DL, MVT::i32)
1464 if (!VT.isVector()) {
1465 Result = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, MVT::i32, Result,
1466 DAG.getConstant(0, DL, MVT::i32));
1469 SDValue MergedValues[2] = {
1473 return DAG.getMergeValues(MergedValues, DL);
1476 // For most operations returning SDValue() will result in the node being
1477 // expanded by the DAG Legalizer. This is not the case for ISD::LOAD, so we
1478 // need to manually expand loads that may be legal in some address spaces and
1479 // illegal in others. SEXT loads from CONSTANT_BUFFER_0 are supported for
1480 // compute shaders, since the data is sign extended when it is uploaded to the
1481 // buffer. However SEXT loads from other address spaces are not supported, so
1482 // we need to expand them here.
1483 if (LoadNode->getExtensionType() == ISD::SEXTLOAD) {
1484 EVT MemVT = LoadNode->getMemoryVT();
1485 assert(!MemVT.isVector() && (MemVT == MVT::i16 || MemVT == MVT::i8));
1486 SDValue NewLoad = DAG.getExtLoad(
1487 ISD::EXTLOAD, DL, VT, Chain, Ptr, LoadNode->getPointerInfo(), MemVT,
1488 LoadNode->getAlignment(), LoadNode->getMemOperand()->getFlags());
1489 SDValue Res = DAG.getNode(ISD::SIGN_EXTEND_INREG, DL, VT, NewLoad,
1490 DAG.getValueType(MemVT));
1492 SDValue MergedValues[2] = { Res, Chain };
1493 return DAG.getMergeValues(MergedValues, DL);
1496 if (LoadNode->getAddressSpace() != AMDGPUASI.PRIVATE_ADDRESS) {
1500 // DWORDADDR ISD marks already shifted address
1501 if (Ptr.getOpcode() != AMDGPUISD::DWORDADDR) {
1502 assert(VT == MVT::i32);
1503 Ptr = DAG.getNode(ISD::SRL, DL, MVT::i32, Ptr, DAG.getConstant(2, DL, MVT::i32));
1504 Ptr = DAG.getNode(AMDGPUISD::DWORDADDR, DL, MVT::i32, Ptr);
1505 return DAG.getLoad(MVT::i32, DL, Chain, Ptr, LoadNode->getMemOperand());
1510 SDValue R600TargetLowering::LowerBRCOND(SDValue Op, SelectionDAG &DAG) const {
1511 SDValue Chain = Op.getOperand(0);
1512 SDValue Cond = Op.getOperand(1);
1513 SDValue Jump = Op.getOperand(2);
1515 return DAG.getNode(AMDGPUISD::BRANCH_COND, SDLoc(Op), Op.getValueType(),
1519 SDValue R600TargetLowering::lowerFrameIndex(SDValue Op,
1520 SelectionDAG &DAG) const {
1521 MachineFunction &MF = DAG.getMachineFunction();
1522 const R600FrameLowering *TFL = getSubtarget()->getFrameLowering();
1524 FrameIndexSDNode *FIN = cast<FrameIndexSDNode>(Op);
1526 unsigned FrameIndex = FIN->getIndex();
1527 unsigned IgnoredFrameReg;
1529 TFL->getFrameIndexReference(MF, FrameIndex, IgnoredFrameReg);
1530 return DAG.getConstant(Offset * 4 * TFL->getStackWidth(MF), SDLoc(Op),
1534 /// XXX Only kernel functions are supported, so we can assume for now that
1535 /// every function is a kernel function, but in the future we should use
1536 /// separate calling conventions for kernel and non-kernel functions.
1537 SDValue R600TargetLowering::LowerFormalArguments(
1538 SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
1539 const SmallVectorImpl<ISD::InputArg> &Ins, const SDLoc &DL,
1540 SelectionDAG &DAG, SmallVectorImpl<SDValue> &InVals) const {
1541 SmallVector<CCValAssign, 16> ArgLocs;
1542 CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(), ArgLocs,
1544 MachineFunction &MF = DAG.getMachineFunction();
1545 R600MachineFunctionInfo *MFI = MF.getInfo<R600MachineFunctionInfo>();
1547 SmallVector<ISD::InputArg, 8> LocalIns;
1549 if (AMDGPU::isShader(CallConv)) {
1550 CCInfo.AnalyzeFormalArguments(Ins, CCAssignFnForCall(CallConv, isVarArg));
1552 analyzeFormalArgumentsCompute(CCInfo, Ins);
1555 for (unsigned i = 0, e = Ins.size(); i < e; ++i) {
1556 CCValAssign &VA = ArgLocs[i];
1557 const ISD::InputArg &In = Ins[i];
1559 EVT MemVT = VA.getLocVT();
1560 if (!VT.isVector() && MemVT.isVector()) {
1561 // Get load source type if scalarized.
1562 MemVT = MemVT.getVectorElementType();
1565 if (AMDGPU::isShader(CallConv)) {
1566 unsigned Reg = MF.addLiveIn(VA.getLocReg(), &AMDGPU::R600_Reg128RegClass);
1567 SDValue Register = DAG.getCopyFromReg(Chain, DL, Reg, VT);
1568 InVals.push_back(Register);
1572 PointerType *PtrTy = PointerType::get(VT.getTypeForEVT(*DAG.getContext()),
1573 AMDGPUASI.CONSTANT_BUFFER_0);
1575 // i64 isn't a legal type, so the register type used ends up as i32, which
1576 // isn't expected here. It attempts to create this sextload, but it ends up
1577 // being invalid. Somehow this seems to work with i64 arguments, but breaks
1580 // The first 36 bytes of the input buffer contains information about
1581 // thread group and global sizes.
1582 ISD::LoadExtType Ext = ISD::NON_EXTLOAD;
1583 if (MemVT.getScalarSizeInBits() != VT.getScalarSizeInBits()) {
1584 // FIXME: This should really check the extload type, but the handling of
1585 // extload vector parameters seems to be broken.
1587 // Ext = In.Flags.isSExt() ? ISD::SEXTLOAD : ISD::ZEXTLOAD;
1588 Ext = ISD::SEXTLOAD;
1591 // Compute the offset from the value.
1592 // XXX - I think PartOffset should give you this, but it seems to give the
1593 // size of the register which isn't useful.
1595 unsigned ValBase = ArgLocs[In.getOrigArgIndex()].getLocMemOffset();
1596 unsigned PartOffset = VA.getLocMemOffset();
1597 unsigned Offset = Subtarget->getExplicitKernelArgOffset(MF) + VA.getLocMemOffset();
1599 MachinePointerInfo PtrInfo(UndefValue::get(PtrTy), PartOffset - ValBase);
1600 SDValue Arg = DAG.getLoad(
1601 ISD::UNINDEXED, Ext, VT, DL, Chain,
1602 DAG.getConstant(Offset, DL, MVT::i32), DAG.getUNDEF(MVT::i32), PtrInfo,
1603 MemVT, /* Alignment = */ 4, MachineMemOperand::MONonTemporal |
1604 MachineMemOperand::MODereferenceable |
1605 MachineMemOperand::MOInvariant);
1607 // 4 is the preferred alignment for the CONSTANT memory space.
1608 InVals.push_back(Arg);
1609 MFI->setABIArgOffset(Offset + MemVT.getStoreSize());
1614 EVT R600TargetLowering::getSetCCResultType(const DataLayout &DL, LLVMContext &,
1618 return VT.changeVectorElementTypeToInteger();
1621 bool R600TargetLowering::canMergeStoresTo(unsigned AS, EVT MemVT) const {
1622 // Local and Private addresses do not handle vectors. Limit to i32
1623 if ((AS == AMDGPUASI.LOCAL_ADDRESS || AS == AMDGPUASI.PRIVATE_ADDRESS)) {
1624 return (MemVT.getSizeInBits() <= 32);
1629 bool R600TargetLowering::allowsMisalignedMemoryAccesses(EVT VT,
1632 bool *IsFast) const {
1636 if (!VT.isSimple() || VT == MVT::Other)
1639 if (VT.bitsLT(MVT::i32))
1642 // TODO: This is a rough estimate.
1646 return VT.bitsGT(MVT::i32) && Align % 4 == 0;
1649 static SDValue CompactSwizzlableVector(
1650 SelectionDAG &DAG, SDValue VectorEntry,
1651 DenseMap<unsigned, unsigned> &RemapSwizzle) {
1652 assert(VectorEntry.getOpcode() == ISD::BUILD_VECTOR);
1653 assert(RemapSwizzle.empty());
1654 SDValue NewBldVec[4] = {
1655 VectorEntry.getOperand(0),
1656 VectorEntry.getOperand(1),
1657 VectorEntry.getOperand(2),
1658 VectorEntry.getOperand(3)
1661 for (unsigned i = 0; i < 4; i++) {
1662 if (NewBldVec[i].isUndef())
1663 // We mask write here to teach later passes that the ith element of this
1664 // vector is undef. Thus we can use it to reduce 128 bits reg usage,
1665 // break false dependencies and additionnaly make assembly easier to read.
1666 RemapSwizzle[i] = 7; // SEL_MASK_WRITE
1667 if (ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(NewBldVec[i])) {
1669 RemapSwizzle[i] = 4; // SEL_0
1670 NewBldVec[i] = DAG.getUNDEF(MVT::f32);
1671 } else if (C->isExactlyValue(1.0)) {
1672 RemapSwizzle[i] = 5; // SEL_1
1673 NewBldVec[i] = DAG.getUNDEF(MVT::f32);
1677 if (NewBldVec[i].isUndef())
1679 for (unsigned j = 0; j < i; j++) {
1680 if (NewBldVec[i] == NewBldVec[j]) {
1681 NewBldVec[i] = DAG.getUNDEF(NewBldVec[i].getValueType());
1682 RemapSwizzle[i] = j;
1688 return DAG.getBuildVector(VectorEntry.getValueType(), SDLoc(VectorEntry),
1692 static SDValue ReorganizeVector(SelectionDAG &DAG, SDValue VectorEntry,
1693 DenseMap<unsigned, unsigned> &RemapSwizzle) {
1694 assert(VectorEntry.getOpcode() == ISD::BUILD_VECTOR);
1695 assert(RemapSwizzle.empty());
1696 SDValue NewBldVec[4] = {
1697 VectorEntry.getOperand(0),
1698 VectorEntry.getOperand(1),
1699 VectorEntry.getOperand(2),
1700 VectorEntry.getOperand(3)
1702 bool isUnmovable[4] = { false, false, false, false };
1703 for (unsigned i = 0; i < 4; i++) {
1704 RemapSwizzle[i] = i;
1705 if (NewBldVec[i].getOpcode() == ISD::EXTRACT_VECTOR_ELT) {
1706 unsigned Idx = dyn_cast<ConstantSDNode>(NewBldVec[i].getOperand(1))
1709 isUnmovable[Idx] = true;
1713 for (unsigned i = 0; i < 4; i++) {
1714 if (NewBldVec[i].getOpcode() == ISD::EXTRACT_VECTOR_ELT) {
1715 unsigned Idx = dyn_cast<ConstantSDNode>(NewBldVec[i].getOperand(1))
1717 if (isUnmovable[Idx])
1720 std::swap(NewBldVec[Idx], NewBldVec[i]);
1721 std::swap(RemapSwizzle[i], RemapSwizzle[Idx]);
1726 return DAG.getBuildVector(VectorEntry.getValueType(), SDLoc(VectorEntry),
1730 SDValue R600TargetLowering::OptimizeSwizzle(SDValue BuildVector, SDValue Swz[4],
1732 const SDLoc &DL) const {
1733 assert(BuildVector.getOpcode() == ISD::BUILD_VECTOR);
1734 // Old -> New swizzle values
1735 DenseMap<unsigned, unsigned> SwizzleRemap;
1737 BuildVector = CompactSwizzlableVector(DAG, BuildVector, SwizzleRemap);
1738 for (unsigned i = 0; i < 4; i++) {
1739 unsigned Idx = cast<ConstantSDNode>(Swz[i])->getZExtValue();
1740 if (SwizzleRemap.find(Idx) != SwizzleRemap.end())
1741 Swz[i] = DAG.getConstant(SwizzleRemap[Idx], DL, MVT::i32);
1744 SwizzleRemap.clear();
1745 BuildVector = ReorganizeVector(DAG, BuildVector, SwizzleRemap);
1746 for (unsigned i = 0; i < 4; i++) {
1747 unsigned Idx = cast<ConstantSDNode>(Swz[i])->getZExtValue();
1748 if (SwizzleRemap.find(Idx) != SwizzleRemap.end())
1749 Swz[i] = DAG.getConstant(SwizzleRemap[Idx], DL, MVT::i32);
1755 //===----------------------------------------------------------------------===//
1756 // Custom DAG Optimizations
1757 //===----------------------------------------------------------------------===//
1759 SDValue R600TargetLowering::PerformDAGCombine(SDNode *N,
1760 DAGCombinerInfo &DCI) const {
1761 SelectionDAG &DAG = DCI.DAG;
1764 switch (N->getOpcode()) {
1765 // (f32 fp_round (f64 uint_to_fp a)) -> (f32 uint_to_fp a)
1766 case ISD::FP_ROUND: {
1767 SDValue Arg = N->getOperand(0);
1768 if (Arg.getOpcode() == ISD::UINT_TO_FP && Arg.getValueType() == MVT::f64) {
1769 return DAG.getNode(ISD::UINT_TO_FP, DL, N->getValueType(0),
1775 // (i32 fp_to_sint (fneg (select_cc f32, f32, 1.0, 0.0 cc))) ->
1776 // (i32 select_cc f32, f32, -1, 0 cc)
1778 // Mesa's GLSL frontend generates the above pattern a lot and we can lower
1779 // this to one of the SET*_DX10 instructions.
1780 case ISD::FP_TO_SINT: {
1781 SDValue FNeg = N->getOperand(0);
1782 if (FNeg.getOpcode() != ISD::FNEG) {
1785 SDValue SelectCC = FNeg.getOperand(0);
1786 if (SelectCC.getOpcode() != ISD::SELECT_CC ||
1787 SelectCC.getOperand(0).getValueType() != MVT::f32 || // LHS
1788 SelectCC.getOperand(2).getValueType() != MVT::f32 || // True
1789 !isHWTrueValue(SelectCC.getOperand(2)) ||
1790 !isHWFalseValue(SelectCC.getOperand(3))) {
1794 return DAG.getNode(ISD::SELECT_CC, DL, N->getValueType(0),
1795 SelectCC.getOperand(0), // LHS
1796 SelectCC.getOperand(1), // RHS
1797 DAG.getConstant(-1, DL, MVT::i32), // True
1798 DAG.getConstant(0, DL, MVT::i32), // False
1799 SelectCC.getOperand(4)); // CC
1804 // insert_vector_elt (build_vector elt0, ... , eltN), NewEltIdx, idx
1805 // => build_vector elt0, ... , NewEltIdx, ... , eltN
1806 case ISD::INSERT_VECTOR_ELT: {
1807 SDValue InVec = N->getOperand(0);
1808 SDValue InVal = N->getOperand(1);
1809 SDValue EltNo = N->getOperand(2);
1811 // If the inserted element is an UNDEF, just use the input vector.
1812 if (InVal.isUndef())
1815 EVT VT = InVec.getValueType();
1817 // If we can't generate a legal BUILD_VECTOR, exit
1818 if (!isOperationLegal(ISD::BUILD_VECTOR, VT))
1821 // Check that we know which element is being inserted
1822 if (!isa<ConstantSDNode>(EltNo))
1824 unsigned Elt = cast<ConstantSDNode>(EltNo)->getZExtValue();
1826 // Check that the operand is a BUILD_VECTOR (or UNDEF, which can essentially
1827 // be converted to a BUILD_VECTOR). Fill in the Ops vector with the
1829 SmallVector<SDValue, 8> Ops;
1830 if (InVec.getOpcode() == ISD::BUILD_VECTOR) {
1831 Ops.append(InVec.getNode()->op_begin(),
1832 InVec.getNode()->op_end());
1833 } else if (InVec.isUndef()) {
1834 unsigned NElts = VT.getVectorNumElements();
1835 Ops.append(NElts, DAG.getUNDEF(InVal.getValueType()));
1840 // Insert the element
1841 if (Elt < Ops.size()) {
1842 // All the operands of BUILD_VECTOR must have the same type;
1843 // we enforce that here.
1844 EVT OpVT = Ops[0].getValueType();
1845 if (InVal.getValueType() != OpVT)
1846 InVal = OpVT.bitsGT(InVal.getValueType()) ?
1847 DAG.getNode(ISD::ANY_EXTEND, DL, OpVT, InVal) :
1848 DAG.getNode(ISD::TRUNCATE, DL, OpVT, InVal);
1852 // Return the new vector
1853 return DAG.getBuildVector(VT, DL, Ops);
1856 // Extract_vec (Build_vector) generated by custom lowering
1857 // also needs to be customly combined
1858 case ISD::EXTRACT_VECTOR_ELT: {
1859 SDValue Arg = N->getOperand(0);
1860 if (Arg.getOpcode() == ISD::BUILD_VECTOR) {
1861 if (ConstantSDNode *Const = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
1862 unsigned Element = Const->getZExtValue();
1863 return Arg->getOperand(Element);
1866 if (Arg.getOpcode() == ISD::BITCAST &&
1867 Arg.getOperand(0).getOpcode() == ISD::BUILD_VECTOR &&
1868 (Arg.getOperand(0).getValueType().getVectorNumElements() ==
1869 Arg.getValueType().getVectorNumElements())) {
1870 if (ConstantSDNode *Const = dyn_cast<ConstantSDNode>(N->getOperand(1))) {
1871 unsigned Element = Const->getZExtValue();
1872 return DAG.getNode(ISD::BITCAST, DL, N->getVTList(),
1873 Arg->getOperand(0).getOperand(Element));
1879 case ISD::SELECT_CC: {
1880 // Try common optimizations
1881 if (SDValue Ret = AMDGPUTargetLowering::PerformDAGCombine(N, DCI))
1884 // fold selectcc (selectcc x, y, a, b, cc), b, a, b, seteq ->
1885 // selectcc x, y, a, b, inv(cc)
1887 // fold selectcc (selectcc x, y, a, b, cc), b, a, b, setne ->
1888 // selectcc x, y, a, b, cc
1889 SDValue LHS = N->getOperand(0);
1890 if (LHS.getOpcode() != ISD::SELECT_CC) {
1894 SDValue RHS = N->getOperand(1);
1895 SDValue True = N->getOperand(2);
1896 SDValue False = N->getOperand(3);
1897 ISD::CondCode NCC = cast<CondCodeSDNode>(N->getOperand(4))->get();
1899 if (LHS.getOperand(2).getNode() != True.getNode() ||
1900 LHS.getOperand(3).getNode() != False.getNode() ||
1901 RHS.getNode() != False.getNode()) {
1906 default: return SDValue();
1907 case ISD::SETNE: return LHS;
1909 ISD::CondCode LHSCC = cast<CondCodeSDNode>(LHS.getOperand(4))->get();
1910 LHSCC = ISD::getSetCCInverse(LHSCC,
1911 LHS.getOperand(0).getValueType().isInteger());
1912 if (DCI.isBeforeLegalizeOps() ||
1913 isCondCodeLegal(LHSCC, LHS.getOperand(0).getSimpleValueType()))
1914 return DAG.getSelectCC(DL,
1926 case AMDGPUISD::R600_EXPORT: {
1927 SDValue Arg = N->getOperand(1);
1928 if (Arg.getOpcode() != ISD::BUILD_VECTOR)
1931 SDValue NewArgs[8] = {
1932 N->getOperand(0), // Chain
1934 N->getOperand(2), // ArrayBase
1935 N->getOperand(3), // Type
1936 N->getOperand(4), // SWZ_X
1937 N->getOperand(5), // SWZ_Y
1938 N->getOperand(6), // SWZ_Z
1939 N->getOperand(7) // SWZ_W
1941 NewArgs[1] = OptimizeSwizzle(N->getOperand(1), &NewArgs[4], DAG, DL);
1942 return DAG.getNode(AMDGPUISD::R600_EXPORT, DL, N->getVTList(), NewArgs);
1944 case AMDGPUISD::TEXTURE_FETCH: {
1945 SDValue Arg = N->getOperand(1);
1946 if (Arg.getOpcode() != ISD::BUILD_VECTOR)
1949 SDValue NewArgs[19] = {
1970 NewArgs[1] = OptimizeSwizzle(N->getOperand(1), &NewArgs[2], DAG, DL);
1971 return DAG.getNode(AMDGPUISD::TEXTURE_FETCH, DL, N->getVTList(), NewArgs);
1976 return AMDGPUTargetLowering::PerformDAGCombine(N, DCI);
1979 bool R600TargetLowering::FoldOperand(SDNode *ParentNode, unsigned SrcIdx,
1980 SDValue &Src, SDValue &Neg, SDValue &Abs,
1981 SDValue &Sel, SDValue &Imm,
1982 SelectionDAG &DAG) const {
1983 const R600InstrInfo *TII = getSubtarget()->getInstrInfo();
1984 if (!Src.isMachineOpcode())
1987 switch (Src.getMachineOpcode()) {
1988 case AMDGPU::FNEG_R600:
1991 Src = Src.getOperand(0);
1992 Neg = DAG.getTargetConstant(1, SDLoc(ParentNode), MVT::i32);
1994 case AMDGPU::FABS_R600:
1997 Src = Src.getOperand(0);
1998 Abs = DAG.getTargetConstant(1, SDLoc(ParentNode), MVT::i32);
2000 case AMDGPU::CONST_COPY: {
2001 unsigned Opcode = ParentNode->getMachineOpcode();
2002 bool HasDst = TII->getOperandIdx(Opcode, AMDGPU::OpName::dst) > -1;
2007 SDValue CstOffset = Src.getOperand(0);
2008 if (ParentNode->getValueType(0).isVector())
2011 // Gather constants values
2012 int SrcIndices[] = {
2013 TII->getOperandIdx(Opcode, AMDGPU::OpName::src0),
2014 TII->getOperandIdx(Opcode, AMDGPU::OpName::src1),
2015 TII->getOperandIdx(Opcode, AMDGPU::OpName::src2),
2016 TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_X),
2017 TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_Y),
2018 TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_Z),
2019 TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_W),
2020 TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_X),
2021 TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_Y),
2022 TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_Z),
2023 TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_W)
2025 std::vector<unsigned> Consts;
2026 for (int OtherSrcIdx : SrcIndices) {
2027 int OtherSelIdx = TII->getSelIdx(Opcode, OtherSrcIdx);
2028 if (OtherSrcIdx < 0 || OtherSelIdx < 0)
2034 if (RegisterSDNode *Reg =
2035 dyn_cast<RegisterSDNode>(ParentNode->getOperand(OtherSrcIdx))) {
2036 if (Reg->getReg() == AMDGPU::ALU_CONST) {
2038 = cast<ConstantSDNode>(ParentNode->getOperand(OtherSelIdx));
2039 Consts.push_back(Cst->getZExtValue());
2044 ConstantSDNode *Cst = cast<ConstantSDNode>(CstOffset);
2045 Consts.push_back(Cst->getZExtValue());
2046 if (!TII->fitsConstReadLimitations(Consts)) {
2051 Src = DAG.getRegister(AMDGPU::ALU_CONST, MVT::f32);
2054 case AMDGPU::MOV_IMM_GLOBAL_ADDR:
2055 // Check if the Imm slot is used. Taken from below.
2056 if (cast<ConstantSDNode>(Imm)->getZExtValue())
2058 Imm = Src.getOperand(0);
2059 Src = DAG.getRegister(AMDGPU::ALU_LITERAL_X, MVT::i32);
2061 case AMDGPU::MOV_IMM_I32:
2062 case AMDGPU::MOV_IMM_F32: {
2063 unsigned ImmReg = AMDGPU::ALU_LITERAL_X;
2064 uint64_t ImmValue = 0;
2066 if (Src.getMachineOpcode() == AMDGPU::MOV_IMM_F32) {
2067 ConstantFPSDNode *FPC = dyn_cast<ConstantFPSDNode>(Src.getOperand(0));
2068 float FloatValue = FPC->getValueAPF().convertToFloat();
2069 if (FloatValue == 0.0) {
2070 ImmReg = AMDGPU::ZERO;
2071 } else if (FloatValue == 0.5) {
2072 ImmReg = AMDGPU::HALF;
2073 } else if (FloatValue == 1.0) {
2074 ImmReg = AMDGPU::ONE;
2076 ImmValue = FPC->getValueAPF().bitcastToAPInt().getZExtValue();
2079 ConstantSDNode *C = dyn_cast<ConstantSDNode>(Src.getOperand(0));
2080 uint64_t Value = C->getZExtValue();
2082 ImmReg = AMDGPU::ZERO;
2083 } else if (Value == 1) {
2084 ImmReg = AMDGPU::ONE_INT;
2090 // Check that we aren't already using an immediate.
2091 // XXX: It's possible for an instruction to have more than one
2092 // immediate operand, but this is not supported yet.
2093 if (ImmReg == AMDGPU::ALU_LITERAL_X) {
2096 ConstantSDNode *C = dyn_cast<ConstantSDNode>(Imm);
2098 if (C->getZExtValue())
2100 Imm = DAG.getTargetConstant(ImmValue, SDLoc(ParentNode), MVT::i32);
2102 Src = DAG.getRegister(ImmReg, MVT::i32);
2110 /// \brief Fold the instructions after selecting them
2111 SDNode *R600TargetLowering::PostISelFolding(MachineSDNode *Node,
2112 SelectionDAG &DAG) const {
2113 const R600InstrInfo *TII = getSubtarget()->getInstrInfo();
2114 if (!Node->isMachineOpcode())
2117 unsigned Opcode = Node->getMachineOpcode();
2120 std::vector<SDValue> Ops(Node->op_begin(), Node->op_end());
2122 if (Opcode == AMDGPU::DOT_4) {
2123 int OperandIdx[] = {
2124 TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_X),
2125 TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_Y),
2126 TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_Z),
2127 TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_W),
2128 TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_X),
2129 TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_Y),
2130 TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_Z),
2131 TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_W)
2134 TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_neg_X),
2135 TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_neg_Y),
2136 TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_neg_Z),
2137 TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_neg_W),
2138 TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_neg_X),
2139 TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_neg_Y),
2140 TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_neg_Z),
2141 TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_neg_W)
2144 TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_abs_X),
2145 TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_abs_Y),
2146 TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_abs_Z),
2147 TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_abs_W),
2148 TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_abs_X),
2149 TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_abs_Y),
2150 TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_abs_Z),
2151 TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_abs_W)
2153 for (unsigned i = 0; i < 8; i++) {
2154 if (OperandIdx[i] < 0)
2156 SDValue &Src = Ops[OperandIdx[i] - 1];
2157 SDValue &Neg = Ops[NegIdx[i] - 1];
2158 SDValue &Abs = Ops[AbsIdx[i] - 1];
2159 bool HasDst = TII->getOperandIdx(Opcode, AMDGPU::OpName::dst) > -1;
2160 int SelIdx = TII->getSelIdx(Opcode, OperandIdx[i]);
2163 SDValue &Sel = (SelIdx > -1) ? Ops[SelIdx] : FakeOp;
2164 if (FoldOperand(Node, i, Src, Neg, Abs, Sel, FakeOp, DAG))
2165 return DAG.getMachineNode(Opcode, SDLoc(Node), Node->getVTList(), Ops);
2167 } else if (Opcode == AMDGPU::REG_SEQUENCE) {
2168 for (unsigned i = 1, e = Node->getNumOperands(); i < e; i += 2) {
2169 SDValue &Src = Ops[i];
2170 if (FoldOperand(Node, i, Src, FakeOp, FakeOp, FakeOp, FakeOp, DAG))
2171 return DAG.getMachineNode(Opcode, SDLoc(Node), Node->getVTList(), Ops);
2173 } else if (Opcode == AMDGPU::CLAMP_R600) {
2174 SDValue Src = Node->getOperand(0);
2175 if (!Src.isMachineOpcode() ||
2176 !TII->hasInstrModifiers(Src.getMachineOpcode()))
2178 int ClampIdx = TII->getOperandIdx(Src.getMachineOpcode(),
2179 AMDGPU::OpName::clamp);
2183 std::vector<SDValue> Ops(Src->op_begin(), Src->op_end());
2184 Ops[ClampIdx - 1] = DAG.getTargetConstant(1, DL, MVT::i32);
2185 return DAG.getMachineNode(Src.getMachineOpcode(), DL,
2186 Node->getVTList(), Ops);
2188 if (!TII->hasInstrModifiers(Opcode))
2190 int OperandIdx[] = {
2191 TII->getOperandIdx(Opcode, AMDGPU::OpName::src0),
2192 TII->getOperandIdx(Opcode, AMDGPU::OpName::src1),
2193 TII->getOperandIdx(Opcode, AMDGPU::OpName::src2)
2196 TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_neg),
2197 TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_neg),
2198 TII->getOperandIdx(Opcode, AMDGPU::OpName::src2_neg)
2201 TII->getOperandIdx(Opcode, AMDGPU::OpName::src0_abs),
2202 TII->getOperandIdx(Opcode, AMDGPU::OpName::src1_abs),
2205 for (unsigned i = 0; i < 3; i++) {
2206 if (OperandIdx[i] < 0)
2208 SDValue &Src = Ops[OperandIdx[i] - 1];
2209 SDValue &Neg = Ops[NegIdx[i] - 1];
2211 SDValue &Abs = (AbsIdx[i] > -1) ? Ops[AbsIdx[i] - 1] : FakeAbs;
2212 bool HasDst = TII->getOperandIdx(Opcode, AMDGPU::OpName::dst) > -1;
2213 int SelIdx = TII->getSelIdx(Opcode, OperandIdx[i]);
2214 int ImmIdx = TII->getOperandIdx(Opcode, AMDGPU::OpName::literal);
2219 SDValue &Sel = (SelIdx > -1) ? Ops[SelIdx] : FakeOp;
2220 SDValue &Imm = Ops[ImmIdx];
2221 if (FoldOperand(Node, i, Src, Neg, Abs, Sel, Imm, DAG))
2222 return DAG.getMachineNode(Opcode, SDLoc(Node), Node->getVTList(), Ops);