[AArch64] Fix NZCV reg live-in bug in F128CSEL codegen.
[oota-llvm.git] / lib / Target / R600 / AMDGPUISelDAGToDAG.cpp
1 //===-- AMDILISelDAGToDAG.cpp - A dag to dag inst selector for AMDIL ------===//
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 Defines an instruction selector for the AMDGPU target.
12 //
13 //===----------------------------------------------------------------------===//
14 #include "AMDGPUInstrInfo.h"
15 #include "AMDGPUISelLowering.h" // For AMDGPUISD
16 #include "AMDGPURegisterInfo.h"
17 #include "R600InstrInfo.h"
18 #include "SIISelLowering.h"
19 #include "llvm/ADT/ValueMap.h"
20 #include "llvm/Analysis/ValueTracking.h"
21 #include "llvm/CodeGen/MachineRegisterInfo.h"
22 #include "llvm/CodeGen/PseudoSourceValue.h"
23 #include "llvm/CodeGen/SelectionDAG.h"
24 #include "llvm/CodeGen/SelectionDAGISel.h"
25 #include "llvm/Support/Compiler.h"
26 #include <list>
27 #include <queue>
28
29 using namespace llvm;
30
31 //===----------------------------------------------------------------------===//
32 // Instruction Selector Implementation
33 //===----------------------------------------------------------------------===//
34
35 namespace {
36 /// AMDGPU specific code to select AMDGPU machine instructions for
37 /// SelectionDAG operations.
38 class AMDGPUDAGToDAGISel : public SelectionDAGISel {
39   // Subtarget - Keep a pointer to the AMDGPU Subtarget around so that we can
40   // make the right decision when generating code for different targets.
41   const AMDGPUSubtarget &Subtarget;
42 public:
43   AMDGPUDAGToDAGISel(TargetMachine &TM);
44   virtual ~AMDGPUDAGToDAGISel();
45
46   SDNode *Select(SDNode *N);
47   virtual const char *getPassName() const;
48   virtual void PostprocessISelDAG();
49
50 private:
51   inline SDValue getSmallIPtrImm(unsigned Imm);
52   bool FoldOperand(SDValue &Src, SDValue &Sel, SDValue &Neg, SDValue &Abs,
53                    const R600InstrInfo *TII);
54   bool FoldOperands(unsigned, const R600InstrInfo *, std::vector<SDValue> &);
55   bool FoldDotOperands(unsigned, const R600InstrInfo *, std::vector<SDValue> &);
56
57   // Complex pattern selectors
58   bool SelectADDRParam(SDValue Addr, SDValue& R1, SDValue& R2);
59   bool SelectADDR(SDValue N, SDValue &R1, SDValue &R2);
60   bool SelectADDR64(SDValue N, SDValue &R1, SDValue &R2);
61   SDValue SimplifyI24(SDValue &Op);
62   bool SelectI24(SDValue Addr, SDValue &Op);
63   bool SelectU24(SDValue Addr, SDValue &Op);
64
65   static bool checkType(const Value *ptr, unsigned int addrspace);
66
67   static bool isGlobalStore(const StoreSDNode *N);
68   static bool isPrivateStore(const StoreSDNode *N);
69   static bool isLocalStore(const StoreSDNode *N);
70   static bool isRegionStore(const StoreSDNode *N);
71
72   bool isCPLoad(const LoadSDNode *N) const;
73   bool isConstantLoad(const LoadSDNode *N, int cbID) const;
74   bool isGlobalLoad(const LoadSDNode *N) const;
75   bool isParamLoad(const LoadSDNode *N) const;
76   bool isPrivateLoad(const LoadSDNode *N) const;
77   bool isLocalLoad(const LoadSDNode *N) const;
78   bool isRegionLoad(const LoadSDNode *N) const;
79
80   const TargetRegisterClass *getOperandRegClass(SDNode *N, unsigned OpNo) const;
81   bool SelectGlobalValueConstantOffset(SDValue Addr, SDValue& IntPtr);
82   bool SelectGlobalValueVariableOffset(SDValue Addr,
83       SDValue &BaseReg, SDValue& Offset);
84   bool SelectADDRVTX_READ(SDValue Addr, SDValue &Base, SDValue &Offset);
85   bool SelectADDRIndirect(SDValue Addr, SDValue &Base, SDValue &Offset);
86
87   // Include the pieces autogenerated from the target description.
88 #include "AMDGPUGenDAGISel.inc"
89 };
90 }  // end anonymous namespace
91
92 /// \brief This pass converts a legalized DAG into a AMDGPU-specific
93 // DAG, ready for instruction scheduling.
94 FunctionPass *llvm::createAMDGPUISelDag(TargetMachine &TM
95                                        ) {
96   return new AMDGPUDAGToDAGISel(TM);
97 }
98
99 AMDGPUDAGToDAGISel::AMDGPUDAGToDAGISel(TargetMachine &TM)
100   : SelectionDAGISel(TM), Subtarget(TM.getSubtarget<AMDGPUSubtarget>()) {
101 }
102
103 AMDGPUDAGToDAGISel::~AMDGPUDAGToDAGISel() {
104 }
105
106 /// \brief Determine the register class for \p OpNo
107 /// \returns The register class of the virtual register that will be used for
108 /// the given operand number \OpNo or NULL if the register class cannot be
109 /// determined.
110 const TargetRegisterClass *AMDGPUDAGToDAGISel::getOperandRegClass(SDNode *N,
111                                                           unsigned OpNo) const {
112   if (!N->isMachineOpcode()) {
113     return NULL;
114   }
115   switch (N->getMachineOpcode()) {
116   default: {
117     const MCInstrDesc &Desc = TM.getInstrInfo()->get(N->getMachineOpcode());
118     unsigned OpIdx = Desc.getNumDefs() + OpNo;
119     if (OpIdx >= Desc.getNumOperands())
120       return NULL;
121     int RegClass = Desc.OpInfo[OpIdx].RegClass;
122     if (RegClass == -1) {
123       return NULL;
124     }
125     return TM.getRegisterInfo()->getRegClass(RegClass);
126   }
127   case AMDGPU::REG_SEQUENCE: {
128     const TargetRegisterClass *SuperRC = TM.getRegisterInfo()->getRegClass(
129                       cast<ConstantSDNode>(N->getOperand(0))->getZExtValue());
130     unsigned SubRegIdx =
131             dyn_cast<ConstantSDNode>(N->getOperand(OpNo + 1))->getZExtValue();
132     return TM.getRegisterInfo()->getSubClassWithSubReg(SuperRC, SubRegIdx);
133   }
134   }
135 }
136
137 SDValue AMDGPUDAGToDAGISel::getSmallIPtrImm(unsigned int Imm) {
138   return CurDAG->getTargetConstant(Imm, MVT::i32);
139 }
140
141 bool AMDGPUDAGToDAGISel::SelectADDRParam(
142     SDValue Addr, SDValue& R1, SDValue& R2) {
143
144   if (Addr.getOpcode() == ISD::FrameIndex) {
145     if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
146       R1 = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i32);
147       R2 = CurDAG->getTargetConstant(0, MVT::i32);
148     } else {
149       R1 = Addr;
150       R2 = CurDAG->getTargetConstant(0, MVT::i32);
151     }
152   } else if (Addr.getOpcode() == ISD::ADD) {
153     R1 = Addr.getOperand(0);
154     R2 = Addr.getOperand(1);
155   } else {
156     R1 = Addr;
157     R2 = CurDAG->getTargetConstant(0, MVT::i32);
158   }
159   return true;
160 }
161
162 bool AMDGPUDAGToDAGISel::SelectADDR(SDValue Addr, SDValue& R1, SDValue& R2) {
163   if (Addr.getOpcode() == ISD::TargetExternalSymbol ||
164       Addr.getOpcode() == ISD::TargetGlobalAddress) {
165     return false;
166   }
167   return SelectADDRParam(Addr, R1, R2);
168 }
169
170
171 bool AMDGPUDAGToDAGISel::SelectADDR64(SDValue Addr, SDValue& R1, SDValue& R2) {
172   if (Addr.getOpcode() == ISD::TargetExternalSymbol ||
173       Addr.getOpcode() == ISD::TargetGlobalAddress) {
174     return false;
175   }
176
177   if (Addr.getOpcode() == ISD::FrameIndex) {
178     if (FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Addr)) {
179       R1 = CurDAG->getTargetFrameIndex(FIN->getIndex(), MVT::i64);
180       R2 = CurDAG->getTargetConstant(0, MVT::i64);
181     } else {
182       R1 = Addr;
183       R2 = CurDAG->getTargetConstant(0, MVT::i64);
184     }
185   } else if (Addr.getOpcode() == ISD::ADD) {
186     R1 = Addr.getOperand(0);
187     R2 = Addr.getOperand(1);
188   } else {
189     R1 = Addr;
190     R2 = CurDAG->getTargetConstant(0, MVT::i64);
191   }
192   return true;
193 }
194
195 SDNode *AMDGPUDAGToDAGISel::Select(SDNode *N) {
196   unsigned int Opc = N->getOpcode();
197   if (N->isMachineOpcode()) {
198     N->setNodeId(-1);
199     return NULL;   // Already selected.
200   }
201   switch (Opc) {
202   default: break;
203   case ISD::BUILD_VECTOR: {
204     unsigned RegClassID;
205     const AMDGPUSubtarget &ST = TM.getSubtarget<AMDGPUSubtarget>();
206     const AMDGPURegisterInfo *TRI =
207                    static_cast<const AMDGPURegisterInfo*>(TM.getRegisterInfo());
208     const SIRegisterInfo *SIRI =
209                    static_cast<const SIRegisterInfo*>(TM.getRegisterInfo());
210     EVT VT = N->getValueType(0);
211     unsigned NumVectorElts = VT.getVectorNumElements();
212     assert(VT.getVectorElementType().bitsEq(MVT::i32));
213     if (ST.getGeneration() >= AMDGPUSubtarget::SOUTHERN_ISLANDS) {
214       bool UseVReg = true;
215       for (SDNode::use_iterator U = N->use_begin(), E = SDNode::use_end();
216                                                     U != E; ++U) {
217         if (!U->isMachineOpcode()) {
218           continue;
219         }
220         const TargetRegisterClass *RC = getOperandRegClass(*U, U.getOperandNo());
221         if (!RC) {
222           continue;
223         }
224         if (SIRI->isSGPRClass(RC)) {
225           UseVReg = false;
226         }
227       }
228       switch(NumVectorElts) {
229       case 1: RegClassID = UseVReg ? AMDGPU::VReg_32RegClassID :
230                                      AMDGPU::SReg_32RegClassID;
231         break;
232       case 2: RegClassID = UseVReg ? AMDGPU::VReg_64RegClassID :
233                                      AMDGPU::SReg_64RegClassID;
234         break;
235       case 4: RegClassID = UseVReg ? AMDGPU::VReg_128RegClassID :
236                                      AMDGPU::SReg_128RegClassID;
237         break;
238       case 8: RegClassID = UseVReg ? AMDGPU::VReg_256RegClassID :
239                                      AMDGPU::SReg_256RegClassID;
240         break;
241       case 16: RegClassID = UseVReg ? AMDGPU::VReg_512RegClassID :
242                                       AMDGPU::SReg_512RegClassID;
243         break;
244       default: llvm_unreachable("Do not know how to lower this BUILD_VECTOR");
245       }
246     } else {
247       // BUILD_VECTOR was lowered into an IMPLICIT_DEF + 4 INSERT_SUBREG
248       // that adds a 128 bits reg copy when going through TwoAddressInstructions
249       // pass. We want to avoid 128 bits copies as much as possible because they
250       // can't be bundled by our scheduler.
251       switch(NumVectorElts) {
252       case 2: RegClassID = AMDGPU::R600_Reg64RegClassID; break;
253       case 4: RegClassID = AMDGPU::R600_Reg128RegClassID; break;
254       default: llvm_unreachable("Do not know how to lower this BUILD_VECTOR");
255       }
256     }
257
258     SDValue RegClass = CurDAG->getTargetConstant(RegClassID, MVT::i32);
259
260     if (NumVectorElts == 1) {
261       return CurDAG->SelectNodeTo(N, AMDGPU::COPY_TO_REGCLASS,
262                                   VT.getVectorElementType(),
263                                   N->getOperand(0), RegClass);
264     }
265
266     assert(NumVectorElts <= 16 && "Vectors with more than 16 elements not "
267                                   "supported yet");
268     // 16 = Max Num Vector Elements
269     // 2 = 2 REG_SEQUENCE operands per element (value, subreg index)
270     // 1 = Vector Register Class
271     SDValue RegSeqArgs[16 * 2 + 1];
272
273     RegSeqArgs[0] = CurDAG->getTargetConstant(RegClassID, MVT::i32);
274     bool IsRegSeq = true;
275     for (unsigned i = 0; i < N->getNumOperands(); i++) {
276       // XXX: Why is this here?
277       if (dyn_cast<RegisterSDNode>(N->getOperand(i))) {
278         IsRegSeq = false;
279         break;
280       }
281       RegSeqArgs[1 + (2 * i)] = N->getOperand(i);
282       RegSeqArgs[1 + (2 * i) + 1] =
283               CurDAG->getTargetConstant(TRI->getSubRegFromChannel(i), MVT::i32);
284     }
285     if (!IsRegSeq)
286       break;
287     return CurDAG->SelectNodeTo(N, AMDGPU::REG_SEQUENCE, N->getVTList(),
288         RegSeqArgs, 2 * N->getNumOperands() + 1);
289   }
290   case ISD::BUILD_PAIR: {
291     SDValue RC, SubReg0, SubReg1;
292     const AMDGPUSubtarget &ST = TM.getSubtarget<AMDGPUSubtarget>();
293     if (ST.getGeneration() <= AMDGPUSubtarget::NORTHERN_ISLANDS) {
294       break;
295     }
296     if (N->getValueType(0) == MVT::i128) {
297       RC = CurDAG->getTargetConstant(AMDGPU::SReg_128RegClassID, MVT::i32);
298       SubReg0 = CurDAG->getTargetConstant(AMDGPU::sub0_sub1, MVT::i32);
299       SubReg1 = CurDAG->getTargetConstant(AMDGPU::sub2_sub3, MVT::i32);
300     } else if (N->getValueType(0) == MVT::i64) {
301       RC = CurDAG->getTargetConstant(AMDGPU::VSrc_64RegClassID, MVT::i32);
302       SubReg0 = CurDAG->getTargetConstant(AMDGPU::sub0, MVT::i32);
303       SubReg1 = CurDAG->getTargetConstant(AMDGPU::sub1, MVT::i32);
304     } else {
305       llvm_unreachable("Unhandled value type for BUILD_PAIR");
306     }
307     const SDValue Ops[] = { RC, N->getOperand(0), SubReg0,
308                             N->getOperand(1), SubReg1 };
309     return CurDAG->getMachineNode(TargetOpcode::REG_SEQUENCE,
310                                   SDLoc(N), N->getValueType(0), Ops);
311   }
312   }
313   return SelectCode(N);
314 }
315
316
317 bool AMDGPUDAGToDAGISel::checkType(const Value *ptr, unsigned int addrspace) {
318   if (!ptr) {
319     return false;
320   }
321   Type *ptrType = ptr->getType();
322   return dyn_cast<PointerType>(ptrType)->getAddressSpace() == addrspace;
323 }
324
325 bool AMDGPUDAGToDAGISel::isGlobalStore(const StoreSDNode *N) {
326   return checkType(N->getSrcValue(), AMDGPUAS::GLOBAL_ADDRESS);
327 }
328
329 bool AMDGPUDAGToDAGISel::isPrivateStore(const StoreSDNode *N) {
330   return (!checkType(N->getSrcValue(), AMDGPUAS::LOCAL_ADDRESS)
331           && !checkType(N->getSrcValue(), AMDGPUAS::GLOBAL_ADDRESS)
332           && !checkType(N->getSrcValue(), AMDGPUAS::REGION_ADDRESS));
333 }
334
335 bool AMDGPUDAGToDAGISel::isLocalStore(const StoreSDNode *N) {
336   return checkType(N->getSrcValue(), AMDGPUAS::LOCAL_ADDRESS);
337 }
338
339 bool AMDGPUDAGToDAGISel::isRegionStore(const StoreSDNode *N) {
340   return checkType(N->getSrcValue(), AMDGPUAS::REGION_ADDRESS);
341 }
342
343 bool AMDGPUDAGToDAGISel::isConstantLoad(const LoadSDNode *N, int CbId) const {
344   if (CbId == -1) {
345     return checkType(N->getSrcValue(), AMDGPUAS::CONSTANT_ADDRESS);
346   }
347   return checkType(N->getSrcValue(), AMDGPUAS::CONSTANT_BUFFER_0 + CbId);
348 }
349
350 bool AMDGPUDAGToDAGISel::isGlobalLoad(const LoadSDNode *N) const {
351   if (N->getAddressSpace() == AMDGPUAS::CONSTANT_ADDRESS) {
352     const AMDGPUSubtarget &ST = TM.getSubtarget<AMDGPUSubtarget>();
353     if (ST.getGeneration() < AMDGPUSubtarget::SOUTHERN_ISLANDS ||
354         N->getMemoryVT().bitsLT(MVT::i32)) {
355       return true;
356     }
357   }
358   return checkType(N->getSrcValue(), AMDGPUAS::GLOBAL_ADDRESS);
359 }
360
361 bool AMDGPUDAGToDAGISel::isParamLoad(const LoadSDNode *N) const {
362   return checkType(N->getSrcValue(), AMDGPUAS::PARAM_I_ADDRESS);
363 }
364
365 bool AMDGPUDAGToDAGISel::isLocalLoad(const  LoadSDNode *N) const {
366   return checkType(N->getSrcValue(), AMDGPUAS::LOCAL_ADDRESS);
367 }
368
369 bool AMDGPUDAGToDAGISel::isRegionLoad(const  LoadSDNode *N) const {
370   return checkType(N->getSrcValue(), AMDGPUAS::REGION_ADDRESS);
371 }
372
373 bool AMDGPUDAGToDAGISel::isCPLoad(const LoadSDNode *N) const {
374   MachineMemOperand *MMO = N->getMemOperand();
375   if (checkType(N->getSrcValue(), AMDGPUAS::PRIVATE_ADDRESS)) {
376     if (MMO) {
377       const Value *V = MMO->getValue();
378       const PseudoSourceValue *PSV = dyn_cast<PseudoSourceValue>(V);
379       if (PSV && PSV == PseudoSourceValue::getConstantPool()) {
380         return true;
381       }
382     }
383   }
384   return false;
385 }
386
387 bool AMDGPUDAGToDAGISel::isPrivateLoad(const LoadSDNode *N) const {
388   if (checkType(N->getSrcValue(), AMDGPUAS::PRIVATE_ADDRESS)) {
389     // Check to make sure we are not a constant pool load or a constant load
390     // that is marked as a private load
391     if (isCPLoad(N) || isConstantLoad(N, -1)) {
392       return false;
393     }
394   }
395   if (!checkType(N->getSrcValue(), AMDGPUAS::LOCAL_ADDRESS)
396       && !checkType(N->getSrcValue(), AMDGPUAS::GLOBAL_ADDRESS)
397       && !checkType(N->getSrcValue(), AMDGPUAS::REGION_ADDRESS)
398       && !checkType(N->getSrcValue(), AMDGPUAS::CONSTANT_ADDRESS)
399       && !checkType(N->getSrcValue(), AMDGPUAS::PARAM_D_ADDRESS)
400       && !checkType(N->getSrcValue(), AMDGPUAS::PARAM_I_ADDRESS)) {
401     return true;
402   }
403   return false;
404 }
405
406 const char *AMDGPUDAGToDAGISel::getPassName() const {
407   return "AMDGPU DAG->DAG Pattern Instruction Selection";
408 }
409
410 #ifdef DEBUGTMP
411 #undef INT64_C
412 #endif
413 #undef DEBUGTMP
414
415 //===----------------------------------------------------------------------===//
416 // Complex Patterns
417 //===----------------------------------------------------------------------===//
418
419 bool AMDGPUDAGToDAGISel::SelectGlobalValueConstantOffset(SDValue Addr,
420     SDValue& IntPtr) {
421   if (ConstantSDNode *Cst = dyn_cast<ConstantSDNode>(Addr)) {
422     IntPtr = CurDAG->getIntPtrConstant(Cst->getZExtValue() / 4, true);
423     return true;
424   }
425   return false;
426 }
427
428 bool AMDGPUDAGToDAGISel::SelectGlobalValueVariableOffset(SDValue Addr,
429     SDValue& BaseReg, SDValue &Offset) {
430   if (!dyn_cast<ConstantSDNode>(Addr)) {
431     BaseReg = Addr;
432     Offset = CurDAG->getIntPtrConstant(0, true);
433     return true;
434   }
435   return false;
436 }
437
438 bool AMDGPUDAGToDAGISel::SelectADDRVTX_READ(SDValue Addr, SDValue &Base,
439                                            SDValue &Offset) {
440   ConstantSDNode * IMMOffset;
441
442   if (Addr.getOpcode() == ISD::ADD
443       && (IMMOffset = dyn_cast<ConstantSDNode>(Addr.getOperand(1)))
444       && isInt<16>(IMMOffset->getZExtValue())) {
445
446       Base = Addr.getOperand(0);
447       Offset = CurDAG->getTargetConstant(IMMOffset->getZExtValue(), MVT::i32);
448       return true;
449   // If the pointer address is constant, we can move it to the offset field.
450   } else if ((IMMOffset = dyn_cast<ConstantSDNode>(Addr))
451              && isInt<16>(IMMOffset->getZExtValue())) {
452     Base = CurDAG->getCopyFromReg(CurDAG->getEntryNode(),
453                                   SDLoc(CurDAG->getEntryNode()),
454                                   AMDGPU::ZERO, MVT::i32);
455     Offset = CurDAG->getTargetConstant(IMMOffset->getZExtValue(), MVT::i32);
456     return true;
457   }
458
459   // Default case, no offset
460   Base = Addr;
461   Offset = CurDAG->getTargetConstant(0, MVT::i32);
462   return true;
463 }
464
465 bool AMDGPUDAGToDAGISel::SelectADDRIndirect(SDValue Addr, SDValue &Base,
466                                             SDValue &Offset) {
467   ConstantSDNode *C;
468
469   if ((C = dyn_cast<ConstantSDNode>(Addr))) {
470     Base = CurDAG->getRegister(AMDGPU::INDIRECT_BASE_ADDR, MVT::i32);
471     Offset = CurDAG->getTargetConstant(C->getZExtValue(), MVT::i32);
472   } else if ((Addr.getOpcode() == ISD::ADD || Addr.getOpcode() == ISD::OR) &&
473             (C = dyn_cast<ConstantSDNode>(Addr.getOperand(1)))) {
474     Base = Addr.getOperand(0);
475     Offset = CurDAG->getTargetConstant(C->getZExtValue(), MVT::i32);
476   } else {
477     Base = Addr;
478     Offset = CurDAG->getTargetConstant(0, MVT::i32);
479   }
480
481   return true;
482 }
483
484 SDValue AMDGPUDAGToDAGISel::SimplifyI24(SDValue &Op) {
485   APInt Demanded = APInt(32, 0x00FFFFFF);
486   APInt KnownZero, KnownOne;
487   TargetLowering::TargetLoweringOpt TLO(*CurDAG, true, true);
488   const TargetLowering *TLI = getTargetLowering();
489   if (TLI->SimplifyDemandedBits(Op, Demanded, KnownZero, KnownOne, TLO)) {
490     CurDAG->ReplaceAllUsesWith(Op, TLO.New);
491     CurDAG->RepositionNode(Op.getNode(), TLO.New.getNode());
492     return SimplifyI24(TLO.New);
493   } else {
494     return  Op;
495   }
496 }
497
498 bool AMDGPUDAGToDAGISel::SelectI24(SDValue Op, SDValue &I24) {
499
500   assert(Op.getValueType() == MVT::i32);
501
502   if (CurDAG->ComputeNumSignBits(Op) == 9) {
503     I24 = SimplifyI24(Op);
504     return true;
505   }
506   return false;
507 }
508
509 bool AMDGPUDAGToDAGISel::SelectU24(SDValue Op, SDValue &U24) {
510   APInt KnownZero;
511   APInt KnownOne;
512   CurDAG->ComputeMaskedBits(Op, KnownZero, KnownOne);
513
514   assert (Op.getValueType() == MVT::i32);
515
516   // ANY_EXTEND and EXTLOAD operations can only be done on types smaller than
517   // i32.  These smaller types are legal to use with the i24 instructions.
518   if ((KnownZero & APInt(KnownZero.getBitWidth(), 0xFF000000)) == 0xFF000000 ||
519        Op.getOpcode() == ISD::ANY_EXTEND ||
520        ISD::isEXTLoad(Op.getNode())) {
521     U24 = SimplifyI24(Op);
522     return true;
523   }
524   return false;
525 }
526
527 void AMDGPUDAGToDAGISel::PostprocessISelDAG() {
528   const AMDGPUTargetLowering& Lowering =
529     (*(const AMDGPUTargetLowering*)getTargetLowering());
530   bool IsModified = false;
531   do {
532     IsModified = false;
533     // Go over all selected nodes and try to fold them a bit more
534     for (SelectionDAG::allnodes_iterator I = CurDAG->allnodes_begin(),
535          E = CurDAG->allnodes_end(); I != E; ++I) {
536
537       SDNode *Node = I;
538
539       MachineSDNode *MachineNode = dyn_cast<MachineSDNode>(I);
540       if (!MachineNode)
541         continue;
542
543       SDNode *ResNode = Lowering.PostISelFolding(MachineNode, *CurDAG);
544       if (ResNode != Node) {
545         ReplaceUses(Node, ResNode);
546         IsModified = true;
547       }
548     }
549     CurDAG->RemoveDeadNodes();
550   } while (IsModified);
551 }