1 //===-- SIISelLowering.cpp - SI 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 SI
13 //===----------------------------------------------------------------------===//
15 #include "SIISelLowering.h"
17 #include "AMDILIntrinsicInfo.h"
18 #include "SIInstrInfo.h"
19 #include "SIMachineFunctionInfo.h"
20 #include "SIRegisterInfo.h"
21 #include "llvm/IR/Function.h"
22 #include "llvm/CodeGen/CallingConvLower.h"
23 #include "llvm/CodeGen/MachineInstrBuilder.h"
24 #include "llvm/CodeGen/MachineRegisterInfo.h"
25 #include "llvm/CodeGen/SelectionDAG.h"
29 SITargetLowering::SITargetLowering(TargetMachine &TM) :
30 AMDGPUTargetLowering(TM),
31 TII(static_cast<const SIInstrInfo*>(TM.getInstrInfo())),
32 TRI(TM.getRegisterInfo()) {
34 addRegisterClass(MVT::i1, &AMDGPU::SReg_64RegClass);
35 addRegisterClass(MVT::i64, &AMDGPU::SReg_64RegClass);
37 addRegisterClass(MVT::v16i8, &AMDGPU::SReg_128RegClass);
38 addRegisterClass(MVT::v32i8, &AMDGPU::SReg_256RegClass);
39 addRegisterClass(MVT::v64i8, &AMDGPU::SReg_512RegClass);
41 addRegisterClass(MVT::i32, &AMDGPU::VReg_32RegClass);
42 addRegisterClass(MVT::f32, &AMDGPU::VReg_32RegClass);
44 addRegisterClass(MVT::v1i32, &AMDGPU::VReg_32RegClass);
46 addRegisterClass(MVT::v2i32, &AMDGPU::VReg_64RegClass);
47 addRegisterClass(MVT::v2f32, &AMDGPU::VReg_64RegClass);
49 addRegisterClass(MVT::v4i32, &AMDGPU::VReg_128RegClass);
50 addRegisterClass(MVT::v4f32, &AMDGPU::VReg_128RegClass);
52 addRegisterClass(MVT::v8i32, &AMDGPU::VReg_256RegClass);
53 addRegisterClass(MVT::v8f32, &AMDGPU::VReg_256RegClass);
55 addRegisterClass(MVT::v16i32, &AMDGPU::VReg_512RegClass);
56 addRegisterClass(MVT::v16f32, &AMDGPU::VReg_512RegClass);
58 computeRegisterProperties();
60 setOperationAction(ISD::ADD, MVT::i64, Legal);
61 setOperationAction(ISD::ADD, MVT::i32, Legal);
63 setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);
65 // We need to custom lower loads from the USER_SGPR address space, so we can
66 // add the SGPRs as livein registers.
67 setOperationAction(ISD::LOAD, MVT::i32, Custom);
68 setOperationAction(ISD::LOAD, MVT::i64, Custom);
70 setOperationAction(ISD::SELECT_CC, MVT::f32, Custom);
71 setOperationAction(ISD::SELECT_CC, MVT::i32, Custom);
73 setOperationAction(ISD::SELECT_CC, MVT::Other, Expand);
74 setTargetDAGCombine(ISD::SELECT_CC);
76 setTargetDAGCombine(ISD::SETCC);
79 SDValue SITargetLowering::LowerFormalArguments(
81 CallingConv::ID CallConv,
83 const SmallVectorImpl<ISD::InputArg> &Ins,
84 DebugLoc DL, SelectionDAG &DAG,
85 SmallVectorImpl<SDValue> &InVals) const {
87 const TargetRegisterInfo *TRI = getTargetMachine().getRegisterInfo();
89 MachineFunction &MF = DAG.getMachineFunction();
90 FunctionType *FType = MF.getFunction()->getFunctionType();
92 assert(CallConv == CallingConv::C);
94 SmallVector<ISD::InputArg, 16> Splits;
95 for (unsigned i = 0, e = Ins.size(); i != e; ++i) {
96 const ISD::InputArg &Arg = Ins[i];
98 // Split vertices into their elements
99 if (Arg.VT.isVector()) {
100 ISD::InputArg NewArg = Arg;
101 NewArg.Flags.setSplit();
102 NewArg.VT = Arg.VT.getVectorElementType();
104 // We REALLY want the ORIGINAL number of vertex elements here, e.g. a
105 // three or five element vertex only needs three or five registers,
106 // NOT four or eigth.
107 Type *ParamType = FType->getParamType(Arg.OrigArgIndex);
108 unsigned NumElements = ParamType->getVectorNumElements();
110 for (unsigned j = 0; j != NumElements; ++j) {
111 Splits.push_back(NewArg);
112 NewArg.PartOffset += NewArg.VT.getStoreSize();
116 Splits.push_back(Arg);
120 SmallVector<CCValAssign, 16> ArgLocs;
121 CCState CCInfo(CallConv, isVarArg, DAG.getMachineFunction(),
122 getTargetMachine(), ArgLocs, *DAG.getContext());
124 AnalyzeFormalArguments(CCInfo, Splits);
126 for (unsigned i = 0, e = Ins.size(), ArgIdx = 0; i != e; ++i) {
128 CCValAssign &VA = ArgLocs[ArgIdx++];
129 assert(VA.isRegLoc() && "Parameter must be in a register!");
131 unsigned Reg = VA.getLocReg();
132 MVT VT = VA.getLocVT();
134 if (VT == MVT::i64) {
135 // For now assume it is a pointer
136 Reg = TRI->getMatchingSuperReg(Reg, AMDGPU::sub0,
137 &AMDGPU::SReg_64RegClass);
138 Reg = MF.addLiveIn(Reg, &AMDGPU::SReg_64RegClass);
139 InVals.push_back(DAG.getCopyFromReg(Chain, DL, Reg, VT));
143 const TargetRegisterClass *RC = TRI->getMinimalPhysRegClass(Reg, VT);
145 Reg = MF.addLiveIn(Reg, RC);
146 SDValue Val = DAG.getCopyFromReg(Chain, DL, Reg, VT);
148 const ISD::InputArg &Arg = Ins[i];
149 if (Arg.VT.isVector()) {
151 // Build a vector from the registers
152 Type *ParamType = FType->getParamType(Arg.OrigArgIndex);
153 unsigned NumElements = ParamType->getVectorNumElements();
155 SmallVector<SDValue, 4> Regs;
157 for (unsigned j = 1; j != NumElements; ++j) {
158 Reg = ArgLocs[ArgIdx++].getLocReg();
159 Reg = MF.addLiveIn(Reg, RC);
160 Regs.push_back(DAG.getCopyFromReg(Chain, DL, Reg, VT));
163 // Fill up the missing vector elements
164 NumElements = Arg.VT.getVectorNumElements() - NumElements;
165 for (unsigned j = 0; j != NumElements; ++j)
166 Regs.push_back(DAG.getUNDEF(VT));
168 InVals.push_back(DAG.getNode(ISD::BUILD_VECTOR, DL, Arg.VT,
169 Regs.data(), Regs.size()));
173 InVals.push_back(Val);
178 MachineBasicBlock * SITargetLowering::EmitInstrWithCustomInserter(
179 MachineInstr * MI, MachineBasicBlock * BB) const {
180 MachineRegisterInfo & MRI = BB->getParent()->getRegInfo();
181 MachineBasicBlock::iterator I = MI;
183 switch (MI->getOpcode()) {
185 return AMDGPUTargetLowering::EmitInstrWithCustomInserter(MI, BB);
186 case AMDGPU::BRANCH: return BB;
187 case AMDGPU::SI_INTERP:
188 LowerSI_INTERP(MI, *BB, I, MRI);
191 LowerSI_WQM(MI, *BB, I, MRI);
197 void SITargetLowering::LowerSI_WQM(MachineInstr *MI, MachineBasicBlock &BB,
198 MachineBasicBlock::iterator I, MachineRegisterInfo & MRI) const {
199 BuildMI(BB, I, BB.findDebugLoc(I), TII->get(AMDGPU::S_WQM_B64), AMDGPU::EXEC)
200 .addReg(AMDGPU::EXEC);
202 MI->eraseFromParent();
205 void SITargetLowering::LowerSI_INTERP(MachineInstr *MI, MachineBasicBlock &BB,
206 MachineBasicBlock::iterator I, MachineRegisterInfo & MRI) const {
207 unsigned tmp = MRI.createVirtualRegister(&AMDGPU::VReg_32RegClass);
208 unsigned M0 = MRI.createVirtualRegister(&AMDGPU::M0RegRegClass);
209 MachineOperand dst = MI->getOperand(0);
210 MachineOperand iReg = MI->getOperand(1);
211 MachineOperand jReg = MI->getOperand(2);
212 MachineOperand attr_chan = MI->getOperand(3);
213 MachineOperand attr = MI->getOperand(4);
214 MachineOperand params = MI->getOperand(5);
216 BuildMI(BB, I, BB.findDebugLoc(I), TII->get(AMDGPU::S_MOV_B32), M0)
219 BuildMI(BB, I, BB.findDebugLoc(I), TII->get(AMDGPU::V_INTERP_P1_F32), tmp)
221 .addOperand(attr_chan)
225 BuildMI(BB, I, BB.findDebugLoc(I), TII->get(AMDGPU::V_INTERP_P2_F32))
229 .addOperand(attr_chan)
233 MI->eraseFromParent();
236 EVT SITargetLowering::getSetCCResultType(EVT VT) const {
240 //===----------------------------------------------------------------------===//
241 // Custom DAG Lowering Operations
242 //===----------------------------------------------------------------------===//
244 SDValue SITargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
245 switch (Op.getOpcode()) {
246 default: return AMDGPUTargetLowering::LowerOperation(Op, DAG);
247 case ISD::BRCOND: return LowerBRCOND(Op, DAG);
248 case ISD::LOAD: return LowerLOAD(Op, DAG);
249 case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG);
250 case ISD::INTRINSIC_WO_CHAIN: {
251 unsigned IntrinsicID =
252 cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
253 EVT VT = Op.getValueType();
254 switch (IntrinsicID) {
255 case AMDGPUIntrinsic::SI_vs_load_buffer_index:
256 return CreateLiveInRegister(DAG, &AMDGPU::VReg_32RegClass,
258 default: return AMDGPUTargetLowering::LowerOperation(Op, DAG);
266 /// \brief Helper function for LowerBRCOND
267 static SDNode *findUser(SDValue Value, unsigned Opcode) {
269 SDNode *Parent = Value.getNode();
270 for (SDNode::use_iterator I = Parent->use_begin(), E = Parent->use_end();
273 if (I.getUse().get() != Value)
276 if (I->getOpcode() == Opcode)
282 /// This transforms the control flow intrinsics to get the branch destination as
283 /// last parameter, also switches branch target with BR if the need arise
284 SDValue SITargetLowering::LowerBRCOND(SDValue BRCOND,
285 SelectionDAG &DAG) const {
287 DebugLoc DL = BRCOND.getDebugLoc();
289 SDNode *Intr = BRCOND.getOperand(1).getNode();
290 SDValue Target = BRCOND.getOperand(2);
293 if (Intr->getOpcode() == ISD::SETCC) {
294 // As long as we negate the condition everything is fine
295 SDNode *SetCC = Intr;
296 assert(SetCC->getConstantOperandVal(1) == 1);
297 assert(cast<CondCodeSDNode>(SetCC->getOperand(2).getNode())->get() ==
299 Intr = SetCC->getOperand(0).getNode();
302 // Get the target from BR if we don't negate the condition
303 BR = findUser(BRCOND, ISD::BR);
304 Target = BR->getOperand(1);
307 assert(Intr->getOpcode() == ISD::INTRINSIC_W_CHAIN);
309 // Build the result and
310 SmallVector<EVT, 4> Res;
311 for (unsigned i = 1, e = Intr->getNumValues(); i != e; ++i)
312 Res.push_back(Intr->getValueType(i));
314 // operands of the new intrinsic call
315 SmallVector<SDValue, 4> Ops;
316 Ops.push_back(BRCOND.getOperand(0));
317 for (unsigned i = 1, e = Intr->getNumOperands(); i != e; ++i)
318 Ops.push_back(Intr->getOperand(i));
319 Ops.push_back(Target);
321 // build the new intrinsic call
322 SDNode *Result = DAG.getNode(
323 Res.size() > 1 ? ISD::INTRINSIC_W_CHAIN : ISD::INTRINSIC_VOID, DL,
324 DAG.getVTList(Res.data(), Res.size()), Ops.data(), Ops.size()).getNode();
327 // Give the branch instruction our target
332 DAG.MorphNodeTo(BR, ISD::BR, BR->getVTList(), Ops, 2);
335 SDValue Chain = SDValue(Result, Result->getNumValues() - 1);
337 // Copy the intrinsic results to registers
338 for (unsigned i = 1, e = Intr->getNumValues() - 1; i != e; ++i) {
339 SDNode *CopyToReg = findUser(SDValue(Intr, i), ISD::CopyToReg);
343 Chain = DAG.getCopyToReg(
345 CopyToReg->getOperand(1),
346 SDValue(Result, i - 1),
349 DAG.ReplaceAllUsesWith(SDValue(CopyToReg, 0), CopyToReg->getOperand(0));
352 // Remove the old intrinsic from the chain
353 DAG.ReplaceAllUsesOfValueWith(
354 SDValue(Intr, Intr->getNumValues() - 1),
355 Intr->getOperand(0));
360 SDValue SITargetLowering::LowerLOAD(SDValue Op, SelectionDAG &DAG) const {
361 EVT VT = Op.getValueType();
362 LoadSDNode *Ptr = dyn_cast<LoadSDNode>(Op);
366 unsigned AddrSpace = Ptr->getPointerInfo().getAddrSpace();
368 // We only need to lower USER_SGPR address space loads
369 if (AddrSpace != AMDGPUAS::USER_SGPR_ADDRESS) {
373 // Loads from the USER_SGPR address space can only have constant value
375 ConstantSDNode *BasePtr = dyn_cast<ConstantSDNode>(Ptr->getBasePtr());
378 unsigned TypeDwordWidth = VT.getSizeInBits() / 32;
379 const TargetRegisterClass * dstClass;
380 switch (TypeDwordWidth) {
382 assert(!"USER_SGPR value size not implemented");
385 dstClass = &AMDGPU::SReg_32RegClass;
388 dstClass = &AMDGPU::SReg_64RegClass;
391 uint64_t Index = BasePtr->getZExtValue();
392 assert(Index % TypeDwordWidth == 0 && "USER_SGPR not properly aligned");
393 unsigned SGPRIndex = Index / TypeDwordWidth;
394 unsigned Reg = dstClass->getRegister(SGPRIndex);
396 DAG.ReplaceAllUsesOfValueWith(Op, CreateLiveInRegister(DAG, dstClass, Reg,
401 SDValue SITargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const {
402 SDValue LHS = Op.getOperand(0);
403 SDValue RHS = Op.getOperand(1);
404 SDValue True = Op.getOperand(2);
405 SDValue False = Op.getOperand(3);
406 SDValue CC = Op.getOperand(4);
407 EVT VT = Op.getValueType();
408 DebugLoc DL = Op.getDebugLoc();
410 // Possible Min/Max pattern
411 SDValue MinMax = LowerMinMax(Op, DAG);
412 if (MinMax.getNode()) {
416 SDValue Cond = DAG.getNode(ISD::SETCC, DL, MVT::i1, LHS, RHS, CC);
417 return DAG.getNode(ISD::SELECT, DL, VT, Cond, True, False);
420 //===----------------------------------------------------------------------===//
421 // Custom DAG optimizations
422 //===----------------------------------------------------------------------===//
424 SDValue SITargetLowering::PerformDAGCombine(SDNode *N,
425 DAGCombinerInfo &DCI) const {
426 SelectionDAG &DAG = DCI.DAG;
427 DebugLoc DL = N->getDebugLoc();
428 EVT VT = N->getValueType(0);
430 switch (N->getOpcode()) {
432 case ISD::SELECT_CC: {
434 ConstantSDNode *True, *False;
435 // i1 selectcc(l, r, -1, 0, cc) -> i1 setcc(l, r, cc)
436 if ((True = dyn_cast<ConstantSDNode>(N->getOperand(2)))
437 && (False = dyn_cast<ConstantSDNode>(N->getOperand(3)))
438 && True->isAllOnesValue()
439 && False->isNullValue()
441 return DAG.getNode(ISD::SETCC, DL, VT, N->getOperand(0),
442 N->getOperand(1), N->getOperand(4));
448 SDValue Arg0 = N->getOperand(0);
449 SDValue Arg1 = N->getOperand(1);
450 SDValue CC = N->getOperand(2);
451 ConstantSDNode * C = NULL;
452 ISD::CondCode CCOp = dyn_cast<CondCodeSDNode>(CC)->get();
454 // i1 setcc (sext(i1), 0, setne) -> i1 setcc(i1, 0, setne)
456 && Arg0.getOpcode() == ISD::SIGN_EXTEND
457 && Arg0.getOperand(0).getValueType() == MVT::i1
458 && (C = dyn_cast<ConstantSDNode>(Arg1))
460 && CCOp == ISD::SETNE) {
461 return SimplifySetCC(VT, Arg0.getOperand(0),
462 DAG.getConstant(0, MVT::i1), CCOp, true, DCI, DL);
470 /// \brief Test if RegClass is one of the VSrc classes
471 static bool isVSrc(unsigned RegClass) {
472 return AMDGPU::VSrc_32RegClassID == RegClass ||
473 AMDGPU::VSrc_64RegClassID == RegClass;
476 /// \brief Test if RegClass is one of the SSrc classes
477 static bool isSSrc(unsigned RegClass) {
478 return AMDGPU::SSrc_32RegClassID == RegClass ||
479 AMDGPU::SSrc_64RegClassID == RegClass;
482 /// \brief Analyze the possible immediate value Op
484 /// Returns -1 if it isn't an immediate, 0 if it's and inline immediate
485 /// and the immediate value if it's a literal immediate
486 int32_t SITargetLowering::analyzeImmediate(const SDNode *N) const {
493 if (const ConstantSDNode *Node = dyn_cast<ConstantSDNode>(N))
494 Imm.I = Node->getSExtValue();
495 else if (const ConstantFPSDNode *Node = dyn_cast<ConstantFPSDNode>(N))
496 Imm.F = Node->getValueAPF().convertToFloat();
498 return -1; // It isn't an immediate
500 if ((Imm.I >= -16 && Imm.I <= 64) ||
501 Imm.F == 0.5f || Imm.F == -0.5f ||
502 Imm.F == 1.0f || Imm.F == -1.0f ||
503 Imm.F == 2.0f || Imm.F == -2.0f ||
504 Imm.F == 4.0f || Imm.F == -4.0f)
505 return 0; // It's an inline immediate
507 return Imm.I; // It's a literal immediate
510 /// \brief Try to fold an immediate directly into an instruction
511 bool SITargetLowering::foldImm(SDValue &Operand, int32_t &Immediate,
512 bool &ScalarSlotUsed) const {
514 MachineSDNode *Mov = dyn_cast<MachineSDNode>(Operand);
515 if (Mov == 0 || !TII->isMov(Mov->getMachineOpcode()))
518 const SDValue &Op = Mov->getOperand(0);
519 int32_t Value = analyzeImmediate(Op.getNode());
521 // Not an immediate at all
524 } else if (Value == 0) {
525 // Inline immediates can always be fold
529 } else if (Value == Immediate) {
530 // Already fold literal immediate
534 } else if (!ScalarSlotUsed && !Immediate) {
535 // Fold this literal immediate
536 ScalarSlotUsed = true;
546 /// \brief Does "Op" fit into register class "RegClass" ?
547 bool SITargetLowering::fitsRegClass(SelectionDAG &DAG, SDValue &Op,
548 unsigned RegClass) const {
550 MachineRegisterInfo &MRI = DAG.getMachineFunction().getRegInfo();
551 SDNode *Node = Op.getNode();
554 if (MachineSDNode *MN = dyn_cast<MachineSDNode>(Node)) {
555 const MCInstrDesc &Desc = TII->get(MN->getMachineOpcode());
556 OpClass = Desc.OpInfo[Op.getResNo()].RegClass;
558 } else if (Node->getOpcode() == ISD::CopyFromReg) {
559 RegisterSDNode *Reg = cast<RegisterSDNode>(Node->getOperand(1).getNode());
560 OpClass = MRI.getRegClass(Reg->getReg())->getID();
568 return TRI->getRegClass(RegClass)->hasSubClassEq(TRI->getRegClass(OpClass));
571 /// \brief Make sure that we don't exeed the number of allowed scalars
572 void SITargetLowering::ensureSRegLimit(SelectionDAG &DAG, SDValue &Operand,
574 bool &ScalarSlotUsed) const {
576 // First map the operands register class to a destination class
577 if (RegClass == AMDGPU::VSrc_32RegClassID)
578 RegClass = AMDGPU::VReg_32RegClassID;
579 else if (RegClass == AMDGPU::VSrc_64RegClassID)
580 RegClass = AMDGPU::VReg_64RegClassID;
584 // Nothing todo if they fit naturaly
585 if (fitsRegClass(DAG, Operand, RegClass))
588 // If the scalar slot isn't used yet use it now
589 if (!ScalarSlotUsed) {
590 ScalarSlotUsed = true;
594 // This is a conservative aproach, it is possible that we can't determine
595 // the correct register class and copy too often, but better save than sorry.
596 SDValue RC = DAG.getTargetConstant(RegClass, MVT::i32);
597 SDNode *Node = DAG.getMachineNode(TargetOpcode::COPY_TO_REGCLASS, DebugLoc(),
598 Operand.getValueType(), Operand, RC);
599 Operand = SDValue(Node, 0);
602 SDNode *SITargetLowering::PostISelFolding(MachineSDNode *Node,
603 SelectionDAG &DAG) const {
605 // Original encoding (either e32 or e64)
606 int Opcode = Node->getMachineOpcode();
607 const MCInstrDesc *Desc = &TII->get(Opcode);
609 unsigned NumDefs = Desc->getNumDefs();
610 unsigned NumOps = Desc->getNumOperands();
612 // e64 version if available, -1 otherwise
613 int OpcodeE64 = AMDGPU::getVOPe64(Opcode);
614 const MCInstrDesc *DescE64 = OpcodeE64 == -1 ? 0 : &TII->get(OpcodeE64);
616 assert(!DescE64 || DescE64->getNumDefs() == NumDefs);
617 assert(!DescE64 || DescE64->getNumOperands() == (NumOps + 4));
619 int32_t Immediate = Desc->getSize() == 4 ? 0 : -1;
620 bool HaveVSrc = false, HaveSSrc = false;
622 // First figure out what we alread have in this instruction
623 for (unsigned i = 0, e = Node->getNumOperands(), Op = NumDefs;
624 i != e && Op < NumOps; ++i, ++Op) {
626 unsigned RegClass = Desc->OpInfo[Op].RegClass;
627 if (isVSrc(RegClass))
629 else if (isSSrc(RegClass))
634 int32_t Imm = analyzeImmediate(Node->getOperand(i).getNode());
635 if (Imm != -1 && Imm != 0) {
641 // If we neither have VSrc nor SSrc it makes no sense to continue
642 if (!HaveVSrc && !HaveSSrc)
645 // No scalar allowed when we have both VSrc and SSrc
646 bool ScalarSlotUsed = HaveVSrc && HaveSSrc;
648 // Second go over the operands and try to fold them
649 std::vector<SDValue> Ops;
650 bool Promote2e64 = false;
651 for (unsigned i = 0, e = Node->getNumOperands(), Op = NumDefs;
652 i != e && Op < NumOps; ++i, ++Op) {
654 const SDValue &Operand = Node->getOperand(i);
655 Ops.push_back(Operand);
657 // Already folded immediate ?
658 if (isa<ConstantSDNode>(Operand.getNode()) ||
659 isa<ConstantFPSDNode>(Operand.getNode()))
662 // Is this a VSrc or SSrc operand ?
663 unsigned RegClass = Desc->OpInfo[Op].RegClass;
664 if (!isVSrc(RegClass) && !isSSrc(RegClass)) {
666 if (i == 1 && Desc->isCommutable() &&
667 fitsRegClass(DAG, Ops[0], RegClass) &&
668 foldImm(Ops[1], Immediate, ScalarSlotUsed)) {
670 assert(isVSrc(Desc->OpInfo[NumDefs].RegClass) ||
671 isSSrc(Desc->OpInfo[NumDefs].RegClass));
673 // Swap commutable operands
674 SDValue Tmp = Ops[1];
678 } else if (DescE64 && !Immediate) {
679 // Test if it makes sense to switch to e64 encoding
681 RegClass = DescE64->OpInfo[Op].RegClass;
683 if ((isVSrc(RegClass) || isSSrc(RegClass)) &&
684 foldImm(Ops[i], TmpImm, ScalarSlotUsed)) {
695 // Try to fold the immediates
696 if (!foldImm(Ops[i], Immediate, ScalarSlotUsed)) {
697 // Folding didn't worked, make sure we don't hit the SReg limit
698 ensureSRegLimit(DAG, Ops[i], RegClass, ScalarSlotUsed);
703 // Add the modifier flags while promoting
704 for (unsigned i = 0; i < 4; ++i)
705 Ops.push_back(DAG.getTargetConstant(0, MVT::i32));
708 // Add optional chain and glue
709 for (unsigned i = NumOps - NumDefs, e = Node->getNumOperands(); i < e; ++i)
710 Ops.push_back(Node->getOperand(i));
712 // Either create a complete new or update the current instruction
714 return DAG.getMachineNode(OpcodeE64, Node->getDebugLoc(),
715 Node->getVTList(), Ops.data(), Ops.size());
717 return DAG.UpdateNodeOperands(Node, Ops.data(), Ops.size());