R600: Promote f64 vector load/stores to i64 for consistency
[oota-llvm.git] / lib / Target / R600 / AMDGPUISelLowering.cpp
1 //===-- AMDGPUISelLowering.cpp - AMDGPU Common DAG lowering functions -----===//
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 This is the parent TargetLowering class for hardware code gen
12 /// targets.
13 //
14 //===----------------------------------------------------------------------===//
15
16 #include "AMDGPUISelLowering.h"
17 #include "AMDGPU.h"
18 #include "AMDGPUFrameLowering.h"
19 #include "AMDGPURegisterInfo.h"
20 #include "AMDGPUSubtarget.h"
21 #include "AMDILIntrinsicInfo.h"
22 #include "R600MachineFunctionInfo.h"
23 #include "SIMachineFunctionInfo.h"
24 #include "llvm/Analysis/ValueTracking.h"
25 #include "llvm/CodeGen/CallingConvLower.h"
26 #include "llvm/CodeGen/MachineFunction.h"
27 #include "llvm/CodeGen/MachineRegisterInfo.h"
28 #include "llvm/CodeGen/SelectionDAG.h"
29 #include "llvm/CodeGen/TargetLoweringObjectFileImpl.h"
30 #include "llvm/IR/DataLayout.h"
31 #include "llvm/IR/DiagnosticInfo.h"
32 #include "llvm/IR/DiagnosticPrinter.h"
33
34 using namespace llvm;
35
36 namespace {
37
38 /// Diagnostic information for unimplemented or unsupported feature reporting.
39 class DiagnosticInfoUnsupported : public DiagnosticInfo {
40 private:
41   const Twine &Description;
42   const Function &Fn;
43
44   static int KindID;
45
46   static int getKindID() {
47     if (KindID == 0)
48       KindID = llvm::getNextAvailablePluginDiagnosticKind();
49     return KindID;
50   }
51
52 public:
53   DiagnosticInfoUnsupported(const Function &Fn, const Twine &Desc,
54                           DiagnosticSeverity Severity = DS_Error)
55     : DiagnosticInfo(getKindID(), Severity),
56       Description(Desc),
57       Fn(Fn) { }
58
59   const Function &getFunction() const { return Fn; }
60   const Twine &getDescription() const { return Description; }
61
62   void print(DiagnosticPrinter &DP) const override {
63     DP << "unsupported " << getDescription() << " in " << Fn.getName();
64   }
65
66   static bool classof(const DiagnosticInfo *DI) {
67     return DI->getKind() == getKindID();
68   }
69 };
70
71 int DiagnosticInfoUnsupported::KindID = 0;
72 }
73
74
75 static bool allocateStack(unsigned ValNo, MVT ValVT, MVT LocVT,
76                       CCValAssign::LocInfo LocInfo,
77                       ISD::ArgFlagsTy ArgFlags, CCState &State) {
78   unsigned Offset = State.AllocateStack(ValVT.getStoreSize(),
79                                         ArgFlags.getOrigAlign());
80   State.addLoc(CCValAssign::getMem(ValNo, ValVT, Offset, LocVT, LocInfo));
81
82   return true;
83 }
84
85 #include "AMDGPUGenCallingConv.inc"
86
87 AMDGPUTargetLowering::AMDGPUTargetLowering(TargetMachine &TM) :
88   TargetLowering(TM, new TargetLoweringObjectFileELF()) {
89
90   Subtarget = &TM.getSubtarget<AMDGPUSubtarget>();
91
92   // Initialize target lowering borrowed from AMDIL
93   InitAMDILLowering();
94
95   // We need to custom lower some of the intrinsics
96   setOperationAction(ISD::INTRINSIC_WO_CHAIN, MVT::Other, Custom);
97
98   // Library functions.  These default to Expand, but we have instructions
99   // for them.
100   setOperationAction(ISD::FCEIL,  MVT::f32, Legal);
101   setOperationAction(ISD::FEXP2,  MVT::f32, Legal);
102   setOperationAction(ISD::FPOW,   MVT::f32, Legal);
103   setOperationAction(ISD::FLOG2,  MVT::f32, Legal);
104   setOperationAction(ISD::FABS,   MVT::f32, Legal);
105   setOperationAction(ISD::FFLOOR, MVT::f32, Legal);
106   setOperationAction(ISD::FRINT,  MVT::f32, Legal);
107   setOperationAction(ISD::FROUND, MVT::f32, Legal);
108   setOperationAction(ISD::FTRUNC, MVT::f32, Legal);
109
110   // The hardware supports ROTR, but not ROTL
111   setOperationAction(ISD::ROTL, MVT::i32, Expand);
112
113   // Lower floating point store/load to integer store/load to reduce the number
114   // of patterns in tablegen.
115   setOperationAction(ISD::STORE, MVT::f32, Promote);
116   AddPromotedToType(ISD::STORE, MVT::f32, MVT::i32);
117
118   setOperationAction(ISD::STORE, MVT::v2f32, Promote);
119   AddPromotedToType(ISD::STORE, MVT::v2f32, MVT::v2i32);
120
121   setOperationAction(ISD::STORE, MVT::v4f32, Promote);
122   AddPromotedToType(ISD::STORE, MVT::v4f32, MVT::v4i32);
123
124   setOperationAction(ISD::STORE, MVT::v8f32, Promote);
125   AddPromotedToType(ISD::STORE, MVT::v8f32, MVT::v8i32);
126
127   setOperationAction(ISD::STORE, MVT::v16f32, Promote);
128   AddPromotedToType(ISD::STORE, MVT::v16f32, MVT::v16i32);
129
130   setOperationAction(ISD::STORE, MVT::f64, Promote);
131   AddPromotedToType(ISD::STORE, MVT::f64, MVT::i64);
132
133   setOperationAction(ISD::STORE, MVT::v2f64, Promote);
134   AddPromotedToType(ISD::STORE, MVT::v2f64, MVT::v2i64);
135
136   // Custom lowering of vector stores is required for local address space
137   // stores.
138   setOperationAction(ISD::STORE, MVT::v4i32, Custom);
139   // XXX: Native v2i32 local address space stores are possible, but not
140   // currently implemented.
141   setOperationAction(ISD::STORE, MVT::v2i32, Custom);
142
143   setTruncStoreAction(MVT::v2i32, MVT::v2i16, Custom);
144   setTruncStoreAction(MVT::v2i32, MVT::v2i8, Custom);
145   setTruncStoreAction(MVT::v4i32, MVT::v4i8, Custom);
146
147   // XXX: This can be change to Custom, once ExpandVectorStores can
148   // handle 64-bit stores.
149   setTruncStoreAction(MVT::v4i32, MVT::v4i16, Expand);
150
151   setTruncStoreAction(MVT::i64, MVT::i16, Expand);
152   setTruncStoreAction(MVT::i64, MVT::i8, Expand);
153   setTruncStoreAction(MVT::i64, MVT::i1, Expand);
154   setTruncStoreAction(MVT::v2i64, MVT::v2i1, Expand);
155   setTruncStoreAction(MVT::v4i64, MVT::v4i1, Expand);
156
157
158   setOperationAction(ISD::LOAD, MVT::f32, Promote);
159   AddPromotedToType(ISD::LOAD, MVT::f32, MVT::i32);
160
161   setOperationAction(ISD::LOAD, MVT::v2f32, Promote);
162   AddPromotedToType(ISD::LOAD, MVT::v2f32, MVT::v2i32);
163
164   setOperationAction(ISD::LOAD, MVT::v4f32, Promote);
165   AddPromotedToType(ISD::LOAD, MVT::v4f32, MVT::v4i32);
166
167   setOperationAction(ISD::LOAD, MVT::v8f32, Promote);
168   AddPromotedToType(ISD::LOAD, MVT::v8f32, MVT::v8i32);
169
170   setOperationAction(ISD::LOAD, MVT::v16f32, Promote);
171   AddPromotedToType(ISD::LOAD, MVT::v16f32, MVT::v16i32);
172
173   setOperationAction(ISD::LOAD, MVT::f64, Promote);
174   AddPromotedToType(ISD::LOAD, MVT::f64, MVT::i64);
175
176   setOperationAction(ISD::LOAD, MVT::v2f64, Promote);
177   AddPromotedToType(ISD::LOAD, MVT::v2f64, MVT::v2i64);
178
179   setOperationAction(ISD::CONCAT_VECTORS, MVT::v4i32, Custom);
180   setOperationAction(ISD::CONCAT_VECTORS, MVT::v4f32, Custom);
181   setOperationAction(ISD::CONCAT_VECTORS, MVT::v8i32, Custom);
182   setOperationAction(ISD::CONCAT_VECTORS, MVT::v8f32, Custom);
183   setOperationAction(ISD::EXTRACT_SUBVECTOR, MVT::v2f32, Custom);
184   setOperationAction(ISD::EXTRACT_SUBVECTOR, MVT::v2i32, Custom);
185   setOperationAction(ISD::EXTRACT_SUBVECTOR, MVT::v4f32, Custom);
186   setOperationAction(ISD::EXTRACT_SUBVECTOR, MVT::v4i32, Custom);
187   setOperationAction(ISD::EXTRACT_SUBVECTOR, MVT::v8f32, Custom);
188   setOperationAction(ISD::EXTRACT_SUBVECTOR, MVT::v8i32, Custom);
189
190   setLoadExtAction(ISD::EXTLOAD, MVT::v2i8, Expand);
191   setLoadExtAction(ISD::SEXTLOAD, MVT::v2i8, Expand);
192   setLoadExtAction(ISD::ZEXTLOAD, MVT::v2i8, Expand);
193   setLoadExtAction(ISD::EXTLOAD, MVT::v4i8, Expand);
194   setLoadExtAction(ISD::SEXTLOAD, MVT::v4i8, Expand);
195   setLoadExtAction(ISD::ZEXTLOAD, MVT::v4i8, Expand);
196   setLoadExtAction(ISD::EXTLOAD, MVT::v2i16, Expand);
197   setLoadExtAction(ISD::SEXTLOAD, MVT::v2i16, Expand);
198   setLoadExtAction(ISD::ZEXTLOAD, MVT::v2i16, Expand);
199   setLoadExtAction(ISD::EXTLOAD, MVT::v4i16, Expand);
200   setLoadExtAction(ISD::SEXTLOAD, MVT::v4i16, Expand);
201   setLoadExtAction(ISD::ZEXTLOAD, MVT::v4i16, Expand);
202
203   setOperationAction(ISD::BR_CC, MVT::i1, Expand);
204
205   setOperationAction(ISD::FNEG, MVT::v2f32, Expand);
206   setOperationAction(ISD::FNEG, MVT::v4f32, Expand);
207
208   setOperationAction(ISD::UINT_TO_FP, MVT::i64, Custom);
209
210   setOperationAction(ISD::MUL, MVT::i64, Expand);
211   setOperationAction(ISD::SUB, MVT::i64, Expand);
212
213   setOperationAction(ISD::UDIV, MVT::i32, Expand);
214   setOperationAction(ISD::UDIVREM, MVT::i32, Custom);
215   setOperationAction(ISD::UDIVREM, MVT::i64, Custom);
216   setOperationAction(ISD::UREM, MVT::i32, Expand);
217   setOperationAction(ISD::VSELECT, MVT::v2f32, Expand);
218   setOperationAction(ISD::VSELECT, MVT::v4f32, Expand);
219
220   static const MVT::SimpleValueType IntTypes[] = {
221     MVT::v2i32, MVT::v4i32
222   };
223   const size_t NumIntTypes = array_lengthof(IntTypes);
224
225   for (unsigned int x  = 0; x < NumIntTypes; ++x) {
226     MVT::SimpleValueType VT = IntTypes[x];
227     //Expand the following operations for the current type by default
228     setOperationAction(ISD::ADD,  VT, Expand);
229     setOperationAction(ISD::AND,  VT, Expand);
230     setOperationAction(ISD::FP_TO_SINT, VT, Expand);
231     setOperationAction(ISD::FP_TO_UINT, VT, Expand);
232     setOperationAction(ISD::MUL,  VT, Expand);
233     setOperationAction(ISD::OR,   VT, Expand);
234     setOperationAction(ISD::SHL,  VT, Expand);
235     setOperationAction(ISD::SINT_TO_FP, VT, Expand);
236     setOperationAction(ISD::SRL,  VT, Expand);
237     setOperationAction(ISD::SRA,  VT, Expand);
238     setOperationAction(ISD::SUB,  VT, Expand);
239     setOperationAction(ISD::UDIV, VT, Expand);
240     setOperationAction(ISD::UINT_TO_FP, VT, Expand);
241     setOperationAction(ISD::UREM, VT, Expand);
242     setOperationAction(ISD::SELECT, VT, Expand);
243     setOperationAction(ISD::VSELECT, VT, Expand);
244     setOperationAction(ISD::XOR,  VT, Expand);
245   }
246
247   static const MVT::SimpleValueType FloatTypes[] = {
248     MVT::v2f32, MVT::v4f32
249   };
250   const size_t NumFloatTypes = array_lengthof(FloatTypes);
251
252   for (unsigned int x = 0; x < NumFloatTypes; ++x) {
253     MVT::SimpleValueType VT = FloatTypes[x];
254     setOperationAction(ISD::FABS, VT, Expand);
255     setOperationAction(ISD::FADD, VT, Expand);
256     setOperationAction(ISD::FCOS, VT, Expand);
257     setOperationAction(ISD::FDIV, VT, Expand);
258     setOperationAction(ISD::FPOW, VT, Expand);
259     setOperationAction(ISD::FFLOOR, VT, Expand);
260     setOperationAction(ISD::FTRUNC, VT, Expand);
261     setOperationAction(ISD::FMUL, VT, Expand);
262     setOperationAction(ISD::FRINT, VT, Expand);
263     setOperationAction(ISD::FSQRT, VT, Expand);
264     setOperationAction(ISD::FSIN, VT, Expand);
265     setOperationAction(ISD::FSUB, VT, Expand);
266     setOperationAction(ISD::SELECT, VT, Expand);
267   }
268
269   setTargetDAGCombine(ISD::MUL);
270 }
271
272 //===----------------------------------------------------------------------===//
273 // Target Information
274 //===----------------------------------------------------------------------===//
275
276 MVT AMDGPUTargetLowering::getVectorIdxTy() const {
277   return MVT::i32;
278 }
279
280 bool AMDGPUTargetLowering::isLoadBitCastBeneficial(EVT LoadTy,
281                                                    EVT CastTy) const {
282   if (LoadTy.getSizeInBits() != CastTy.getSizeInBits())
283     return true;
284
285   unsigned LScalarSize = LoadTy.getScalarType().getSizeInBits();
286   unsigned CastScalarSize = CastTy.getScalarType().getSizeInBits();
287
288   return ((LScalarSize <= CastScalarSize) ||
289           (CastScalarSize >= 32) ||
290           (LScalarSize < 32));
291 }
292
293 //===---------------------------------------------------------------------===//
294 // Target Properties
295 //===---------------------------------------------------------------------===//
296
297 bool AMDGPUTargetLowering::isFAbsFree(EVT VT) const {
298   assert(VT.isFloatingPoint());
299   return VT == MVT::f32;
300 }
301
302 bool AMDGPUTargetLowering::isFNegFree(EVT VT) const {
303   assert(VT.isFloatingPoint());
304   return VT == MVT::f32;
305 }
306
307 bool AMDGPUTargetLowering::isTruncateFree(EVT Source, EVT Dest) const {
308   // Truncate is just accessing a subregister.
309   return Dest.bitsLT(Source) && (Dest.getSizeInBits() % 32 == 0);
310 }
311
312 bool AMDGPUTargetLowering::isTruncateFree(Type *Source, Type *Dest) const {
313   // Truncate is just accessing a subregister.
314   return Dest->getPrimitiveSizeInBits() < Source->getPrimitiveSizeInBits() &&
315          (Dest->getPrimitiveSizeInBits() % 32 == 0);
316 }
317
318 bool AMDGPUTargetLowering::isZExtFree(Type *Src, Type *Dest) const {
319   const DataLayout *DL = getDataLayout();
320   unsigned SrcSize = DL->getTypeSizeInBits(Src->getScalarType());
321   unsigned DestSize = DL->getTypeSizeInBits(Dest->getScalarType());
322
323   return SrcSize == 32 && DestSize == 64;
324 }
325
326 bool AMDGPUTargetLowering::isZExtFree(EVT Src, EVT Dest) const {
327   // Any register load of a 64-bit value really requires 2 32-bit moves. For all
328   // practical purposes, the extra mov 0 to load a 64-bit is free.  As used,
329   // this will enable reducing 64-bit operations the 32-bit, which is always
330   // good.
331   return Src == MVT::i32 && Dest == MVT::i64;
332 }
333
334 bool AMDGPUTargetLowering::isNarrowingProfitable(EVT SrcVT, EVT DestVT) const {
335   // There aren't really 64-bit registers, but pairs of 32-bit ones and only a
336   // limited number of native 64-bit operations. Shrinking an operation to fit
337   // in a single 32-bit register should always be helpful. As currently used,
338   // this is much less general than the name suggests, and is only used in
339   // places trying to reduce the sizes of loads. Shrinking loads to < 32-bits is
340   // not profitable, and may actually be harmful.
341   return SrcVT.getSizeInBits() > 32 && DestVT.getSizeInBits() == 32;
342 }
343
344 //===---------------------------------------------------------------------===//
345 // TargetLowering Callbacks
346 //===---------------------------------------------------------------------===//
347
348 void AMDGPUTargetLowering::AnalyzeFormalArguments(CCState &State,
349                              const SmallVectorImpl<ISD::InputArg> &Ins) const {
350
351   State.AnalyzeFormalArguments(Ins, CC_AMDGPU);
352 }
353
354 SDValue AMDGPUTargetLowering::LowerReturn(
355                                      SDValue Chain,
356                                      CallingConv::ID CallConv,
357                                      bool isVarArg,
358                                      const SmallVectorImpl<ISD::OutputArg> &Outs,
359                                      const SmallVectorImpl<SDValue> &OutVals,
360                                      SDLoc DL, SelectionDAG &DAG) const {
361   return DAG.getNode(AMDGPUISD::RET_FLAG, DL, MVT::Other, Chain);
362 }
363
364 //===---------------------------------------------------------------------===//
365 // Target specific lowering
366 //===---------------------------------------------------------------------===//
367
368 SDValue AMDGPUTargetLowering::LowerCall(CallLoweringInfo &CLI,
369                                         SmallVectorImpl<SDValue> &InVals) const {
370   SDValue Callee = CLI.Callee;
371   SelectionDAG &DAG = CLI.DAG;
372
373   const Function &Fn = *DAG.getMachineFunction().getFunction();
374
375   StringRef FuncName("<unknown>");
376
377   if (const ExternalSymbolSDNode *G = dyn_cast<ExternalSymbolSDNode>(Callee))
378     FuncName = G->getSymbol();
379   else if (const GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
380     FuncName = G->getGlobal()->getName();
381
382   DiagnosticInfoUnsupported NoCalls(Fn, "call to function " + FuncName);
383   DAG.getContext()->diagnose(NoCalls);
384   return SDValue();
385 }
386
387 SDValue AMDGPUTargetLowering::LowerOperation(SDValue Op, SelectionDAG &DAG)
388     const {
389   switch (Op.getOpcode()) {
390   default:
391     Op.getNode()->dump();
392     llvm_unreachable("Custom lowering code for this"
393                      "instruction is not implemented yet!");
394     break;
395   // AMDIL DAG lowering
396   case ISD::SDIV: return LowerSDIV(Op, DAG);
397   case ISD::SREM: return LowerSREM(Op, DAG);
398   case ISD::SIGN_EXTEND_INREG: return LowerSIGN_EXTEND_INREG(Op, DAG);
399   case ISD::BRCOND: return LowerBRCOND(Op, DAG);
400   // AMDGPU DAG lowering
401   case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG);
402   case ISD::EXTRACT_SUBVECTOR: return LowerEXTRACT_SUBVECTOR(Op, DAG);
403   case ISD::FrameIndex: return LowerFrameIndex(Op, DAG);
404   case ISD::INTRINSIC_WO_CHAIN: return LowerINTRINSIC_WO_CHAIN(Op, DAG);
405   case ISD::UDIVREM: return LowerUDIVREM(Op, DAG);
406   case ISD::UINT_TO_FP: return LowerUINT_TO_FP(Op, DAG);
407   }
408   return Op;
409 }
410
411 void AMDGPUTargetLowering::ReplaceNodeResults(SDNode *N,
412                                               SmallVectorImpl<SDValue> &Results,
413                                               SelectionDAG &DAG) const {
414   switch (N->getOpcode()) {
415   case ISD::SIGN_EXTEND_INREG:
416     // Different parts of legalization seem to interpret which type of
417     // sign_extend_inreg is the one to check for custom lowering. The extended
418     // from type is what really matters, but some places check for custom
419     // lowering of the result type. This results in trying to use
420     // ReplaceNodeResults to sext_in_reg to an illegal type, so we'll just do
421     // nothing here and let the illegal result integer be handled normally.
422     return;
423   case ISD::UDIV: {
424     SDValue Op = SDValue(N, 0);
425     SDLoc DL(Op);
426     EVT VT = Op.getValueType();
427     SDValue UDIVREM = DAG.getNode(ISD::UDIVREM, DL, DAG.getVTList(VT, VT),
428       N->getOperand(0), N->getOperand(1));
429     Results.push_back(UDIVREM);
430     break;
431   }
432   case ISD::UREM: {
433     SDValue Op = SDValue(N, 0);
434     SDLoc DL(Op);
435     EVT VT = Op.getValueType();
436     SDValue UDIVREM = DAG.getNode(ISD::UDIVREM, DL, DAG.getVTList(VT, VT),
437       N->getOperand(0), N->getOperand(1));
438     Results.push_back(UDIVREM.getValue(1));
439     break;
440   }
441   case ISD::UDIVREM: {
442     SDValue Op = SDValue(N, 0);
443     SDLoc DL(Op);
444     EVT VT = Op.getValueType();
445     EVT HalfVT = VT.getHalfSizedIntegerVT(*DAG.getContext());
446
447     SDValue one = DAG.getConstant(1, HalfVT);
448     SDValue zero = DAG.getConstant(0, HalfVT);
449
450     //HiLo split
451     SDValue LHS = N->getOperand(0);
452     SDValue LHS_Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, HalfVT, LHS, zero);
453     SDValue LHS_Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, HalfVT, LHS, one);
454
455     SDValue RHS = N->getOperand(1);
456     SDValue RHS_Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, HalfVT, RHS, zero);
457     SDValue RHS_Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, HalfVT, RHS, one);
458
459     // Get Speculative values
460     SDValue DIV_Part = DAG.getNode(ISD::UDIV, DL, HalfVT, LHS_Hi, RHS_Lo);
461     SDValue REM_Part = DAG.getNode(ISD::UREM, DL, HalfVT, LHS_Hi, RHS_Lo);
462
463     SDValue REM_Hi = zero;
464     SDValue REM_Lo = DAG.getSelectCC(DL, RHS_Hi, zero, REM_Part, LHS_Hi, ISD::SETEQ);
465
466     SDValue DIV_Hi = DAG.getSelectCC(DL, RHS_Hi, zero, DIV_Part, zero, ISD::SETEQ);
467     SDValue DIV_Lo = zero;
468
469     const unsigned halfBitWidth = HalfVT.getSizeInBits();
470
471     for (unsigned i = 0; i < halfBitWidth; ++i) {
472       SDValue POS = DAG.getConstant(halfBitWidth - i - 1, HalfVT);
473       // Get Value of high bit
474       SDValue HBit;
475       if (halfBitWidth == 32 && Subtarget->hasBFE()) {
476         HBit = DAG.getNode(AMDGPUISD::BFE_U32, DL, HalfVT, LHS_Lo, POS, one);
477       } else {
478         HBit = DAG.getNode(ISD::SRL, DL, HalfVT, LHS_Lo, POS);
479         HBit = DAG.getNode(ISD::AND, DL, HalfVT, HBit, one);
480       }
481
482       SDValue Carry = DAG.getNode(ISD::SRL, DL, HalfVT, REM_Lo,
483         DAG.getConstant(halfBitWidth - 1, HalfVT));
484       REM_Hi = DAG.getNode(ISD::SHL, DL, HalfVT, REM_Hi, one);
485       REM_Hi = DAG.getNode(ISD::OR, DL, HalfVT, REM_Hi, Carry);
486
487       REM_Lo = DAG.getNode(ISD::SHL, DL, HalfVT, REM_Lo, one);
488       REM_Lo = DAG.getNode(ISD::OR, DL, HalfVT, REM_Lo, HBit);
489
490
491       SDValue REM = DAG.getNode(ISD::BUILD_PAIR, DL, VT, REM_Lo, REM_Hi);
492
493       SDValue BIT = DAG.getConstant(1 << (halfBitWidth - i - 1), HalfVT);
494       SDValue realBIT = DAG.getSelectCC(DL, REM, RHS, BIT, zero, ISD::SETGE);
495
496       DIV_Lo = DAG.getNode(ISD::OR, DL, HalfVT, DIV_Lo, realBIT);
497
498       // Update REM
499
500       SDValue REM_sub = DAG.getNode(ISD::SUB, DL, VT, REM, RHS);
501
502       REM = DAG.getSelectCC(DL, REM, RHS, REM_sub, REM, ISD::SETGE);
503       REM_Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, HalfVT, REM, zero);
504       REM_Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, HalfVT, REM, one);
505     }
506
507     SDValue REM = DAG.getNode(ISD::BUILD_PAIR, DL, VT, REM_Lo, REM_Hi);
508     SDValue DIV = DAG.getNode(ISD::BUILD_PAIR, DL, VT, DIV_Lo, DIV_Hi);
509     Results.push_back(DIV);
510     Results.push_back(REM);
511     break;
512   }
513   default:
514     return;
515   }
516 }
517
518 SDValue AMDGPUTargetLowering::LowerConstantInitializer(const Constant* Init,
519                                                        const GlobalValue *GV,
520                                                        const SDValue &InitPtr,
521                                                        SDValue Chain,
522                                                        SelectionDAG &DAG) const {
523   const DataLayout *TD = getTargetMachine().getDataLayout();
524   SDLoc DL(InitPtr);
525   if (const ConstantInt *CI = dyn_cast<ConstantInt>(Init)) {
526     EVT VT = EVT::getEVT(CI->getType());
527     PointerType *PtrTy = PointerType::get(CI->getType(), 0);
528     return DAG.getStore(Chain, DL,  DAG.getConstant(*CI, VT), InitPtr,
529                  MachinePointerInfo(UndefValue::get(PtrTy)), false, false,
530                  TD->getPrefTypeAlignment(CI->getType()));
531   } else if (const ConstantFP *CFP = dyn_cast<ConstantFP>(Init)) {
532     EVT VT = EVT::getEVT(CFP->getType());
533     PointerType *PtrTy = PointerType::get(CFP->getType(), 0);
534     return DAG.getStore(Chain, DL, DAG.getConstantFP(*CFP, VT), InitPtr,
535                  MachinePointerInfo(UndefValue::get(PtrTy)), false, false,
536                  TD->getPrefTypeAlignment(CFP->getType()));
537   } else if (Init->getType()->isAggregateType()) {
538     EVT PtrVT = InitPtr.getValueType();
539     unsigned NumElements = Init->getType()->getArrayNumElements();
540     SmallVector<SDValue, 8> Chains;
541     for (unsigned i = 0; i < NumElements; ++i) {
542       SDValue Offset = DAG.getConstant(i * TD->getTypeAllocSize(
543           Init->getType()->getArrayElementType()), PtrVT);
544       SDValue Ptr = DAG.getNode(ISD::ADD, DL, PtrVT, InitPtr, Offset);
545       Chains.push_back(LowerConstantInitializer(Init->getAggregateElement(i),
546                        GV, Ptr, Chain, DAG));
547     }
548     return DAG.getNode(ISD::TokenFactor, DL, MVT::Other, Chains);
549   } else {
550     Init->dump();
551     llvm_unreachable("Unhandled constant initializer");
552   }
553 }
554
555 SDValue AMDGPUTargetLowering::LowerGlobalAddress(AMDGPUMachineFunction* MFI,
556                                                  SDValue Op,
557                                                  SelectionDAG &DAG) const {
558
559   const DataLayout *TD = getTargetMachine().getDataLayout();
560   GlobalAddressSDNode *G = cast<GlobalAddressSDNode>(Op);
561   const GlobalValue *GV = G->getGlobal();
562
563   switch (G->getAddressSpace()) {
564   default: llvm_unreachable("Global Address lowering not implemented for this "
565                             "address space");
566   case AMDGPUAS::LOCAL_ADDRESS: {
567     // XXX: What does the value of G->getOffset() mean?
568     assert(G->getOffset() == 0 &&
569          "Do not know what to do with an non-zero offset");
570
571     unsigned Offset;
572     if (MFI->LocalMemoryObjects.count(GV) == 0) {
573       uint64_t Size = TD->getTypeAllocSize(GV->getType()->getElementType());
574       Offset = MFI->LDSSize;
575       MFI->LocalMemoryObjects[GV] = Offset;
576       // XXX: Account for alignment?
577       MFI->LDSSize += Size;
578     } else {
579       Offset = MFI->LocalMemoryObjects[GV];
580     }
581
582     return DAG.getConstant(Offset, getPointerTy(G->getAddressSpace()));
583   }
584   case AMDGPUAS::CONSTANT_ADDRESS: {
585     MachineFrameInfo *FrameInfo = DAG.getMachineFunction().getFrameInfo();
586     Type *EltType = GV->getType()->getElementType();
587     unsigned Size = TD->getTypeAllocSize(EltType);
588     unsigned Alignment = TD->getPrefTypeAlignment(EltType);
589
590     const GlobalVariable *Var = dyn_cast<GlobalVariable>(GV);
591     const Constant *Init = Var->getInitializer();
592     int FI = FrameInfo->CreateStackObject(Size, Alignment, false);
593     SDValue InitPtr = DAG.getFrameIndex(FI,
594         getPointerTy(AMDGPUAS::PRIVATE_ADDRESS));
595     SmallVector<SDNode*, 8> WorkList;
596
597     for (SDNode::use_iterator I = DAG.getEntryNode()->use_begin(),
598                               E = DAG.getEntryNode()->use_end(); I != E; ++I) {
599       if (I->getOpcode() != AMDGPUISD::REGISTER_LOAD && I->getOpcode() != ISD::LOAD)
600         continue;
601       WorkList.push_back(*I);
602     }
603     SDValue Chain = LowerConstantInitializer(Init, GV, InitPtr, DAG.getEntryNode(), DAG);
604     for (SmallVector<SDNode*, 8>::iterator I = WorkList.begin(),
605                                            E = WorkList.end(); I != E; ++I) {
606       SmallVector<SDValue, 8> Ops;
607       Ops.push_back(Chain);
608       for (unsigned i = 1; i < (*I)->getNumOperands(); ++i) {
609         Ops.push_back((*I)->getOperand(i));
610       }
611       DAG.UpdateNodeOperands(*I, Ops);
612     }
613     return DAG.getZExtOrTrunc(InitPtr, SDLoc(Op),
614         getPointerTy(AMDGPUAS::CONSTANT_ADDRESS));
615   }
616   }
617 }
618
619 SDValue AMDGPUTargetLowering::LowerCONCAT_VECTORS(SDValue Op,
620                                                   SelectionDAG &DAG) const {
621   SmallVector<SDValue, 8> Args;
622   SDValue A = Op.getOperand(0);
623   SDValue B = Op.getOperand(1);
624
625   DAG.ExtractVectorElements(A, Args);
626   DAG.ExtractVectorElements(B, Args);
627
628   return DAG.getNode(ISD::BUILD_VECTOR, SDLoc(Op), Op.getValueType(), Args);
629 }
630
631 SDValue AMDGPUTargetLowering::LowerEXTRACT_SUBVECTOR(SDValue Op,
632                                                      SelectionDAG &DAG) const {
633
634   SmallVector<SDValue, 8> Args;
635   unsigned Start = cast<ConstantSDNode>(Op.getOperand(1))->getZExtValue();
636   EVT VT = Op.getValueType();
637   DAG.ExtractVectorElements(Op.getOperand(0), Args, Start,
638                             VT.getVectorNumElements());
639
640   return DAG.getNode(ISD::BUILD_VECTOR, SDLoc(Op), Op.getValueType(), Args);
641 }
642
643 SDValue AMDGPUTargetLowering::LowerFrameIndex(SDValue Op,
644                                               SelectionDAG &DAG) const {
645
646   MachineFunction &MF = DAG.getMachineFunction();
647   const AMDGPUFrameLowering *TFL =
648    static_cast<const AMDGPUFrameLowering*>(getTargetMachine().getFrameLowering());
649
650   FrameIndexSDNode *FIN = dyn_cast<FrameIndexSDNode>(Op);
651   assert(FIN);
652
653   unsigned FrameIndex = FIN->getIndex();
654   unsigned Offset = TFL->getFrameIndexOffset(MF, FrameIndex);
655   return DAG.getConstant(Offset * 4 * TFL->getStackWidth(MF),
656                          Op.getValueType());
657 }
658
659 SDValue AMDGPUTargetLowering::LowerINTRINSIC_WO_CHAIN(SDValue Op,
660     SelectionDAG &DAG) const {
661   unsigned IntrinsicID = cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue();
662   SDLoc DL(Op);
663   EVT VT = Op.getValueType();
664
665   switch (IntrinsicID) {
666     default: return Op;
667     case AMDGPUIntrinsic::AMDIL_abs:
668       return LowerIntrinsicIABS(Op, DAG);
669     case AMDGPUIntrinsic::AMDIL_exp:
670       return DAG.getNode(ISD::FEXP2, DL, VT, Op.getOperand(1));
671     case AMDGPUIntrinsic::AMDGPU_lrp:
672       return LowerIntrinsicLRP(Op, DAG);
673     case AMDGPUIntrinsic::AMDIL_fraction:
674       return DAG.getNode(AMDGPUISD::FRACT, DL, VT, Op.getOperand(1));
675     case AMDGPUIntrinsic::AMDIL_max:
676       return DAG.getNode(AMDGPUISD::FMAX, DL, VT, Op.getOperand(1),
677                                                   Op.getOperand(2));
678     case AMDGPUIntrinsic::AMDGPU_imax:
679       return DAG.getNode(AMDGPUISD::SMAX, DL, VT, Op.getOperand(1),
680                                                   Op.getOperand(2));
681     case AMDGPUIntrinsic::AMDGPU_umax:
682       return DAG.getNode(AMDGPUISD::UMAX, DL, VT, Op.getOperand(1),
683                                                   Op.getOperand(2));
684     case AMDGPUIntrinsic::AMDIL_min:
685       return DAG.getNode(AMDGPUISD::FMIN, DL, VT, Op.getOperand(1),
686                                                   Op.getOperand(2));
687     case AMDGPUIntrinsic::AMDGPU_imin:
688       return DAG.getNode(AMDGPUISD::SMIN, DL, VT, Op.getOperand(1),
689                                                   Op.getOperand(2));
690     case AMDGPUIntrinsic::AMDGPU_umin:
691       return DAG.getNode(AMDGPUISD::UMIN, DL, VT, Op.getOperand(1),
692                                                   Op.getOperand(2));
693
694     case AMDGPUIntrinsic::AMDGPU_bfe_i32:
695       return DAG.getNode(AMDGPUISD::BFE_I32, DL, VT,
696                          Op.getOperand(1),
697                          Op.getOperand(2),
698                          Op.getOperand(3));
699
700     case AMDGPUIntrinsic::AMDGPU_bfe_u32:
701       return DAG.getNode(AMDGPUISD::BFE_U32, DL, VT,
702                          Op.getOperand(1),
703                          Op.getOperand(2),
704                          Op.getOperand(3));
705
706     case AMDGPUIntrinsic::AMDGPU_bfi:
707       return DAG.getNode(AMDGPUISD::BFI, DL, VT,
708                          Op.getOperand(1),
709                          Op.getOperand(2),
710                          Op.getOperand(3));
711
712     case AMDGPUIntrinsic::AMDGPU_bfm:
713       return DAG.getNode(AMDGPUISD::BFM, DL, VT,
714                          Op.getOperand(1),
715                          Op.getOperand(2));
716
717     case AMDGPUIntrinsic::AMDIL_round_nearest:
718       return DAG.getNode(ISD::FRINT, DL, VT, Op.getOperand(1));
719   }
720 }
721
722 ///IABS(a) = SMAX(sub(0, a), a)
723 SDValue AMDGPUTargetLowering::LowerIntrinsicIABS(SDValue Op,
724     SelectionDAG &DAG) const {
725
726   SDLoc DL(Op);
727   EVT VT = Op.getValueType();
728   SDValue Neg = DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, VT),
729                                               Op.getOperand(1));
730
731   return DAG.getNode(AMDGPUISD::SMAX, DL, VT, Neg, Op.getOperand(1));
732 }
733
734 /// Linear Interpolation
735 /// LRP(a, b, c) = muladd(a,  b, (1 - a) * c)
736 SDValue AMDGPUTargetLowering::LowerIntrinsicLRP(SDValue Op,
737     SelectionDAG &DAG) const {
738   SDLoc DL(Op);
739   EVT VT = Op.getValueType();
740   SDValue OneSubA = DAG.getNode(ISD::FSUB, DL, VT,
741                                 DAG.getConstantFP(1.0f, MVT::f32),
742                                 Op.getOperand(1));
743   SDValue OneSubAC = DAG.getNode(ISD::FMUL, DL, VT, OneSubA,
744                                                     Op.getOperand(3));
745   return DAG.getNode(ISD::FADD, DL, VT,
746       DAG.getNode(ISD::FMUL, DL, VT, Op.getOperand(1), Op.getOperand(2)),
747       OneSubAC);
748 }
749
750 /// \brief Generate Min/Max node
751 SDValue AMDGPUTargetLowering::LowerMinMax(SDValue Op,
752     SelectionDAG &DAG) const {
753   SDLoc DL(Op);
754   EVT VT = Op.getValueType();
755
756   SDValue LHS = Op.getOperand(0);
757   SDValue RHS = Op.getOperand(1);
758   SDValue True = Op.getOperand(2);
759   SDValue False = Op.getOperand(3);
760   SDValue CC = Op.getOperand(4);
761
762   if (VT != MVT::f32 ||
763       !((LHS == True && RHS == False) || (LHS == False && RHS == True))) {
764     return SDValue();
765   }
766
767   ISD::CondCode CCOpcode = cast<CondCodeSDNode>(CC)->get();
768   switch (CCOpcode) {
769   case ISD::SETOEQ:
770   case ISD::SETONE:
771   case ISD::SETUNE:
772   case ISD::SETNE:
773   case ISD::SETUEQ:
774   case ISD::SETEQ:
775   case ISD::SETFALSE:
776   case ISD::SETFALSE2:
777   case ISD::SETTRUE:
778   case ISD::SETTRUE2:
779   case ISD::SETUO:
780   case ISD::SETO:
781     llvm_unreachable("Operation should already be optimised!");
782   case ISD::SETULE:
783   case ISD::SETULT:
784   case ISD::SETOLE:
785   case ISD::SETOLT:
786   case ISD::SETLE:
787   case ISD::SETLT: {
788     if (LHS == True)
789       return DAG.getNode(AMDGPUISD::FMIN, DL, VT, LHS, RHS);
790     else
791       return DAG.getNode(AMDGPUISD::FMAX, DL, VT, LHS, RHS);
792   }
793   case ISD::SETGT:
794   case ISD::SETGE:
795   case ISD::SETUGE:
796   case ISD::SETOGE:
797   case ISD::SETUGT:
798   case ISD::SETOGT: {
799     if (LHS == True)
800       return DAG.getNode(AMDGPUISD::FMAX, DL, VT, LHS, RHS);
801     else
802       return DAG.getNode(AMDGPUISD::FMIN, DL, VT, LHS, RHS);
803   }
804   case ISD::SETCC_INVALID:
805     llvm_unreachable("Invalid setcc condcode!");
806   }
807   return Op;
808 }
809
810 SDValue AMDGPUTargetLowering::SplitVectorLoad(const SDValue &Op,
811                                               SelectionDAG &DAG) const {
812   LoadSDNode *Load = dyn_cast<LoadSDNode>(Op);
813   EVT MemEltVT = Load->getMemoryVT().getVectorElementType();
814   EVT EltVT = Op.getValueType().getVectorElementType();
815   EVT PtrVT = Load->getBasePtr().getValueType();
816   unsigned NumElts = Load->getMemoryVT().getVectorNumElements();
817   SmallVector<SDValue, 8> Loads;
818   SDLoc SL(Op);
819
820   for (unsigned i = 0, e = NumElts; i != e; ++i) {
821     SDValue Ptr = DAG.getNode(ISD::ADD, SL, PtrVT, Load->getBasePtr(),
822                     DAG.getConstant(i * (MemEltVT.getSizeInBits() / 8), PtrVT));
823     Loads.push_back(DAG.getExtLoad(Load->getExtensionType(), SL, EltVT,
824                         Load->getChain(), Ptr,
825                         MachinePointerInfo(Load->getMemOperand()->getValue()),
826                         MemEltVT, Load->isVolatile(), Load->isNonTemporal(),
827                         Load->getAlignment()));
828   }
829   return DAG.getNode(ISD::BUILD_VECTOR, SL, Op.getValueType(), Loads);
830 }
831
832 SDValue AMDGPUTargetLowering::MergeVectorStore(const SDValue &Op,
833                                                SelectionDAG &DAG) const {
834   StoreSDNode *Store = dyn_cast<StoreSDNode>(Op);
835   EVT MemVT = Store->getMemoryVT();
836   unsigned MemBits = MemVT.getSizeInBits();
837
838   // Byte stores are really expensive, so if possible, try to pack 32-bit vector
839   // truncating store into an i32 store.
840   // XXX: We could also handle optimize other vector bitwidths.
841   if (!MemVT.isVector() || MemBits > 32) {
842     return SDValue();
843   }
844
845   SDLoc DL(Op);
846   SDValue Value = Store->getValue();
847   EVT VT = Value.getValueType();
848   EVT ElemVT = VT.getVectorElementType();
849   SDValue Ptr = Store->getBasePtr();
850   EVT MemEltVT = MemVT.getVectorElementType();
851   unsigned MemEltBits = MemEltVT.getSizeInBits();
852   unsigned MemNumElements = MemVT.getVectorNumElements();
853   unsigned PackedSize = MemVT.getStoreSizeInBits();
854   SDValue Mask = DAG.getConstant((1 << MemEltBits) - 1, MVT::i32);
855
856   assert(Value.getValueType().getScalarSizeInBits() >= 32);
857
858   SDValue PackedValue;
859   for (unsigned i = 0; i < MemNumElements; ++i) {
860     SDValue Elt = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, DL, ElemVT, Value,
861                               DAG.getConstant(i, MVT::i32));
862     Elt = DAG.getZExtOrTrunc(Elt, DL, MVT::i32);
863     Elt = DAG.getNode(ISD::AND, DL, MVT::i32, Elt, Mask); // getZeroExtendInReg
864
865     SDValue Shift = DAG.getConstant(MemEltBits * i, MVT::i32);
866     Elt = DAG.getNode(ISD::SHL, DL, MVT::i32, Elt, Shift);
867
868     if (i == 0) {
869       PackedValue = Elt;
870     } else {
871       PackedValue = DAG.getNode(ISD::OR, DL, MVT::i32, PackedValue, Elt);
872     }
873   }
874
875   if (PackedSize < 32) {
876     EVT PackedVT = EVT::getIntegerVT(*DAG.getContext(), PackedSize);
877     return DAG.getTruncStore(Store->getChain(), DL, PackedValue, Ptr,
878                              Store->getMemOperand()->getPointerInfo(),
879                              PackedVT,
880                              Store->isNonTemporal(), Store->isVolatile(),
881                              Store->getAlignment());
882   }
883
884   return DAG.getStore(Store->getChain(), DL, PackedValue, Ptr,
885                       Store->getMemOperand()->getPointerInfo(),
886                       Store->isVolatile(),  Store->isNonTemporal(),
887                       Store->getAlignment());
888 }
889
890 SDValue AMDGPUTargetLowering::SplitVectorStore(SDValue Op,
891                                             SelectionDAG &DAG) const {
892   StoreSDNode *Store = cast<StoreSDNode>(Op);
893   EVT MemEltVT = Store->getMemoryVT().getVectorElementType();
894   EVT EltVT = Store->getValue().getValueType().getVectorElementType();
895   EVT PtrVT = Store->getBasePtr().getValueType();
896   unsigned NumElts = Store->getMemoryVT().getVectorNumElements();
897   SDLoc SL(Op);
898
899   SmallVector<SDValue, 8> Chains;
900
901   for (unsigned i = 0, e = NumElts; i != e; ++i) {
902     SDValue Val = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SL, EltVT,
903                               Store->getValue(), DAG.getConstant(i, MVT::i32));
904     SDValue Ptr = DAG.getNode(ISD::ADD, SL, PtrVT,
905                               Store->getBasePtr(),
906                             DAG.getConstant(i * (MemEltVT.getSizeInBits() / 8),
907                                             PtrVT));
908     Chains.push_back(DAG.getTruncStore(Store->getChain(), SL, Val, Ptr,
909                          MachinePointerInfo(Store->getMemOperand()->getValue()),
910                          MemEltVT, Store->isVolatile(), Store->isNonTemporal(),
911                          Store->getAlignment()));
912   }
913   return DAG.getNode(ISD::TokenFactor, SL, MVT::Other, Chains);
914 }
915
916 SDValue AMDGPUTargetLowering::LowerLOAD(SDValue Op, SelectionDAG &DAG) const {
917   SDLoc DL(Op);
918   LoadSDNode *Load = cast<LoadSDNode>(Op);
919   ISD::LoadExtType ExtType = Load->getExtensionType();
920   EVT VT = Op.getValueType();
921   EVT MemVT = Load->getMemoryVT();
922
923   if (ExtType != ISD::NON_EXTLOAD && !VT.isVector() && VT.getSizeInBits() > 32) {
924     // We can do the extload to 32-bits, and then need to separately extend to
925     // 64-bits.
926
927     SDValue ExtLoad32 = DAG.getExtLoad(ExtType, DL, MVT::i32,
928                                        Load->getChain(),
929                                        Load->getBasePtr(),
930                                        MemVT,
931                                        Load->getMemOperand());
932     return DAG.getNode(ISD::getExtForLoadExtType(ExtType), DL, VT, ExtLoad32);
933   }
934
935   if (ExtType == ISD::NON_EXTLOAD && VT.getSizeInBits() < 32) {
936     assert(VT == MVT::i1 && "Only i1 non-extloads expected");
937     // FIXME: Copied from PPC
938     // First, load into 32 bits, then truncate to 1 bit.
939
940     SDValue Chain = Load->getChain();
941     SDValue BasePtr = Load->getBasePtr();
942     MachineMemOperand *MMO = Load->getMemOperand();
943
944     SDValue NewLD = DAG.getExtLoad(ISD::EXTLOAD, DL, MVT::i32, Chain,
945                                    BasePtr, MVT::i8, MMO);
946     return DAG.getNode(ISD::TRUNCATE, DL, VT, NewLD);
947   }
948
949   // Lower loads constant address space global variable loads
950   if (Load->getAddressSpace() == AMDGPUAS::CONSTANT_ADDRESS &&
951       isa<GlobalVariable>(
952           GetUnderlyingObject(Load->getMemOperand()->getValue()))) {
953
954     SDValue Ptr = DAG.getZExtOrTrunc(Load->getBasePtr(), DL,
955         getPointerTy(AMDGPUAS::PRIVATE_ADDRESS));
956     Ptr = DAG.getNode(ISD::SRL, DL, MVT::i32, Ptr,
957         DAG.getConstant(2, MVT::i32));
958     return DAG.getNode(AMDGPUISD::REGISTER_LOAD, DL, Op.getValueType(),
959                        Load->getChain(), Ptr,
960                        DAG.getTargetConstant(0, MVT::i32), Op.getOperand(2));
961   }
962
963   if (Load->getAddressSpace() != AMDGPUAS::PRIVATE_ADDRESS ||
964       ExtType == ISD::NON_EXTLOAD || Load->getMemoryVT().bitsGE(MVT::i32))
965     return SDValue();
966
967
968   SDValue Ptr = DAG.getNode(ISD::SRL, DL, MVT::i32, Load->getBasePtr(),
969                             DAG.getConstant(2, MVT::i32));
970   SDValue Ret = DAG.getNode(AMDGPUISD::REGISTER_LOAD, DL, Op.getValueType(),
971                             Load->getChain(), Ptr,
972                             DAG.getTargetConstant(0, MVT::i32),
973                             Op.getOperand(2));
974   SDValue ByteIdx = DAG.getNode(ISD::AND, DL, MVT::i32,
975                                 Load->getBasePtr(),
976                                 DAG.getConstant(0x3, MVT::i32));
977   SDValue ShiftAmt = DAG.getNode(ISD::SHL, DL, MVT::i32, ByteIdx,
978                                  DAG.getConstant(3, MVT::i32));
979
980   Ret = DAG.getNode(ISD::SRL, DL, MVT::i32, Ret, ShiftAmt);
981
982   EVT MemEltVT = MemVT.getScalarType();
983   if (ExtType == ISD::SEXTLOAD) {
984     SDValue MemEltVTNode = DAG.getValueType(MemEltVT);
985     return DAG.getNode(ISD::SIGN_EXTEND_INREG, DL, MVT::i32, Ret, MemEltVTNode);
986   }
987
988   return DAG.getZeroExtendInReg(Ret, DL, MemEltVT);
989 }
990
991 SDValue AMDGPUTargetLowering::LowerSTORE(SDValue Op, SelectionDAG &DAG) const {
992   SDLoc DL(Op);
993   SDValue Result = AMDGPUTargetLowering::MergeVectorStore(Op, DAG);
994   if (Result.getNode()) {
995     return Result;
996   }
997
998   StoreSDNode *Store = cast<StoreSDNode>(Op);
999   SDValue Chain = Store->getChain();
1000   if ((Store->getAddressSpace() == AMDGPUAS::LOCAL_ADDRESS ||
1001        Store->getAddressSpace() == AMDGPUAS::PRIVATE_ADDRESS) &&
1002       Store->getValue().getValueType().isVector()) {
1003     return SplitVectorStore(Op, DAG);
1004   }
1005
1006   EVT MemVT = Store->getMemoryVT();
1007   if (Store->getAddressSpace() == AMDGPUAS::PRIVATE_ADDRESS &&
1008       MemVT.bitsLT(MVT::i32)) {
1009     unsigned Mask = 0;
1010     if (Store->getMemoryVT() == MVT::i8) {
1011       Mask = 0xff;
1012     } else if (Store->getMemoryVT() == MVT::i16) {
1013       Mask = 0xffff;
1014     }
1015     SDValue BasePtr = Store->getBasePtr();
1016     SDValue Ptr = DAG.getNode(ISD::SRL, DL, MVT::i32, BasePtr,
1017                               DAG.getConstant(2, MVT::i32));
1018     SDValue Dst = DAG.getNode(AMDGPUISD::REGISTER_LOAD, DL, MVT::i32,
1019                               Chain, Ptr, DAG.getTargetConstant(0, MVT::i32));
1020
1021     SDValue ByteIdx = DAG.getNode(ISD::AND, DL, MVT::i32, BasePtr,
1022                                   DAG.getConstant(0x3, MVT::i32));
1023
1024     SDValue ShiftAmt = DAG.getNode(ISD::SHL, DL, MVT::i32, ByteIdx,
1025                                    DAG.getConstant(3, MVT::i32));
1026
1027     SDValue SExtValue = DAG.getNode(ISD::SIGN_EXTEND, DL, MVT::i32,
1028                                     Store->getValue());
1029
1030     SDValue MaskedValue = DAG.getZeroExtendInReg(SExtValue, DL, MemVT);
1031
1032     SDValue ShiftedValue = DAG.getNode(ISD::SHL, DL, MVT::i32,
1033                                        MaskedValue, ShiftAmt);
1034
1035     SDValue DstMask = DAG.getNode(ISD::SHL, DL, MVT::i32, DAG.getConstant(Mask, MVT::i32),
1036                                   ShiftAmt);
1037     DstMask = DAG.getNode(ISD::XOR, DL, MVT::i32, DstMask,
1038                           DAG.getConstant(0xffffffff, MVT::i32));
1039     Dst = DAG.getNode(ISD::AND, DL, MVT::i32, Dst, DstMask);
1040
1041     SDValue Value = DAG.getNode(ISD::OR, DL, MVT::i32, Dst, ShiftedValue);
1042     return DAG.getNode(AMDGPUISD::REGISTER_STORE, DL, MVT::Other,
1043                        Chain, Value, Ptr, DAG.getTargetConstant(0, MVT::i32));
1044   }
1045   return SDValue();
1046 }
1047
1048 SDValue AMDGPUTargetLowering::LowerUDIVREM(SDValue Op,
1049     SelectionDAG &DAG) const {
1050   SDLoc DL(Op);
1051   EVT VT = Op.getValueType();
1052
1053   SDValue Num = Op.getOperand(0);
1054   SDValue Den = Op.getOperand(1);
1055
1056   // RCP =  URECIP(Den) = 2^32 / Den + e
1057   // e is rounding error.
1058   SDValue RCP = DAG.getNode(AMDGPUISD::URECIP, DL, VT, Den);
1059
1060   // RCP_LO = umulo(RCP, Den) */
1061   SDValue RCP_LO = DAG.getNode(ISD::UMULO, DL, VT, RCP, Den);
1062
1063   // RCP_HI = mulhu (RCP, Den) */
1064   SDValue RCP_HI = DAG.getNode(ISD::MULHU, DL, VT, RCP, Den);
1065
1066   // NEG_RCP_LO = -RCP_LO
1067   SDValue NEG_RCP_LO = DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, VT),
1068                                                      RCP_LO);
1069
1070   // ABS_RCP_LO = (RCP_HI == 0 ? NEG_RCP_LO : RCP_LO)
1071   SDValue ABS_RCP_LO = DAG.getSelectCC(DL, RCP_HI, DAG.getConstant(0, VT),
1072                                            NEG_RCP_LO, RCP_LO,
1073                                            ISD::SETEQ);
1074   // Calculate the rounding error from the URECIP instruction
1075   // E = mulhu(ABS_RCP_LO, RCP)
1076   SDValue E = DAG.getNode(ISD::MULHU, DL, VT, ABS_RCP_LO, RCP);
1077
1078   // RCP_A_E = RCP + E
1079   SDValue RCP_A_E = DAG.getNode(ISD::ADD, DL, VT, RCP, E);
1080
1081   // RCP_S_E = RCP - E
1082   SDValue RCP_S_E = DAG.getNode(ISD::SUB, DL, VT, RCP, E);
1083
1084   // Tmp0 = (RCP_HI == 0 ? RCP_A_E : RCP_SUB_E)
1085   SDValue Tmp0 = DAG.getSelectCC(DL, RCP_HI, DAG.getConstant(0, VT),
1086                                      RCP_A_E, RCP_S_E,
1087                                      ISD::SETEQ);
1088   // Quotient = mulhu(Tmp0, Num)
1089   SDValue Quotient = DAG.getNode(ISD::MULHU, DL, VT, Tmp0, Num);
1090
1091   // Num_S_Remainder = Quotient * Den
1092   SDValue Num_S_Remainder = DAG.getNode(ISD::UMULO, DL, VT, Quotient, Den);
1093
1094   // Remainder = Num - Num_S_Remainder
1095   SDValue Remainder = DAG.getNode(ISD::SUB, DL, VT, Num, Num_S_Remainder);
1096
1097   // Remainder_GE_Den = (Remainder >= Den ? -1 : 0)
1098   SDValue Remainder_GE_Den = DAG.getSelectCC(DL, Remainder, Den,
1099                                                  DAG.getConstant(-1, VT),
1100                                                  DAG.getConstant(0, VT),
1101                                                  ISD::SETUGE);
1102   // Remainder_GE_Zero = (Num >= Num_S_Remainder ? -1 : 0)
1103   SDValue Remainder_GE_Zero = DAG.getSelectCC(DL, Num,
1104                                                   Num_S_Remainder,
1105                                                   DAG.getConstant(-1, VT),
1106                                                   DAG.getConstant(0, VT),
1107                                                   ISD::SETUGE);
1108   // Tmp1 = Remainder_GE_Den & Remainder_GE_Zero
1109   SDValue Tmp1 = DAG.getNode(ISD::AND, DL, VT, Remainder_GE_Den,
1110                                                Remainder_GE_Zero);
1111
1112   // Calculate Division result:
1113
1114   // Quotient_A_One = Quotient + 1
1115   SDValue Quotient_A_One = DAG.getNode(ISD::ADD, DL, VT, Quotient,
1116                                                          DAG.getConstant(1, VT));
1117
1118   // Quotient_S_One = Quotient - 1
1119   SDValue Quotient_S_One = DAG.getNode(ISD::SUB, DL, VT, Quotient,
1120                                                          DAG.getConstant(1, VT));
1121
1122   // Div = (Tmp1 == 0 ? Quotient : Quotient_A_One)
1123   SDValue Div = DAG.getSelectCC(DL, Tmp1, DAG.getConstant(0, VT),
1124                                      Quotient, Quotient_A_One, ISD::SETEQ);
1125
1126   // Div = (Remainder_GE_Zero == 0 ? Quotient_S_One : Div)
1127   Div = DAG.getSelectCC(DL, Remainder_GE_Zero, DAG.getConstant(0, VT),
1128                             Quotient_S_One, Div, ISD::SETEQ);
1129
1130   // Calculate Rem result:
1131
1132   // Remainder_S_Den = Remainder - Den
1133   SDValue Remainder_S_Den = DAG.getNode(ISD::SUB, DL, VT, Remainder, Den);
1134
1135   // Remainder_A_Den = Remainder + Den
1136   SDValue Remainder_A_Den = DAG.getNode(ISD::ADD, DL, VT, Remainder, Den);
1137
1138   // Rem = (Tmp1 == 0 ? Remainder : Remainder_S_Den)
1139   SDValue Rem = DAG.getSelectCC(DL, Tmp1, DAG.getConstant(0, VT),
1140                                     Remainder, Remainder_S_Den, ISD::SETEQ);
1141
1142   // Rem = (Remainder_GE_Zero == 0 ? Remainder_A_Den : Rem)
1143   Rem = DAG.getSelectCC(DL, Remainder_GE_Zero, DAG.getConstant(0, VT),
1144                             Remainder_A_Den, Rem, ISD::SETEQ);
1145   SDValue Ops[2] = {
1146     Div,
1147     Rem
1148   };
1149   return DAG.getMergeValues(Ops, DL);
1150 }
1151
1152 SDValue AMDGPUTargetLowering::LowerUINT_TO_FP(SDValue Op,
1153                                                SelectionDAG &DAG) const {
1154   SDValue S0 = Op.getOperand(0);
1155   SDLoc DL(Op);
1156   if (Op.getValueType() != MVT::f32 || S0.getValueType() != MVT::i64)
1157     return SDValue();
1158
1159   // f32 uint_to_fp i64
1160   SDValue Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i32, S0,
1161                            DAG.getConstant(0, MVT::i32));
1162   SDValue FloatLo = DAG.getNode(ISD::UINT_TO_FP, DL, MVT::f32, Lo);
1163   SDValue Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, MVT::i32, S0,
1164                            DAG.getConstant(1, MVT::i32));
1165   SDValue FloatHi = DAG.getNode(ISD::UINT_TO_FP, DL, MVT::f32, Hi);
1166   FloatHi = DAG.getNode(ISD::FMUL, DL, MVT::f32, FloatHi,
1167                         DAG.getConstantFP(4294967296.0f, MVT::f32)); // 2^32
1168   return DAG.getNode(ISD::FADD, DL, MVT::f32, FloatLo, FloatHi);
1169
1170 }
1171
1172 SDValue AMDGPUTargetLowering::ExpandSIGN_EXTEND_INREG(SDValue Op,
1173                                                       unsigned BitsDiff,
1174                                                       SelectionDAG &DAG) const {
1175   MVT VT = Op.getSimpleValueType();
1176   SDLoc DL(Op);
1177   SDValue Shift = DAG.getConstant(BitsDiff, VT);
1178   // Shift left by 'Shift' bits.
1179   SDValue Shl = DAG.getNode(ISD::SHL, DL, VT, Op.getOperand(0), Shift);
1180   // Signed shift Right by 'Shift' bits.
1181   return DAG.getNode(ISD::SRA, DL, VT, Shl, Shift);
1182 }
1183
1184 SDValue AMDGPUTargetLowering::LowerSIGN_EXTEND_INREG(SDValue Op,
1185                                                      SelectionDAG &DAG) const {
1186   EVT ExtraVT = cast<VTSDNode>(Op.getOperand(1))->getVT();
1187   MVT VT = Op.getSimpleValueType();
1188   MVT ScalarVT = VT.getScalarType();
1189
1190   if (!VT.isVector())
1191     return SDValue();
1192
1193   SDValue Src = Op.getOperand(0);
1194   SDLoc DL(Op);
1195
1196   // TODO: Don't scalarize on Evergreen?
1197   unsigned NElts = VT.getVectorNumElements();
1198   SmallVector<SDValue, 8> Args;
1199   DAG.ExtractVectorElements(Src, Args, 0, NElts);
1200
1201   SDValue VTOp = DAG.getValueType(ExtraVT.getScalarType());
1202   for (unsigned I = 0; I < NElts; ++I)
1203     Args[I] = DAG.getNode(ISD::SIGN_EXTEND_INREG, DL, ScalarVT, Args[I], VTOp);
1204
1205   return DAG.getNode(ISD::BUILD_VECTOR, DL, VT, Args);
1206 }
1207
1208 //===----------------------------------------------------------------------===//
1209 // Custom DAG optimizations
1210 //===----------------------------------------------------------------------===//
1211
1212 static bool isU24(SDValue Op, SelectionDAG &DAG) {
1213   APInt KnownZero, KnownOne;
1214   EVT VT = Op.getValueType();
1215   DAG.ComputeMaskedBits(Op, KnownZero, KnownOne);
1216
1217   return (VT.getSizeInBits() - KnownZero.countLeadingOnes()) <= 24;
1218 }
1219
1220 static bool isI24(SDValue Op, SelectionDAG &DAG) {
1221   EVT VT = Op.getValueType();
1222
1223   // In order for this to be a signed 24-bit value, bit 23, must
1224   // be a sign bit.
1225   return VT.getSizeInBits() >= 24 && // Types less than 24-bit should be treated
1226                                      // as unsigned 24-bit values.
1227          (VT.getSizeInBits() - DAG.ComputeNumSignBits(Op)) < 24;
1228 }
1229
1230 static void simplifyI24(SDValue Op, TargetLowering::DAGCombinerInfo &DCI) {
1231
1232   SelectionDAG &DAG = DCI.DAG;
1233   const TargetLowering &TLI = DAG.getTargetLoweringInfo();
1234   EVT VT = Op.getValueType();
1235
1236   APInt Demanded = APInt::getLowBitsSet(VT.getSizeInBits(), 24);
1237   APInt KnownZero, KnownOne;
1238   TargetLowering::TargetLoweringOpt TLO(DAG, true, true);
1239   if (TLI.SimplifyDemandedBits(Op, Demanded, KnownZero, KnownOne, TLO))
1240     DCI.CommitTargetLoweringOpt(TLO);
1241 }
1242
1243 SDValue AMDGPUTargetLowering::PerformDAGCombine(SDNode *N,
1244                                             DAGCombinerInfo &DCI) const {
1245   SelectionDAG &DAG = DCI.DAG;
1246   SDLoc DL(N);
1247
1248   switch(N->getOpcode()) {
1249     default: break;
1250     case ISD::MUL: {
1251       EVT VT = N->getValueType(0);
1252       SDValue N0 = N->getOperand(0);
1253       SDValue N1 = N->getOperand(1);
1254       SDValue Mul;
1255
1256       // FIXME: Add support for 24-bit multiply with 64-bit output on SI.
1257       if (VT.isVector() || VT.getSizeInBits() > 32)
1258         break;
1259
1260       if (Subtarget->hasMulU24() && isU24(N0, DAG) && isU24(N1, DAG)) {
1261         N0 = DAG.getZExtOrTrunc(N0, DL, MVT::i32);
1262         N1 = DAG.getZExtOrTrunc(N1, DL, MVT::i32);
1263         Mul = DAG.getNode(AMDGPUISD::MUL_U24, DL, MVT::i32, N0, N1);
1264       } else if (Subtarget->hasMulI24() && isI24(N0, DAG) && isI24(N1, DAG)) {
1265         N0 = DAG.getSExtOrTrunc(N0, DL, MVT::i32);
1266         N1 = DAG.getSExtOrTrunc(N1, DL, MVT::i32);
1267         Mul = DAG.getNode(AMDGPUISD::MUL_I24, DL, MVT::i32, N0, N1);
1268       } else {
1269         break;
1270       }
1271
1272       // We need to use sext even for MUL_U24, because MUL_U24 is used
1273       // for signed multiply of 8 and 16-bit types.
1274       SDValue Reg = DAG.getSExtOrTrunc(Mul, DL, VT);
1275
1276       return Reg;
1277     }
1278     case AMDGPUISD::MUL_I24:
1279     case AMDGPUISD::MUL_U24: {
1280       SDValue N0 = N->getOperand(0);
1281       SDValue N1 = N->getOperand(1);
1282       simplifyI24(N0, DCI);
1283       simplifyI24(N1, DCI);
1284       return SDValue();
1285     }
1286   }
1287   return SDValue();
1288 }
1289
1290 //===----------------------------------------------------------------------===//
1291 // Helper functions
1292 //===----------------------------------------------------------------------===//
1293
1294 void AMDGPUTargetLowering::getOriginalFunctionArgs(
1295                                SelectionDAG &DAG,
1296                                const Function *F,
1297                                const SmallVectorImpl<ISD::InputArg> &Ins,
1298                                SmallVectorImpl<ISD::InputArg> &OrigIns) const {
1299
1300   for (unsigned i = 0, e = Ins.size(); i < e; ++i) {
1301     if (Ins[i].ArgVT == Ins[i].VT) {
1302       OrigIns.push_back(Ins[i]);
1303       continue;
1304     }
1305
1306     EVT VT;
1307     if (Ins[i].ArgVT.isVector() && !Ins[i].VT.isVector()) {
1308       // Vector has been split into scalars.
1309       VT = Ins[i].ArgVT.getVectorElementType();
1310     } else if (Ins[i].VT.isVector() && Ins[i].ArgVT.isVector() &&
1311                Ins[i].ArgVT.getVectorElementType() !=
1312                Ins[i].VT.getVectorElementType()) {
1313       // Vector elements have been promoted
1314       VT = Ins[i].ArgVT;
1315     } else {
1316       // Vector has been spilt into smaller vectors.
1317       VT = Ins[i].VT;
1318     }
1319
1320     ISD::InputArg Arg(Ins[i].Flags, VT, VT, Ins[i].Used,
1321                       Ins[i].OrigArgIndex, Ins[i].PartOffset);
1322     OrigIns.push_back(Arg);
1323   }
1324 }
1325
1326 bool AMDGPUTargetLowering::isHWTrueValue(SDValue Op) const {
1327   if (ConstantFPSDNode * CFP = dyn_cast<ConstantFPSDNode>(Op)) {
1328     return CFP->isExactlyValue(1.0);
1329   }
1330   if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
1331     return C->isAllOnesValue();
1332   }
1333   return false;
1334 }
1335
1336 bool AMDGPUTargetLowering::isHWFalseValue(SDValue Op) const {
1337   if (ConstantFPSDNode * CFP = dyn_cast<ConstantFPSDNode>(Op)) {
1338     return CFP->getValueAPF().isZero();
1339   }
1340   if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Op)) {
1341     return C->isNullValue();
1342   }
1343   return false;
1344 }
1345
1346 SDValue AMDGPUTargetLowering::CreateLiveInRegister(SelectionDAG &DAG,
1347                                                   const TargetRegisterClass *RC,
1348                                                    unsigned Reg, EVT VT) const {
1349   MachineFunction &MF = DAG.getMachineFunction();
1350   MachineRegisterInfo &MRI = MF.getRegInfo();
1351   unsigned VirtualRegister;
1352   if (!MRI.isLiveIn(Reg)) {
1353     VirtualRegister = MRI.createVirtualRegister(RC);
1354     MRI.addLiveIn(Reg, VirtualRegister);
1355   } else {
1356     VirtualRegister = MRI.getLiveInVirtReg(Reg);
1357   }
1358   return DAG.getRegister(VirtualRegister, VT);
1359 }
1360
1361 #define NODE_NAME_CASE(node) case AMDGPUISD::node: return #node;
1362
1363 const char* AMDGPUTargetLowering::getTargetNodeName(unsigned Opcode) const {
1364   switch (Opcode) {
1365   default: return nullptr;
1366   // AMDIL DAG nodes
1367   NODE_NAME_CASE(CALL);
1368   NODE_NAME_CASE(UMUL);
1369   NODE_NAME_CASE(DIV_INF);
1370   NODE_NAME_CASE(RET_FLAG);
1371   NODE_NAME_CASE(BRANCH_COND);
1372
1373   // AMDGPU DAG nodes
1374   NODE_NAME_CASE(DWORDADDR)
1375   NODE_NAME_CASE(FRACT)
1376   NODE_NAME_CASE(FMAX)
1377   NODE_NAME_CASE(SMAX)
1378   NODE_NAME_CASE(UMAX)
1379   NODE_NAME_CASE(FMIN)
1380   NODE_NAME_CASE(SMIN)
1381   NODE_NAME_CASE(UMIN)
1382   NODE_NAME_CASE(BFE_U32)
1383   NODE_NAME_CASE(BFE_I32)
1384   NODE_NAME_CASE(BFI)
1385   NODE_NAME_CASE(BFM)
1386   NODE_NAME_CASE(MUL_U24)
1387   NODE_NAME_CASE(MUL_I24)
1388   NODE_NAME_CASE(URECIP)
1389   NODE_NAME_CASE(DOT4)
1390   NODE_NAME_CASE(EXPORT)
1391   NODE_NAME_CASE(CONST_ADDRESS)
1392   NODE_NAME_CASE(REGISTER_LOAD)
1393   NODE_NAME_CASE(REGISTER_STORE)
1394   NODE_NAME_CASE(LOAD_CONSTANT)
1395   NODE_NAME_CASE(LOAD_INPUT)
1396   NODE_NAME_CASE(SAMPLE)
1397   NODE_NAME_CASE(SAMPLEB)
1398   NODE_NAME_CASE(SAMPLED)
1399   NODE_NAME_CASE(SAMPLEL)
1400   NODE_NAME_CASE(STORE_MSKOR)
1401   NODE_NAME_CASE(TBUFFER_STORE_FORMAT)
1402   }
1403 }
1404
1405 static void computeMaskedBitsForMinMax(const SDValue Op0,
1406                                        const SDValue Op1,
1407                                        APInt &KnownZero,
1408                                        APInt &KnownOne,
1409                                        const SelectionDAG &DAG,
1410                                        unsigned Depth) {
1411   APInt Op0Zero, Op0One;
1412   APInt Op1Zero, Op1One;
1413   DAG.ComputeMaskedBits(Op0, Op0Zero, Op0One, Depth);
1414   DAG.ComputeMaskedBits(Op1, Op1Zero, Op1One, Depth);
1415
1416   KnownZero = Op0Zero & Op1Zero;
1417   KnownOne = Op0One & Op1One;
1418 }
1419
1420 void AMDGPUTargetLowering::computeMaskedBitsForTargetNode(
1421   const SDValue Op,
1422   APInt &KnownZero,
1423   APInt &KnownOne,
1424   const SelectionDAG &DAG,
1425   unsigned Depth) const {
1426
1427   KnownZero = KnownOne = APInt(KnownOne.getBitWidth(), 0); // Don't know anything.
1428   unsigned Opc = Op.getOpcode();
1429   switch (Opc) {
1430   case ISD::INTRINSIC_WO_CHAIN: {
1431     // FIXME: The intrinsic should just use the node.
1432     switch (cast<ConstantSDNode>(Op.getOperand(0))->getZExtValue()) {
1433     case AMDGPUIntrinsic::AMDGPU_imax:
1434     case AMDGPUIntrinsic::AMDGPU_umax:
1435     case AMDGPUIntrinsic::AMDGPU_imin:
1436     case AMDGPUIntrinsic::AMDGPU_umin:
1437       computeMaskedBitsForMinMax(Op.getOperand(1), Op.getOperand(2),
1438                                  KnownZero, KnownOne, DAG, Depth);
1439       break;
1440     default:
1441       break;
1442     }
1443
1444     break;
1445   }
1446   case AMDGPUISD::SMAX:
1447   case AMDGPUISD::UMAX:
1448   case AMDGPUISD::SMIN:
1449   case AMDGPUISD::UMIN:
1450     computeMaskedBitsForMinMax(Op.getOperand(0), Op.getOperand(1),
1451                                KnownZero, KnownOne, DAG, Depth);
1452     break;
1453   default:
1454     break;
1455   }
1456 }