LLVM  5.0.0
AMDGPUISelLowering.cpp
Go to the documentation of this file.
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 "AMDGPUCallLowering.h"
19 #include "AMDGPUFrameLowering.h"
20 #include "AMDGPUIntrinsicInfo.h"
21 #include "AMDGPURegisterInfo.h"
22 #include "AMDGPUSubtarget.h"
24 #include "SIInstrInfo.h"
25 #include "SIMachineFunctionInfo.h"
31 #include "llvm/IR/DataLayout.h"
32 #include "llvm/IR/DiagnosticInfo.h"
33 #include "llvm/Support/KnownBits.h"
34 using namespace llvm;
35 
36 static bool allocateKernArg(unsigned ValNo, MVT ValVT, MVT LocVT,
37  CCValAssign::LocInfo LocInfo,
38  ISD::ArgFlagsTy ArgFlags, CCState &State) {
39  MachineFunction &MF = State.getMachineFunction();
41 
42  uint64_t Offset = MFI->allocateKernArg(LocVT.getStoreSize(),
43  ArgFlags.getOrigAlign());
44  State.addLoc(CCValAssign::getCustomMem(ValNo, ValVT, Offset, LocVT, LocInfo));
45  return true;
46 }
47 
48 static bool allocateCCRegs(unsigned ValNo, MVT ValVT, MVT LocVT,
49  CCValAssign::LocInfo LocInfo,
50  ISD::ArgFlagsTy ArgFlags, CCState &State,
51  const TargetRegisterClass *RC,
52  unsigned NumRegs) {
53  ArrayRef<MCPhysReg> RegList = makeArrayRef(RC->begin(), NumRegs);
54  unsigned RegResult = State.AllocateReg(RegList);
55  if (RegResult == AMDGPU::NoRegister)
56  return false;
57 
58  State.addLoc(CCValAssign::getReg(ValNo, ValVT, RegResult, LocVT, LocInfo));
59  return true;
60 }
61 
62 static bool allocateSGPRTuple(unsigned ValNo, MVT ValVT, MVT LocVT,
63  CCValAssign::LocInfo LocInfo,
64  ISD::ArgFlagsTy ArgFlags, CCState &State) {
65  switch (LocVT.SimpleTy) {
66  case MVT::i64:
67  case MVT::f64:
68  case MVT::v2i32:
69  case MVT::v2f32: {
70  // Up to SGPR0-SGPR39
71  return allocateCCRegs(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State,
72  &AMDGPU::SGPR_64RegClass, 20);
73  }
74  default:
75  return false;
76  }
77 }
78 
79 // Allocate up to VGPR31.
80 //
81 // TODO: Since there are no VGPR alignent requirements would it be better to
82 // split into individual scalar registers?
83 static bool allocateVGPRTuple(unsigned ValNo, MVT ValVT, MVT LocVT,
84  CCValAssign::LocInfo LocInfo,
85  ISD::ArgFlagsTy ArgFlags, CCState &State) {
86  switch (LocVT.SimpleTy) {
87  case MVT::i64:
88  case MVT::f64:
89  case MVT::v2i32:
90  case MVT::v2f32: {
91  return allocateCCRegs(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State,
92  &AMDGPU::VReg_64RegClass, 31);
93  }
94  case MVT::v4i32:
95  case MVT::v4f32:
96  case MVT::v2i64:
97  case MVT::v2f64: {
98  return allocateCCRegs(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State,
99  &AMDGPU::VReg_128RegClass, 29);
100  }
101  case MVT::v8i32:
102  case MVT::v8f32: {
103  return allocateCCRegs(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State,
104  &AMDGPU::VReg_256RegClass, 25);
105 
106  }
107  case MVT::v16i32:
108  case MVT::v16f32: {
109  return allocateCCRegs(ValNo, ValVT, LocVT, LocInfo, ArgFlags, State,
110  &AMDGPU::VReg_512RegClass, 17);
111 
112  }
113  default:
114  return false;
115  }
116 }
117 
118 #include "AMDGPUGenCallingConv.inc"
119 
120 // Find a larger type to do a load / store of a vector with.
122  unsigned StoreSize = VT.getStoreSizeInBits();
123  if (StoreSize <= 32)
124  return EVT::getIntegerVT(Ctx, StoreSize);
125 
126  assert(StoreSize % 32 == 0 && "Store size not a multiple of 32");
127  return EVT::getVectorVT(Ctx, MVT::i32, StoreSize / 32);
128 }
129 
131 {
132  assert(Op.getOpcode() == ISD::OR);
133 
134  SDValue N0 = Op->getOperand(0);
135  SDValue N1 = Op->getOperand(1);
136  EVT VT = N0.getValueType();
137 
138  if (VT.isInteger() && !VT.isVector()) {
139  KnownBits LHSKnown, RHSKnown;
140  DAG.computeKnownBits(N0, LHSKnown);
141 
142  if (LHSKnown.Zero.getBoolValue()) {
143  DAG.computeKnownBits(N1, RHSKnown);
144 
145  if (!(~RHSKnown.Zero & ~LHSKnown.Zero))
146  return true;
147  }
148  }
149 
150  return false;
151 }
152 
154  const AMDGPUSubtarget &STI)
155  : TargetLowering(TM), Subtarget(&STI) {
157  // Lower floating point store/load to integer store/load to reduce the number
158  // of patterns in tablegen.
161 
164 
167 
170 
173 
176 
179 
182 
185 
186  // There are no 64-bit extloads. These should be done as a 32-bit extload and
187  // an extension to 64-bit.
188  for (MVT VT : MVT::integer_valuetypes()) {
192  }
193 
194  for (MVT VT : MVT::integer_valuetypes()) {
195  if (VT == MVT::i64)
196  continue;
197 
202 
207 
212  }
213 
214  for (MVT VT : MVT::integer_vector_valuetypes()) {
227  }
228 
233 
238 
243 
246 
249 
252 
255 
258 
261 
264 
267 
270 
275 
280 
285 
288 
291 
294 
297 
298 
303 
306 
307  // This is totally unsupported, just custom lower to produce an error.
309 
310  // Library functions. These default to Expand, but we have instructions
311  // for them.
322 
325 
328 
331 
332  // v_mad_f32 does not support denormals according to some sources.
333  if (!Subtarget->hasFP32Denormals())
335 
336  // Expand to fneg + fadd.
338 
349 
355  }
356 
357  if (!Subtarget->hasBFI()) {
358  // fcopysign can be done in a single instruction with BFI.
361  }
362 
366 
367  const MVT ScalarIntVTs[] = { MVT::i32, MVT::i64 };
368  for (MVT VT : ScalarIntVTs) {
369  // These should use [SU]DIVREM, so set them to expand
374 
375  // GPU does not have divrem function for signed or unsigned.
378 
379  // GPU does not have [S|U]MUL_LOHI functions as a single instruction.
382 
386  }
387 
388  if (!Subtarget->hasBCNT(32))
390 
391  if (!Subtarget->hasBCNT(64))
393 
394  // The hardware supports 32-bit ROTR, but not ROTL.
398 
409 
414 
415  if (Subtarget->hasFFBH())
417 
418  if (Subtarget->hasFFBL())
420 
423 
424  // We only really have 32-bit BFE instructions (and 16-bit on VI).
425  //
426  // On SI+ there are 64-bit BFEs, but they are scalar only and there isn't any
427  // effort to match them now. We want this to be false for i64 cases when the
428  // extraction isn't restricted to the upper or lower half. Ideally we would
429  // have some pass reduce 64-bit extracts to 32-bit if possible. Extracts that
430  // span the midpoint are probably relatively rare, so don't worry about them
431  // for now.
432  if (Subtarget->hasBFE())
433  setHasExtractBitsInsn(true);
434 
435  static const MVT::SimpleValueType VectorIntTypes[] = {
437  };
438 
439  for (MVT VT : VectorIntTypes) {
440  // Expand the following operations for the current type by default.
478  }
479 
480  static const MVT::SimpleValueType FloatVectorTypes[] = {
482  };
483 
484  for (MVT VT : FloatVectorTypes) {
510  }
511 
512  // This causes using an unrolled select operation rather than expansion with
513  // bit operations. This is in general better, but the alternative using BFI
514  // instructions may be better if the select sources are SGPRs.
517 
520 
521  // There are no libcalls of any kind.
522  for (int I = 0; I < RTLIB::UNKNOWN_LIBCALL; ++I)
523  setLibcallName(static_cast<RTLIB::Libcall>(I), nullptr);
524 
527 
529  setJumpIsExpensive(true);
530 
531  // FIXME: This is only partially true. If we have to do vector compares, any
532  // SGPR pair can be a condition register. If we have a uniform condition, we
533  // are better off doing SALU operations, where there is only one SCC. For now,
534  // we don't have a way of knowing during instruction selection if a condition
535  // will be uniform and we always use vector compares. Assume we are using
536  // vector compares until that is fixed.
538 
539  // SI at least has hardware support for floating point exceptions, but no way
540  // of using or handling them is implemented. They are also optional in OpenCL
541  // (Section 7.3)
543 
545 
546  // We want to find all load dependencies for long chains of stores to enable
547  // merging into very wide vectors. The problem is with vectors with > 4
548  // elements. MergeConsecutiveStores will attempt to merge these because x8/x16
549  // vectors are a legal type, even though we have to split the loads
550  // usually. When we can more precisely specify load legality per address
551  // space, we should be able to make FindBetterChain/MergeConsecutiveStores
552  // smarter so that they can figure out what to do in 2 iterations without all
553  // N > 4 stores on the same chain.
555 
556  // memcpy/memmove/memset are expanded in the IR, so we shouldn't need to worry
557  // about these during lowering.
558  MaxStoresPerMemcpy = 0xffffffff;
559  MaxStoresPerMemmove = 0xffffffff;
560  MaxStoresPerMemset = 0xffffffff;
561 
578 }
579 
580 //===----------------------------------------------------------------------===//
581 // Target Information
582 //===----------------------------------------------------------------------===//
583 
585 static bool fnegFoldsIntoOp(unsigned Opc) {
586  switch (Opc) {
587  case ISD::FADD:
588  case ISD::FSUB:
589  case ISD::FMUL:
590  case ISD::FMA:
591  case ISD::FMAD:
592  case ISD::FMINNUM:
593  case ISD::FMAXNUM:
594  case ISD::FSIN:
595  case ISD::FTRUNC:
596  case ISD::FRINT:
597  case ISD::FNEARBYINT:
598  case AMDGPUISD::RCP:
600  case AMDGPUISD::SIN_HW:
604  return true;
605  default:
606  return false;
607  }
608 }
609 
610 /// \p returns true if the operation will definitely need to use a 64-bit
611 /// encoding, and thus will use a VOP3 encoding regardless of the source
612 /// modifiers.
614 static bool opMustUseVOP3Encoding(const SDNode *N, MVT VT) {
615  return N->getNumOperands() > 2 || VT == MVT::f64;
616 }
617 
618 // Most FP instructions support source modifiers, but this could be refined
619 // slightly.
621 static bool hasSourceMods(const SDNode *N) {
622  if (isa<MemSDNode>(N))
623  return false;
624 
625  switch (N->getOpcode()) {
626  case ISD::CopyToReg:
627  case ISD::SELECT:
628  case ISD::FDIV:
629  case ISD::FREM:
630  case ISD::INLINEASM:
634 
635  // TODO: Should really be looking at the users of the bitcast. These are
636  // problematic because bitcasts are used to legalize all stores to integer
637  // types.
638  case ISD::BITCAST:
639  return false;
640  default:
641  return true;
642  }
643 }
644 
646  unsigned CostThreshold) {
647  // Some users (such as 3-operand FMA/MAD) must use a VOP3 encoding, and thus
648  // it is truly free to use a source modifier in all cases. If there are
649  // multiple users but for each one will necessitate using VOP3, there will be
650  // a code size increase. Try to avoid increasing code size unless we know it
651  // will save on the instruction count.
652  unsigned NumMayIncreaseSize = 0;
653  MVT VT = N->getValueType(0).getScalarType().getSimpleVT();
654 
655  // XXX - Should this limit number of uses to check?
656  for (const SDNode *U : N->uses()) {
657  if (!hasSourceMods(U))
658  return false;
659 
660  if (!opMustUseVOP3Encoding(U, VT)) {
661  if (++NumMayIncreaseSize > CostThreshold)
662  return false;
663  }
664  }
665 
666  return true;
667 }
668 
670  return MVT::i32;
671 }
672 
674  return true;
675 }
676 
677 // The backend supports 32 and 64 bit floating point immediates.
678 // FIXME: Why are we reporting vectors of FP immediates as legal?
679 bool AMDGPUTargetLowering::isFPImmLegal(const APFloat &Imm, EVT VT) const {
680  EVT ScalarVT = VT.getScalarType();
681  return (ScalarVT == MVT::f32 || ScalarVT == MVT::f64 ||
682  (ScalarVT == MVT::f16 && Subtarget->has16BitInsts()));
683 }
684 
685 // We don't want to shrink f64 / f32 constants.
687  EVT ScalarVT = VT.getScalarType();
688  return (ScalarVT != MVT::f32 && ScalarVT != MVT::f64);
689 }
690 
693  EVT NewVT) const {
694 
695  unsigned NewSize = NewVT.getStoreSizeInBits();
696 
697  // If we are reducing to a 32-bit load, this is always better.
698  if (NewSize == 32)
699  return true;
700 
701  EVT OldVT = N->getValueType(0);
702  unsigned OldSize = OldVT.getStoreSizeInBits();
703 
704  // Don't produce extloads from sub 32-bit types. SI doesn't have scalar
705  // extloads, so doing one requires using a buffer_load. In cases where we
706  // still couldn't use a scalar load, using the wider load shouldn't really
707  // hurt anything.
708 
709  // If the old size already had to be an extload, there's no harm in continuing
710  // to reduce the width.
711  return (OldSize < 32);
712 }
713 
715  EVT CastTy) const {
716 
717  assert(LoadTy.getSizeInBits() == CastTy.getSizeInBits());
718 
719  if (LoadTy.getScalarType() == MVT::i32)
720  return false;
721 
722  unsigned LScalarSize = LoadTy.getScalarSizeInBits();
723  unsigned CastScalarSize = CastTy.getScalarSizeInBits();
724 
725  return (LScalarSize < CastScalarSize) ||
726  (CastScalarSize >= 32);
727 }
728 
729 // SI+ has instructions for cttz / ctlz for 32-bit values. This is probably also
730 // profitable with the expansion for 64-bit since it's generally good to
731 // speculate things.
732 // FIXME: These should really have the size as a parameter.
734  return true;
735 }
736 
738  return true;
739 }
740 
741 //===---------------------------------------------------------------------===//
742 // Target Properties
743 //===---------------------------------------------------------------------===//
744 
746  assert(VT.isFloatingPoint());
747 
748  // Packed operations do not have a fabs modifier.
749  return VT == MVT::f32 || VT == MVT::f64 ||
750  (Subtarget->has16BitInsts() && VT == MVT::f16);
751 }
752 
754  assert(VT.isFloatingPoint());
755  return VT == MVT::f32 || VT == MVT::f64 ||
756  (Subtarget->has16BitInsts() && VT == MVT::f16) ||
757  (Subtarget->hasVOP3PInsts() && VT == MVT::v2f16);
758 }
759 
761  unsigned NumElem,
762  unsigned AS) const {
763  return true;
764 }
765 
767  // There are few operations which truly have vector input operands. Any vector
768  // operation is going to involve operations on each component, and a
769  // build_vector will be a copy per element, so it always makes sense to use a
770  // build_vector input in place of the extracted element to avoid a copy into a
771  // super register.
772  //
773  // We should probably only do this if all users are extracts only, but this
774  // should be the common case.
775  return true;
776 }
777 
779  // Truncate is just accessing a subregister.
780 
781  unsigned SrcSize = Source.getSizeInBits();
782  unsigned DestSize = Dest.getSizeInBits();
783 
784  return DestSize < SrcSize && DestSize % 32 == 0 ;
785 }
786 
788  // Truncate is just accessing a subregister.
789 
790  unsigned SrcSize = Source->getScalarSizeInBits();
791  unsigned DestSize = Dest->getScalarSizeInBits();
792 
793  if (DestSize== 16 && Subtarget->has16BitInsts())
794  return SrcSize >= 32;
795 
796  return DestSize < SrcSize && DestSize % 32 == 0;
797 }
798 
799 bool AMDGPUTargetLowering::isZExtFree(Type *Src, Type *Dest) const {
800  unsigned SrcSize = Src->getScalarSizeInBits();
801  unsigned DestSize = Dest->getScalarSizeInBits();
802 
803  if (SrcSize == 16 && Subtarget->has16BitInsts())
804  return DestSize >= 32;
805 
806  return SrcSize == 32 && DestSize == 64;
807 }
808 
809 bool AMDGPUTargetLowering::isZExtFree(EVT Src, EVT Dest) const {
810  // Any register load of a 64-bit value really requires 2 32-bit moves. For all
811  // practical purposes, the extra mov 0 to load a 64-bit is free. As used,
812  // this will enable reducing 64-bit operations the 32-bit, which is always
813  // good.
814 
815  if (Src == MVT::i16)
816  return Dest == MVT::i32 ||Dest == MVT::i64 ;
817 
818  return Src == MVT::i32 && Dest == MVT::i64;
819 }
820 
822  return isZExtFree(Val.getValueType(), VT2);
823 }
824 
826  // There aren't really 64-bit registers, but pairs of 32-bit ones and only a
827  // limited number of native 64-bit operations. Shrinking an operation to fit
828  // in a single 32-bit register should always be helpful. As currently used,
829  // this is much less general than the name suggests, and is only used in
830  // places trying to reduce the sizes of loads. Shrinking loads to < 32-bits is
831  // not profitable, and may actually be harmful.
832  return SrcVT.getSizeInBits() > 32 && DestVT.getSizeInBits() == 32;
833 }
834 
835 //===---------------------------------------------------------------------===//
836 // TargetLowering Callbacks
837 //===---------------------------------------------------------------------===//
838 
840  bool IsVarArg) {
841  switch (CC) {
844  return CC_AMDGPU_Kernel;
850  return CC_AMDGPU;
851  case CallingConv::C:
852  case CallingConv::Fast:
853  return CC_AMDGPU_Func;
854  default:
855  report_fatal_error("Unsupported calling convention.");
856  }
857 }
858 
860  bool IsVarArg) {
861  switch (CC) {
864  return CC_AMDGPU_Kernel;
870  return RetCC_SI_Shader;
871  case CallingConv::C:
872  case CallingConv::Fast:
873  return RetCC_AMDGPU_Func;
874  default:
875  report_fatal_error("Unsupported calling convention.");
876  }
877 }
878 
879 /// The SelectionDAGBuilder will automatically promote function arguments
880 /// with illegal types. However, this does not work for the AMDGPU targets
881 /// since the function arguments are stored in memory as these illegal types.
882 /// In order to handle this properly we need to get the original types sizes
883 /// from the LLVM IR Function and fixup the ISD:InputArg values before
884 /// passing them to AnalyzeFormalArguments()
885 
886 /// When the SelectionDAGBuilder computes the Ins, it takes care of splitting
887 /// input values across multiple registers. Each item in the Ins array
888 /// represents a single value that will be stored in registers. Ins[x].VT is
889 /// the value type of the value that will be stored in the register, so
890 /// whatever SDNode we lower the argument to needs to be this type.
891 ///
892 /// In order to correctly lower the arguments we need to know the size of each
893 /// argument. Since Ins[x].VT gives us the size of the register that will
894 /// hold the value, we need to look at Ins[x].ArgVT to see the 'real' type
895 /// for the orignal function argument so that we can deduce the correct memory
896 /// type to use for Ins[x]. In most cases the correct memory type will be
897 /// Ins[x].ArgVT. However, this will not always be the case. If, for example,
898 /// we have a kernel argument of type v8i8, this argument will be split into
899 /// 8 parts and each part will be represented by its own item in the Ins array.
900 /// For each part the Ins[x].ArgVT will be the v8i8, which is the full type of
901 /// the argument before it was split. From this, we deduce that the memory type
902 /// for each individual part is i8. We pass the memory type as LocVT to the
903 /// calling convention analysis function and the register type (Ins[x].VT) as
904 /// the ValVT.
906  const SmallVectorImpl<ISD::InputArg> &Ins) const {
907  for (unsigned i = 0, e = Ins.size(); i != e; ++i) {
908  const ISD::InputArg &In = Ins[i];
909  EVT MemVT;
910 
911  unsigned NumRegs = getNumRegisters(State.getContext(), In.ArgVT);
912 
913  if (!Subtarget->isAmdHsaOS() &&
914  (In.ArgVT == MVT::i16 || In.ArgVT == MVT::i8 || In.ArgVT == MVT::f16)) {
915  // The ABI says the caller will extend these values to 32-bits.
916  MemVT = In.ArgVT.isInteger() ? MVT::i32 : MVT::f32;
917  } else if (NumRegs == 1) {
918  // This argument is not split, so the IR type is the memory type.
919  assert(!In.Flags.isSplit());
920  if (In.ArgVT.isExtended()) {
921  // We have an extended type, like i24, so we should just use the register type
922  MemVT = In.VT;
923  } else {
924  MemVT = In.ArgVT;
925  }
926  } else if (In.ArgVT.isVector() && In.VT.isVector() &&
927  In.ArgVT.getScalarType() == In.VT.getScalarType()) {
929  // We have a vector value which has been split into a vector with
930  // the same scalar type, but fewer elements. This should handle
931  // all the floating-point vector types.
932  MemVT = In.VT;
933  } else if (In.ArgVT.isVector() &&
934  In.ArgVT.getVectorNumElements() == NumRegs) {
935  // This arg has been split so that each element is stored in a separate
936  // register.
937  MemVT = In.ArgVT.getScalarType();
938  } else if (In.ArgVT.isExtended()) {
939  // We have an extended type, like i65.
940  MemVT = In.VT;
941  } else {
942  unsigned MemoryBits = In.ArgVT.getStoreSizeInBits() / NumRegs;
943  assert(In.ArgVT.getStoreSizeInBits() % NumRegs == 0);
944  if (In.VT.isInteger()) {
945  MemVT = EVT::getIntegerVT(State.getContext(), MemoryBits);
946  } else if (In.VT.isVector()) {
948  unsigned NumElements = In.VT.getVectorNumElements();
949  assert(MemoryBits % NumElements == 0);
950  // This vector type has been split into another vector type with
951  // a different elements size.
952  EVT ScalarVT = EVT::getIntegerVT(State.getContext(),
953  MemoryBits / NumElements);
954  MemVT = EVT::getVectorVT(State.getContext(), ScalarVT, NumElements);
955  } else {
956  llvm_unreachable("cannot deduce memory type.");
957  }
958  }
959 
960  // Convert one element vectors to scalar.
961  if (MemVT.isVector() && MemVT.getVectorNumElements() == 1)
962  MemVT = MemVT.getScalarType();
963 
964  if (MemVT.isExtended()) {
965  // This should really only happen if we have vec3 arguments
966  assert(MemVT.isVector() && MemVT.getVectorNumElements() == 3);
967  MemVT = MemVT.getPow2VectorType(State.getContext());
968  }
969 
970  assert(MemVT.isSimple());
972  State);
973  }
974 }
975 
977  SDValue Chain, CallingConv::ID CallConv,
978  bool isVarArg,
980  const SmallVectorImpl<SDValue> &OutVals,
981  const SDLoc &DL, SelectionDAG &DAG) const {
982  // FIXME: Fails for r600 tests
983  //assert(!isVarArg && Outs.empty() && OutVals.empty() &&
984  // "wave terminate should not have return values");
985  return DAG.getNode(AMDGPUISD::ENDPGM, DL, MVT::Other, Chain);
986 }
987 
988 //===---------------------------------------------------------------------===//
989 // Target specific lowering
990 //===---------------------------------------------------------------------===//
991 
992 /// Selects the correct CCAssignFn for a given CallingConvention value.
994  bool IsVarArg) {
995  return AMDGPUCallLowering::CCAssignFnForCall(CC, IsVarArg);
996 }
997 
999  bool IsVarArg) {
1000  return AMDGPUCallLowering::CCAssignFnForReturn(CC, IsVarArg);
1001 }
1002 
1004  SmallVectorImpl<SDValue> &InVals) const {
1005  SDValue Callee = CLI.Callee;
1006  SelectionDAG &DAG = CLI.DAG;
1007 
1008  const Function &Fn = *DAG.getMachineFunction().getFunction();
1009 
1010  StringRef FuncName("<unknown>");
1011 
1012  if (const ExternalSymbolSDNode *G = dyn_cast<ExternalSymbolSDNode>(Callee))
1013  FuncName = G->getSymbol();
1014  else if (const GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee))
1015  FuncName = G->getGlobal()->getName();
1016 
1017  DiagnosticInfoUnsupported NoCalls(
1018  Fn, "unsupported call to function " + FuncName, CLI.DL.getDebugLoc());
1019  DAG.getContext()->diagnose(NoCalls);
1020 
1021  if (!CLI.IsTailCall) {
1022  for (unsigned I = 0, E = CLI.Ins.size(); I != E; ++I)
1023  InVals.push_back(DAG.getUNDEF(CLI.Ins[I].VT));
1024  }
1025 
1026  return DAG.getEntryNode();
1027 }
1028 
1030  SelectionDAG &DAG) const {
1031  const Function &Fn = *DAG.getMachineFunction().getFunction();
1032 
1033  DiagnosticInfoUnsupported NoDynamicAlloca(Fn, "unsupported dynamic alloca",
1034  SDLoc(Op).getDebugLoc());
1035  DAG.getContext()->diagnose(NoDynamicAlloca);
1036  auto Ops = {DAG.getConstant(0, SDLoc(), Op.getValueType()), Op.getOperand(0)};
1037  return DAG.getMergeValues(Ops, SDLoc());
1038 }
1039 
1041  SelectionDAG &DAG) const {
1042  switch (Op.getOpcode()) {
1043  default:
1044  Op->print(errs(), &DAG);
1045  llvm_unreachable("Custom lowering code for this"
1046  "instruction is not implemented yet!");
1047  break;
1048  case ISD::SIGN_EXTEND_INREG: return LowerSIGN_EXTEND_INREG(Op, DAG);
1049  case ISD::CONCAT_VECTORS: return LowerCONCAT_VECTORS(Op, DAG);
1050  case ISD::EXTRACT_SUBVECTOR: return LowerEXTRACT_SUBVECTOR(Op, DAG);
1051  case ISD::UDIVREM: return LowerUDIVREM(Op, DAG);
1052  case ISD::SDIVREM: return LowerSDIVREM(Op, DAG);
1053  case ISD::FREM: return LowerFREM(Op, DAG);
1054  case ISD::FCEIL: return LowerFCEIL(Op, DAG);
1055  case ISD::FTRUNC: return LowerFTRUNC(Op, DAG);
1056  case ISD::FRINT: return LowerFRINT(Op, DAG);
1057  case ISD::FNEARBYINT: return LowerFNEARBYINT(Op, DAG);
1058  case ISD::FROUND: return LowerFROUND(Op, DAG);
1059  case ISD::FFLOOR: return LowerFFLOOR(Op, DAG);
1060  case ISD::SINT_TO_FP: return LowerSINT_TO_FP(Op, DAG);
1061  case ISD::UINT_TO_FP: return LowerUINT_TO_FP(Op, DAG);
1062  case ISD::FP_TO_FP16: return LowerFP_TO_FP16(Op, DAG);
1063  case ISD::FP_TO_SINT: return LowerFP_TO_SINT(Op, DAG);
1064  case ISD::FP_TO_UINT: return LowerFP_TO_UINT(Op, DAG);
1065  case ISD::CTLZ:
1066  case ISD::CTLZ_ZERO_UNDEF:
1067  return LowerCTLZ(Op, DAG);
1068  case ISD::DYNAMIC_STACKALLOC: return LowerDYNAMIC_STACKALLOC(Op, DAG);
1069  }
1070  return Op;
1071 }
1072 
1075  SelectionDAG &DAG) const {
1076  switch (N->getOpcode()) {
1078  // Different parts of legalization seem to interpret which type of
1079  // sign_extend_inreg is the one to check for custom lowering. The extended
1080  // from type is what really matters, but some places check for custom
1081  // lowering of the result type. This results in trying to use
1082  // ReplaceNodeResults to sext_in_reg to an illegal type, so we'll just do
1083  // nothing here and let the illegal result integer be handled normally.
1084  return;
1085  default:
1086  return;
1087  }
1088 }
1089 
1090 static bool hasDefinedInitializer(const GlobalValue *GV) {
1091  const GlobalVariable *GVar = dyn_cast<GlobalVariable>(GV);
1092  if (!GVar || !GVar->hasInitializer())
1093  return false;
1094 
1095  return !isa<UndefValue>(GVar->getInitializer());
1096 }
1097 
1099  SDValue Op,
1100  SelectionDAG &DAG) const {
1101 
1102  const DataLayout &DL = DAG.getDataLayout();
1103  GlobalAddressSDNode *G = cast<GlobalAddressSDNode>(Op);
1104  const GlobalValue *GV = G->getGlobal();
1105 
1106  if (G->getAddressSpace() == AMDGPUASI.LOCAL_ADDRESS) {
1107  // XXX: What does the value of G->getOffset() mean?
1108  assert(G->getOffset() == 0 &&
1109  "Do not know what to do with an non-zero offset");
1110 
1111  // TODO: We could emit code to handle the initialization somewhere.
1112  if (!hasDefinedInitializer(GV)) {
1113  unsigned Offset = MFI->allocateLDSGlobal(DL, *GV);
1114  return DAG.getConstant(Offset, SDLoc(Op), Op.getValueType());
1115  }
1116  }
1117 
1118  const Function &Fn = *DAG.getMachineFunction().getFunction();
1119  DiagnosticInfoUnsupported BadInit(
1120  Fn, "unsupported initializer for address space", SDLoc(Op).getDebugLoc());
1121  DAG.getContext()->diagnose(BadInit);
1122  return SDValue();
1123 }
1124 
1126  SelectionDAG &DAG) const {
1128 
1129  for (const SDUse &U : Op->ops())
1130  DAG.ExtractVectorElements(U.get(), Args);
1131 
1132  return DAG.getBuildVector(Op.getValueType(), SDLoc(Op), Args);
1133 }
1134 
1136  SelectionDAG &DAG) const {
1137 
1139  unsigned Start = cast<ConstantSDNode>(Op.getOperand(1))->getZExtValue();
1140  EVT VT = Op.getValueType();
1141  DAG.ExtractVectorElements(Op.getOperand(0), Args, Start,
1142  VT.getVectorNumElements());
1143 
1144  return DAG.getBuildVector(Op.getValueType(), SDLoc(Op), Args);
1145 }
1146 
1147 /// \brief Generate Min/Max node
1149  SDValue LHS, SDValue RHS,
1150  SDValue True, SDValue False,
1151  SDValue CC,
1152  DAGCombinerInfo &DCI) const {
1153  if (!(LHS == True && RHS == False) && !(LHS == False && RHS == True))
1154  return SDValue();
1155 
1156  SelectionDAG &DAG = DCI.DAG;
1157  ISD::CondCode CCOpcode = cast<CondCodeSDNode>(CC)->get();
1158  switch (CCOpcode) {
1159  case ISD::SETOEQ:
1160  case ISD::SETONE:
1161  case ISD::SETUNE:
1162  case ISD::SETNE:
1163  case ISD::SETUEQ:
1164  case ISD::SETEQ:
1165  case ISD::SETFALSE:
1166  case ISD::SETFALSE2:
1167  case ISD::SETTRUE:
1168  case ISD::SETTRUE2:
1169  case ISD::SETUO:
1170  case ISD::SETO:
1171  break;
1172  case ISD::SETULE:
1173  case ISD::SETULT: {
1174  if (LHS == True)
1175  return DAG.getNode(AMDGPUISD::FMIN_LEGACY, DL, VT, RHS, LHS);
1176  return DAG.getNode(AMDGPUISD::FMAX_LEGACY, DL, VT, LHS, RHS);
1177  }
1178  case ISD::SETOLE:
1179  case ISD::SETOLT:
1180  case ISD::SETLE:
1181  case ISD::SETLT: {
1182  // Ordered. Assume ordered for undefined.
1183 
1184  // Only do this after legalization to avoid interfering with other combines
1185  // which might occur.
1186  if (DCI.getDAGCombineLevel() < AfterLegalizeDAG &&
1187  !DCI.isCalledByLegalizer())
1188  return SDValue();
1189 
1190  // We need to permute the operands to get the correct NaN behavior. The
1191  // selected operand is the second one based on the failing compare with NaN,
1192  // so permute it based on the compare type the hardware uses.
1193  if (LHS == True)
1194  return DAG.getNode(AMDGPUISD::FMIN_LEGACY, DL, VT, LHS, RHS);
1195  return DAG.getNode(AMDGPUISD::FMAX_LEGACY, DL, VT, RHS, LHS);
1196  }
1197  case ISD::SETUGE:
1198  case ISD::SETUGT: {
1199  if (LHS == True)
1200  return DAG.getNode(AMDGPUISD::FMAX_LEGACY, DL, VT, RHS, LHS);
1201  return DAG.getNode(AMDGPUISD::FMIN_LEGACY, DL, VT, LHS, RHS);
1202  }
1203  case ISD::SETGT:
1204  case ISD::SETGE:
1205  case ISD::SETOGE:
1206  case ISD::SETOGT: {
1207  if (DCI.getDAGCombineLevel() < AfterLegalizeDAG &&
1208  !DCI.isCalledByLegalizer())
1209  return SDValue();
1210 
1211  if (LHS == True)
1212  return DAG.getNode(AMDGPUISD::FMAX_LEGACY, DL, VT, LHS, RHS);
1213  return DAG.getNode(AMDGPUISD::FMIN_LEGACY, DL, VT, RHS, LHS);
1214  }
1215  case ISD::SETCC_INVALID:
1216  llvm_unreachable("Invalid setcc condcode!");
1217  }
1218  return SDValue();
1219 }
1220 
1221 std::pair<SDValue, SDValue>
1223  SDLoc SL(Op);
1224 
1225  SDValue Vec = DAG.getNode(ISD::BITCAST, SL, MVT::v2i32, Op);
1226 
1227  const SDValue Zero = DAG.getConstant(0, SL, MVT::i32);
1228  const SDValue One = DAG.getConstant(1, SL, MVT::i32);
1229 
1230  SDValue Lo = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SL, MVT::i32, Vec, Zero);
1231  SDValue Hi = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SL, MVT::i32, Vec, One);
1232 
1233  return std::make_pair(Lo, Hi);
1234 }
1235 
1237  SDLoc SL(Op);
1238 
1239  SDValue Vec = DAG.getNode(ISD::BITCAST, SL, MVT::v2i32, Op);
1240  const SDValue Zero = DAG.getConstant(0, SL, MVT::i32);
1241  return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SL, MVT::i32, Vec, Zero);
1242 }
1243 
1245  SDLoc SL(Op);
1246 
1247  SDValue Vec = DAG.getNode(ISD::BITCAST, SL, MVT::v2i32, Op);
1248  const SDValue One = DAG.getConstant(1, SL, MVT::i32);
1249  return DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SL, MVT::i32, Vec, One);
1250 }
1251 
1253  SelectionDAG &DAG) const {
1254  LoadSDNode *Load = cast<LoadSDNode>(Op);
1255  EVT VT = Op.getValueType();
1256 
1257 
1258  // If this is a 2 element vector, we really want to scalarize and not create
1259  // weird 1 element vectors.
1260  if (VT.getVectorNumElements() == 2)
1261  return scalarizeVectorLoad(Load, DAG);
1262 
1263  SDValue BasePtr = Load->getBasePtr();
1264  EVT PtrVT = BasePtr.getValueType();
1265  EVT MemVT = Load->getMemoryVT();
1266  SDLoc SL(Op);
1267 
1268  const MachinePointerInfo &SrcValue = Load->getMemOperand()->getPointerInfo();
1269 
1270  EVT LoVT, HiVT;
1271  EVT LoMemVT, HiMemVT;
1272  SDValue Lo, Hi;
1273 
1274  std::tie(LoVT, HiVT) = DAG.GetSplitDestVTs(VT);
1275  std::tie(LoMemVT, HiMemVT) = DAG.GetSplitDestVTs(MemVT);
1276  std::tie(Lo, Hi) = DAG.SplitVector(Op, SL, LoVT, HiVT);
1277 
1278  unsigned Size = LoMemVT.getStoreSize();
1279  unsigned BaseAlign = Load->getAlignment();
1280  unsigned HiAlign = MinAlign(BaseAlign, Size);
1281 
1282  SDValue LoLoad = DAG.getExtLoad(Load->getExtensionType(), SL, LoVT,
1283  Load->getChain(), BasePtr, SrcValue, LoMemVT,
1284  BaseAlign, Load->getMemOperand()->getFlags());
1285  SDValue HiPtr = DAG.getNode(ISD::ADD, SL, PtrVT, BasePtr,
1286  DAG.getConstant(Size, SL, PtrVT));
1287  SDValue HiLoad =
1288  DAG.getExtLoad(Load->getExtensionType(), SL, HiVT, Load->getChain(),
1289  HiPtr, SrcValue.getWithOffset(LoMemVT.getStoreSize()),
1290  HiMemVT, HiAlign, Load->getMemOperand()->getFlags());
1291 
1292  SDValue Ops[] = {
1293  DAG.getNode(ISD::CONCAT_VECTORS, SL, VT, LoLoad, HiLoad),
1295  LoLoad.getValue(1), HiLoad.getValue(1))
1296  };
1297 
1298  return DAG.getMergeValues(Ops, SL);
1299 }
1300 
1302  SelectionDAG &DAG) const {
1303  StoreSDNode *Store = cast<StoreSDNode>(Op);
1304  SDValue Val = Store->getValue();
1305  EVT VT = Val.getValueType();
1306 
1307  // If this is a 2 element vector, we really want to scalarize and not create
1308  // weird 1 element vectors.
1309  if (VT.getVectorNumElements() == 2)
1310  return scalarizeVectorStore(Store, DAG);
1311 
1312  EVT MemVT = Store->getMemoryVT();
1313  SDValue Chain = Store->getChain();
1314  SDValue BasePtr = Store->getBasePtr();
1315  SDLoc SL(Op);
1316 
1317  EVT LoVT, HiVT;
1318  EVT LoMemVT, HiMemVT;
1319  SDValue Lo, Hi;
1320 
1321  std::tie(LoVT, HiVT) = DAG.GetSplitDestVTs(VT);
1322  std::tie(LoMemVT, HiMemVT) = DAG.GetSplitDestVTs(MemVT);
1323  std::tie(Lo, Hi) = DAG.SplitVector(Val, SL, LoVT, HiVT);
1324 
1325  EVT PtrVT = BasePtr.getValueType();
1326  SDValue HiPtr = DAG.getNode(ISD::ADD, SL, PtrVT, BasePtr,
1327  DAG.getConstant(LoMemVT.getStoreSize(), SL,
1328  PtrVT));
1329 
1330  const MachinePointerInfo &SrcValue = Store->getMemOperand()->getPointerInfo();
1331  unsigned BaseAlign = Store->getAlignment();
1332  unsigned Size = LoMemVT.getStoreSize();
1333  unsigned HiAlign = MinAlign(BaseAlign, Size);
1334 
1335  SDValue LoStore =
1336  DAG.getTruncStore(Chain, SL, Lo, BasePtr, SrcValue, LoMemVT, BaseAlign,
1337  Store->getMemOperand()->getFlags());
1338  SDValue HiStore =
1339  DAG.getTruncStore(Chain, SL, Hi, HiPtr, SrcValue.getWithOffset(Size),
1340  HiMemVT, HiAlign, Store->getMemOperand()->getFlags());
1341 
1342  return DAG.getNode(ISD::TokenFactor, SL, MVT::Other, LoStore, HiStore);
1343 }
1344 
1345 // This is a shortcut for integer division because we have fast i32<->f32
1346 // conversions, and fast f32 reciprocal instructions. The fractional part of a
1347 // float is enough to accurately represent up to a 24-bit signed integer.
1349  bool Sign) const {
1350  SDLoc DL(Op);
1351  EVT VT = Op.getValueType();
1352  SDValue LHS = Op.getOperand(0);
1353  SDValue RHS = Op.getOperand(1);
1354  MVT IntVT = MVT::i32;
1355  MVT FltVT = MVT::f32;
1356 
1357  unsigned LHSSignBits = DAG.ComputeNumSignBits(LHS);
1358  if (LHSSignBits < 9)
1359  return SDValue();
1360 
1361  unsigned RHSSignBits = DAG.ComputeNumSignBits(RHS);
1362  if (RHSSignBits < 9)
1363  return SDValue();
1364 
1365  unsigned BitSize = VT.getSizeInBits();
1366  unsigned SignBits = std::min(LHSSignBits, RHSSignBits);
1367  unsigned DivBits = BitSize - SignBits;
1368  if (Sign)
1369  ++DivBits;
1370 
1373 
1374  SDValue jq = DAG.getConstant(1, DL, IntVT);
1375 
1376  if (Sign) {
1377  // char|short jq = ia ^ ib;
1378  jq = DAG.getNode(ISD::XOR, DL, VT, LHS, RHS);
1379 
1380  // jq = jq >> (bitsize - 2)
1381  jq = DAG.getNode(ISD::SRA, DL, VT, jq,
1382  DAG.getConstant(BitSize - 2, DL, VT));
1383 
1384  // jq = jq | 0x1
1385  jq = DAG.getNode(ISD::OR, DL, VT, jq, DAG.getConstant(1, DL, VT));
1386  }
1387 
1388  // int ia = (int)LHS;
1389  SDValue ia = LHS;
1390 
1391  // int ib, (int)RHS;
1392  SDValue ib = RHS;
1393 
1394  // float fa = (float)ia;
1395  SDValue fa = DAG.getNode(ToFp, DL, FltVT, ia);
1396 
1397  // float fb = (float)ib;
1398  SDValue fb = DAG.getNode(ToFp, DL, FltVT, ib);
1399 
1400  SDValue fq = DAG.getNode(ISD::FMUL, DL, FltVT,
1401  fa, DAG.getNode(AMDGPUISD::RCP, DL, FltVT, fb));
1402 
1403  // fq = trunc(fq);
1404  fq = DAG.getNode(ISD::FTRUNC, DL, FltVT, fq);
1405 
1406  // float fqneg = -fq;
1407  SDValue fqneg = DAG.getNode(ISD::FNEG, DL, FltVT, fq);
1408 
1409  // float fr = mad(fqneg, fb, fa);
1410  unsigned OpCode = Subtarget->hasFP32Denormals() ?
1412  (unsigned)ISD::FMAD;
1413  SDValue fr = DAG.getNode(OpCode, DL, FltVT, fqneg, fb, fa);
1414 
1415  // int iq = (int)fq;
1416  SDValue iq = DAG.getNode(ToInt, DL, IntVT, fq);
1417 
1418  // fr = fabs(fr);
1419  fr = DAG.getNode(ISD::FABS, DL, FltVT, fr);
1420 
1421  // fb = fabs(fb);
1422  fb = DAG.getNode(ISD::FABS, DL, FltVT, fb);
1423 
1424  EVT SetCCVT = getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT);
1425 
1426  // int cv = fr >= fb;
1427  SDValue cv = DAG.getSetCC(DL, SetCCVT, fr, fb, ISD::SETOGE);
1428 
1429  // jq = (cv ? jq : 0);
1430  jq = DAG.getNode(ISD::SELECT, DL, VT, cv, jq, DAG.getConstant(0, DL, VT));
1431 
1432  // dst = iq + jq;
1433  SDValue Div = DAG.getNode(ISD::ADD, DL, VT, iq, jq);
1434 
1435  // Rem needs compensation, it's easier to recompute it
1436  SDValue Rem = DAG.getNode(ISD::MUL, DL, VT, Div, RHS);
1437  Rem = DAG.getNode(ISD::SUB, DL, VT, LHS, Rem);
1438 
1439  // Truncate to number of bits this divide really is.
1440  if (Sign) {
1441  SDValue InRegSize
1442  = DAG.getValueType(EVT::getIntegerVT(*DAG.getContext(), DivBits));
1443  Div = DAG.getNode(ISD::SIGN_EXTEND_INREG, DL, VT, Div, InRegSize);
1444  Rem = DAG.getNode(ISD::SIGN_EXTEND_INREG, DL, VT, Rem, InRegSize);
1445  } else {
1446  SDValue TruncMask = DAG.getConstant((UINT64_C(1) << DivBits) - 1, DL, VT);
1447  Div = DAG.getNode(ISD::AND, DL, VT, Div, TruncMask);
1448  Rem = DAG.getNode(ISD::AND, DL, VT, Rem, TruncMask);
1449  }
1450 
1451  return DAG.getMergeValues({ Div, Rem }, DL);
1452 }
1453 
1455  SelectionDAG &DAG,
1457  assert(Op.getValueType() == MVT::i64);
1458 
1459  SDLoc DL(Op);
1460  EVT VT = Op.getValueType();
1461  EVT HalfVT = VT.getHalfSizedIntegerVT(*DAG.getContext());
1462 
1463  SDValue one = DAG.getConstant(1, DL, HalfVT);
1464  SDValue zero = DAG.getConstant(0, DL, HalfVT);
1465 
1466  //HiLo split
1467  SDValue LHS = Op.getOperand(0);
1468  SDValue LHS_Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, HalfVT, LHS, zero);
1469  SDValue LHS_Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, HalfVT, LHS, one);
1470 
1471  SDValue RHS = Op.getOperand(1);
1472  SDValue RHS_Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, HalfVT, RHS, zero);
1473  SDValue RHS_Hi = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, HalfVT, RHS, one);
1474 
1475  if (VT == MVT::i64 &&
1476  DAG.MaskedValueIsZero(RHS, APInt::getHighBitsSet(64, 32)) &&
1477  DAG.MaskedValueIsZero(LHS, APInt::getHighBitsSet(64, 32))) {
1478 
1479  SDValue Res = DAG.getNode(ISD::UDIVREM, DL, DAG.getVTList(HalfVT, HalfVT),
1480  LHS_Lo, RHS_Lo);
1481 
1482  SDValue DIV = DAG.getBuildVector(MVT::v2i32, DL, {Res.getValue(0), zero});
1483  SDValue REM = DAG.getBuildVector(MVT::v2i32, DL, {Res.getValue(1), zero});
1484 
1485  Results.push_back(DAG.getNode(ISD::BITCAST, DL, MVT::i64, DIV));
1486  Results.push_back(DAG.getNode(ISD::BITCAST, DL, MVT::i64, REM));
1487  return;
1488  }
1489 
1490  // Get Speculative values
1491  SDValue DIV_Part = DAG.getNode(ISD::UDIV, DL, HalfVT, LHS_Hi, RHS_Lo);
1492  SDValue REM_Part = DAG.getNode(ISD::UREM, DL, HalfVT, LHS_Hi, RHS_Lo);
1493 
1494  SDValue REM_Lo = DAG.getSelectCC(DL, RHS_Hi, zero, REM_Part, LHS_Hi, ISD::SETEQ);
1495  SDValue REM = DAG.getBuildVector(MVT::v2i32, DL, {REM_Lo, zero});
1496  REM = DAG.getNode(ISD::BITCAST, DL, MVT::i64, REM);
1497 
1498  SDValue DIV_Hi = DAG.getSelectCC(DL, RHS_Hi, zero, DIV_Part, zero, ISD::SETEQ);
1499  SDValue DIV_Lo = zero;
1500 
1501  const unsigned halfBitWidth = HalfVT.getSizeInBits();
1502 
1503  for (unsigned i = 0; i < halfBitWidth; ++i) {
1504  const unsigned bitPos = halfBitWidth - i - 1;
1505  SDValue POS = DAG.getConstant(bitPos, DL, HalfVT);
1506  // Get value of high bit
1507  SDValue HBit = DAG.getNode(ISD::SRL, DL, HalfVT, LHS_Lo, POS);
1508  HBit = DAG.getNode(ISD::AND, DL, HalfVT, HBit, one);
1509  HBit = DAG.getNode(ISD::ZERO_EXTEND, DL, VT, HBit);
1510 
1511  // Shift
1512  REM = DAG.getNode(ISD::SHL, DL, VT, REM, DAG.getConstant(1, DL, VT));
1513  // Add LHS high bit
1514  REM = DAG.getNode(ISD::OR, DL, VT, REM, HBit);
1515 
1516  SDValue BIT = DAG.getConstant(1ULL << bitPos, DL, HalfVT);
1517  SDValue realBIT = DAG.getSelectCC(DL, REM, RHS, BIT, zero, ISD::SETUGE);
1518 
1519  DIV_Lo = DAG.getNode(ISD::OR, DL, HalfVT, DIV_Lo, realBIT);
1520 
1521  // Update REM
1522  SDValue REM_sub = DAG.getNode(ISD::SUB, DL, VT, REM, RHS);
1523  REM = DAG.getSelectCC(DL, REM, RHS, REM_sub, REM, ISD::SETUGE);
1524  }
1525 
1526  SDValue DIV = DAG.getBuildVector(MVT::v2i32, DL, {DIV_Lo, DIV_Hi});
1527  DIV = DAG.getNode(ISD::BITCAST, DL, MVT::i64, DIV);
1528  Results.push_back(DIV);
1529  Results.push_back(REM);
1530 }
1531 
1533  SelectionDAG &DAG) const {
1534  SDLoc DL(Op);
1535  EVT VT = Op.getValueType();
1536 
1537  if (VT == MVT::i64) {
1539  LowerUDIVREM64(Op, DAG, Results);
1540  return DAG.getMergeValues(Results, DL);
1541  }
1542 
1543  if (VT == MVT::i32) {
1544  if (SDValue Res = LowerDIVREM24(Op, DAG, false))
1545  return Res;
1546  }
1547 
1548  SDValue Num = Op.getOperand(0);
1549  SDValue Den = Op.getOperand(1);
1550 
1551  // RCP = URECIP(Den) = 2^32 / Den + e
1552  // e is rounding error.
1553  SDValue RCP = DAG.getNode(AMDGPUISD::URECIP, DL, VT, Den);
1554 
1555  // RCP_LO = mul(RCP, Den) */
1556  SDValue RCP_LO = DAG.getNode(ISD::MUL, DL, VT, RCP, Den);
1557 
1558  // RCP_HI = mulhu (RCP, Den) */
1559  SDValue RCP_HI = DAG.getNode(ISD::MULHU, DL, VT, RCP, Den);
1560 
1561  // NEG_RCP_LO = -RCP_LO
1562  SDValue NEG_RCP_LO = DAG.getNode(ISD::SUB, DL, VT, DAG.getConstant(0, DL, VT),
1563  RCP_LO);
1564 
1565  // ABS_RCP_LO = (RCP_HI == 0 ? NEG_RCP_LO : RCP_LO)
1566  SDValue ABS_RCP_LO = DAG.getSelectCC(DL, RCP_HI, DAG.getConstant(0, DL, VT),
1567  NEG_RCP_LO, RCP_LO,
1568  ISD::SETEQ);
1569  // Calculate the rounding error from the URECIP instruction
1570  // E = mulhu(ABS_RCP_LO, RCP)
1571  SDValue E = DAG.getNode(ISD::MULHU, DL, VT, ABS_RCP_LO, RCP);
1572 
1573  // RCP_A_E = RCP + E
1574  SDValue RCP_A_E = DAG.getNode(ISD::ADD, DL, VT, RCP, E);
1575 
1576  // RCP_S_E = RCP - E
1577  SDValue RCP_S_E = DAG.getNode(ISD::SUB, DL, VT, RCP, E);
1578 
1579  // Tmp0 = (RCP_HI == 0 ? RCP_A_E : RCP_SUB_E)
1580  SDValue Tmp0 = DAG.getSelectCC(DL, RCP_HI, DAG.getConstant(0, DL, VT),
1581  RCP_A_E, RCP_S_E,
1582  ISD::SETEQ);
1583  // Quotient = mulhu(Tmp0, Num)
1584  SDValue Quotient = DAG.getNode(ISD::MULHU, DL, VT, Tmp0, Num);
1585 
1586  // Num_S_Remainder = Quotient * Den
1587  SDValue Num_S_Remainder = DAG.getNode(ISD::MUL, DL, VT, Quotient, Den);
1588 
1589  // Remainder = Num - Num_S_Remainder
1590  SDValue Remainder = DAG.getNode(ISD::SUB, DL, VT, Num, Num_S_Remainder);
1591 
1592  // Remainder_GE_Den = (Remainder >= Den ? -1 : 0)
1593  SDValue Remainder_GE_Den = DAG.getSelectCC(DL, Remainder, Den,
1594  DAG.getConstant(-1, DL, VT),
1595  DAG.getConstant(0, DL, VT),
1596  ISD::SETUGE);
1597  // Remainder_GE_Zero = (Num >= Num_S_Remainder ? -1 : 0)
1598  SDValue Remainder_GE_Zero = DAG.getSelectCC(DL, Num,
1599  Num_S_Remainder,
1600  DAG.getConstant(-1, DL, VT),
1601  DAG.getConstant(0, DL, VT),
1602  ISD::SETUGE);
1603  // Tmp1 = Remainder_GE_Den & Remainder_GE_Zero
1604  SDValue Tmp1 = DAG.getNode(ISD::AND, DL, VT, Remainder_GE_Den,
1605  Remainder_GE_Zero);
1606 
1607  // Calculate Division result:
1608 
1609  // Quotient_A_One = Quotient + 1
1610  SDValue Quotient_A_One = DAG.getNode(ISD::ADD, DL, VT, Quotient,
1611  DAG.getConstant(1, DL, VT));
1612 
1613  // Quotient_S_One = Quotient - 1
1614  SDValue Quotient_S_One = DAG.getNode(ISD::SUB, DL, VT, Quotient,
1615  DAG.getConstant(1, DL, VT));
1616 
1617  // Div = (Tmp1 == 0 ? Quotient : Quotient_A_One)
1618  SDValue Div = DAG.getSelectCC(DL, Tmp1, DAG.getConstant(0, DL, VT),
1619  Quotient, Quotient_A_One, ISD::SETEQ);
1620 
1621  // Div = (Remainder_GE_Zero == 0 ? Quotient_S_One : Div)
1622  Div = DAG.getSelectCC(DL, Remainder_GE_Zero, DAG.getConstant(0, DL, VT),
1623  Quotient_S_One, Div, ISD::SETEQ);
1624 
1625  // Calculate Rem result:
1626 
1627  // Remainder_S_Den = Remainder - Den
1628  SDValue Remainder_S_Den = DAG.getNode(ISD::SUB, DL, VT, Remainder, Den);
1629 
1630  // Remainder_A_Den = Remainder + Den
1631  SDValue Remainder_A_Den = DAG.getNode(ISD::ADD, DL, VT, Remainder, Den);
1632 
1633  // Rem = (Tmp1 == 0 ? Remainder : Remainder_S_Den)
1634  SDValue Rem = DAG.getSelectCC(DL, Tmp1, DAG.getConstant(0, DL, VT),
1635  Remainder, Remainder_S_Den, ISD::SETEQ);
1636 
1637  // Rem = (Remainder_GE_Zero == 0 ? Remainder_A_Den : Rem)
1638  Rem = DAG.getSelectCC(DL, Remainder_GE_Zero, DAG.getConstant(0, DL, VT),
1639  Remainder_A_Den, Rem, ISD::SETEQ);
1640  SDValue Ops[2] = {
1641  Div,
1642  Rem
1643  };
1644  return DAG.getMergeValues(Ops, DL);
1645 }
1646 
1648  SelectionDAG &DAG) const {
1649  SDLoc DL(Op);
1650  EVT VT = Op.getValueType();
1651 
1652  SDValue LHS = Op.getOperand(0);
1653  SDValue RHS = Op.getOperand(1);
1654 
1655  SDValue Zero = DAG.getConstant(0, DL, VT);
1656  SDValue NegOne = DAG.getConstant(-1, DL, VT);
1657 
1658  if (VT == MVT::i32) {
1659  if (SDValue Res = LowerDIVREM24(Op, DAG, true))
1660  return Res;
1661  }
1662 
1663  if (VT == MVT::i64 &&
1664  DAG.ComputeNumSignBits(LHS) > 32 &&
1665  DAG.ComputeNumSignBits(RHS) > 32) {
1666  EVT HalfVT = VT.getHalfSizedIntegerVT(*DAG.getContext());
1667 
1668  //HiLo split
1669  SDValue LHS_Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, HalfVT, LHS, Zero);
1670  SDValue RHS_Lo = DAG.getNode(ISD::EXTRACT_ELEMENT, DL, HalfVT, RHS, Zero);
1671  SDValue DIVREM = DAG.getNode(ISD::SDIVREM, DL, DAG.getVTList(HalfVT, HalfVT),
1672  LHS_Lo, RHS_Lo);
1673  SDValue Res[2] = {
1674  DAG.getNode(ISD::SIGN_EXTEND, DL, VT, DIVREM.getValue(0)),
1675  DAG.getNode(ISD::SIGN_EXTEND, DL, VT, DIVREM.getValue(1))
1676  };
1677  return DAG.getMergeValues(Res, DL);
1678  }
1679 
1680  SDValue LHSign = DAG.getSelectCC(DL, LHS, Zero, NegOne, Zero, ISD::SETLT);
1681  SDValue RHSign = DAG.getSelectCC(DL, RHS, Zero, NegOne, Zero, ISD::SETLT);
1682  SDValue DSign = DAG.getNode(ISD::XOR, DL, VT, LHSign, RHSign);
1683  SDValue RSign = LHSign; // Remainder sign is the same as LHS
1684 
1685  LHS = DAG.getNode(ISD::ADD, DL, VT, LHS, LHSign);
1686  RHS = DAG.getNode(ISD::ADD, DL, VT, RHS, RHSign);
1687 
1688  LHS = DAG.getNode(ISD::XOR, DL, VT, LHS, LHSign);
1689  RHS = DAG.getNode(ISD::XOR, DL, VT, RHS, RHSign);
1690 
1691  SDValue Div = DAG.getNode(ISD::UDIVREM, DL, DAG.getVTList(VT, VT), LHS, RHS);
1692  SDValue Rem = Div.getValue(1);
1693 
1694  Div = DAG.getNode(ISD::XOR, DL, VT, Div, DSign);
1695  Rem = DAG.getNode(ISD::XOR, DL, VT, Rem, RSign);
1696 
1697  Div = DAG.getNode(ISD::SUB, DL, VT, Div, DSign);
1698  Rem = DAG.getNode(ISD::SUB, DL, VT, Rem, RSign);
1699 
1700  SDValue Res[2] = {
1701  Div,
1702  Rem
1703  };
1704  return DAG.getMergeValues(Res, DL);
1705 }
1706 
1707 // (frem x, y) -> (fsub x, (fmul (ftrunc (fdiv x, y)), y))
1709  SDLoc SL(Op);
1710  EVT VT = Op.getValueType();
1711  SDValue X = Op.getOperand(0);
1712  SDValue Y = Op.getOperand(1);
1713 
1714  // TODO: Should this propagate fast-math-flags?
1715 
1716  SDValue Div = DAG.getNode(ISD::FDIV, SL, VT, X, Y);
1717  SDValue Floor = DAG.getNode(ISD::FTRUNC, SL, VT, Div);
1718  SDValue Mul = DAG.getNode(ISD::FMUL, SL, VT, Floor, Y);
1719 
1720  return DAG.getNode(ISD::FSUB, SL, VT, X, Mul);
1721 }
1722 
1724  SDLoc SL(Op);
1725  SDValue Src = Op.getOperand(0);
1726 
1727  // result = trunc(src)
1728  // if (src > 0.0 && src != result)
1729  // result += 1.0
1730 
1731  SDValue Trunc = DAG.getNode(ISD::FTRUNC, SL, MVT::f64, Src);
1732 
1733  const SDValue Zero = DAG.getConstantFP(0.0, SL, MVT::f64);
1734  const SDValue One = DAG.getConstantFP(1.0, SL, MVT::f64);
1735 
1736  EVT SetCCVT =
1738 
1739  SDValue Lt0 = DAG.getSetCC(SL, SetCCVT, Src, Zero, ISD::SETOGT);
1740  SDValue NeTrunc = DAG.getSetCC(SL, SetCCVT, Src, Trunc, ISD::SETONE);
1741  SDValue And = DAG.getNode(ISD::AND, SL, SetCCVT, Lt0, NeTrunc);
1742 
1743  SDValue Add = DAG.getNode(ISD::SELECT, SL, MVT::f64, And, One, Zero);
1744  // TODO: Should this propagate fast-math-flags?
1745  return DAG.getNode(ISD::FADD, SL, MVT::f64, Trunc, Add);
1746 }
1747 
1749  SelectionDAG &DAG) {
1750  const unsigned FractBits = 52;
1751  const unsigned ExpBits = 11;
1752 
1753  SDValue ExpPart = DAG.getNode(AMDGPUISD::BFE_U32, SL, MVT::i32,
1754  Hi,
1755  DAG.getConstant(FractBits - 32, SL, MVT::i32),
1756  DAG.getConstant(ExpBits, SL, MVT::i32));
1757  SDValue Exp = DAG.getNode(ISD::SUB, SL, MVT::i32, ExpPart,
1758  DAG.getConstant(1023, SL, MVT::i32));
1759 
1760  return Exp;
1761 }
1762 
1764  SDLoc SL(Op);
1765  SDValue Src = Op.getOperand(0);
1766 
1767  assert(Op.getValueType() == MVT::f64);
1768 
1769  const SDValue Zero = DAG.getConstant(0, SL, MVT::i32);
1770  const SDValue One = DAG.getConstant(1, SL, MVT::i32);
1771 
1772  SDValue VecSrc = DAG.getNode(ISD::BITCAST, SL, MVT::v2i32, Src);
1773 
1774  // Extract the upper half, since this is where we will find the sign and
1775  // exponent.
1776  SDValue Hi = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SL, MVT::i32, VecSrc, One);
1777 
1778  SDValue Exp = extractF64Exponent(Hi, SL, DAG);
1779 
1780  const unsigned FractBits = 52;
1781 
1782  // Extract the sign bit.
1783  const SDValue SignBitMask = DAG.getConstant(UINT32_C(1) << 31, SL, MVT::i32);
1784  SDValue SignBit = DAG.getNode(ISD::AND, SL, MVT::i32, Hi, SignBitMask);
1785 
1786  // Extend back to to 64-bits.
1787  SDValue SignBit64 = DAG.getBuildVector(MVT::v2i32, SL, {Zero, SignBit});
1788  SignBit64 = DAG.getNode(ISD::BITCAST, SL, MVT::i64, SignBit64);
1789 
1790  SDValue BcInt = DAG.getNode(ISD::BITCAST, SL, MVT::i64, Src);
1791  const SDValue FractMask
1792  = DAG.getConstant((UINT64_C(1) << FractBits) - 1, SL, MVT::i64);
1793 
1794  SDValue Shr = DAG.getNode(ISD::SRA, SL, MVT::i64, FractMask, Exp);
1795  SDValue Not = DAG.getNOT(SL, Shr, MVT::i64);
1796  SDValue Tmp0 = DAG.getNode(ISD::AND, SL, MVT::i64, BcInt, Not);
1797 
1798  EVT SetCCVT =
1800 
1801  const SDValue FiftyOne = DAG.getConstant(FractBits - 1, SL, MVT::i32);
1802 
1803  SDValue ExpLt0 = DAG.getSetCC(SL, SetCCVT, Exp, Zero, ISD::SETLT);
1804  SDValue ExpGt51 = DAG.getSetCC(SL, SetCCVT, Exp, FiftyOne, ISD::SETGT);
1805 
1806  SDValue Tmp1 = DAG.getNode(ISD::SELECT, SL, MVT::i64, ExpLt0, SignBit64, Tmp0);
1807  SDValue Tmp2 = DAG.getNode(ISD::SELECT, SL, MVT::i64, ExpGt51, BcInt, Tmp1);
1808 
1809  return DAG.getNode(ISD::BITCAST, SL, MVT::f64, Tmp2);
1810 }
1811 
1813  SDLoc SL(Op);
1814  SDValue Src = Op.getOperand(0);
1815 
1816  assert(Op.getValueType() == MVT::f64);
1817 
1818  APFloat C1Val(APFloat::IEEEdouble(), "0x1.0p+52");
1819  SDValue C1 = DAG.getConstantFP(C1Val, SL, MVT::f64);
1820  SDValue CopySign = DAG.getNode(ISD::FCOPYSIGN, SL, MVT::f64, C1, Src);
1821 
1822  // TODO: Should this propagate fast-math-flags?
1823 
1824  SDValue Tmp1 = DAG.getNode(ISD::FADD, SL, MVT::f64, Src, CopySign);
1825  SDValue Tmp2 = DAG.getNode(ISD::FSUB, SL, MVT::f64, Tmp1, CopySign);
1826 
1827  SDValue Fabs = DAG.getNode(ISD::FABS, SL, MVT::f64, Src);
1828 
1829  APFloat C2Val(APFloat::IEEEdouble(), "0x1.fffffffffffffp+51");
1830  SDValue C2 = DAG.getConstantFP(C2Val, SL, MVT::f64);
1831 
1832  EVT SetCCVT =
1834  SDValue Cond = DAG.getSetCC(SL, SetCCVT, Fabs, C2, ISD::SETOGT);
1835 
1836  return DAG.getSelect(SL, MVT::f64, Cond, Src, Tmp2);
1837 }
1838 
1840  // FNEARBYINT and FRINT are the same, except in their handling of FP
1841  // exceptions. Those aren't really meaningful for us, and OpenCL only has
1842  // rint, so just treat them as equivalent.
1843  return DAG.getNode(ISD::FRINT, SDLoc(Op), Op.getValueType(), Op.getOperand(0));
1844 }
1845 
1846 // XXX - May require not supporting f32 denormals?
1847 
1848 // Don't handle v2f16. The extra instructions to scalarize and repack around the
1849 // compare and vselect end up producing worse code than scalarizing the whole
1850 // operation.
1852  SDLoc SL(Op);
1853  SDValue X = Op.getOperand(0);
1854  EVT VT = Op.getValueType();
1855 
1856  SDValue T = DAG.getNode(ISD::FTRUNC, SL, VT, X);
1857 
1858  // TODO: Should this propagate fast-math-flags?
1859 
1860  SDValue Diff = DAG.getNode(ISD::FSUB, SL, VT, X, T);
1861 
1862  SDValue AbsDiff = DAG.getNode(ISD::FABS, SL, VT, Diff);
1863 
1864  const SDValue Zero = DAG.getConstantFP(0.0, SL, VT);
1865  const SDValue One = DAG.getConstantFP(1.0, SL, VT);
1866  const SDValue Half = DAG.getConstantFP(0.5, SL, VT);
1867 
1868  SDValue SignOne = DAG.getNode(ISD::FCOPYSIGN, SL, VT, One, X);
1869 
1870  EVT SetCCVT =
1871  getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT);
1872 
1873  SDValue Cmp = DAG.getSetCC(SL, SetCCVT, AbsDiff, Half, ISD::SETOGE);
1874 
1875  SDValue Sel = DAG.getNode(ISD::SELECT, SL, VT, Cmp, SignOne, Zero);
1876 
1877  return DAG.getNode(ISD::FADD, SL, VT, T, Sel);
1878 }
1879 
1881  SDLoc SL(Op);
1882  SDValue X = Op.getOperand(0);
1883 
1884  SDValue L = DAG.getNode(ISD::BITCAST, SL, MVT::i64, X);
1885 
1886  const SDValue Zero = DAG.getConstant(0, SL, MVT::i32);
1887  const SDValue One = DAG.getConstant(1, SL, MVT::i32);
1888  const SDValue NegOne = DAG.getConstant(-1, SL, MVT::i32);
1889  const SDValue FiftyOne = DAG.getConstant(51, SL, MVT::i32);
1890  EVT SetCCVT =
1892 
1893  SDValue BC = DAG.getNode(ISD::BITCAST, SL, MVT::v2i32, X);
1894 
1895  SDValue Hi = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SL, MVT::i32, BC, One);
1896 
1897  SDValue Exp = extractF64Exponent(Hi, SL, DAG);
1898 
1899  const SDValue Mask = DAG.getConstant(INT64_C(0x000fffffffffffff), SL,
1900  MVT::i64);
1901 
1902  SDValue M = DAG.getNode(ISD::SRA, SL, MVT::i64, Mask, Exp);
1903  SDValue D = DAG.getNode(ISD::SRA, SL, MVT::i64,
1904  DAG.getConstant(INT64_C(0x0008000000000000), SL,
1905  MVT::i64),
1906  Exp);
1907 
1908  SDValue Tmp0 = DAG.getNode(ISD::AND, SL, MVT::i64, L, M);
1909  SDValue Tmp1 = DAG.getSetCC(SL, SetCCVT,
1910  DAG.getConstant(0, SL, MVT::i64), Tmp0,
1911  ISD::SETNE);
1912 
1913  SDValue Tmp2 = DAG.getNode(ISD::SELECT, SL, MVT::i64, Tmp1,
1914  D, DAG.getConstant(0, SL, MVT::i64));
1915  SDValue K = DAG.getNode(ISD::ADD, SL, MVT::i64, L, Tmp2);
1916 
1917  K = DAG.getNode(ISD::AND, SL, MVT::i64, K, DAG.getNOT(SL, M, MVT::i64));
1918  K = DAG.getNode(ISD::BITCAST, SL, MVT::f64, K);
1919 
1920  SDValue ExpLt0 = DAG.getSetCC(SL, SetCCVT, Exp, Zero, ISD::SETLT);
1921  SDValue ExpGt51 = DAG.getSetCC(SL, SetCCVT, Exp, FiftyOne, ISD::SETGT);
1922  SDValue ExpEqNegOne = DAG.getSetCC(SL, SetCCVT, NegOne, Exp, ISD::SETEQ);
1923 
1924  SDValue Mag = DAG.getNode(ISD::SELECT, SL, MVT::f64,
1925  ExpEqNegOne,
1926  DAG.getConstantFP(1.0, SL, MVT::f64),
1927  DAG.getConstantFP(0.0, SL, MVT::f64));
1928 
1929  SDValue S = DAG.getNode(ISD::FCOPYSIGN, SL, MVT::f64, Mag, X);
1930 
1931  K = DAG.getNode(ISD::SELECT, SL, MVT::f64, ExpLt0, S, K);
1932  K = DAG.getNode(ISD::SELECT, SL, MVT::f64, ExpGt51, X, K);
1933 
1934  return K;
1935 }
1936 
1938  EVT VT = Op.getValueType();
1939 
1940  if (VT == MVT::f32 || VT == MVT::f16)
1941  return LowerFROUND32_16(Op, DAG);
1942 
1943  if (VT == MVT::f64)
1944  return LowerFROUND64(Op, DAG);
1945 
1946  llvm_unreachable("unhandled type");
1947 }
1948 
1950  SDLoc SL(Op);
1951  SDValue Src = Op.getOperand(0);
1952 
1953  // result = trunc(src);
1954  // if (src < 0.0 && src != result)
1955  // result += -1.0.
1956 
1957  SDValue Trunc = DAG.getNode(ISD::FTRUNC, SL, MVT::f64, Src);
1958 
1959  const SDValue Zero = DAG.getConstantFP(0.0, SL, MVT::f64);
1960  const SDValue NegOne = DAG.getConstantFP(-1.0, SL, MVT::f64);
1961 
1962  EVT SetCCVT =
1964 
1965  SDValue Lt0 = DAG.getSetCC(SL, SetCCVT, Src, Zero, ISD::SETOLT);
1966  SDValue NeTrunc = DAG.getSetCC(SL, SetCCVT, Src, Trunc, ISD::SETONE);
1967  SDValue And = DAG.getNode(ISD::AND, SL, SetCCVT, Lt0, NeTrunc);
1968 
1969  SDValue Add = DAG.getNode(ISD::SELECT, SL, MVT::f64, And, NegOne, Zero);
1970  // TODO: Should this propagate fast-math-flags?
1971  return DAG.getNode(ISD::FADD, SL, MVT::f64, Trunc, Add);
1972 }
1973 
1975  SDLoc SL(Op);
1976  SDValue Src = Op.getOperand(0);
1977  bool ZeroUndef = Op.getOpcode() == ISD::CTLZ_ZERO_UNDEF;
1978 
1979  if (ZeroUndef && Src.getValueType() == MVT::i32)
1980  return DAG.getNode(AMDGPUISD::FFBH_U32, SL, MVT::i32, Src);
1981 
1982  SDValue Vec = DAG.getNode(ISD::BITCAST, SL, MVT::v2i32, Src);
1983 
1984  const SDValue Zero = DAG.getConstant(0, SL, MVT::i32);
1985  const SDValue One = DAG.getConstant(1, SL, MVT::i32);
1986 
1987  SDValue Lo = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SL, MVT::i32, Vec, Zero);
1988  SDValue Hi = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SL, MVT::i32, Vec, One);
1989 
1990  EVT SetCCVT = getSetCCResultType(DAG.getDataLayout(),
1991  *DAG.getContext(), MVT::i32);
1992 
1993  SDValue Hi0 = DAG.getSetCC(SL, SetCCVT, Hi, Zero, ISD::SETEQ);
1994 
1995  SDValue CtlzLo = DAG.getNode(ISD::CTLZ_ZERO_UNDEF, SL, MVT::i32, Lo);
1996  SDValue CtlzHi = DAG.getNode(ISD::CTLZ_ZERO_UNDEF, SL, MVT::i32, Hi);
1997 
1998  const SDValue Bits32 = DAG.getConstant(32, SL, MVT::i32);
1999  SDValue Add = DAG.getNode(ISD::ADD, SL, MVT::i32, CtlzLo, Bits32);
2000 
2001  // ctlz(x) = hi_32(x) == 0 ? ctlz(lo_32(x)) + 32 : ctlz(hi_32(x))
2002  SDValue NewCtlz = DAG.getNode(ISD::SELECT, SL, MVT::i32, Hi0, Add, CtlzHi);
2003 
2004  if (!ZeroUndef) {
2005  // Test if the full 64-bit input is zero.
2006 
2007  // FIXME: DAG combines turn what should be an s_and_b64 into a v_or_b32,
2008  // which we probably don't want.
2009  SDValue Lo0 = DAG.getSetCC(SL, SetCCVT, Lo, Zero, ISD::SETEQ);
2010  SDValue SrcIsZero = DAG.getNode(ISD::AND, SL, SetCCVT, Lo0, Hi0);
2011 
2012  // TODO: If i64 setcc is half rate, it can result in 1 fewer instruction
2013  // with the same cycles, otherwise it is slower.
2014  // SDValue SrcIsZero = DAG.getSetCC(SL, SetCCVT, Src,
2015  // DAG.getConstant(0, SL, MVT::i64), ISD::SETEQ);
2016 
2017  const SDValue Bits32 = DAG.getConstant(64, SL, MVT::i32);
2018 
2019  // The instruction returns -1 for 0 input, but the defined intrinsic
2020  // behavior is to return the number of bits.
2021  NewCtlz = DAG.getNode(ISD::SELECT, SL, MVT::i32,
2022  SrcIsZero, Bits32, NewCtlz);
2023  }
2024 
2025  return DAG.getNode(ISD::ZERO_EXTEND, SL, MVT::i64, NewCtlz);
2026 }
2027 
2029  bool Signed) const {
2030  // Unsigned
2031  // cul2f(ulong u)
2032  //{
2033  // uint lz = clz(u);
2034  // uint e = (u != 0) ? 127U + 63U - lz : 0;
2035  // u = (u << lz) & 0x7fffffffffffffffUL;
2036  // ulong t = u & 0xffffffffffUL;
2037  // uint v = (e << 23) | (uint)(u >> 40);
2038  // uint r = t > 0x8000000000UL ? 1U : (t == 0x8000000000UL ? v & 1U : 0U);
2039  // return as_float(v + r);
2040  //}
2041  // Signed
2042  // cl2f(long l)
2043  //{
2044  // long s = l >> 63;
2045  // float r = cul2f((l + s) ^ s);
2046  // return s ? -r : r;
2047  //}
2048 
2049  SDLoc SL(Op);
2050  SDValue Src = Op.getOperand(0);
2051  SDValue L = Src;
2052 
2053  SDValue S;
2054  if (Signed) {
2055  const SDValue SignBit = DAG.getConstant(63, SL, MVT::i64);
2056  S = DAG.getNode(ISD::SRA, SL, MVT::i64, L, SignBit);
2057 
2058  SDValue LPlusS = DAG.getNode(ISD::ADD, SL, MVT::i64, L, S);
2059  L = DAG.getNode(ISD::XOR, SL, MVT::i64, LPlusS, S);
2060  }
2061 
2062  EVT SetCCVT = getSetCCResultType(DAG.getDataLayout(),
2063  *DAG.getContext(), MVT::f32);
2064 
2065 
2066  SDValue ZeroI32 = DAG.getConstant(0, SL, MVT::i32);
2067  SDValue ZeroI64 = DAG.getConstant(0, SL, MVT::i64);
2068  SDValue LZ = DAG.getNode(ISD::CTLZ_ZERO_UNDEF, SL, MVT::i64, L);
2069  LZ = DAG.getNode(ISD::TRUNCATE, SL, MVT::i32, LZ);
2070 
2071  SDValue K = DAG.getConstant(127U + 63U, SL, MVT::i32);
2072  SDValue E = DAG.getSelect(SL, MVT::i32,
2073  DAG.getSetCC(SL, SetCCVT, L, ZeroI64, ISD::SETNE),
2074  DAG.getNode(ISD::SUB, SL, MVT::i32, K, LZ),
2075  ZeroI32);
2076 
2077  SDValue U = DAG.getNode(ISD::AND, SL, MVT::i64,
2078  DAG.getNode(ISD::SHL, SL, MVT::i64, L, LZ),
2079  DAG.getConstant((-1ULL) >> 1, SL, MVT::i64));
2080 
2081  SDValue T = DAG.getNode(ISD::AND, SL, MVT::i64, U,
2082  DAG.getConstant(0xffffffffffULL, SL, MVT::i64));
2083 
2084  SDValue UShl = DAG.getNode(ISD::SRL, SL, MVT::i64,
2085  U, DAG.getConstant(40, SL, MVT::i64));
2086 
2087  SDValue V = DAG.getNode(ISD::OR, SL, MVT::i32,
2088  DAG.getNode(ISD::SHL, SL, MVT::i32, E, DAG.getConstant(23, SL, MVT::i32)),
2089  DAG.getNode(ISD::TRUNCATE, SL, MVT::i32, UShl));
2090 
2091  SDValue C = DAG.getConstant(0x8000000000ULL, SL, MVT::i64);
2092  SDValue RCmp = DAG.getSetCC(SL, SetCCVT, T, C, ISD::SETUGT);
2093  SDValue TCmp = DAG.getSetCC(SL, SetCCVT, T, C, ISD::SETEQ);
2094 
2095  SDValue One = DAG.getConstant(1, SL, MVT::i32);
2096 
2097  SDValue VTrunc1 = DAG.getNode(ISD::AND, SL, MVT::i32, V, One);
2098 
2099  SDValue R = DAG.getSelect(SL, MVT::i32,
2100  RCmp,
2101  One,
2102  DAG.getSelect(SL, MVT::i32, TCmp, VTrunc1, ZeroI32));
2103  R = DAG.getNode(ISD::ADD, SL, MVT::i32, V, R);
2104  R = DAG.getNode(ISD::BITCAST, SL, MVT::f32, R);
2105 
2106  if (!Signed)
2107  return R;
2108 
2109  SDValue RNeg = DAG.getNode(ISD::FNEG, SL, MVT::f32, R);
2110  return DAG.getSelect(SL, MVT::f32, DAG.getSExtOrTrunc(S, SL, SetCCVT), RNeg, R);
2111 }
2112 
2114  bool Signed) const {
2115  SDLoc SL(Op);
2116  SDValue Src = Op.getOperand(0);
2117 
2118  SDValue BC = DAG.getNode(ISD::BITCAST, SL, MVT::v2i32, Src);
2119 
2120  SDValue Lo = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SL, MVT::i32, BC,
2121  DAG.getConstant(0, SL, MVT::i32));
2122  SDValue Hi = DAG.getNode(ISD::EXTRACT_VECTOR_ELT, SL, MVT::i32, BC,
2123  DAG.getConstant(1, SL, MVT::i32));
2124 
2125  SDValue CvtHi = DAG.getNode(Signed ? ISD::SINT_TO_FP : ISD::UINT_TO_FP,
2126  SL, MVT::f64, Hi);
2127 
2128  SDValue CvtLo = DAG.getNode(ISD::UINT_TO_FP, SL, MVT::f64, Lo);
2129 
2130  SDValue LdExp = DAG.getNode(AMDGPUISD::LDEXP, SL, MVT::f64, CvtHi,
2131  DAG.getConstant(32, SL, MVT::i32));
2132  // TODO: Should this propagate fast-math-flags?
2133  return DAG.getNode(ISD::FADD, SL, MVT::f64, LdExp, CvtLo);
2134 }
2135 
2137  SelectionDAG &DAG) const {
2138  assert(Op.getOperand(0).getValueType() == MVT::i64 &&
2139  "operation should be legal");
2140 
2141  // TODO: Factor out code common with LowerSINT_TO_FP.
2142 
2143  EVT DestVT = Op.getValueType();
2144  if (Subtarget->has16BitInsts() && DestVT == MVT::f16) {
2145  SDLoc DL(Op);
2146  SDValue Src = Op.getOperand(0);
2147 
2148  SDValue IntToFp32 = DAG.getNode(Op.getOpcode(), DL, MVT::f32, Src);
2149  SDValue FPRoundFlag = DAG.getIntPtrConstant(0, SDLoc(Op));
2150  SDValue FPRound =
2151  DAG.getNode(ISD::FP_ROUND, DL, MVT::f16, IntToFp32, FPRoundFlag);
2152 
2153  return FPRound;
2154  }
2155 
2156  if (DestVT == MVT::f32)
2157  return LowerINT_TO_FP32(Op, DAG, false);
2158 
2159  assert(DestVT == MVT::f64);
2160  return LowerINT_TO_FP64(Op, DAG, false);
2161 }
2162 
2164  SelectionDAG &DAG) const {
2165  assert(Op.getOperand(0).getValueType() == MVT::i64 &&
2166  "operation should be legal");
2167 
2168  // TODO: Factor out code common with LowerUINT_TO_FP.
2169 
2170  EVT DestVT = Op.getValueType();
2171  if (Subtarget->has16BitInsts() && DestVT == MVT::f16) {
2172  SDLoc DL(Op);
2173  SDValue Src = Op.getOperand(0);
2174 
2175  SDValue IntToFp32 = DAG.getNode(Op.getOpcode(), DL, MVT::f32, Src);
2176  SDValue FPRoundFlag = DAG.getIntPtrConstant(0, SDLoc(Op));
2177  SDValue FPRound =
2178  DAG.getNode(ISD::FP_ROUND, DL, MVT::f16, IntToFp32, FPRoundFlag);
2179 
2180  return FPRound;
2181  }
2182 
2183  if (DestVT == MVT::f32)
2184  return LowerINT_TO_FP32(Op, DAG, true);
2185 
2186  assert(DestVT == MVT::f64);
2187  return LowerINT_TO_FP64(Op, DAG, true);
2188 }
2189 
2191  bool Signed) const {
2192  SDLoc SL(Op);
2193 
2194  SDValue Src = Op.getOperand(0);
2195 
2196  SDValue Trunc = DAG.getNode(ISD::FTRUNC, SL, MVT::f64, Src);
2197 
2198  SDValue K0 = DAG.getConstantFP(BitsToDouble(UINT64_C(0x3df0000000000000)), SL,
2199  MVT::f64);
2200  SDValue K1 = DAG.getConstantFP(BitsToDouble(UINT64_C(0xc1f0000000000000)), SL,
2201  MVT::f64);
2202  // TODO: Should this propagate fast-math-flags?
2203  SDValue Mul = DAG.getNode(ISD::FMUL, SL, MVT::f64, Trunc, K0);
2204 
2205  SDValue FloorMul = DAG.getNode(ISD::FFLOOR, SL, MVT::f64, Mul);
2206 
2207 
2208  SDValue Fma = DAG.getNode(ISD::FMA, SL, MVT::f64, FloorMul, K1, Trunc);
2209 
2210  SDValue Hi = DAG.getNode(Signed ? ISD::FP_TO_SINT : ISD::FP_TO_UINT, SL,
2211  MVT::i32, FloorMul);
2212  SDValue Lo = DAG.getNode(ISD::FP_TO_UINT, SL, MVT::i32, Fma);
2213 
2214  SDValue Result = DAG.getBuildVector(MVT::v2i32, SL, {Lo, Hi});
2215 
2216  return DAG.getNode(ISD::BITCAST, SL, MVT::i64, Result);
2217 }
2218 
2220  SDLoc DL(Op);
2221  SDValue N0 = Op.getOperand(0);
2222 
2223  // Convert to target node to get known bits
2224  if (N0.getValueType() == MVT::f32)
2225  return DAG.getNode(AMDGPUISD::FP_TO_FP16, DL, Op.getValueType(), N0);
2226 
2228  // There is a generic expand for FP_TO_FP16 with unsafe fast math.
2229  return SDValue();
2230  }
2231 
2233 
2234  // f64 -> f16 conversion using round-to-nearest-even rounding mode.
2235  const unsigned ExpMask = 0x7ff;
2236  const unsigned ExpBiasf64 = 1023;
2237  const unsigned ExpBiasf16 = 15;
2238  SDValue Zero = DAG.getConstant(0, DL, MVT::i32);
2239  SDValue One = DAG.getConstant(1, DL, MVT::i32);
2240  SDValue U = DAG.getNode(ISD::BITCAST, DL, MVT::i64, N0);
2241  SDValue UH = DAG.getNode(ISD::SRL, DL, MVT::i64, U,
2242  DAG.getConstant(32, DL, MVT::i64));
2243  UH = DAG.getZExtOrTrunc(UH, DL, MVT::i32);
2244  U = DAG.getZExtOrTrunc(U, DL, MVT::i32);
2245  SDValue E = DAG.getNode(ISD::SRL, DL, MVT::i32, UH,
2246  DAG.getConstant(20, DL, MVT::i64));
2247  E = DAG.getNode(ISD::AND, DL, MVT::i32, E,
2248  DAG.getConstant(ExpMask, DL, MVT::i32));
2249  // Subtract the fp64 exponent bias (1023) to get the real exponent and
2250  // add the f16 bias (15) to get the biased exponent for the f16 format.
2251  E = DAG.getNode(ISD::ADD, DL, MVT::i32, E,
2252  DAG.getConstant(-ExpBiasf64 + ExpBiasf16, DL, MVT::i32));
2253 
2254  SDValue M = DAG.getNode(ISD::SRL, DL, MVT::i32, UH,
2255  DAG.getConstant(8, DL, MVT::i32));
2256  M = DAG.getNode(ISD::AND, DL, MVT::i32, M,
2257  DAG.getConstant(0xffe, DL, MVT::i32));
2258 
2259  SDValue MaskedSig = DAG.getNode(ISD::AND, DL, MVT::i32, UH,
2260  DAG.getConstant(0x1ff, DL, MVT::i32));
2261  MaskedSig = DAG.getNode(ISD::OR, DL, MVT::i32, MaskedSig, U);
2262 
2263  SDValue Lo40Set = DAG.getSelectCC(DL, MaskedSig, Zero, Zero, One, ISD::SETEQ);
2264  M = DAG.getNode(ISD::OR, DL, MVT::i32, M, Lo40Set);
2265 
2266  // (M != 0 ? 0x0200 : 0) | 0x7c00;
2267  SDValue I = DAG.getNode(ISD::OR, DL, MVT::i32,
2268  DAG.getSelectCC(DL, M, Zero, DAG.getConstant(0x0200, DL, MVT::i32),
2269  Zero, ISD::SETNE), DAG.getConstant(0x7c00, DL, MVT::i32));
2270 
2271  // N = M | (E << 12);
2272  SDValue N = DAG.getNode(ISD::OR, DL, MVT::i32, M,
2273  DAG.getNode(ISD::SHL, DL, MVT::i32, E,
2274  DAG.getConstant(12, DL, MVT::i32)));
2275 
2276  // B = clamp(1-E, 0, 13);
2277  SDValue OneSubExp = DAG.getNode(ISD::SUB, DL, MVT::i32,
2278  One, E);
2279  SDValue B = DAG.getNode(ISD::SMAX, DL, MVT::i32, OneSubExp, Zero);
2280  B = DAG.getNode(ISD::SMIN, DL, MVT::i32, B,
2281  DAG.getConstant(13, DL, MVT::i32));
2282 
2283  SDValue SigSetHigh = DAG.getNode(ISD::OR, DL, MVT::i32, M,
2284  DAG.getConstant(0x1000, DL, MVT::i32));
2285 
2286  SDValue D = DAG.getNode(ISD::SRL, DL, MVT::i32, SigSetHigh, B);
2287  SDValue D0 = DAG.getNode(ISD::SHL, DL, MVT::i32, D, B);
2288  SDValue D1 = DAG.getSelectCC(DL, D0, SigSetHigh, One, Zero, ISD::SETNE);
2289  D = DAG.getNode(ISD::OR, DL, MVT::i32, D, D1);
2290 
2291  SDValue V = DAG.getSelectCC(DL, E, One, D, N, ISD::SETLT);
2292  SDValue VLow3 = DAG.getNode(ISD::AND, DL, MVT::i32, V,
2293  DAG.getConstant(0x7, DL, MVT::i32));
2294  V = DAG.getNode(ISD::SRL, DL, MVT::i32, V,
2295  DAG.getConstant(2, DL, MVT::i32));
2296  SDValue V0 = DAG.getSelectCC(DL, VLow3, DAG.getConstant(3, DL, MVT::i32),
2297  One, Zero, ISD::SETEQ);
2298  SDValue V1 = DAG.getSelectCC(DL, VLow3, DAG.getConstant(5, DL, MVT::i32),
2299  One, Zero, ISD::SETGT);
2300  V1 = DAG.getNode(ISD::OR, DL, MVT::i32, V0, V1);
2301  V = DAG.getNode(ISD::ADD, DL, MVT::i32, V, V1);
2302 
2303  V = DAG.getSelectCC(DL, E, DAG.getConstant(30, DL, MVT::i32),
2304  DAG.getConstant(0x7c00, DL, MVT::i32), V, ISD::SETGT);
2305  V = DAG.getSelectCC(DL, E, DAG.getConstant(1039, DL, MVT::i32),
2306  I, V, ISD::SETEQ);
2307 
2308  // Extract the sign bit.
2309  SDValue Sign = DAG.getNode(ISD::SRL, DL, MVT::i32, UH,
2310  DAG.getConstant(16, DL, MVT::i32));
2311  Sign = DAG.getNode(ISD::AND, DL, MVT::i32, Sign,
2312  DAG.getConstant(0x8000, DL, MVT::i32));
2313 
2314  V = DAG.getNode(ISD::OR, DL, MVT::i32, Sign, V);
2315  return DAG.getZExtOrTrunc(V, DL, Op.getValueType());
2316 }
2317 
2319  SelectionDAG &DAG) const {
2320  SDValue Src = Op.getOperand(0);
2321 
2322  // TODO: Factor out code common with LowerFP_TO_UINT.
2323 
2324  EVT SrcVT = Src.getValueType();
2325  if (Subtarget->has16BitInsts() && SrcVT == MVT::f16) {
2326  SDLoc DL(Op);
2327 
2328  SDValue FPExtend = DAG.getNode(ISD::FP_EXTEND, DL, MVT::f32, Src);
2329  SDValue FpToInt32 =
2330  DAG.getNode(Op.getOpcode(), DL, MVT::i64, FPExtend);
2331 
2332  return FpToInt32;
2333  }
2334 
2335  if (Op.getValueType() == MVT::i64 && Src.getValueType() == MVT::f64)
2336  return LowerFP64_TO_INT(Op, DAG, true);
2337 
2338  return SDValue();
2339 }
2340 
2342  SelectionDAG &DAG) const {
2343  SDValue Src = Op.getOperand(0);
2344 
2345  // TODO: Factor out code common with LowerFP_TO_SINT.
2346 
2347  EVT SrcVT = Src.getValueType();
2348  if (Subtarget->has16BitInsts() && SrcVT == MVT::f16) {
2349  SDLoc DL(Op);
2350 
2351  SDValue FPExtend = DAG.getNode(ISD::FP_EXTEND, DL, MVT::f32, Src);
2352  SDValue FpToInt32 =
2353  DAG.getNode(Op.getOpcode(), DL, MVT::i64, FPExtend);
2354 
2355  return FpToInt32;
2356  }
2357 
2358  if (Op.getValueType() == MVT::i64 && Src.getValueType() == MVT::f64)
2359  return LowerFP64_TO_INT(Op, DAG, false);
2360 
2361  return SDValue();
2362 }
2363 
2365  SelectionDAG &DAG) const {
2366  EVT ExtraVT = cast<VTSDNode>(Op.getOperand(1))->getVT();
2367  MVT VT = Op.getSimpleValueType();
2368  MVT ScalarVT = VT.getScalarType();
2369 
2370  assert(VT.isVector());
2371 
2372  SDValue Src = Op.getOperand(0);
2373  SDLoc DL(Op);
2374 
2375  // TODO: Don't scalarize on Evergreen?
2376  unsigned NElts = VT.getVectorNumElements();
2378  DAG.ExtractVectorElements(Src, Args, 0, NElts);
2379 
2380  SDValue VTOp = DAG.getValueType(ExtraVT.getScalarType());
2381  for (unsigned I = 0; I < NElts; ++I)
2382  Args[I] = DAG.getNode(ISD::SIGN_EXTEND_INREG, DL, ScalarVT, Args[I], VTOp);
2383 
2384  return DAG.getBuildVector(VT, DL, Args);
2385 }
2386 
2387 //===----------------------------------------------------------------------===//
2388 // Custom DAG optimizations
2389 //===----------------------------------------------------------------------===//
2390 
2391 static bool isU24(SDValue Op, SelectionDAG &DAG) {
2392  KnownBits Known;
2393  EVT VT = Op.getValueType();
2394  DAG.computeKnownBits(Op, Known);
2395 
2396  return (VT.getSizeInBits() - Known.countMinLeadingZeros()) <= 24;
2397 }
2398 
2399 static bool isI24(SDValue Op, SelectionDAG &DAG) {
2400  EVT VT = Op.getValueType();
2401 
2402  // In order for this to be a signed 24-bit value, bit 23, must
2403  // be a sign bit.
2404  return VT.getSizeInBits() >= 24 && // Types less than 24-bit should be treated
2405  // as unsigned 24-bit values.
2406  (VT.getSizeInBits() - DAG.ComputeNumSignBits(Op)) < 24;
2407 }
2408 
2409 static bool simplifyI24(SDNode *Node24, unsigned OpIdx,
2411 
2412  SelectionDAG &DAG = DCI.DAG;
2413  SDValue Op = Node24->getOperand(OpIdx);
2414  const TargetLowering &TLI = DAG.getTargetLoweringInfo();
2415  EVT VT = Op.getValueType();
2416 
2417  APInt Demanded = APInt::getLowBitsSet(VT.getSizeInBits(), 24);
2418  APInt KnownZero, KnownOne;
2419  TargetLowering::TargetLoweringOpt TLO(DAG, true, true);
2420  if (TLI.SimplifyDemandedBits(Node24, OpIdx, Demanded, DCI, TLO))
2421  return true;
2422 
2423  return false;
2424 }
2425 
2426 template <typename IntTy>
2428  uint32_t Width, const SDLoc &DL) {
2429  if (Width + Offset < 32) {
2430  uint32_t Shl = static_cast<uint32_t>(Src0) << (32 - Offset - Width);
2431  IntTy Result = static_cast<IntTy>(Shl) >> (32 - Width);
2432  return DAG.getConstant(Result, DL, MVT::i32);
2433  }
2434 
2435  return DAG.getConstant(Src0 >> Offset, DL, MVT::i32);
2436 }
2437 
2438 static bool hasVolatileUser(SDNode *Val) {
2439  for (SDNode *U : Val->uses()) {
2440  if (MemSDNode *M = dyn_cast<MemSDNode>(U)) {
2441  if (M->isVolatile())
2442  return true;
2443  }
2444  }
2445 
2446  return false;
2447 }
2448 
2450  // i32 vectors are the canonical memory type.
2451  if (VT.getScalarType() == MVT::i32 || isTypeLegal(VT))
2452  return false;
2453 
2454  if (!VT.isByteSized())
2455  return false;
2456 
2457  unsigned Size = VT.getStoreSize();
2458 
2459  if ((Size == 1 || Size == 2 || Size == 4) && !VT.isVector())
2460  return false;
2461 
2462  if (Size == 3 || (Size > 4 && (Size % 4 != 0)))
2463  return false;
2464 
2465  return true;
2466 }
2467 
2468 // Replace load of an illegal type with a store of a bitcast to a friendlier
2469 // type.
2471  DAGCombinerInfo &DCI) const {
2472  if (!DCI.isBeforeLegalize())
2473  return SDValue();
2474 
2475  LoadSDNode *LN = cast<LoadSDNode>(N);
2476  if (LN->isVolatile() || !ISD::isNormalLoad(LN) || hasVolatileUser(LN))
2477  return SDValue();
2478 
2479  SDLoc SL(N);
2480  SelectionDAG &DAG = DCI.DAG;
2481  EVT VT = LN->getMemoryVT();
2482 
2483  unsigned Size = VT.getStoreSize();
2484  unsigned Align = LN->getAlignment();
2485  if (Align < Size && isTypeLegal(VT)) {
2486  bool IsFast;
2487  unsigned AS = LN->getAddressSpace();
2488 
2489  // Expand unaligned loads earlier than legalization. Due to visitation order
2490  // problems during legalization, the emitted instructions to pack and unpack
2491  // the bytes again are not eliminated in the case of an unaligned copy.
2492  if (!allowsMisalignedMemoryAccesses(VT, AS, Align, &IsFast)) {
2493  if (VT.isVector())
2494  return scalarizeVectorLoad(LN, DAG);
2495 
2496  SDValue Ops[2];
2497  std::tie(Ops[0], Ops[1]) = expandUnalignedLoad(LN, DAG);
2498  return DAG.getMergeValues(Ops, SDLoc(N));
2499  }
2500 
2501  if (!IsFast)
2502  return SDValue();
2503  }
2504 
2505  if (!shouldCombineMemoryType(VT))
2506  return SDValue();
2507 
2508  EVT NewVT = getEquivalentMemType(*DAG.getContext(), VT);
2509 
2510  SDValue NewLoad
2511  = DAG.getLoad(NewVT, SL, LN->getChain(),
2512  LN->getBasePtr(), LN->getMemOperand());
2513 
2514  SDValue BC = DAG.getNode(ISD::BITCAST, SL, VT, NewLoad);
2515  DCI.CombineTo(N, BC, NewLoad.getValue(1));
2516  return SDValue(N, 0);
2517 }
2518 
2519 // Replace store of an illegal type with a store of a bitcast to a friendlier
2520 // type.
2522  DAGCombinerInfo &DCI) const {
2523  if (!DCI.isBeforeLegalize())
2524  return SDValue();
2525 
2526  StoreSDNode *SN = cast<StoreSDNode>(N);
2527  if (SN->isVolatile() || !ISD::isNormalStore(SN))
2528  return SDValue();
2529 
2530  EVT VT = SN->getMemoryVT();
2531  unsigned Size = VT.getStoreSize();
2532 
2533  SDLoc SL(N);
2534  SelectionDAG &DAG = DCI.DAG;
2535  unsigned Align = SN->getAlignment();
2536  if (Align < Size && isTypeLegal(VT)) {
2537  bool IsFast;
2538  unsigned AS = SN->getAddressSpace();
2539 
2540  // Expand unaligned stores earlier than legalization. Due to visitation
2541  // order problems during legalization, the emitted instructions to pack and
2542  // unpack the bytes again are not eliminated in the case of an unaligned
2543  // copy.
2544  if (!allowsMisalignedMemoryAccesses(VT, AS, Align, &IsFast)) {
2545  if (VT.isVector())
2546  return scalarizeVectorStore(SN, DAG);
2547 
2548  return expandUnalignedStore(SN, DAG);
2549  }
2550 
2551  if (!IsFast)
2552  return SDValue();
2553  }
2554 
2555  if (!shouldCombineMemoryType(VT))
2556  return SDValue();
2557 
2558  EVT NewVT = getEquivalentMemType(*DAG.getContext(), VT);
2559  SDValue Val = SN->getValue();
2560 
2561  //DCI.AddToWorklist(Val.getNode());
2562 
2563  bool OtherUses = !Val.hasOneUse();
2564  SDValue CastVal = DAG.getNode(ISD::BITCAST, SL, NewVT, Val);
2565  if (OtherUses) {
2566  SDValue CastBack = DAG.getNode(ISD::BITCAST, SL, VT, CastVal);
2567  DAG.ReplaceAllUsesOfValueWith(Val, CastBack);
2568  }
2569 
2570  return DAG.getStore(SN->getChain(), SL, CastVal,
2571  SN->getBasePtr(), SN->getMemOperand());
2572 }
2573 
2575  DAGCombinerInfo &DCI) const {
2577  if (!CSrc)
2578  return SDValue();
2579 
2580  const APFloat &F = CSrc->getValueAPF();
2582  APFloat::cmpResult Cmp0 = F.compare(Zero);
2583  if (Cmp0 == APFloat::cmpLessThan ||
2585  return DCI.DAG.getConstantFP(Zero, SDLoc(N), N->getValueType(0));
2586  }
2587 
2588  APFloat One(F.getSemantics(), "1.0");
2589  APFloat::cmpResult Cmp1 = F.compare(One);
2590  if (Cmp1 == APFloat::cmpGreaterThan)
2591  return DCI.DAG.getConstantFP(One, SDLoc(N), N->getValueType(0));
2592 
2593  return SDValue(CSrc, 0);
2594 }
2595 
2596 // FIXME: This should go in generic DAG combiner with an isTruncateFree check,
2597 // but isTruncateFree is inaccurate for i16 now because of SALU vs. VALU
2598 // issues.
2600  DAGCombinerInfo &DCI) const {
2601  SelectionDAG &DAG = DCI.DAG;
2602  SDValue N0 = N->getOperand(0);
2603 
2604  // (vt2 (assertzext (truncate vt0:x), vt1)) ->
2605  // (vt2 (truncate (assertzext vt0:x, vt1)))
2606  if (N0.getOpcode() == ISD::TRUNCATE) {
2607  SDValue N1 = N->getOperand(1);
2608  EVT ExtVT = cast<VTSDNode>(N1)->getVT();
2609  SDLoc SL(N);
2610 
2611  SDValue Src = N0.getOperand(0);
2612  EVT SrcVT = Src.getValueType();
2613  if (SrcVT.bitsGE(ExtVT)) {
2614  SDValue NewInReg = DAG.getNode(N->getOpcode(), SL, SrcVT, Src, N1);
2615  return DAG.getNode(ISD::TRUNCATE, SL, N->getValueType(0), NewInReg);
2616  }
2617  }
2618 
2619  return SDValue();
2620 }
2621 /// Split the 64-bit value \p LHS into two 32-bit components, and perform the
2622 /// binary operation \p Opc to it with the corresponding constant operands.
2624  DAGCombinerInfo &DCI, const SDLoc &SL,
2625  unsigned Opc, SDValue LHS,
2626  uint32_t ValLo, uint32_t ValHi) const {
2627  SelectionDAG &DAG = DCI.DAG;
2628  SDValue Lo, Hi;
2629  std::tie(Lo, Hi) = split64BitValue(LHS, DAG);
2630 
2631  SDValue LoRHS = DAG.getConstant(ValLo, SL, MVT::i32);
2632  SDValue HiRHS = DAG.getConstant(ValHi, SL, MVT::i32);
2633 
2634  SDValue LoAnd = DAG.getNode(Opc, SL, MVT::i32, Lo, LoRHS);
2635  SDValue HiAnd = DAG.getNode(Opc, SL, MVT::i32, Hi, HiRHS);
2636 
2637  // Re-visit the ands. It's possible we eliminated one of them and it could
2638  // simplify the vector.
2639  DCI.AddToWorklist(Lo.getNode());
2640  DCI.AddToWorklist(Hi.getNode());
2641 
2642  SDValue Vec = DAG.getBuildVector(MVT::v2i32, SL, {LoAnd, HiAnd});
2643  return DAG.getNode(ISD::BITCAST, SL, MVT::i64, Vec);
2644 }
2645 
2647  DAGCombinerInfo &DCI) const {
2648  EVT VT = N->getValueType(0);
2649 
2651  if (!RHS)
2652  return SDValue();
2653 
2654  SDValue LHS = N->getOperand(0);
2655  unsigned RHSVal = RHS->getZExtValue();
2656  if (!RHSVal)
2657  return LHS;
2658 
2659  SDLoc SL(N);
2660  SelectionDAG &DAG = DCI.DAG;
2661 
2662  switch (LHS->getOpcode()) {
2663  default:
2664  break;
2665  case ISD::ZERO_EXTEND:
2666  case ISD::SIGN_EXTEND:
2667  case ISD::ANY_EXTEND: {
2668  // shl (ext x) => zext (shl x), if shift does not overflow int
2669  if (VT != MVT::i64)
2670  break;
2671  KnownBits Known;
2672  SDValue X = LHS->getOperand(0);
2673  DAG.computeKnownBits(X, Known);
2674  unsigned LZ = Known.countMinLeadingZeros();
2675  if (LZ < RHSVal)
2676  break;
2677  EVT XVT = X.getValueType();
2678  SDValue Shl = DAG.getNode(ISD::SHL, SL, XVT, X, SDValue(RHS, 0));
2679  return DAG.getZExtOrTrunc(Shl, SL, VT);
2680  }
2681  case ISD::OR:
2682  if (!isOrEquivalentToAdd(DAG, LHS))
2683  break;
2685  case ISD::ADD: {
2686  // shl (or|add x, c2), c1 => or|add (shl x, c1), (c2 << c1)
2687  if (ConstantSDNode *C2 = dyn_cast<ConstantSDNode>(LHS->getOperand(1))) {
2688  SDValue Shl = DAG.getNode(ISD::SHL, SL, VT, LHS->getOperand(0),
2689  SDValue(RHS, 0));
2690  SDValue C2V = DAG.getConstant(C2->getAPIntValue() << RHSVal,
2691  SDLoc(C2), VT);
2692  return DAG.getNode(LHS->getOpcode(), SL, VT, Shl, C2V);
2693  }
2694  break;
2695  }
2696  }
2697 
2698  if (VT != MVT::i64)
2699  return SDValue();
2700 
2701  // i64 (shl x, C) -> (build_pair 0, (shl x, C -32))
2702 
2703  // On some subtargets, 64-bit shift is a quarter rate instruction. In the
2704  // common case, splitting this into a move and a 32-bit shift is faster and
2705  // the same code size.
2706  if (RHSVal < 32)
2707  return SDValue();
2708 
2709  SDValue ShiftAmt = DAG.getConstant(RHSVal - 32, SL, MVT::i32);
2710 
2711  SDValue Lo = DAG.getNode(ISD::TRUNCATE, SL, MVT::i32, LHS);
2712  SDValue NewShift = DAG.getNode(ISD::SHL, SL, MVT::i32, Lo, ShiftAmt);
2713 
2714  const SDValue Zero = DAG.getConstant(0, SL, MVT::i32);
2715 
2716  SDValue Vec = DAG.getBuildVector(MVT::v2i32, SL, {Zero, NewShift});
2717  return DAG.getNode(ISD::BITCAST, SL, MVT::i64, Vec);
2718 }
2719 
2721  DAGCombinerInfo &DCI) const {
2722  if (N->getValueType(0) != MVT::i64)
2723  return SDValue();
2724 
2725  const ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N->getOperand(1));
2726  if (!RHS)
2727  return SDValue();
2728 
2729  SelectionDAG &DAG = DCI.DAG;
2730  SDLoc SL(N);
2731  unsigned RHSVal = RHS->getZExtValue();
2732 
2733  // (sra i64:x, 32) -> build_pair x, (sra hi_32(x), 31)
2734  if (RHSVal == 32) {
2735  SDValue Hi = getHiHalf64(N->getOperand(0), DAG);
2736  SDValue NewShift = DAG.getNode(ISD::SRA, SL, MVT::i32, Hi,
2737  DAG.getConstant(31, SL, MVT::i32));
2738 
2739  SDValue BuildVec = DAG.getBuildVector(MVT::v2i32, SL, {Hi, NewShift});
2740  return DAG.getNode(ISD::BITCAST, SL, MVT::i64, BuildVec);
2741  }
2742 
2743  // (sra i64:x, 63) -> build_pair (sra hi_32(x), 31), (sra hi_32(x), 31)
2744  if (RHSVal == 63) {
2745  SDValue Hi = getHiHalf64(N->getOperand(0), DAG);
2746  SDValue NewShift = DAG.getNode(ISD::SRA, SL, MVT::i32, Hi,
2747  DAG.getConstant(31, SL, MVT::i32));
2748  SDValue BuildVec = DAG.getBuildVector(MVT::v2i32, SL, {NewShift, NewShift});
2749  return DAG.getNode(ISD::BITCAST, SL, MVT::i64, BuildVec);
2750  }
2751 
2752  return SDValue();
2753 }
2754 
2756  DAGCombinerInfo &DCI) const {
2757  if (N->getValueType(0) != MVT::i64)
2758  return SDValue();
2759 
2760  const ConstantSDNode *RHS = dyn_cast<ConstantSDNode>(N->getOperand(1));
2761  if (!RHS)
2762  return SDValue();
2763 
2764  unsigned ShiftAmt = RHS->getZExtValue();
2765  if (ShiftAmt < 32)
2766  return SDValue();
2767 
2768  // srl i64:x, C for C >= 32
2769  // =>
2770  // build_pair (srl hi_32(x), C - 32), 0
2771 
2772  SelectionDAG &DAG = DCI.DAG;
2773  SDLoc SL(N);
2774 
2775  SDValue One = DAG.getConstant(1, SL, MVT::i32);
2776  SDValue Zero = DAG.getConstant(0, SL, MVT::i32);
2777 
2778  SDValue VecOp = DAG.getNode(ISD::BITCAST, SL, MVT::v2i32, N->getOperand(0));
2780  VecOp, One);
2781 
2782  SDValue NewConst = DAG.getConstant(ShiftAmt - 32, SL, MVT::i32);
2783  SDValue NewShift = DAG.getNode(ISD::SRL, SL, MVT::i32, Hi, NewConst);
2784 
2785  SDValue BuildPair = DAG.getBuildVector(MVT::v2i32, SL, {NewShift, Zero});
2786 
2787  return DAG.getNode(ISD::BITCAST, SL, MVT::i64, BuildPair);
2788 }
2789 
2790 // We need to specifically handle i64 mul here to avoid unnecessary conversion
2791 // instructions. If we only match on the legalized i64 mul expansion,
2792 // SimplifyDemandedBits will be unable to remove them because there will be
2793 // multiple uses due to the separate mul + mulh[su].
2794 static SDValue getMul24(SelectionDAG &DAG, const SDLoc &SL,
2795  SDValue N0, SDValue N1, unsigned Size, bool Signed) {
2796  if (Size <= 32) {
2797  unsigned MulOpc = Signed ? AMDGPUISD::MUL_I24 : AMDGPUISD::MUL_U24;
2798  return DAG.getNode(MulOpc, SL, MVT::i32, N0, N1);
2799  }
2800 
2801  // Because we want to eliminate extension instructions before the
2802  // operation, we need to create a single user here (i.e. not the separate
2803  // mul_lo + mul_hi) so that SimplifyDemandedBits will deal with it.
2804 
2805  unsigned MulOpc = Signed ? AMDGPUISD::MUL_LOHI_I24 : AMDGPUISD::MUL_LOHI_U24;
2806 
2807  SDValue Mul = DAG.getNode(MulOpc, SL,
2808  DAG.getVTList(MVT::i32, MVT::i32), N0, N1);
2809 
2810  return DAG.getNode(ISD::BUILD_PAIR, SL, MVT::i64,
2811  Mul.getValue(0), Mul.getValue(1));
2812 }
2813 
2815  DAGCombinerInfo &DCI) const {
2816  EVT VT = N->getValueType(0);
2817 
2818  unsigned Size = VT.getSizeInBits();
2819  if (VT.isVector() || Size > 64)
2820  return SDValue();
2821 
2822  // There are i16 integer mul/mad.
2824  return SDValue();
2825 
2826  SelectionDAG &DAG = DCI.DAG;
2827  SDLoc DL(N);
2828 
2829  SDValue N0 = N->getOperand(0);
2830  SDValue N1 = N->getOperand(1);
2831  SDValue Mul;
2832 
2833  if (Subtarget->hasMulU24() && isU24(N0, DAG) && isU24(N1, DAG)) {
2834  N0 = DAG.getZExtOrTrunc(N0, DL, MVT::i32);
2835  N1 = DAG.getZExtOrTrunc(N1, DL, MVT::i32);
2836  Mul = getMul24(DAG, DL, N0, N1, Size, false);
2837  } else if (Subtarget->hasMulI24() && isI24(N0, DAG) && isI24(N1, DAG)) {
2838  N0 = DAG.getSExtOrTrunc(N0, DL, MVT::i32);
2839  N1 = DAG.getSExtOrTrunc(N1, DL, MVT::i32);
2840  Mul = getMul24(DAG, DL, N0, N1, Size, true);
2841  } else {
2842  return SDValue();
2843  }
2844 
2845  // We need to use sext even for MUL_U24, because MUL_U24 is used
2846  // for signed multiply of 8 and 16-bit types.
2847  return DAG.getSExtOrTrunc(Mul, DL, VT);
2848 }
2849 
2851  DAGCombinerInfo &DCI) const {
2852  EVT VT = N->getValueType(0);
2853 
2854  if (!Subtarget->hasMulI24() || VT.isVector())
2855  return SDValue();
2856 
2857  SelectionDAG &DAG = DCI.DAG;
2858  SDLoc DL(N);
2859 
2860  SDValue N0 = N->getOperand(0);
2861  SDValue N1 = N->getOperand(1);
2862 
2863  if (!isI24(N0, DAG) || !isI24(N1, DAG))
2864  return SDValue();
2865 
2866  N0 = DAG.getSExtOrTrunc(N0, DL, MVT::i32);
2867  N1 = DAG.getSExtOrTrunc(N1, DL, MVT::i32);
2868 
2869  SDValue Mulhi = DAG.getNode(AMDGPUISD::MULHI_I24, DL, MVT::i32, N0, N1);
2870  DCI.AddToWorklist(Mulhi.getNode());
2871  return DAG.getSExtOrTrunc(Mulhi, DL, VT);
2872 }
2873 
2875  DAGCombinerInfo &DCI) const {
2876  EVT VT = N->getValueType(0);
2877 
2878  if (!Subtarget->hasMulU24() || VT.isVector() || VT.getSizeInBits() > 32)
2879  return SDValue();
2880 
2881  SelectionDAG &DAG = DCI.DAG;
2882  SDLoc DL(N);
2883 
2884  SDValue N0 = N->getOperand(0);
2885  SDValue N1 = N->getOperand(1);
2886 
2887  if (!isU24(N0, DAG) || !isU24(N1, DAG))
2888  return SDValue();
2889 
2890  N0 = DAG.getZExtOrTrunc(N0, DL, MVT::i32);
2891  N1 = DAG.getZExtOrTrunc(N1, DL, MVT::i32);
2892 
2893  SDValue Mulhi = DAG.getNode(AMDGPUISD::MULHI_U24, DL, MVT::i32, N0, N1);
2894  DCI.AddToWorklist(Mulhi.getNode());
2895  return DAG.getZExtOrTrunc(Mulhi, DL, VT);
2896 }
2897 
2899  SDNode *N, DAGCombinerInfo &DCI) const {
2900  SelectionDAG &DAG = DCI.DAG;
2901 
2902  // Simplify demanded bits before splitting into multiple users.
2903  if (simplifyI24(N, 0, DCI) || simplifyI24(N, 1, DCI))
2904  return SDValue();
2905 
2906  SDValue N0 = N->getOperand(0);
2907  SDValue N1 = N->getOperand(1);
2908 
2909  bool Signed = (N->getOpcode() == AMDGPUISD::MUL_LOHI_I24);
2910 
2911  unsigned MulLoOpc = Signed ? AMDGPUISD::MUL_I24 : AMDGPUISD::MUL_U24;
2912  unsigned MulHiOpc = Signed ? AMDGPUISD::MULHI_I24 : AMDGPUISD::MULHI_U24;
2913 
2914  SDLoc SL(N);
2915 
2916  SDValue MulLo = DAG.getNode(MulLoOpc, SL, MVT::i32, N0, N1);
2917  SDValue MulHi = DAG.getNode(MulHiOpc, SL, MVT::i32, N0, N1);
2918  return DAG.getMergeValues({ MulLo, MulHi }, SL);
2919 }
2920 
2921 static bool isNegativeOne(SDValue Val) {
2922  if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Val))
2923  return C->isAllOnesValue();
2924  return false;
2925 }
2926 
2927 static bool isCtlzOpc(unsigned Opc) {
2928  return Opc == ISD::CTLZ || Opc == ISD::CTLZ_ZERO_UNDEF;
2929 }
2930 
2931 SDValue AMDGPUTargetLowering::getFFBH_U32(SelectionDAG &DAG,
2932  SDValue Op,
2933  const SDLoc &DL) const {
2934  EVT VT = Op.getValueType();
2935  EVT LegalVT = getTypeToTransformTo(*DAG.getContext(), VT);
2936  if (LegalVT != MVT::i32 && (Subtarget->has16BitInsts() &&
2937  LegalVT != MVT::i16))
2938  return SDValue();
2939 
2940  if (VT != MVT::i32)
2941  Op = DAG.getNode(ISD::ZERO_EXTEND, DL, MVT::i32, Op);
2942 
2943  SDValue FFBH = DAG.getNode(AMDGPUISD::FFBH_U32, DL, MVT::i32, Op);
2944  if (VT != MVT::i32)
2945  FFBH = DAG.getNode(ISD::TRUNCATE, DL, VT, FFBH);
2946 
2947  return FFBH;
2948 }
2949 
2950 // The native instructions return -1 on 0 input. Optimize out a select that
2951 // produces -1 on 0.
2952 //
2953 // TODO: If zero is not undef, we could also do this if the output is compared
2954 // against the bitwidth.
2955 //
2956 // TODO: Should probably combine against FFBH_U32 instead of ctlz directly.
2958  SDValue LHS, SDValue RHS,
2959  DAGCombinerInfo &DCI) const {
2960  ConstantSDNode *CmpRhs = dyn_cast<ConstantSDNode>(Cond.getOperand(1));
2961  if (!CmpRhs || !CmpRhs->isNullValue())
2962  return SDValue();
2963 
2964  SelectionDAG &DAG = DCI.DAG;
2965  ISD::CondCode CCOpcode = cast<CondCodeSDNode>(Cond.getOperand(2))->get();
2966  SDValue CmpLHS = Cond.getOperand(0);
2967 
2968  // select (setcc x, 0, eq), -1, (ctlz_zero_undef x) -> ffbh_u32 x
2969  if (CCOpcode == ISD::SETEQ &&
2970  isCtlzOpc(RHS.getOpcode()) &&
2971  RHS.getOperand(0) == CmpLHS &&
2972  isNegativeOne(LHS)) {
2973  return getFFBH_U32(DAG, CmpLHS, SL);
2974  }
2975 
2976  // select (setcc x, 0, ne), (ctlz_zero_undef x), -1 -> ffbh_u32 x
2977  if (CCOpcode == ISD::SETNE &&
2978  isCtlzOpc(LHS.getOpcode()) &&
2979  LHS.getOperand(0) == CmpLHS &&
2980  isNegativeOne(RHS)) {
2981  return getFFBH_U32(DAG, CmpLHS, SL);
2982  }
2983 
2984  return SDValue();
2985 }
2986 
2988  unsigned Op,
2989  const SDLoc &SL,
2990  SDValue Cond,
2991  SDValue N1,
2992  SDValue N2) {
2993  SelectionDAG &DAG = DCI.DAG;
2994  EVT VT = N1.getValueType();
2995 
2996  SDValue NewSelect = DAG.getNode(ISD::SELECT, SL, VT, Cond,
2997  N1.getOperand(0), N2.getOperand(0));
2998  DCI.AddToWorklist(NewSelect.getNode());
2999  return DAG.getNode(Op, SL, VT, NewSelect);
3000 }
3001 
3002 // Pull a free FP operation out of a select so it may fold into uses.
3003 //
3004 // select c, (fneg x), (fneg y) -> fneg (select c, x, y)
3005 // select c, (fneg x), k -> fneg (select c, x, (fneg k))
3006 //
3007 // select c, (fabs x), (fabs y) -> fabs (select c, x, y)
3008 // select c, (fabs x), +k -> fabs (select c, x, k)
3010  SDValue N) {
3011  SelectionDAG &DAG = DCI.DAG;
3012  SDValue Cond = N.getOperand(0);
3013  SDValue LHS = N.getOperand(1);
3014  SDValue RHS = N.getOperand(2);
3015 
3016  EVT VT = N.getValueType();
3017  if ((LHS.getOpcode() == ISD::FABS && RHS.getOpcode() == ISD::FABS) ||
3018  (LHS.getOpcode() == ISD::FNEG && RHS.getOpcode() == ISD::FNEG)) {
3019  return distributeOpThroughSelect(DCI, LHS.getOpcode(),
3020  SDLoc(N), Cond, LHS, RHS);
3021  }
3022 
3023  bool Inv = false;
3024  if (RHS.getOpcode() == ISD::FABS || RHS.getOpcode() == ISD::FNEG) {
3025  std::swap(LHS, RHS);
3026  Inv = true;
3027  }
3028 
3029  // TODO: Support vector constants.
3031  if ((LHS.getOpcode() == ISD::FNEG || LHS.getOpcode() == ISD::FABS) && CRHS) {
3032  SDLoc SL(N);
3033  // If one side is an fneg/fabs and the other is a constant, we can push the
3034  // fneg/fabs down. If it's an fabs, the constant needs to be non-negative.
3035  SDValue NewLHS = LHS.getOperand(0);
3036  SDValue NewRHS = RHS;
3037 
3038  // Careful: if the neg can be folded up, don't try to pull it back down.
3039  bool ShouldFoldNeg = true;
3040 
3041  if (NewLHS.hasOneUse()) {
3042  unsigned Opc = NewLHS.getOpcode();
3043  if (LHS.getOpcode() == ISD::FNEG && fnegFoldsIntoOp(Opc))
3044  ShouldFoldNeg = false;
3045  if (LHS.getOpcode() == ISD::FABS && Opc == ISD::FMUL)
3046  ShouldFoldNeg = false;
3047  }
3048 
3049  if (ShouldFoldNeg) {
3050  if (LHS.getOpcode() == ISD::FNEG)
3051  NewRHS = DAG.getNode(ISD::FNEG, SL, VT, RHS);
3052  else if (CRHS->isNegative())
3053  return SDValue();
3054 
3055  if (Inv)
3056  std::swap(NewLHS, NewRHS);
3057 
3058  SDValue NewSelect = DAG.getNode(ISD::SELECT, SL, VT,
3059  Cond, NewLHS, NewRHS);
3060  DCI.AddToWorklist(NewSelect.getNode());
3061  return DAG.getNode(LHS.getOpcode(), SL, VT, NewSelect);
3062  }
3063  }
3064 
3065  return SDValue();
3066 }
3067 
3068 
3070  DAGCombinerInfo &DCI) const {
3071  if (SDValue Folded = foldFreeOpFromSelect(DCI, SDValue(N, 0)))
3072  return Folded;
3073 
3074  SDValue Cond = N->getOperand(0);
3075  if (Cond.getOpcode() != ISD::SETCC)
3076  return SDValue();
3077 
3078  EVT VT = N->getValueType(0);
3079  SDValue LHS = Cond.getOperand(0);
3080  SDValue RHS = Cond.getOperand(1);
3081  SDValue CC = Cond.getOperand(2);
3082 
3083  SDValue True = N->getOperand(1);
3084  SDValue False = N->getOperand(2);
3085 
3086  if (Cond.hasOneUse()) { // TODO: Look for multiple select uses.
3087  SelectionDAG &DAG = DCI.DAG;
3088  if ((DAG.isConstantValueOfAnyType(True) ||
3089  DAG.isConstantValueOfAnyType(True)) &&
3090  (!DAG.isConstantValueOfAnyType(False) &&
3091  !DAG.isConstantValueOfAnyType(False))) {
3092  // Swap cmp + select pair to move constant to false input.
3093  // This will allow using VOPC cndmasks more often.
3094  // select (setcc x, y), k, x -> select (setcc y, x) x, x
3095 
3096  SDLoc SL(N);
3097  ISD::CondCode NewCC = getSetCCInverse(cast<CondCodeSDNode>(CC)->get(),
3098  LHS.getValueType().isInteger());
3099 
3100  SDValue NewCond = DAG.getSetCC(SL, Cond.getValueType(), LHS, RHS, NewCC);
3101  return DAG.getNode(ISD::SELECT, SL, VT, NewCond, False, True);
3102  }
3103 
3104  if (VT == MVT::f32 && Subtarget->hasFminFmaxLegacy()) {
3105  SDValue MinMax
3106  = combineFMinMaxLegacy(SDLoc(N), VT, LHS, RHS, True, False, CC, DCI);
3107  // Revisit this node so we can catch min3/max3/med3 patterns.
3108  //DCI.AddToWorklist(MinMax.getNode());
3109  return MinMax;
3110  }
3111  }
3112 
3113  // There's no reason to not do this if the condition has other uses.
3114  return performCtlzCombine(SDLoc(N), Cond, True, False, DCI);
3115 }
3116 
3118  if (const ConstantFPSDNode *C = isConstOrConstSplatFP(N))
3119  return C->isZero() && !C->isNegative();
3120  return false;
3121 }
3122 
3123 static unsigned inverseMinMax(unsigned Opc) {
3124  switch (Opc) {
3125  case ISD::FMAXNUM:
3126  return ISD::FMINNUM;
3127  case ISD::FMINNUM:
3128  return ISD::FMAXNUM;
3130  return AMDGPUISD::FMIN_LEGACY;
3132  return AMDGPUISD::FMAX_LEGACY;
3133  default:
3134  llvm_unreachable("invalid min/max opcode");
3135  }
3136 }
3137 
3139  DAGCombinerInfo &DCI) const {
3140  SelectionDAG &DAG = DCI.DAG;
3141  SDValue N0 = N->getOperand(0);
3142  EVT VT = N->getValueType(0);
3143 
3144  unsigned Opc = N0.getOpcode();
3145 
3146  // If the input has multiple uses and we can either fold the negate down, or
3147  // the other uses cannot, give up. This both prevents unprofitable
3148  // transformations and infinite loops: we won't repeatedly try to fold around
3149  // a negate that has no 'good' form.
3150  if (N0.hasOneUse()) {
3151  // This may be able to fold into the source, but at a code size cost. Don't
3152  // fold if the fold into the user is free.
3153  if (allUsesHaveSourceMods(N, 0))
3154  return SDValue();
3155  } else {
3156  if (fnegFoldsIntoOp(Opc) &&
3158  return SDValue();
3159  }
3160 
3161  SDLoc SL(N);
3162  switch (Opc) {
3163  case ISD::FADD: {
3164  if (!mayIgnoreSignedZero(N0))
3165  return SDValue();
3166 
3167  // (fneg (fadd x, y)) -> (fadd (fneg x), (fneg y))
3168  SDValue LHS = N0.getOperand(0);
3169  SDValue RHS = N0.getOperand(1);
3170 
3171  if (LHS.getOpcode() != ISD::FNEG)
3172  LHS = DAG.getNode(ISD::FNEG, SL, VT, LHS);
3173  else
3174  LHS = LHS.getOperand(0);
3175 
3176  if (RHS.getOpcode() != ISD::FNEG)
3177  RHS = DAG.getNode(ISD::FNEG, SL, VT, RHS);
3178  else
3179  RHS = RHS.getOperand(0);
3180 
3181  SDValue Res = DAG.getNode(ISD::FADD, SL, VT, LHS, RHS, N0->getFlags());
3182  if (!N0.hasOneUse())
3183  DAG.ReplaceAllUsesWith(N0, DAG.getNode(ISD::FNEG, SL, VT, Res));
3184  return Res;
3185  }
3186  case ISD::FMUL:
3187  case AMDGPUISD::FMUL_LEGACY: {
3188  // (fneg (fmul x, y)) -> (fmul x, (fneg y))
3189  // (fneg (fmul_legacy x, y)) -> (fmul_legacy x, (fneg y))
3190  SDValue LHS = N0.getOperand(0);
3191  SDValue RHS = N0.getOperand(1);
3192 
3193  if (LHS.getOpcode() == ISD::FNEG)
3194  LHS = LHS.getOperand(0);
3195  else if (RHS.getOpcode() == ISD::FNEG)
3196  RHS = RHS.getOperand(0);
3197  else
3198  RHS = DAG.getNode(ISD::FNEG, SL, VT, RHS);
3199 
3200  SDValue Res = DAG.getNode(Opc, SL, VT, LHS, RHS, N0->getFlags());
3201  if (!N0.hasOneUse())
3202  DAG.ReplaceAllUsesWith(N0, DAG.getNode(ISD::FNEG, SL, VT, Res));
3203  return Res;
3204  }
3205  case ISD::FMA:
3206  case ISD::FMAD: {
3207  if (!mayIgnoreSignedZero(N0))
3208  return SDValue();
3209 
3210  // (fneg (fma x, y, z)) -> (fma x, (fneg y), (fneg z))
3211  SDValue LHS = N0.getOperand(0);
3212  SDValue MHS = N0.getOperand(1);
3213  SDValue RHS = N0.getOperand(2);
3214 
3215  if (LHS.getOpcode() == ISD::FNEG)
3216  LHS = LHS.getOperand(0);
3217  else if (MHS.getOpcode() == ISD::FNEG)
3218  MHS = MHS.getOperand(0);
3219  else
3220  MHS = DAG.getNode(ISD::FNEG, SL, VT, MHS);
3221 
3222  if (RHS.getOpcode() != ISD::FNEG)
3223  RHS = DAG.getNode(ISD::FNEG, SL, VT, RHS);
3224  else
3225  RHS = RHS.getOperand(0);
3226 
3227  SDValue Res = DAG.getNode(Opc, SL, VT, LHS, MHS, RHS);
3228  if (!N0.hasOneUse())
3229  DAG.ReplaceAllUsesWith(N0, DAG.getNode(ISD::FNEG, SL, VT, Res));
3230  return Res;
3231  }
3232  case ISD::FMAXNUM:
3233  case ISD::FMINNUM:
3235  case AMDGPUISD::FMIN_LEGACY: {
3236  // fneg (fmaxnum x, y) -> fminnum (fneg x), (fneg y)
3237  // fneg (fminnum x, y) -> fmaxnum (fneg x), (fneg y)
3238  // fneg (fmax_legacy x, y) -> fmin_legacy (fneg x), (fneg y)
3239  // fneg (fmin_legacy x, y) -> fmax_legacy (fneg x), (fneg y)
3240 
3241  SDValue LHS = N0.getOperand(0);
3242  SDValue RHS = N0.getOperand(1);
3243 
3244  // 0 doesn't have a negated inline immediate.
3245  // TODO: Shouldn't fold 1/2pi either, and should be generalized to other
3246  // operations.
3247  if (isConstantFPZero(RHS))
3248  return SDValue();
3249 
3250  SDValue NegLHS = DAG.getNode(ISD::FNEG, SL, VT, LHS);
3251  SDValue NegRHS = DAG.getNode(ISD::FNEG, SL, VT, RHS);
3252  unsigned Opposite = inverseMinMax(Opc);
3253 
3254  SDValue Res = DAG.getNode(Opposite, SL, VT, NegLHS, NegRHS, N0->getFlags());
3255  if (!N0.hasOneUse())
3256  DAG.ReplaceAllUsesWith(N0, DAG.getNode(ISD::FNEG, SL, VT, Res));
3257  return Res;
3258  }
3259  case ISD::FP_EXTEND:
3260  case ISD::FTRUNC:
3261  case ISD::FRINT:
3262  case ISD::FNEARBYINT: // XXX - Should fround be handled?
3263  case ISD::FSIN:
3264  case AMDGPUISD::RCP:
3265  case AMDGPUISD::RCP_LEGACY:
3266  case AMDGPUISD::SIN_HW: {
3267  SDValue CvtSrc = N0.getOperand(0);
3268  if (CvtSrc.getOpcode() == ISD::FNEG) {
3269  // (fneg (fp_extend (fneg x))) -> (fp_extend x)
3270  // (fneg (rcp (fneg x))) -> (rcp x)
3271  return DAG.getNode(Opc, SL, VT, CvtSrc.getOperand(0));
3272  }
3273 
3274  if (!N0.hasOneUse())
3275  return SDValue();
3276 
3277  // (fneg (fp_extend x)) -> (fp_extend (fneg x))
3278  // (fneg (rcp x)) -> (rcp (fneg x))
3279  SDValue Neg = DAG.getNode(ISD::FNEG, SL, CvtSrc.getValueType(), CvtSrc);
3280  return DAG.getNode(Opc, SL, VT, Neg, N0->getFlags());
3281  }
3282  case ISD::FP_ROUND: {
3283  SDValue CvtSrc = N0.getOperand(0);
3284 
3285  if (CvtSrc.getOpcode() == ISD::FNEG) {
3286  // (fneg (fp_round (fneg x))) -> (fp_round x)
3287  return DAG.getNode(ISD::FP_ROUND, SL, VT,
3288  CvtSrc.getOperand(0), N0.getOperand(1));
3289  }
3290 
3291  if (!N0.hasOneUse())
3292  return SDValue();
3293 
3294  // (fneg (fp_round x)) -> (fp_round (fneg x))
3295  SDValue Neg = DAG.getNode(ISD::FNEG, SL, CvtSrc.getValueType(), CvtSrc);
3296  return DAG.getNode(ISD::FP_ROUND, SL, VT, Neg, N0.getOperand(1));
3297  }
3298  case ISD::FP16_TO_FP: {
3299  // v_cvt_f32_f16 supports source modifiers on pre-VI targets without legal
3300  // f16, but legalization of f16 fneg ends up pulling it out of the source.
3301  // Put the fneg back as a legal source operation that can be matched later.
3302  SDLoc SL(N);
3303 
3304  SDValue Src = N0.getOperand(0);
3305  EVT SrcVT = Src.getValueType();
3306 
3307  // fneg (fp16_to_fp x) -> fp16_to_fp (xor x, 0x8000)
3308  SDValue IntFNeg = DAG.getNode(ISD::XOR, SL, SrcVT, Src,
3309  DAG.getConstant(0x8000, SL, SrcVT));
3310  return DAG.getNode(ISD::FP16_TO_FP, SL, N->getValueType(0), IntFNeg);
3311  }
3312  default:
3313  return SDValue();
3314  }
3315 }
3316 
3318  DAGCombinerInfo &DCI) const {
3319  SelectionDAG &DAG = DCI.DAG;
3320  SDValue N0 = N->getOperand(0);
3321 
3322  if (!N0.hasOneUse())
3323  return SDValue();
3324 
3325  switch (N0.getOpcode()) {
3326  case ISD::FP16_TO_FP: {
3327  assert(!Subtarget->has16BitInsts() && "should only see if f16 is illegal");
3328  SDLoc SL(N);
3329  SDValue Src = N0.getOperand(0);
3330  EVT SrcVT = Src.getValueType();
3331 
3332  // fabs (fp16_to_fp x) -> fp16_to_fp (and x, 0x7fff)
3333  SDValue IntFAbs = DAG.getNode(ISD::AND, SL, SrcVT, Src,
3334  DAG.getConstant(0x7fff, SL, SrcVT));
3335  return DAG.getNode(ISD::FP16_TO_FP, SL, N->getValueType(0), IntFAbs);
3336  }
3337  default:
3338  return SDValue();
3339  }
3340 }
3341 
3343  DAGCombinerInfo &DCI) const {
3344  SelectionDAG &DAG = DCI.DAG;
3345  SDLoc DL(N);
3346 
3347  switch(N->getOpcode()) {
3348  default:
3349  break;
3350  case ISD::BITCAST: {
3351  EVT DestVT = N->getValueType(0);
3352 
3353  // Push casts through vector builds. This helps avoid emitting a large
3354  // number of copies when materializing floating point vector constants.
3355  //
3356  // vNt1 bitcast (vNt0 (build_vector t0:x, t0:y)) =>
3357  // vnt1 = build_vector (t1 (bitcast t0:x)), (t1 (bitcast t0:y))
3358  if (DestVT.isVector()) {
3359  SDValue Src = N->getOperand(0);
3360  if (Src.getOpcode() == ISD::BUILD_VECTOR) {
3361  EVT SrcVT = Src.getValueType();
3362  unsigned NElts = DestVT.getVectorNumElements();
3363 
3364  if (SrcVT.getVectorNumElements() == NElts) {
3365  EVT DestEltVT = DestVT.getVectorElementType();
3366 
3367  SmallVector<SDValue, 8> CastedElts;
3368  SDLoc SL(N);
3369  for (unsigned I = 0, E = SrcVT.getVectorNumElements(); I != E; ++I) {
3370  SDValue Elt = Src.getOperand(I);
3371  CastedElts.push_back(DAG.getNode(ISD::BITCAST, DL, DestEltVT, Elt));
3372  }
3373 
3374  return DAG.getBuildVector(DestVT, SL, CastedElts);
3375  }
3376  }
3377  }
3378 
3379  if (DestVT.getSizeInBits() != 64 && !DestVT.isVector())
3380  break;
3381 
3382  // Fold bitcasts of constants.
3383  //
3384  // v2i32 (bitcast i64:k) -> build_vector lo_32(k), hi_32(k)
3385  // TODO: Generalize and move to DAGCombiner
3386  SDValue Src = N->getOperand(0);
3387  if (ConstantSDNode *C = dyn_cast<ConstantSDNode>(Src)) {
3388  assert(Src.getValueType() == MVT::i64);
3389  SDLoc SL(N);
3390  uint64_t CVal = C->getZExtValue();
3391  return DAG.getNode(ISD::BUILD_VECTOR, SL, DestVT,
3392  DAG.getConstant(Lo_32(CVal), SL, MVT::i32),
3393  DAG.getConstant(Hi_32(CVal), SL, MVT::i32));
3394  }
3395 
3396  if (ConstantFPSDNode *C = dyn_cast<ConstantFPSDNode>(Src)) {
3397  const APInt &Val = C->getValueAPF().bitcastToAPInt();
3398  SDLoc SL(N);
3399  uint64_t CVal = Val.getZExtValue();
3401  DAG.getConstant(Lo_32(CVal), SL, MVT::i32),
3402  DAG.getConstant(Hi_32(CVal), SL, MVT::i32));
3403 
3404  return DAG.getNode(ISD::BITCAST, SL, DestVT, Vec);
3405  }
3406 
3407  break;
3408  }
3409  case ISD::SHL: {
3411  break;
3412 
3413  return performShlCombine(N, DCI);
3414  }
3415  case ISD::SRL: {
3417  break;
3418 
3419  return performSrlCombine(N, DCI);
3420  }
3421  case ISD::SRA: {
3423  break;
3424 
3425  return performSraCombine(N, DCI);
3426  }
3427  case ISD::MUL:
3428  return performMulCombine(N, DCI);
3429  case ISD::MULHS:
3430  return performMulhsCombine(N, DCI);
3431  case ISD::MULHU:
3432  return performMulhuCombine(N, DCI);
3433  case AMDGPUISD::MUL_I24:
3434  case AMDGPUISD::MUL_U24:
3435  case AMDGPUISD::MULHI_I24:
3436  case AMDGPUISD::MULHI_U24: {
3437  // If the first call to simplify is successfull, then N may end up being
3438  // deleted, so we shouldn't call simplifyI24 again.
3439  simplifyI24(N, 0, DCI) || simplifyI24(N, 1, DCI);
3440  return SDValue();
3441  }
3444  return performMulLoHi24Combine(N, DCI);
3445  case ISD::SELECT:
3446  return performSelectCombine(N, DCI);
3447  case ISD::FNEG:
3448  return performFNegCombine(N, DCI);
3449  case ISD::FABS:
3450  return performFAbsCombine(N, DCI);
3451  case AMDGPUISD::BFE_I32:
3452  case AMDGPUISD::BFE_U32: {
3453  assert(!N->getValueType(0).isVector() &&
3454  "Vector handling of BFE not implemented");
3456  if (!Width)
3457  break;
3458 
3459  uint32_t WidthVal = Width->getZExtValue() & 0x1f;
3460  if (WidthVal == 0)
3461  return DAG.getConstant(0, DL, MVT::i32);
3462 
3464  if (!Offset)
3465  break;
3466 
3467  SDValue BitsFrom = N->getOperand(0);
3468  uint32_t OffsetVal = Offset->getZExtValue() & 0x1f;
3469 
3470  bool Signed = N->getOpcode() == AMDGPUISD::BFE_I32;
3471 
3472  if (OffsetVal == 0) {
3473  // This is already sign / zero extended, so try to fold away extra BFEs.
3474  unsigned SignBits = Signed ? (32 - WidthVal + 1) : (32 - WidthVal);
3475 
3476  unsigned OpSignBits = DAG.ComputeNumSignBits(BitsFrom);
3477  if (OpSignBits >= SignBits)
3478  return BitsFrom;
3479 
3480  EVT SmallVT = EVT::getIntegerVT(*DAG.getContext(), WidthVal);
3481  if (Signed) {
3482  // This is a sign_extend_inreg. Replace it to take advantage of existing
3483  // DAG Combines. If not eliminated, we will match back to BFE during
3484  // selection.
3485 
3486  // TODO: The sext_inreg of extended types ends, although we can could
3487  // handle them in a single BFE.
3488  return DAG.getNode(ISD::SIGN_EXTEND_INREG, DL, MVT::i32, BitsFrom,
3489  DAG.getValueType(SmallVT));
3490  }
3491 
3492  return DAG.getZeroExtendInReg(BitsFrom, DL, SmallVT);
3493  }
3494 
3495  if (ConstantSDNode *CVal = dyn_cast<ConstantSDNode>(BitsFrom)) {
3496  if (Signed) {
3497  return constantFoldBFE<int32_t>(DAG,
3498  CVal->getSExtValue(),
3499  OffsetVal,
3500  WidthVal,
3501  DL);
3502  }
3503 
3504  return constantFoldBFE<uint32_t>(DAG,
3505  CVal->getZExtValue(),
3506  OffsetVal,
3507  WidthVal,
3508  DL);
3509  }
3510 
3511  if ((OffsetVal + WidthVal) >= 32 &&
3512  !(Subtarget->hasSDWA() && OffsetVal == 16 && WidthVal == 16)) {
3513  SDValue ShiftVal = DAG.getConstant(OffsetVal, DL, MVT::i32);
3514  return DAG.getNode(Signed ? ISD::SRA : ISD::SRL, DL, MVT::i32,
3515  BitsFrom, ShiftVal);
3516  }
3517 
3518  if (BitsFrom.hasOneUse()) {
3519  APInt Demanded = APInt::getBitsSet(32,
3520  OffsetVal,
3521  OffsetVal + WidthVal);
3522 
3523  KnownBits Known;
3525  !DCI.isBeforeLegalizeOps());
3526  const TargetLowering &TLI = DAG.getTargetLoweringInfo();
3527  if (TLI.ShrinkDemandedConstant(BitsFrom, Demanded, TLO) ||
3528  TLI.SimplifyDemandedBits(BitsFrom, Demanded, Known, TLO)) {
3529  DCI.CommitTargetLoweringOpt(TLO);
3530  }
3531  }
3532 
3533  break;
3534  }
3535  case ISD::LOAD:
3536  return performLoadCombine(N, DCI);
3537  case ISD::STORE:
3538  return performStoreCombine(N, DCI);
3539  case AMDGPUISD::CLAMP:
3540  return performClampCombine(N, DCI);
3541  case AMDGPUISD::RCP: {
3542  if (const auto *CFP = dyn_cast<ConstantFPSDNode>(N->getOperand(0))) {
3543  // XXX - Should this flush denormals?
3544  const APFloat &Val = CFP->getValueAPF();
3545  APFloat One(Val.getSemantics(), "1.0");
3546  return DAG.getConstantFP(One / Val, SDLoc(N), N->getValueType(0));
3547  }
3548 
3549  break;
3550  }
3551  case ISD::AssertZext:
3552  case ISD::AssertSext:
3553  return performAssertSZExtCombine(N, DCI);
3554  }
3555  return SDValue();
3556 }
3557 
3558 //===----------------------------------------------------------------------===//
3559 // Helper functions
3560 //===----------------------------------------------------------------------===//
3561 
3563  const TargetRegisterClass *RC,
3564  unsigned Reg, EVT VT,
3565  const SDLoc &SL,
3566  bool RawReg) const {
3567  MachineFunction &MF = DAG.getMachineFunction();
3569  unsigned VReg;
3570 
3571  if (!MRI.isLiveIn(Reg)) {
3572  VReg = MRI.createVirtualRegister(RC);
3573  MRI.addLiveIn(Reg, VReg);
3574  } else {
3575  VReg = MRI.getLiveInVirtReg(Reg);
3576  }
3577 
3578  if (RawReg)
3579  return DAG.getRegister(VReg, VT);
3580 
3581  return DAG.getCopyFromReg(DAG.getEntryNode(), SL, VReg, VT);
3582 }
3583 
3585  const AMDGPUMachineFunction *MFI, const ImplicitParameter Param) const {
3586  unsigned Alignment = Subtarget->getAlignmentForImplicitArgPtr();
3587  uint64_t ArgOffset = alignTo(MFI->getABIArgOffset(), Alignment);
3588  switch (Param) {
3589  case GRID_DIM:
3590  return ArgOffset;
3591  case GRID_OFFSET:
3592  return ArgOffset + 4;
3593  }
3594  llvm_unreachable("unexpected implicit parameter type");
3595 }
3596 
3597 #define NODE_NAME_CASE(node) case AMDGPUISD::node: return #node;
3598 
3599 const char* AMDGPUTargetLowering::getTargetNodeName(unsigned Opcode) const {
3600  switch ((AMDGPUISD::NodeType)Opcode) {
3601  case AMDGPUISD::FIRST_NUMBER: break;
3602  // AMDIL DAG nodes
3605 
3606  // AMDGPU DAG nodes
3708  }
3709  return nullptr;
3710 }
3711 
3713  SelectionDAG &DAG, int Enabled,
3714  int &RefinementSteps,
3715  bool &UseOneConstNR,
3716  bool Reciprocal) const {
3717  EVT VT = Operand.getValueType();
3718 
3719  if (VT == MVT::f32) {
3720  RefinementSteps = 0;
3721  return DAG.getNode(AMDGPUISD::RSQ, SDLoc(Operand), VT, Operand);
3722  }
3723 
3724  // TODO: There is also f64 rsq instruction, but the documentation is less
3725  // clear on its precision.
3726 
3727  return SDValue();
3728 }
3729 
3731  SelectionDAG &DAG, int Enabled,
3732  int &RefinementSteps) const {
3733  EVT VT = Operand.getValueType();
3734 
3735  if (VT == MVT::f32) {
3736  // Reciprocal, < 1 ulp error.
3737  //
3738  // This reciprocal approximation converges to < 0.5 ulp error with one
3739  // newton rhapson performed with two fused multiple adds (FMAs).
3740 
3741  RefinementSteps = 0;
3742  return DAG.getNode(AMDGPUISD::RCP, SDLoc(Operand), VT, Operand);
3743  }
3744 
3745  // TODO: There is also f64 rcp instruction, but the documentation is less
3746  // clear on its precision.
3747 
3748  return SDValue();
3749 }
3750 
3752  const SDValue Op, KnownBits &Known,
3753  const APInt &DemandedElts, const SelectionDAG &DAG, unsigned Depth) const {
3754 
3755  Known.resetAll(); // Don't know anything.
3756 
3757  KnownBits Known2;
3758  unsigned Opc = Op.getOpcode();
3759 
3760  switch (Opc) {
3761  default:
3762  break;
3763  case AMDGPUISD::CARRY:
3764  case AMDGPUISD::BORROW: {
3765  Known.Zero = APInt::getHighBitsSet(32, 31);
3766  break;
3767  }
3768 
3769  case AMDGPUISD::BFE_I32:
3770  case AMDGPUISD::BFE_U32: {
3772  if (!CWidth)
3773  return;
3774 
3775  uint32_t Width = CWidth->getZExtValue() & 0x1f;
3776 
3777  if (Opc == AMDGPUISD::BFE_U32)
3778  Known.Zero = APInt::getHighBitsSet(32, 32 - Width);
3779 
3780  break;
3781  }
3782  case AMDGPUISD::FP_TO_FP16:
3783  case AMDGPUISD::FP16_ZEXT: {
3784  unsigned BitWidth = Known.getBitWidth();
3785 
3786  // High bits are zero.
3787  Known.Zero = APInt::getHighBitsSet(BitWidth, BitWidth - 16);
3788  break;
3789  }
3790  }
3791 }
3792 
3794  SDValue Op, const APInt &DemandedElts, const SelectionDAG &DAG,
3795  unsigned Depth) const {
3796  switch (Op.getOpcode()) {
3797  case AMDGPUISD::BFE_I32: {
3799  if (!Width)
3800  return 1;
3801 
3802  unsigned SignBits = 32 - Width->getZExtValue() + 1;
3803  if (!isNullConstant(Op.getOperand(1)))
3804  return SignBits;
3805 
3806  // TODO: Could probably figure something out with non-0 offsets.
3807  unsigned Op0SignBits = DAG.ComputeNumSignBits(Op.getOperand(0), Depth + 1);
3808  return std::max(SignBits, Op0SignBits);
3809  }
3810 
3811  case AMDGPUISD::BFE_U32: {
3813  return Width ? 32 - (Width->getZExtValue() & 0x1f) : 1;
3814  }
3815 
3816  case AMDGPUISD::CARRY:
3817  case AMDGPUISD::BORROW:
3818  return 31;
3819  case AMDGPUISD::FP_TO_FP16:
3820  case AMDGPUISD::FP16_ZEXT:
3821  return 16;
3822  default:
3823  return 1;
3824  }
3825 }
unsigned ComputeNumSignBitsForTargetNode(SDValue Op, const APInt &DemandedElts, const SelectionDAG &DAG, unsigned Depth=0) const override
This method can be implemented by targets that want to expose additional information about sign bits ...
MachineLoop * L
MVT getSimpleValueType() const
Return the simple ValueType of the referenced return value.
SDValue getStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, unsigned Alignment=0, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
Helper function to build ISD::STORE nodes.
Calling convention used for Mesa compute shaders.
Definition: CallingConv.h:196
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
Definition: ISDOpcodes.h:544
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
Definition: ISDOpcodes.h:511
SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg, const SmallVectorImpl< ISD::OutputArg > &Outs, const SmallVectorImpl< SDValue > &OutVals, const SDLoc &DL, SelectionDAG &DAG) const override
This hook must be implemented to lower outgoing return values, described by the Outs array...
A parsed version of the target data layout string in and methods for querying it. ...
Definition: DataLayout.h:109
FMINNUM/FMAXNUM - Perform floating-point minimum or maximum on two values.
Definition: ISDOpcodes.h:568
SDValue getValue(unsigned R) const
void setLoadExtAction(unsigned ExtType, MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified load with extension does not work with the specified type and indicate wh...
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
unsigned allocateLDSGlobal(const DataLayout &DL, const GlobalValue &GV)
SDValue performLoadCombine(SDNode *N, DAGCombinerInfo &DCI) const
EXTRACT_ELEMENT - This is used to get the lower or upper (determined by a Constant, which is required to be operand #1) half of the integer or float value specified as operand #0.
Definition: ISDOpcodes.h:184
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
Flags getFlags() const
Return the raw flags of the source value,.
LLVMContext * getContext() const
Definition: SelectionDAG.h:381
static SDValue distributeOpThroughSelect(TargetLowering::DAGCombinerInfo &DCI, unsigned Op, const SDLoc &SL, SDValue Cond, SDValue N1, SDValue N2)
Diagnostic information for unsupported feature in backend.
AMDGPU specific subclass of TargetSubtarget.
uint64_t getZExtValue() const
Get zero extended value.
Definition: APInt.h:1542
SDValue getSetCC(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS, ISD::CondCode Cond)
Helper function to make it easier to build SetCC's if you just have an ISD::CondCode instead of an SD...
Definition: SelectionDAG.h:884
SDValue PerformDAGCombine(SDNode *N, DAGCombinerInfo &DCI) const override
This method will be invoked for all target nodes and for any target-independent nodes that the target...
SDValue CombineTo(SDNode *N, ArrayRef< SDValue > To, bool AddTo=true)
SDValue scalarizeVectorStore(StoreSDNode *ST, SelectionDAG &DAG) const
void LowerUDIVREM64(SDValue Op, SelectionDAG &DAG, SmallVectorImpl< SDValue > &Results) const
static bool allocateVGPRTuple(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
bool shouldReduceLoadWidth(SDNode *Load, ISD::LoadExtType ExtType, EVT ExtVT) const override
EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR (an vector value) starting with the ...
Definition: ISDOpcodes.h:332
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:103
unsigned getNumRegisters(LLVMContext &Context, EVT VT) const
Return the number of registers that this ValueType will eventually require.
InputArg - This struct carries flags and type information about a single incoming (formal) argument o...
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
Definition: ISDOpcodes.h:341
bool hasOneUse() const
Return true if there is exactly one node using value ResNo of Node.
SDValue getHiHalf64(SDValue Op, SelectionDAG &DAG) const
static bool isConstantFPZero(SDValue N)
const TargetMachine & getTargetMachine() const
SDValue performMulhuCombine(SDNode *N, DAGCombinerInfo &DCI) const
unsigned createVirtualRegister(const TargetRegisterClass *RegClass)
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
void addLiveIn(unsigned Reg, unsigned vreg=0)
addLiveIn - Add the specified register as a live-in.
constexpr uint32_t Lo_32(uint64_t Value)
Return the low 32 bits of a 64 bit value.
Definition: MathExtras.h:281
virtual SDValue LowerGlobalAddress(AMDGPUMachineFunction *MFI, SDValue Op, SelectionDAG &DAG) const
Carry-setting nodes for multiple precision addition and subtraction.
Definition: ISDOpcodes.h:222
bool isExtended() const
Test if the given EVT is extended (as opposed to being simple).
Definition: ValueTypes.h:131
SDValue LowerFRINT(SDValue Op, SelectionDAG &DAG) const
This file describes how to lower LLVM calls to machine code calls.
SDValue LowerINT_TO_FP64(SDValue Op, SelectionDAG &DAG, bool Signed) const
DataLayout DL
SDValue LowerFP_TO_SINT(SDValue Op, SelectionDAG &DAG) const
SDValue LowerDYNAMIC_STACKALLOC(SDValue Op, SelectionDAG &DAG) const
static CCAssignFn * CCAssignFnForReturn(CallingConv::ID CC, bool IsVarArg)
SDValue LowerUINT_TO_FP(SDValue Op, SelectionDAG &DAG) const
SDValue LowerCTLZ(SDValue Op, SelectionDAG &DAG) const
std::pair< EVT, EVT > GetSplitDestVTs(const EVT &VT) const
Compute the VTs needed for the low/hi parts of a type which is split (or expanded) into two not neces...
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
Definition: APInt.h:641
const GlobalValue * getGlobal() const
void setHasFloatingPointExceptions(bool FPExceptions=true)
Tells the code generator that this target supports floating point exceptions and cares about preservi...
AMDGPUAS getAMDGPUAS(const Module &M)
bool CCAssignFn(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
CCAssignFn - This function assigns a location for Val, updating State to reflect the change...
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
Function Alias Analysis Results
static CCAssignFn * CCAssignFnForCall(CallingConv::ID CC, bool IsVarArg)
unsigned getNumOperands() const
Return the number of values used by this operation.
void setBooleanVectorContents(BooleanContent Ty)
Specify how the target extends the result of a vector boolean value from a vector of i1 to a wider ty...
const SDValue & getOperand(unsigned Num) const
Calling convention used for Mesa geometry shaders.
Definition: CallingConv.h:190
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
SDValue getSelect(const SDLoc &DL, EVT VT, SDValue Cond, SDValue LHS, SDValue RHS)
Helper function to make it easier to build Select's if you just have operands and don't want to check...
Definition: SelectionDAG.h:897
uint64_t alignTo(uint64_t Value, uint64_t Align, uint64_t Skew=0)
Returns the next integer (mod 2**64) that is greater than or equal to Value and is a multiple of Alig...
Definition: MathExtras.h:677
virtual bool allowsMisalignedMemoryAccesses(EVT, unsigned AddrSpace=0, unsigned Align=1, bool *=nullptr) const
Determine if the target supports unaligned memory accesses.
static APFloat getZero(const fltSemantics &Sem, bool Negative=false)
Factory for Positive and Negative Zero.
Definition: APFloat.h:855
static SDValue extractF64Exponent(SDValue Hi, const SDLoc &SL, SelectionDAG &DAG)
SDValue getLoHalf64(SDValue Op, SelectionDAG &DAG) const
SDValue getTruncStore(SDValue Chain, const SDLoc &dl, SDValue Val, SDValue Ptr, MachinePointerInfo PtrInfo, EVT TVT, unsigned Alignment=0, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
[US]{MIN/MAX} - Binary minimum or maximum or signed or unsigned integers.
Definition: ISDOpcodes.h:358
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
const MachinePointerInfo & getPointerInfo() const
SDValue LowerCall(CallLoweringInfo &CLI, SmallVectorImpl< SDValue > &InVals) const override
This hook must be implemented to lower calls into the specified DAG.
void computeKnownBitsForTargetNode(const SDValue Op, KnownBits &Known, const APInt &DemandedElts, const SelectionDAG &DAG, unsigned Depth=0) const override
Determine which of the bits specified in Mask are known to be either zero or one and return them in t...
SDValue scalarizeVectorLoad(LoadSDNode *LD, SelectionDAG &DAG) const
Turn load of vector type into a load of the individual elements.
SDValue performMulCombine(SDNode *N, DAGCombinerInfo &DCI) const
const Constant * getInitializer() const
getInitializer - Return the initializer for this global variable.
CLAMP value between 0.0 and 1.0.
const SDValue & getBasePtr() const
std::pair< SDValue, SDValue > split64BitValue(SDValue Op, SelectionDAG &DAG) const
Return 64-bit value Op as two 32-bit integers.
LLVMContext & getContext() const
bool hasFPExceptions() const
SDValue performSrlCombine(SDNode *N, DAGCombinerInfo &DCI) const
SDValue splitBinaryBitConstantOpImpl(DAGCombinerInfo &DCI, const SDLoc &SL, unsigned Opc, SDValue LHS, uint32_t ValLo, uint32_t ValHi) const
Split the 64-bit value LHS into two 32-bit components, and perform the binary operation Opc to it wit...
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
Definition: ISDOpcodes.h:403
NodeType
ISD::NodeType enum - This enum defines the target-independent operators for a SelectionDAG.
Definition: ISDOpcodes.h:39
static bool simplifyI24(SDNode *Node24, unsigned OpIdx, TargetLowering::DAGCombinerInfo &DCI)
SDValue LowerDIVREM24(SDValue Op, SelectionDAG &DAG, bool sign) const
void setTruncStoreAction(MVT ValVT, MVT MemVT, LegalizeAction Action)
Indicate that the specified truncating store does not work with the specified type and indicate what ...
static const unsigned LOCAL_ADDRESS
Address space for local memory.
Definition: AMDGPU.h:175
bool storeOfVectorConstantIsCheap(EVT MemVT, unsigned NumElem, unsigned AS) const override
Return true if it is expected to be cheaper to do a store of a non-zero vector constant with the give...
bool isCheapToSpeculateCttz() const override
Return true if it is cheap to speculate a call to intrinsic cttz.
A convenience struct that encapsulates a DAG, and two SDValues for returning information from TargetL...
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
Definition: ISDOpcodes.h:209
SDValue expandUnalignedStore(StoreSDNode *ST, SelectionDAG &DAG) const
Expands an unaligned store to 2 half-size stores for integer values, and possibly more for vectors...
bool isVector() const
Return true if this is a vector value type.
Definition: ValueTypes.h:151
SDValue getIntPtrConstant(uint64_t Val, const SDLoc &DL, bool isTarget=false)
bool isNegative() const
Return true if the value is negative.
uint64_t allocateKernArg(uint64_t Size, unsigned Align)
SDValue LowerUDIVREM(SDValue Op, SelectionDAG &DAG) const
SDValue LowerFP_TO_UINT(SDValue Op, SelectionDAG &DAG) const
Pointer to the start of the shader's constant data.
SDValue performMulLoHi24Combine(SDNode *N, DAGCombinerInfo &DCI) const
ArrayRef< T > makeArrayRef(const T &OneElt)
Construct an ArrayRef from a single element.
Definition: ArrayRef.h:451
Shift and rotation operations.
Definition: ISDOpcodes.h:378
bool isNormalStore(const SDNode *N)
Returns true if the specified node is a non-truncating and unindexed store.
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
MachineFunction & getMachineFunction() const
Definition: SelectionDAG.h:375
BUILD_PAIR - This is the opposite of EXTRACT_ELEMENT in some ways.
Definition: ISDOpcodes.h:190
CopyToReg - This node has three operands: a chain, a register number to set to this value...
Definition: ISDOpcodes.h:170
void addLoc(const CCValAssign &V)
SDValue getRecipEstimate(SDValue Operand, SelectionDAG &DAG, int Enabled, int &RefinementSteps) const override
Return a reciprocal estimate value for the input operand.
iterator begin() const
begin/end - Return all of the registers in this class.
unsigned getAddressSpace() const
Reg
All possible values of the reg field in the ModR/M byte.
MachinePointerInfo getWithOffset(int64_t O) const
SimpleValueType SimpleTy
MVT getScalarType() const
If this is a vector, return the element type, otherwise return this.
static bool isI24(SDValue Op, SelectionDAG &DAG)
EVT getScalarType() const
If this is a vector type, return the element type, otherwise return this.
Definition: ValueTypes.h:260
SDValue combineFMinMaxLegacy(const SDLoc &DL, EVT VT, SDValue LHS, SDValue RHS, SDValue True, SDValue False, SDValue CC, DAGCombinerInfo &DCI) const
Generate Min/Max node.
void setOperationAction(unsigned Op, MVT VT, LegalizeAction Action)
Indicate that the specified operation does not work with the specified type and indicate what to do a...
SDValue LowerFROUND32_16(SDValue Op, SelectionDAG &DAG) const
bool bitsGE(EVT VT) const
Return true if this has no less bits than VT.
Definition: ValueTypes.h:235
SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
unsigned getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
void setJumpIsExpensive(bool isExpensive=true)
Tells the code generator not to expand logic operations on comparison predicates into separate sequen...
SDValue LowerFROUND(SDValue Op, SelectionDAG &DAG) const
Interface to describe a layout of a stack frame on an AMDGPU target.
SDValue LowerOperation(SDValue Op, SelectionDAG &DAG) const override
This callback is invoked for operations that are unsupported by the target, which are registered to u...
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
bool isInteger() const
Return true if this is an integer or a vector integer type.
Definition: ValueTypes.h:141
Calling convention used for Mesa hull shaders.
Definition: CallingConv.h:206
INLINEASM - Represents an inline asm block.
Definition: ISDOpcodes.h:633
SDValue getExtLoad(ISD::LoadExtType ExtType, const SDLoc &dl, EVT VT, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, EVT MemVT, unsigned Alignment=0, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes())
bool getBoolValue() const
Convert APInt to a boolean value.
Definition: APInt.h:471
SmallVector< ISD::InputArg, 32 > Ins
SDValue getMergeValues(ArrayRef< SDValue > Ops, const SDLoc &dl)
Create a MERGE_VALUES node from the given operands.
EVT getVectorElementType() const
Given a vector type, return the type of each element.
Definition: ValueTypes.h:265
TargetRegisterInfo interface that is implemented by all hw codegen targets.
MachineFunction & getMachineFunction() const
void ReplaceNodeResults(SDNode *N, SmallVectorImpl< SDValue > &Results, SelectionDAG &DAG) const override
This callback is invoked when a node result type is illegal for the target, and the operation was reg...
SDValue getSExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either sign-extending or trunca...
static bool allocateCCRegs(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State, const TargetRegisterClass *RC, unsigned NumRegs)
#define F(x, y, z)
Definition: MD5.cpp:55
bool isCheapToSpeculateCtlz() const override
Return true if it is cheap to speculate a call to intrinsic ctlz.
[SU]INT_TO_FP - These operators convert integers (whose interpreted sign depends on the first letter)...
Definition: ISDOpcodes.h:454
const AMDGPUSubtarget * Subtarget
bool isLiveIn(unsigned Reg) const
SDValue performSelectCombine(SDNode *N, DAGCombinerInfo &DCI) const
Select with a vector condition (op #0) and two vector operands (ops #1 and #2), returning a vector re...
Definition: ISDOpcodes.h:397
Simple integer binary arithmetic operators.
Definition: ISDOpcodes.h:200
static bool hasVolatileUser(SDNode *Val)
const SDValue & getBasePtr() const
EVT getHalfSizedIntegerVT(LLVMContext &Context) const
Finds the smallest simple value type that is greater than or equal to half the width of this EVT...
Definition: ValueTypes.h:328
SDValue getUNDEF(EVT VT)
Return an UNDEF node. UNDEF does not have a useful SDLoc.
Definition: SelectionDAG.h:816
cmpResult
IEEE-754R 5.11: Floating Point Comparison Relations.
Definition: APFloat.h:166
static mvt_range integer_vector_valuetypes()
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out...
Definition: ISDOpcodes.h:909
static const fltSemantics & IEEEdouble() LLVM_READNONE
Definition: APFloat.cpp:122
EVT getMemoryVT() const
Return the type of the in-memory value.
static SDValue getMul24(SelectionDAG &DAG, const SDLoc &SL, SDValue N0, SDValue N1, unsigned Size, bool Signed)
unsigned getBitWidth() const
Get the bit width of this value.
Definition: KnownBits.h:40
Generation getGeneration() const
const DataLayout & getDataLayout() const
Definition: SelectionDAG.h:376
bool bitsLE(EVT VT) const
Return true if this has no more bits than VT.
Definition: ValueTypes.h:247
This class is used to represent ISD::STORE nodes.
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
Definition: ISDOpcodes.h:497
This node is for VLIW targets and it is used to represent a vector that is stored in consecutive regi...
static LLVM_READNONE bool fnegFoldsIntoOp(unsigned Opc)
static CCValAssign getReg(unsigned ValNo, MVT ValVT, unsigned RegNo, MVT LocVT, LocInfo HTP)
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector with the specified, possibly variable...
Definition: ISDOpcodes.h:301
static bool isCtlzOpc(unsigned Opc)
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
Definition: APInt.h:629
SDValue performAssertSZExtCombine(SDNode *N, DAGCombinerInfo &DCI) const
SPIR_KERNEL - Calling convention for SPIR kernel functions.
Definition: CallingConv.h:137
SDValue LowerCONCAT_VECTORS(SDValue Op, SelectionDAG &DAG) const
SDValue LowerFP_TO_FP16(SDValue Op, SelectionDAG &DAG) const
static SDValue constantFoldBFE(SelectionDAG &DAG, IntTy Src0, uint32_t Offset, uint32_t Width, const SDLoc &DL)
SDNode * getNode() const
get the SDNode which holds the desired result
constexpr uint64_t MinAlign(uint64_t A, uint64_t B)
A and B are either alignments or offsets.
Definition: MathExtras.h:602
unsigned getScalarSizeInBits() const
Definition: ValueTypes.h:298
unsigned getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
Definition: ValueTypes.h:304
bool isTypeLegal(EVT VT) const
Return true if the target has native support for the specified value type.
bool isNormalLoad(const SDNode *N)
Returns true if the specified node is a non-extending and unindexed load.
SDValue LowerFCEIL(SDValue Op, SelectionDAG &DAG) const
unsigned UnsafeFPMath
UnsafeFPMath - This flag is enabled when the -enable-unsafe-fp-math flag is specified on the command ...
SDValue LowerFREM(SDValue Op, SelectionDAG &DAG) const
Split a vector store into multiple scalar stores.
unsigned getStoreSizeInBits() const
Return the number of bits overwritten by a store of the specified value type.
Definition: ValueTypes.h:310
bool isInteger() const
Return true if this is an integer or a vector integer type.
std::pair< SDValue, SDValue > expandUnalignedLoad(LoadSDNode *LD, SelectionDAG &DAG) const
Expands an unaligned load to 2 half-size loads for an integer, and possibly more for vectors...
unsigned const MachineRegisterInfo * MRI
unsigned getVectorNumElements() const
Machine Value Type.
SDValue performFNegCombine(SDNode *N, DAGCombinerInfo &DCI) const
const SDValue & getOperand(unsigned i) const
The instances of the Type class are immutable: once they are created, they are never changed...
Definition: Type.h:46
This is an important class for using LLVM in a threaded context.
Definition: LLVMContext.h:68
Simple binary floating point operators.
Definition: ISDOpcodes.h:259
void setTargetDAGCombine(ISD::NodeType NT)
Targets should invoke this method for each target independent node that they want to provide a custom...
SDValue performSraCombine(SDNode *N, DAGCombinerInfo &DCI) const
unsigned countMinLeadingZeros() const
Returns the minimum number of leading zero bits.
Definition: KnownBits.h:148
void resetAll()
Resets the known state of all bits.
Definition: KnownBits.h:66
SDValue performShlCombine(SDNode *N, DAGCombinerInfo &DCI) const
bool isVector() const
Return true if this is a vector value type.
const SDNodeFlags getFlags() const
LoadExtType
LoadExtType enum - This enum defines the three variants of LOADEXT (load with extension).
Definition: ISDOpcodes.h:884
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
Carry-using nodes for multiple precision addition and subtraction.
Definition: ISDOpcodes.h:231
unsigned getLiveInVirtReg(unsigned PReg) const
getLiveInVirtReg - If PReg is a live-in physical register, return the corresponding live-in physical ...
bool shouldCombineMemoryType(EVT VT) const
static unsigned inverseMinMax(unsigned Opc)
void setBooleanContents(BooleanContent Ty)
Specify how the target extends the result of integer and floating point boolean values from i1 to a w...
static bool hasDefinedInitializer(const GlobalValue *GV)
const char * getTargetNodeName(unsigned Opcode) const override
This method returns the name of a target specific DAG node.
SDValue performFAbsCombine(SDNode *N, DAGCombinerInfo &DCI) const
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang","erlang-compatible garbage collector")
static bool allocateKernArg(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
unsigned getOpcode() const
TRAP - Trapping instruction.
Definition: ISDOpcodes.h:727
static bool isOrEquivalentToAdd(SelectionDAG &DAG, SDValue Op)
bool hasFP32Denormals() const
static bool allocateSGPRTuple(unsigned ValNo, MVT ValVT, MVT LocVT, CCValAssign::LocInfo LocInfo, ISD::ArgFlagsTy ArgFlags, CCState &State)
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
Definition: ISDOpcodes.h:57
bool isLoadBitCastBeneficial(EVT, EVT) const final
Return true if the following transform is beneficial: fold (conv (load x)) -> (load (conv*)x) On archi...
bool isVolatile() const
const SDValue & getValue() const
void AddPromotedToType(unsigned Opc, MVT OrigVT, MVT DestVT)
If Opc/OrigVT is specified as being promoted, the promotion code defaults to trying a larger integer/...
bool has16BitInsts() const
unsigned MaxStoresPerMemmove
Specify maximum bytes of store instructions per memmove call.
Bit counting operators with an undefined result for zero inputs.
Definition: ISDOpcodes.h:384
Val, OUTCHAIN = ATOMIC_CMP_SWAP(INCHAIN, ptr, cmp, swap) For double-word atomic operations: ValLo...
Definition: ISDOpcodes.h:756
bool MaskedValueIsZero(SDValue Op, const APInt &Mask, unsigned Depth=0) const
Return true if 'Op & Mask' is known to be zero.
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
Definition: ISDOpcodes.h:529
Extended Value Type.
Definition: ValueTypes.h:34
const APFloat & getValueAPF() const
SDValue LowerFFLOOR(SDValue Op, SelectionDAG &DAG) const
Calling convention used for Mesa vertex shaders.
Definition: CallingConv.h:187
This structure contains all information that is necessary for lowering calls.
This class contains a discriminated union of information about pointers in memory operands...
bool isFPImmLegal(const APFloat &Imm, EVT VT) const override
Returns true if the target can instruction select the specified FP immediate natively.
unsigned GatherAllAliasesMaxDepth
Depth that GatherAllAliases should should continue looking for chain dependencies when trying to find...
SDValue LowerSIGN_EXTEND_INREG(SDValue Op, SelectionDAG &DAG) const
SDValue getLoad(EVT VT, const SDLoc &dl, SDValue Chain, SDValue Ptr, MachinePointerInfo PtrInfo, unsigned Alignment=0, MachineMemOperand::Flags MMOFlags=MachineMemOperand::MONone, const AAMDNodes &AAInfo=AAMDNodes(), const MDNode *Ranges=nullptr)
Loads are not normal binary operators: their result type is not determined by their operands...
void print(raw_ostream &OS, const SelectionDAG *G=nullptr) const
static CCAssignFn * CCAssignFnForCall(CallingConv::ID CC, bool IsVarArg)
Selects the correct CCAssignFn for a given CallingConvention value.
void setHasExtractBitsInsn(bool hasExtractInsn=true)
Tells the code generator that the target has BitExtract instructions.
SDValue LowerFNEARBYINT(SDValue Op, SelectionDAG &DAG) const
static LLVM_READONLY bool hasSourceMods(const SDNode *N)
SDValue SplitVectorStore(SDValue Op, SelectionDAG &DAG) const
Split a vector store into 2 stores of half the vector.
static bool isU24(SDValue Op, SelectionDAG &DAG)
TokenFactor - This node takes multiple tokens as input and produces a single token result...
Definition: ISDOpcodes.h:50
SDValue LowerSINT_TO_FP(SDValue Op, SelectionDAG &DAG) const
CCState - This class holds information needed while lowering arguments and return values...
#define E
Definition: LargeTest.cpp:27
const DebugLoc & getDebugLoc() const
#define B
Definition: LargeTest.cpp:24
SDValue SplitVectorLoad(SDValue Op, SelectionDAG &DAG) const
Split a vector load into 2 loads of half the vector.
void computeKnownBits(SDValue Op, KnownBits &Known, unsigned Depth=0) const
Determine which bits of Op are known to be either zero or one and return them in Known.
bool isFAbsFree(EVT VT) const override
Return true if an fabs operation is free to the point where it is never worthwhile to replace it with...
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
Definition: ISDOpcodes.h:313
std::pair< SDValue, SDValue > SplitVector(const SDValue &N, const SDLoc &DL, const EVT &LoVT, const EVT &HiVT)
Split the vector with EXTRACT_SUBVECTOR using the provides VTs and return the low/high part...
unsigned getScalarSizeInBits() const LLVM_READONLY
If this is a vector type, return the getPrimitiveSizeInBits value for the element type...
Definition: Type.cpp:130
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
Definition: SelectionDAG.h:209
Interface definition of the TargetLowering class that is common to all AMD GPUs.
SDValue getZExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either zero-extending or trunca...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Definition: SmallVector.h:861
Calling convention used for Mesa pixel shaders.
Definition: CallingConv.h:193
SDValue getBuildVector(EVT VT, const SDLoc &DL, ArrayRef< SDValue > Ops)
Return an ISD::BUILD_VECTOR node.
Definition: SelectionDAG.h:698
virtual EVT getSetCCResultType(const DataLayout &DL, LLVMContext &Context, EVT VT) const
Return the ValueType of the result of SETCC operations.
const DataFlowGraph & G
Definition: RDFGraph.cpp:206
const SDValue & getChain() const
Byte Swap and Counting operators.
Definition: ISDOpcodes.h:381
const size_t N
FP16_TO_FP, FP_TO_FP16 - These operators are used to perform promotions and truncation for half-preci...
Definition: ISDOpcodes.h:554
SDValue performCtlzCombine(const SDLoc &SL, SDValue Cond, SDValue LHS, SDValue RHS, DAGCombinerInfo &DCI) const
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
This is an abstract virtual class for memory operations.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
void setHasMultipleConditionRegisters(bool hasManyRegs=true)
Tells the code generator that the target has multiple (allocatable) condition registers that can be u...
void ExtractVectorElements(SDValue Op, SmallVectorImpl< SDValue > &Args, unsigned Start=0, unsigned Count=0)
Append the extracted elements from Start to Count out of the vector Op in Args.
Represents one node in the SelectionDAG.
CondCode getSetCCInverse(CondCode Operation, bool isInteger)
Return the operation corresponding to !(X op Y), where 'op' is a valid SetCC operation.
SDValue LowerFTRUNC(SDValue Op, SelectionDAG &DAG) const
SDValue getNOT(const SDLoc &DL, SDValue Val, EVT VT)
Create a bitwise NOT operation as (XOR Val, -1).
double BitsToDouble(uint64_t Bits)
This function takes a 64-bit integer and returns the bit equivalent double.
Definition: MathExtras.h:565
static mvt_range integer_valuetypes()
static bool allUsesHaveSourceMods(const SDNode *N, unsigned CostThreshold=4)
C - The default llvm calling convention, compatible with C.
Definition: CallingConv.h:35
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
Definition: BitVector.h:923
ISD::LoadExtType getExtensionType() const
Return whether this is a plain node, or one of the varieties of value-extending loads.
static EVT getVectorVT(LLVMContext &Context, EVT VT, unsigned NumElements, bool IsScalable=false)
Returns the EVT that represents a vector NumElements in length, where each element is of type VT...
Definition: ValueTypes.h:73
Class for arbitrary precision integers.
Definition: APInt.h:69
bool hasInitializer() const
Definitions have initializers, declarations don't.
SDValue getConstantFP(double Val, const SDLoc &DL, EVT VT, bool isTarget=false)
Create a ConstantFPSDNode wrapping a constant value.
iterator_range< use_iterator > uses()
Select(COND, TRUEVAL, FALSEVAL).
Definition: ISDOpcodes.h:388
Interface for the AMDGPU Implementation of the Intrinsic Info class.
ZERO_EXTEND - Used for integer types, zeroing the new bits.
Definition: ISDOpcodes.h:444
bool isAmdHsaOS() const
SDValue LowerINT_TO_FP32(SDValue Op, SelectionDAG &DAG, bool Signed) const
ANY_EXTEND - Used for integer types. The high bits are undefined.
Definition: ISDOpcodes.h:447
FCOPYSIGN(X, Y) - Return the value of X with the sign of Y.
Definition: ISDOpcodes.h:286
constexpr char Size[]
Key for Kernel::Arg::Metadata::mSize.
static APInt getBitsSet(unsigned numBits, unsigned loBit, unsigned hiBit)
Get a value with a block of bits set.
Definition: APInt.h:600
llvm_unreachable("Unknown RegBank!")
unsigned getAddressSpace() const
Return the address space for the associated pointer.
MachineRegisterInfo - Keep track of information for virtual and physical registers, including vreg register classes, use/def chains for registers, etc.
static CCAssignFn * CCAssignFnForReturn(CallingConv::ID CC, bool IsVarArg)
bool isConstantValueOfAnyType(SDValue N)
SDValue LowerFP64_TO_INT(SDValue Op, SelectionDAG &DAG, bool Signed) const
BR_JT - Jumptable branch.
Definition: ISDOpcodes.h:604
ConstantFPSDNode * isConstOrConstSplatFP(SDValue V)
Returns the SDNode if it is a constant splat BuildVector or constant float.
Represents a use of a SDNode.
Interface definition for SIInstrInfo.
Bitwise operators - logical and, logical or, logical xor.
Definition: ISDOpcodes.h:361
bool isNarrowingProfitable(EVT VT1, EVT VT2) const override
Return true if it's profitable to narrow operations of type VT1 to VT2.
SDValue getCopyFromReg(SDValue Chain, const SDLoc &dl, unsigned Reg, EVT VT)
Definition: SelectionDAG.h:669
SelectSupportKind
Enum that describes what type of support for selects the target has.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
Definition: ISDOpcodes.h:205
SDValue performMulhsCombine(SDNode *N, DAGCombinerInfo &DCI) const
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
Definition: ISDOpcodes.h:462
#define C
Definition: LargeTest.cpp:25
static CCValAssign getCustomMem(unsigned ValNo, MVT ValVT, unsigned Offset, MVT LocVT, LocInfo HTP)
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
Definition: ISDOpcodes.h:580
TargetOptions Options
Definition: TargetMachine.h:95
#define LLVM_READNONE
Definition: Compiler.h:161
unsigned getSizeInBits() const
Return the size of the specified value type in bits.
Definition: ValueTypes.h:292
void ReplaceAllUsesWith(SDValue From, SDValue Op)
Modify anything using 'From' to use 'To' instead.
#define I(x, y, z)
Definition: MD5.cpp:58
ArrayRef< SDUse > ops() const
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
Definition: SmallVector.h:135
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
bool isTruncateFree(EVT Src, EVT Dest) const override
AMDGPUTargetLowering(const TargetMachine &TM, const AMDGPUSubtarget &STI)
bool enableDX10Clamp() const
#define NODE_NAME_CASE(node)
Fast - This calling convention attempts to make calls as fast as possible (e.g.
Definition: CallingConv.h:43
void setLibcallName(RTLIB::Libcall Call, const char *Name)
Rename the default libcall routine name for the specified libcall.
void analyzeFormalArgumentsCompute(CCState &State, const SmallVectorImpl< ISD::InputArg > &Ins) const
The SelectionDAGBuilder will automatically promote function arguments with illegal types...
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
Definition: Casting.h:323
static volatile int Zero
SDValue performStoreCombine(SDNode *N, DAGCombinerInfo &DCI) const
#define LLVM_READONLY
Definition: Compiler.h:168
unsigned MaxStoresPerMemcpy
Specify maximum bytes of store instructions per memcpy call.
static bool isNegativeOne(SDValue Val)
void diagnose(const DiagnosticInfo &DI)
Report a message to the currently installed diagnostic handler.
bool isFNegFree(EVT VT) const override
Return true if an fneg operation is free to the point where it is never worthwhile to replace it with...
EVT getValueType() const
Return the ValueType of the referenced return value.
SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
EVT getPow2VectorType(LLVMContext &Context) const
Widens the length of the given vector EVT up to the nearest power of 2 and returns that type...
Definition: ValueTypes.h:366
SDValue LowerFROUND64(SDValue Op, SelectionDAG &DAG) const
bool isByteSized() const
Return true if the bit size is a multiple of 8.
Definition: ValueTypes.h:212
CONCAT_VECTORS(VECTOR0, VECTOR1, ...) - Given a number of values of vector type with the same length ...
Definition: ISDOpcodes.h:319
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
Definition: ValueTypes.h:136
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isSimple() const
Test if the given EVT is simple (as opposed to being extended).
Definition: ValueTypes.h:126
static LLVM_READONLY bool opMustUseVOP3Encoding(const SDNode *N, MVT VT)
returns true if the operation will definitely need to use a 64-bit encoding, and thus will use a VOP3...
void setSchedulingPreference(Sched::Preference Pref)
Specify the target scheduling preference.
SDValue CreateLiveInRegister(SelectionDAG &DAG, const TargetRegisterClass *RC, unsigned Reg, EVT VT, const SDLoc &SL, bool RawReg=false) const
Helper function that adds Reg to the LiveIn list of the DAG's MachineFunction.
constexpr uint32_t Hi_32(uint64_t Value)
Return the high 32 bits of a 64 bit value.
Definition: MathExtras.h:276
EVT getTypeToTransformTo(LLVMContext &Context, EVT VT) const
For types supported by the target, this is an identity function.
FMA - Perform a * b + c with no intermediate rounding step.
Definition: ISDOpcodes.h:276
SDValue getRegister(unsigned Reg, EVT VT)
bool isNullConstant(SDValue V)
Returns true if V is a constant integer zero.
SDValue getSelectCC(const SDLoc &DL, SDValue LHS, SDValue RHS, SDValue True, SDValue False, ISD::CondCode Cond)
Helper function to make it easier to build SelectCC's if you just have an ISD::CondCode instead of an...
Definition: SelectionDAG.h:910
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
Definition: Compiler.h:235
SDValue getValueType(EVT)
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
Definition: BitmaskEnum.h:81
unsigned ComputeNumSignBits(SDValue Op, unsigned Depth=0) const
Return the number of times the sign bit of the register is replicated into the other bits...
bool hasVOP3PInsts() const
const TargetLowering & getTargetLoweringInfo() const
Definition: SelectionDAG.h:379
void ReplaceAllUsesOfValueWith(SDValue From, SDValue To)
Replace any uses of From with To, leaving uses of other values produced by From.Val alone...
static EVT getEquivalentMemType(LLVMContext &Context, EVT VT)
bool hasFminFmaxLegacy() const
cmpResult compare(const APFloat &RHS) const
Definition: APFloat.h:1102
Primary interface to the complete machine description for the target machine.
Definition: TargetMachine.h:56
static SDValue foldFreeOpFromSelect(TargetLowering::DAGCombinerInfo &DCI, SDValue N)
bool hasBCNT(unsigned Size) const
bool isZExtFree(Type *Src, Type *Dest) const override
Return true if any actual instruction that defines a value of type FromTy implicitly zero-extends the...
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:49
FMAD - Perform a * b + c, while getting the same result as the separately rounded operations...
Definition: ISDOpcodes.h:280
SetCC operator - This evaluates to a true value iff the condition is true.
Definition: ISDOpcodes.h:411
uint32_t getImplicitParameterOffset(const AMDGPUMachineFunction *MFI, const ImplicitParameter Param) const
Helper function that returns the byte offset of the given type of implicit parameter.
unsigned MaxStoresPerMemset
Specify maximum number of store instructions per memset call.
unsigned getOrigAlign() const
static GCMetadataPrinterRegistry::Add< OcamlGCMetadataPrinter > Y("ocaml","ocaml 3.10-compatible collector")
SDValue LowerEXTRACT_SUBVECTOR(SDValue Op, SelectionDAG &DAG) const
Conversion operators.
Definition: ISDOpcodes.h:441
bool aggressivelyPreferBuildVectorSources(EVT VecVT) const override
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
Definition: SelectionDAG.h:434
SDValue LowerSDIVREM(SDValue Op, SelectionDAG &DAG) const
SDValue getZeroExtendInReg(SDValue Op, const SDLoc &DL, EVT SrcTy)
Return the expression required to zero extend the Op value assuming it was the smaller SrcTy value...
TRUNCATE - Completely drop the high bits.
Definition: ISDOpcodes.h:450
unsigned getAlignment() const
unsigned AllocateReg(unsigned Reg)
AllocateReg - Attempt to allocate one register.
bool ShouldShrinkFPConstant(EVT VT) const override
If true, then instruction selection should seek to shrink the FP constant of the specified type to a ...
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
FNEG, FABS, FSQRT, FSIN, FCOS, FPOWI, FPOW, FLOG, FLOG2, FLOG10, FEXP, FEXP2, FCEIL, FTRUNC, FRINT, FNEARBYINT, FROUND, FFLOOR - Perform various unary floating point operations.
Definition: ISDOpcodes.h:560
Calling convention for AMDGPU code object kernels.
Definition: CallingConv.h:199
static EVT getIntegerVT(LLVMContext &Context, unsigned BitWidth)
Returns the EVT that represents an integer with the given number of bits.
Definition: ValueTypes.h:64
bool SimplifyDemandedBits(SDNode *User, unsigned OpIdx, const APInt &Demanded, DAGCombinerInfo &DCI, TargetLoweringOpt &TLO) const
Helper for SimplifyDemandedBits that can simplify an operation with multiple uses.
const fltSemantics & getSemantics() const
Definition: APFloat.h:1140
MVT getVectorIdxTy(const DataLayout &) const override
Returns the type to be used for the index operand of: ISD::INSERT_VECTOR_ELT, ISD::EXTRACT_VECTOR_ELT...
SDValue getSqrtEstimate(SDValue Operand, SelectionDAG &DAG, int Enabled, int &RefinementSteps, bool &UseOneConstNR, bool Reciprocal) const override
Hooks for building estimates in place of slower divisions and square roots.
#define D
Definition: LargeTest.cpp:26
bool PredictableSelectIsExpensive
Tells the code generator that select is more expensive than a branch if the branch is usually predict...
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
Definition: ValueTypes.h:253
bool mayIgnoreSignedZero(SDValue Op) const
void CommitTargetLoweringOpt(const TargetLoweringOpt &TLO)
bool isSelectSupported(SelectSupportKind) const override
uint64_t getZExtValue() const
MULHU/MULHS - Multiply high - Multiply two integers of type iN, producing an unsigned/signed value of...
Definition: ISDOpcodes.h:354
BRIND - Indirect branch.
Definition: ISDOpcodes.h:600
unsigned getAlignmentForImplicitArgPtr() const
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
Definition: ValueTypes.h:273
SDValue performClampCombine(SDNode *N, DAGCombinerInfo &DCI) const
This class is used to represent ISD::LOAD nodes.
DYNAMIC_STACKALLOC - Allocate some number of bytes on the stack aligned to a specified boundary...
Definition: ISDOpcodes.h:589