R600/SI: remove shader type intrinsic
[oota-llvm.git] / lib / Target / R600 / SIISelLowering.cpp
1 //===-- SIISelLowering.cpp - SI DAG Lowering Implementation ---------------===//
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 /// \file
11 /// \brief Custom DAG lowering for SI
12 //
13 //===----------------------------------------------------------------------===//
14
15 #include "SIISelLowering.h"
16 #include "AMDIL.h"
17 #include "AMDILIntrinsicInfo.h"
18 #include "SIInstrInfo.h"
19 #include "SIMachineFunctionInfo.h"
20 #include "SIRegisterInfo.h"
21 #include "llvm/CodeGen/MachineInstrBuilder.h"
22 #include "llvm/CodeGen/MachineRegisterInfo.h"
23 #include "llvm/CodeGen/SelectionDAG.h"
24
25 using namespace llvm;
26
27 SITargetLowering::SITargetLowering(TargetMachine &TM) :
28     AMDGPUTargetLowering(TM),
29     TII(static_cast<const SIInstrInfo*>(TM.getInstrInfo())),
30     TRI(TM.getRegisterInfo()) {
31
32   addRegisterClass(MVT::i1, &AMDGPU::SReg_64RegClass);
33   addRegisterClass(MVT::i64, &AMDGPU::SReg_64RegClass);
34
35   addRegisterClass(MVT::v16i8, &AMDGPU::SReg_128RegClass);
36   addRegisterClass(MVT::v32i8, &AMDGPU::SReg_256RegClass);
37   addRegisterClass(MVT::v64i8, &AMDGPU::SReg_512RegClass);
38
39   addRegisterClass(MVT::i32, &AMDGPU::VReg_32RegClass);
40   addRegisterClass(MVT::f32, &AMDGPU::VReg_32RegClass);
41
42   addRegisterClass(MVT::v1i32, &AMDGPU::VReg_32RegClass);
43
44   addRegisterClass(MVT::v2i32, &AMDGPU::VReg_64RegClass);
45   addRegisterClass(MVT::v2f32, &AMDGPU::VReg_64RegClass);
46
47   addRegisterClass(MVT::v4i32, &AMDGPU::VReg_128RegClass);
48   addRegisterClass(MVT::v4f32, &AMDGPU::VReg_128RegClass);
49
50   addRegisterClass(MVT::v8i32, &AMDGPU::VReg_256RegClass);
51   addRegisterClass(MVT::v8f32, &AMDGPU::VReg_256RegClass);
52
53   addRegisterClass(MVT::v16i32, &AMDGPU::VReg_512RegClass);
54   addRegisterClass(MVT::v16f32, &AMDGPU::VReg_512RegClass);
55
56   computeRegisterProperties();
57
58   setOperationAction(ISD::ADD, MVT::i64, Legal);
59   setOperationAction(ISD::ADD, MVT::i32, Legal);
60
61   setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);
62
63   // We need to custom lower loads from the USER_SGPR address space, so we can
64   // add the SGPRs as livein registers.
65   setOperationAction(ISD::LOAD, MVT::i32, Custom);
66   setOperationAction(ISD::LOAD, MVT::i64, Custom);
67
68   setOperationAction(ISD::SELECT_CC, MVT::f32, Custom);
69   setOperationAction(ISD::SELECT_CC, MVT::i32, Custom);
70
71   setOperationAction(ISD::SELECT_CC, MVT::Other, Expand);
72   setTargetDAGCombine(ISD::SELECT_CC);
73
74   setTargetDAGCombine(ISD::SETCC);
75 }
76
77 MachineBasicBlock * SITargetLowering::EmitInstrWithCustomInserter(
78     MachineInstr * MI, MachineBasicBlock * BB) const {
79   MachineRegisterInfo & MRI = BB->getParent()->getRegInfo();
80   MachineBasicBlock::iterator I = MI;
81
82   switch (MI->getOpcode()) {
83   default:
84     return AMDGPUTargetLowering::EmitInstrWithCustomInserter(MI, BB);
85   case AMDGPU::BRANCH: return BB;
86   case AMDGPU::SI_INTERP:
87     LowerSI_INTERP(MI, *BB, I, MRI);
88     break;
89   case AMDGPU::SI_WQM:
90     LowerSI_WQM(MI, *BB, I, MRI);
91     break;
92   }
93   return BB;
94 }
95
96 void SITargetLowering::LowerSI_WQM(MachineInstr *MI, MachineBasicBlock &BB,
97     MachineBasicBlock::iterator I, MachineRegisterInfo & MRI) const {
98   BuildMI(BB, I, BB.findDebugLoc(I), TII->get(AMDGPU::S_WQM_B64), AMDGPU::EXEC)
99           .addReg(AMDGPU::EXEC);
100
101   MI->eraseFromParent();
102 }
103
104 void SITargetLowering::LowerSI_INTERP(MachineInstr *MI, MachineBasicBlock &BB,
105     MachineBasicBlock::iterator I, MachineRegisterInfo & MRI) const {
106   unsigned tmp = MRI.createVirtualRegister(&AMDGPU::VReg_32RegClass);
107   unsigned M0 = MRI.createVirtualRegister(&AMDGPU::M0RegRegClass);
108   MachineOperand dst = MI->getOperand(0);
109   MachineOperand iReg = MI->getOperand(1);
110   MachineOperand jReg = MI->getOperand(2);
111   MachineOperand attr_chan = MI->getOperand(3);
112   MachineOperand attr = MI->getOperand(4);
113   MachineOperand params = MI->getOperand(5);
114
115   BuildMI(BB, I, BB.findDebugLoc(I), TII->get(AMDGPU::S_MOV_B32), M0)
116           .addOperand(params);
117
118   BuildMI(BB, I, BB.findDebugLoc(I), TII->get(AMDGPU::V_INTERP_P1_F32), tmp)
119           .addOperand(iReg)
120           .addOperand(attr_chan)
121           .addOperand(attr)
122           .addReg(M0);
123
124   BuildMI(BB, I, BB.findDebugLoc(I), TII->get(AMDGPU::V_INTERP_P2_F32))
125           .addOperand(dst)
126           .addReg(tmp)
127           .addOperand(jReg)
128           .addOperand(attr_chan)
129           .addOperand(attr)
130           .addReg(M0);
131
132   MI->eraseFromParent();
133 }
134
135 EVT SITargetLowering::getSetCCResultType(EVT VT) const {
136   return MVT::i1;
137 }
138
139 //===----------------------------------------------------------------------===//
140 // Custom DAG Lowering Operations
141 //===----------------------------------------------------------------------===//
142
143 SDValue SITargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG) const {
144   switch (Op.getOpcode()) {
145   default: return AMDGPUTargetLowering::LowerOperation(Op, DAG);
146   case ISD::BRCOND: return LowerBRCOND(Op, DAG);
147   case ISD::LOAD: return LowerLOAD(Op, DAG);
148   case ISD::SELECT_CC: return LowerSELECT_CC(Op, DAG);
149   case ISD::INTRINSIC_WO_CHAIN: {
150     unsigned IntrinsicID =
151                          cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
152     EVT VT = Op.getValueType();
153     switch (IntrinsicID) {
154     case AMDGPUIntrinsic::SI_vs_load_buffer_index:
155       return CreateLiveInRegister(DAG, &AMDGPU::VReg_32RegClass,
156                                   AMDGPU::VGPR0, VT);
157     default: return AMDGPUTargetLowering::LowerOperation(Op, DAG);
158     }
159     break;
160   }
161   }
162   return SDValue();
163 }
164
165 /// \brief Helper function for LowerBRCOND
166 static SDNode *findUser(SDValue Value, unsigned Opcode) {
167
168   SDNode *Parent = Value.getNode();
169   for (SDNode::use_iterator I = Parent->use_begin(), E = Parent->use_end();
170        I != E; ++I) {
171
172     if (I.getUse().get() != Value)
173       continue;
174
175     if (I->getOpcode() == Opcode)
176       return *I;
177   }
178   return 0;
179 }
180
181 /// This transforms the control flow intrinsics to get the branch destination as
182 /// last parameter, also switches branch target with BR if the need arise
183 SDValue SITargetLowering::LowerBRCOND(SDValue BRCOND,
184                                       SelectionDAG &DAG) const {
185
186   DebugLoc DL = BRCOND.getDebugLoc();
187
188   SDNode *Intr = BRCOND.getOperand(1).getNode();
189   SDValue Target = BRCOND.getOperand(2);
190   SDNode *BR = 0;
191
192   if (Intr->getOpcode() == ISD::SETCC) {
193     // As long as we negate the condition everything is fine
194     SDNode *SetCC = Intr;
195     assert(SetCC->getConstantOperandVal(1) == 1);
196     assert(cast<CondCodeSDNode>(SetCC->getOperand(2).getNode())->get() ==
197            ISD::SETNE);
198     Intr = SetCC->getOperand(0).getNode();
199
200   } else {
201     // Get the target from BR if we don't negate the condition
202     BR = findUser(BRCOND, ISD::BR);
203     Target = BR->getOperand(1);
204   }
205
206   assert(Intr->getOpcode() == ISD::INTRINSIC_W_CHAIN);
207
208   // Build the result and
209   SmallVector<EVT, 4> Res;
210   for (unsigned i = 1, e = Intr->getNumValues(); i != e; ++i)
211     Res.push_back(Intr->getValueType(i));
212
213   // operands of the new intrinsic call
214   SmallVector<SDValue, 4> Ops;
215   Ops.push_back(BRCOND.getOperand(0));
216   for (unsigned i = 1, e = Intr->getNumOperands(); i != e; ++i)
217     Ops.push_back(Intr->getOperand(i));
218   Ops.push_back(Target);
219
220   // build the new intrinsic call
221   SDNode *Result = DAG.getNode(
222     Res.size() > 1 ? ISD::INTRINSIC_W_CHAIN : ISD::INTRINSIC_VOID, DL,
223     DAG.getVTList(Res.data(), Res.size()), Ops.data(), Ops.size()).getNode();
224
225   if (BR) {
226     // Give the branch instruction our target
227     SDValue Ops[] = {
228       BR->getOperand(0),
229       BRCOND.getOperand(2)
230     };
231     DAG.MorphNodeTo(BR, ISD::BR, BR->getVTList(), Ops, 2);
232   }
233
234   SDValue Chain = SDValue(Result, Result->getNumValues() - 1);
235
236   // Copy the intrinsic results to registers
237   for (unsigned i = 1, e = Intr->getNumValues() - 1; i != e; ++i) {
238     SDNode *CopyToReg = findUser(SDValue(Intr, i), ISD::CopyToReg);
239     if (!CopyToReg)
240       continue;
241
242     Chain = DAG.getCopyToReg(
243       Chain, DL,
244       CopyToReg->getOperand(1),
245       SDValue(Result, i - 1),
246       SDValue());
247
248     DAG.ReplaceAllUsesWith(SDValue(CopyToReg, 0), CopyToReg->getOperand(0));
249   }
250
251   // Remove the old intrinsic from the chain
252   DAG.ReplaceAllUsesOfValueWith(
253     SDValue(Intr, Intr->getNumValues() - 1),
254     Intr->getOperand(0));
255
256   return Chain;
257 }
258
259 SDValue SITargetLowering::LowerLOAD(SDValue Op, SelectionDAG &DAG) const {
260   EVT VT = Op.getValueType();
261   LoadSDNode *Ptr = dyn_cast<LoadSDNode>(Op);
262
263   assert(Ptr);
264
265   unsigned AddrSpace = Ptr->getPointerInfo().getAddrSpace();
266
267   // We only need to lower USER_SGPR address space loads
268   if (AddrSpace != AMDGPUAS::USER_SGPR_ADDRESS) {
269     return SDValue();
270   }
271
272   // Loads from the USER_SGPR address space can only have constant value
273   // pointers.
274   ConstantSDNode *BasePtr = dyn_cast<ConstantSDNode>(Ptr->getBasePtr());
275   assert(BasePtr);
276
277   unsigned TypeDwordWidth = VT.getSizeInBits() / 32;
278   const TargetRegisterClass * dstClass;
279   switch (TypeDwordWidth) {
280     default:
281       assert(!"USER_SGPR value size not implemented");
282       return SDValue();
283     case 1:
284       dstClass = &AMDGPU::SReg_32RegClass;
285       break;
286     case 2:
287       dstClass = &AMDGPU::SReg_64RegClass;
288       break;
289   }
290   uint64_t Index = BasePtr->getZExtValue();
291   assert(Index % TypeDwordWidth == 0 && "USER_SGPR not properly aligned");
292   unsigned SGPRIndex = Index / TypeDwordWidth;
293   unsigned Reg = dstClass->getRegister(SGPRIndex);
294
295   DAG.ReplaceAllUsesOfValueWith(Op, CreateLiveInRegister(DAG, dstClass, Reg,
296                                                          VT));
297   return SDValue();
298 }
299
300 SDValue SITargetLowering::LowerSELECT_CC(SDValue Op, SelectionDAG &DAG) const {
301   SDValue LHS = Op.getOperand(0);
302   SDValue RHS = Op.getOperand(1);
303   SDValue True = Op.getOperand(2);
304   SDValue False = Op.getOperand(3);
305   SDValue CC = Op.getOperand(4);
306   EVT VT = Op.getValueType();
307   DebugLoc DL = Op.getDebugLoc();
308
309   // Possible Min/Max pattern
310   SDValue MinMax = LowerMinMax(Op, DAG);
311   if (MinMax.getNode()) {
312     return MinMax;
313   }
314
315   SDValue Cond = DAG.getNode(ISD::SETCC, DL, MVT::i1, LHS, RHS, CC);
316   return DAG.getNode(ISD::SELECT, DL, VT, Cond, True, False);
317 }
318
319 //===----------------------------------------------------------------------===//
320 // Custom DAG optimizations
321 //===----------------------------------------------------------------------===//
322
323 SDValue SITargetLowering::PerformDAGCombine(SDNode *N,
324                                             DAGCombinerInfo &DCI) const {
325   SelectionDAG &DAG = DCI.DAG;
326   DebugLoc DL = N->getDebugLoc();
327   EVT VT = N->getValueType(0);
328
329   switch (N->getOpcode()) {
330     default: break;
331     case ISD::SELECT_CC: {
332       N->dump();
333       ConstantSDNode *True, *False;
334       // i1 selectcc(l, r, -1, 0, cc) -> i1 setcc(l, r, cc)
335       if ((True = dyn_cast<ConstantSDNode>(N->getOperand(2)))
336           && (False = dyn_cast<ConstantSDNode>(N->getOperand(3)))
337           && True->isAllOnesValue()
338           && False->isNullValue()
339           && VT == MVT::i1) {
340         return DAG.getNode(ISD::SETCC, DL, VT, N->getOperand(0),
341                            N->getOperand(1), N->getOperand(4));
342
343       }
344       break;
345     }
346     case ISD::SETCC: {
347       SDValue Arg0 = N->getOperand(0);
348       SDValue Arg1 = N->getOperand(1);
349       SDValue CC = N->getOperand(2);
350       ConstantSDNode * C = NULL;
351       ISD::CondCode CCOp = dyn_cast<CondCodeSDNode>(CC)->get();
352
353       // i1 setcc (sext(i1), 0, setne) -> i1 setcc(i1, 0, setne)
354       if (VT == MVT::i1
355           && Arg0.getOpcode() == ISD::SIGN_EXTEND
356           && Arg0.getOperand(0).getValueType() == MVT::i1
357           && (C = dyn_cast<ConstantSDNode>(Arg1))
358           && C->isNullValue()
359           && CCOp == ISD::SETNE) {
360         return SimplifySetCC(VT, Arg0.getOperand(0),
361                              DAG.getConstant(0, MVT::i1), CCOp, true, DCI, DL);
362       }
363       break;
364     }
365   }
366   return SDValue();
367 }
368
369 /// \brief Test if RegClass is one of the VSrc classes 
370 static bool isVSrc(unsigned RegClass) {
371   return AMDGPU::VSrc_32RegClassID == RegClass ||
372          AMDGPU::VSrc_64RegClassID == RegClass;
373 }
374
375 /// \brief Test if RegClass is one of the SSrc classes 
376 static bool isSSrc(unsigned RegClass) {
377   return AMDGPU::SSrc_32RegClassID == RegClass ||
378          AMDGPU::SSrc_64RegClassID == RegClass;
379 }
380
381 /// \brief Analyze the possible immediate value Op
382 ///
383 /// Returns -1 if it isn't an immediate, 0 if it's and inline immediate
384 /// and the immediate value if it's a literal immediate
385 int32_t SITargetLowering::analyzeImmediate(const SDNode *N) const {
386
387   union {
388     int32_t I;
389     float F;
390   } Imm;
391
392   if (const ConstantSDNode *Node = dyn_cast<ConstantSDNode>(N))
393     Imm.I = Node->getSExtValue();
394   else if (const ConstantFPSDNode *Node = dyn_cast<ConstantFPSDNode>(N))
395     Imm.F = Node->getValueAPF().convertToFloat();
396   else
397     return -1; // It isn't an immediate
398
399   if ((Imm.I >= -16 && Imm.I <= 64) ||
400       Imm.F == 0.5f || Imm.F == -0.5f ||
401       Imm.F == 1.0f || Imm.F == -1.0f ||
402       Imm.F == 2.0f || Imm.F == -2.0f ||
403       Imm.F == 4.0f || Imm.F == -4.0f)
404     return 0; // It's an inline immediate
405
406   return Imm.I; // It's a literal immediate
407 }
408
409 /// \brief Try to fold an immediate directly into an instruction
410 bool SITargetLowering::foldImm(SDValue &Operand, int32_t &Immediate,
411                                bool &ScalarSlotUsed) const {
412
413   MachineSDNode *Mov = dyn_cast<MachineSDNode>(Operand);
414   if (Mov == 0 || !TII->isMov(Mov->getMachineOpcode()))
415     return false;
416
417   const SDValue &Op = Mov->getOperand(0);
418   int32_t Value = analyzeImmediate(Op.getNode());
419   if (Value == -1) {
420     // Not an immediate at all
421     return false;
422
423   } else if (Value == 0) {
424     // Inline immediates can always be fold
425     Operand = Op;
426     return true;
427
428   } else if (Value == Immediate) {
429     // Already fold literal immediate
430     Operand = Op;
431     return true;
432
433   } else if (!ScalarSlotUsed && !Immediate) {
434     // Fold this literal immediate
435     ScalarSlotUsed = true;
436     Immediate = Value;
437     Operand = Op;
438     return true;
439
440   }
441
442   return false;
443 }
444
445 /// \brief Does "Op" fit into register class "RegClass" ?
446 bool SITargetLowering::fitsRegClass(SelectionDAG &DAG, SDValue &Op,
447                                     unsigned RegClass) const {
448
449   MachineRegisterInfo &MRI = DAG.getMachineFunction().getRegInfo(); 
450   SDNode *Node = Op.getNode();
451
452   int OpClass;
453   if (MachineSDNode *MN = dyn_cast<MachineSDNode>(Node)) {
454     const MCInstrDesc &Desc = TII->get(MN->getMachineOpcode());
455     OpClass = Desc.OpInfo[Op.getResNo()].RegClass;
456
457   } else if (Node->getOpcode() == ISD::CopyFromReg) {
458     RegisterSDNode *Reg = cast<RegisterSDNode>(Node->getOperand(1).getNode());
459     OpClass = MRI.getRegClass(Reg->getReg())->getID();
460
461   } else
462     return false;
463
464   if (OpClass == -1)
465     return false;
466
467   return TRI->getRegClass(RegClass)->hasSubClassEq(TRI->getRegClass(OpClass));
468 }
469
470 /// \brief Make sure that we don't exeed the number of allowed scalars
471 void SITargetLowering::ensureSRegLimit(SelectionDAG &DAG, SDValue &Operand,
472                                        unsigned RegClass,
473                                        bool &ScalarSlotUsed) const {
474
475   // First map the operands register class to a destination class
476   if (RegClass == AMDGPU::VSrc_32RegClassID)
477     RegClass = AMDGPU::VReg_32RegClassID;
478   else if (RegClass == AMDGPU::VSrc_64RegClassID)
479     RegClass = AMDGPU::VReg_64RegClassID;
480   else
481     return;
482
483   // Nothing todo if they fit naturaly
484   if (fitsRegClass(DAG, Operand, RegClass))
485     return;
486
487   // If the scalar slot isn't used yet use it now
488   if (!ScalarSlotUsed) {
489     ScalarSlotUsed = true;
490     return;
491   }
492
493   // This is a conservative aproach, it is possible that we can't determine
494   // the correct register class and copy too often, but better save than sorry.
495   SDValue RC = DAG.getTargetConstant(RegClass, MVT::i32);
496   SDNode *Node = DAG.getMachineNode(TargetOpcode::COPY_TO_REGCLASS, DebugLoc(),
497                                     Operand.getValueType(), Operand, RC);
498   Operand = SDValue(Node, 0);
499 }
500
501 SDNode *SITargetLowering::PostISelFolding(MachineSDNode *Node,
502                                           SelectionDAG &DAG) const {
503
504   // Original encoding (either e32 or e64)
505   int Opcode = Node->getMachineOpcode();
506   const MCInstrDesc *Desc = &TII->get(Opcode);
507
508   unsigned NumDefs = Desc->getNumDefs();
509   unsigned NumOps = Desc->getNumOperands();
510
511   // e64 version if available, -1 otherwise
512   int OpcodeE64 = AMDGPU::getVOPe64(Opcode);
513   const MCInstrDesc *DescE64 = OpcodeE64 == -1 ? 0 : &TII->get(OpcodeE64);
514
515   assert(!DescE64 || DescE64->getNumDefs() == NumDefs);
516   assert(!DescE64 || DescE64->getNumOperands() == (NumOps + 4));
517
518   int32_t Immediate = Desc->getSize() == 4 ? 0 : -1;
519   bool HaveVSrc = false, HaveSSrc = false;
520
521   // First figure out what we alread have in this instruction
522   for (unsigned i = 0, e = Node->getNumOperands(), Op = NumDefs;
523        i != e && Op < NumOps; ++i, ++Op) {
524
525     unsigned RegClass = Desc->OpInfo[Op].RegClass;
526     if (isVSrc(RegClass))
527       HaveVSrc = true;
528     else if (isSSrc(RegClass))
529       HaveSSrc = true;
530     else
531       continue;
532
533     int32_t Imm = analyzeImmediate(Node->getOperand(i).getNode());
534     if (Imm != -1 && Imm != 0) {
535       // Literal immediate
536       Immediate = Imm;
537     }
538   }
539
540   // If we neither have VSrc nor SSrc it makes no sense to continue
541   if (!HaveVSrc && !HaveSSrc)
542     return Node;
543
544   // No scalar allowed when we have both VSrc and SSrc
545   bool ScalarSlotUsed = HaveVSrc && HaveSSrc;
546
547   // Second go over the operands and try to fold them
548   std::vector<SDValue> Ops;
549   bool Promote2e64 = false;
550   for (unsigned i = 0, e = Node->getNumOperands(), Op = NumDefs;
551        i != e && Op < NumOps; ++i, ++Op) {
552
553     const SDValue &Operand = Node->getOperand(i);
554     Ops.push_back(Operand);
555
556     // Already folded immediate ?
557     if (isa<ConstantSDNode>(Operand.getNode()) ||
558         isa<ConstantFPSDNode>(Operand.getNode()))
559       continue;
560
561     // Is this a VSrc or SSrc operand ?
562     unsigned RegClass = Desc->OpInfo[Op].RegClass;
563     if (!isVSrc(RegClass) && !isSSrc(RegClass)) {
564
565       if (i == 1 && Desc->isCommutable() &&
566           fitsRegClass(DAG, Ops[0], RegClass) &&
567           foldImm(Ops[1], Immediate, ScalarSlotUsed)) {
568
569         assert(isVSrc(Desc->OpInfo[NumDefs].RegClass) ||
570                isSSrc(Desc->OpInfo[NumDefs].RegClass));
571
572         // Swap commutable operands
573         SDValue Tmp = Ops[1];
574         Ops[1] = Ops[0];
575         Ops[0] = Tmp;
576
577       } else if (DescE64 && !Immediate) {
578         // Test if it makes sense to switch to e64 encoding
579
580         RegClass = DescE64->OpInfo[Op].RegClass;
581         int32_t TmpImm = -1;
582         if ((isVSrc(RegClass) || isSSrc(RegClass)) &&
583             foldImm(Ops[i], TmpImm, ScalarSlotUsed)) {
584
585           Immediate = -1;
586           Promote2e64 = true;
587           Desc = DescE64;
588           DescE64 = 0;
589         }
590       }
591       continue;
592     }
593
594     // Try to fold the immediates
595     if (!foldImm(Ops[i], Immediate, ScalarSlotUsed)) {
596       // Folding didn't worked, make sure we don't hit the SReg limit
597       ensureSRegLimit(DAG, Ops[i], RegClass, ScalarSlotUsed);
598     }
599   }
600
601   if (Promote2e64) {
602     // Add the modifier flags while promoting
603     for (unsigned i = 0; i < 4; ++i)
604       Ops.push_back(DAG.getTargetConstant(0, MVT::i32));
605   }
606
607   // Add optional chain and glue
608   for (unsigned i = NumOps - NumDefs, e = Node->getNumOperands(); i < e; ++i)
609     Ops.push_back(Node->getOperand(i));
610
611   // Either create a complete new or update the current instruction
612   if (Promote2e64)
613     return DAG.getMachineNode(OpcodeE64, Node->getDebugLoc(),
614                               Node->getVTList(), Ops.data(), Ops.size());
615   else
616     return DAG.UpdateNodeOperands(Node, Ops.data(), Ops.size());
617 }