24 #include "llvm/Config/llvm-config.h" 40 #define DEBUG_TYPE "x86-isel" 42 STATISTIC(NumLoadMoved,
"Number of loads moved below TokenFactor");
51 struct X86ISelAddressMode {
72 unsigned char SymbolFlags;
75 : BaseType(RegBase), Base_FrameIndex(0), Scale(1), IndexReg(), Disp(0),
76 Segment(), GV(nullptr), CP(nullptr), BlockAddr(nullptr), ES(nullptr),
77 MCSym(nullptr), JT(-1), Align(0), SymbolFlags(X86II::
MO_NO_FLAG) {}
79 bool hasSymbolicDisplacement()
const {
80 return GV !=
nullptr || CP !=
nullptr || ES !=
nullptr ||
81 MCSym !=
nullptr || JT != -1 || BlockAddr !=
nullptr;
84 bool hasBaseOrIndexReg()
const {
85 return BaseType == FrameIndexBase ||
90 bool isRIPRelative()
const {
91 if (BaseType != RegBase)
return false;
93 dyn_cast_or_null<RegisterSDNode>(Base_Reg.
getNode()))
94 return RegNode->getReg() == X86::RIP;
103 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 105 dbgs() <<
"X86ISelAddressMode " <<
this <<
'\n';
106 dbgs() <<
"Base_Reg ";
111 if (BaseType == FrameIndexBase)
112 dbgs() <<
" Base.FrameIndex " << Base_FrameIndex <<
'\n';
113 dbgs() <<
" Scale " << Scale <<
'\n' 119 dbgs() <<
" Disp " << Disp <<
'\n' 141 dbgs() <<
" JT" << JT <<
" Align" << Align <<
'\n';
167 OptForMinSize(
false) {}
170 return "X86 DAG->DAG Instruction Selection";
180 void EmitFunctionEntryCode()
override;
184 void PreprocessISelDAG()
override;
185 void PostprocessISelDAG()
override;
188 #include "X86GenDAGISel.inc" 193 bool foldOffsetIntoAddress(uint64_t
Offset, X86ISelAddressMode &AM);
194 bool matchLoadInAddress(
LoadSDNode *
N, X86ISelAddressMode &AM);
195 bool matchWrapper(
SDValue N, X86ISelAddressMode &AM);
196 bool matchAddress(
SDValue N, X86ISelAddressMode &AM);
197 bool matchVectorAddress(
SDValue N, X86ISelAddressMode &AM);
198 bool matchAdd(
SDValue N, X86ISelAddressMode &AM,
unsigned Depth);
199 bool matchAddressRecursively(
SDValue N, X86ISelAddressMode &AM,
201 bool matchAddressBase(
SDValue N, X86ISelAddressMode &AM);
235 return tryFoldLoad(P, P, N, Base, Scale, Index, Disp, Segment);
245 bool SelectInlineAsmMemoryOperand(
const SDValue &
Op,
246 unsigned ConstraintID,
247 std::vector<SDValue> &OutOps)
override;
249 void emitSpecialCodeForMain();
251 inline void getAddressOperands(X86ISelAddressMode &AM,
const SDLoc &DL,
255 Base = (AM.BaseType == X86ISelAddressMode::FrameIndexBase)
256 ? CurDAG->getTargetFrameIndex(
258 TLI->getPointerTy(CurDAG->getDataLayout()))
260 Scale = getI8Imm(AM.Scale, DL);
265 Disp = CurDAG->getTargetGlobalAddress(AM.GV,
SDLoc(),
269 Disp = CurDAG->getTargetConstantPool(AM.CP,
MVT::i32,
270 AM.Align, AM.Disp, AM.SymbolFlags);
272 assert(!AM.Disp &&
"Non-zero displacement is ignored with ES.");
273 Disp = CurDAG->getTargetExternalSymbol(AM.ES,
MVT::i32, AM.SymbolFlags);
274 }
else if (AM.MCSym) {
275 assert(!AM.Disp &&
"Non-zero displacement is ignored with MCSym.");
276 assert(AM.SymbolFlags == 0 &&
"oo");
277 Disp = CurDAG->getMCSymbol(AM.MCSym,
MVT::i32);
278 }
else if (AM.JT != -1) {
279 assert(!AM.Disp &&
"Non-zero displacement is ignored with JT.");
280 Disp = CurDAG->getTargetJumpTable(AM.JT,
MVT::i32, AM.SymbolFlags);
281 }
else if (AM.BlockAddr)
282 Disp = CurDAG->getTargetBlockAddress(AM.BlockAddr,
MVT::i32, AM.Disp,
285 Disp = CurDAG->getTargetConstant(AM.Disp, DL,
MVT::i32);
287 if (AM.Segment.getNode())
288 Segment = AM.Segment;
290 Segment = CurDAG->getRegister(0,
MVT::i32);
299 bool shouldAvoidImmediateInstFormsForSize(
SDNode *
N)
const {
310 UE = N->
use_end(); (UI != UE) && (UseCount < 2); ++UI) {
354 (RegNode = dyn_cast_or_null<RegisterSDNode>(
356 if ((RegNode->getReg() ==
X86::ESP) ||
357 (RegNode->getReg() == X86::RSP))
366 return (UseCount > 1);
370 inline SDValue getI8Imm(
unsigned Imm,
const SDLoc &DL) {
371 return CurDAG->getTargetConstant(Imm, DL,
MVT::i8);
375 inline SDValue getI32Imm(
unsigned Imm,
const SDLoc &DL) {
376 return CurDAG->getTargetConstant(Imm, DL,
MVT::i32);
380 inline SDValue getI64Imm(uint64_t Imm,
const SDLoc &DL) {
381 return CurDAG->getTargetConstant(Imm, DL,
MVT::i64);
384 SDValue getExtractVEXTRACTImmediate(
SDNode *N,
unsigned VecWidth,
386 assert((VecWidth == 128 || VecWidth == 256) &&
"Unexpected vector width");
392 SDValue getInsertVINSERTImmediate(
SDNode *N,
unsigned VecWidth,
394 assert((VecWidth == 128 || VecWidth == 256) &&
"Unexpected vector width");
403 SDNode *getGlobalBaseReg();
414 return Subtarget->getInstrInfo();
420 bool ComplexPatternFuncMutatesDAG()
const override {
424 bool isSExtAbsoluteSymbolRef(
unsigned Width,
SDNode *N)
const;
428 template <
unsigned W
idth>
bool isSExtRelocImm(
SDNode *N)
const {
429 if (
auto *CN = dyn_cast<ConstantSDNode>(N))
430 return isInt<Width>(CN->getSExtValue());
431 return isSExtAbsoluteSymbolRef(Width, N);
435 bool useNonTemporalLoad(
LoadSDNode *N)
const {
447 return Subtarget->hasSSE41();
449 return Subtarget->hasAVX2();
451 return Subtarget->hasAVX512();
455 bool foldLoadStoreIntoMemOperand(
SDNode *Node);
456 bool matchBEXTRFromAnd(
SDNode *Node);
457 bool shrinkAndImmediate(
SDNode *N);
458 bool isMaskZeroExtended(
SDNode *N)
const;
480 return Subtarget->
hasVLX();
494 bool X86DAGToDAGISel::isMaskZeroExtended(
SDNode *N)
const {
542 if (Imm->getAPIntValue().isSignedIntN(8))
551 Imm->getAPIntValue().getBitWidth() == 64 &&
552 Imm->getAPIntValue().isIntN(32))
590 if (
C &&
C->getSExtValue() == -2)
596 if (
C &&
C->getSExtValue() == -2)
638 "Unexpected chain operand");
690 if (isa<MemSDNode>(Chain.
getNode()) &&
691 cast<MemSDNode>(Chain.
getNode())->writeMem())
702 void X86DAGToDAGISel::PreprocessISelDAG() {
704 OptForSize = MF->getFunction().optForSize();
705 OptForMinSize = MF->getFunction().optForMinSize();
706 assert((!OptForMinSize || OptForSize) &&
"OptForMinSize implies OptForSize");
709 E = CurDAG->allnodes_end();
I !=
E; ) {
718 CurDAG->ReplaceAllUsesOfValueWith(
SDValue(N, 0), Res);
720 CurDAG->DeleteNode(N);
727 !Subtarget->useRetpoline() &&
730 (Subtarget->is64Bit() ||
731 !getTargetMachine().isPositionIndependent())))) {
785 if (SrcIsSSE && DstIsSSE)
788 if (!SrcIsSSE && !DstIsSSE) {
804 MemVT = SrcIsSSE ? SrcVT : DstVT;
806 SDValue MemTmp = CurDAG->CreateStackTemporary(MemVT);
811 CurDAG->getTruncStore(CurDAG->getEntryNode(), dl, N->
getOperand(0),
821 CurDAG->ReplaceAllUsesOfValueWith(
SDValue(N, 0), Result);
826 CurDAG->DeleteNode(N);
831 void X86DAGToDAGISel::PostprocessISelDAG() {
841 while (Position != CurDAG->allnodes_begin()) {
851 if (SubRegIdx != X86::sub_xmm && SubRegIdx != X86::sub_ymm)
862 case X86::VMOVAPDrr:
case X86::VMOVUPDrr:
863 case X86::VMOVAPSrr:
case X86::VMOVUPSrr:
864 case X86::VMOVDQArr:
case X86::VMOVDQUrr:
865 case X86::VMOVAPDYrr:
case X86::VMOVUPDYrr:
866 case X86::VMOVAPSYrr:
case X86::VMOVUPSYrr:
867 case X86::VMOVDQAYrr:
case X86::VMOVDQUYrr:
868 case X86::VMOVAPDZ128rr:
case X86::VMOVUPDZ128rr:
869 case X86::VMOVAPSZ128rr:
case X86::VMOVUPSZ128rr:
870 case X86::VMOVDQA32Z128rr:
case X86::VMOVDQU32Z128rr:
871 case X86::VMOVDQA64Z128rr:
case X86::VMOVDQU64Z128rr:
872 case X86::VMOVAPDZ256rr:
case X86::VMOVUPDZ256rr:
873 case X86::VMOVAPSZ256rr:
case X86::VMOVUPSZ256rr:
874 case X86::VMOVDQA32Z256rr:
case X86::VMOVDQU32Z256rr:
875 case X86::VMOVDQA64Z256rr:
case X86::VMOVDQU64Z256rr:
890 CurDAG->RemoveDeadNode(Move.
getNode());
896 void X86DAGToDAGISel::emitSpecialCodeForMain() {
897 if (Subtarget->isTargetCygMing()) {
899 auto &DL = CurDAG->getDataLayout();
904 CurDAG->getExternalSymbol(
"__main", TLI->getPointerTy(DL)),
908 CurDAG->setRoot(Result.second);
912 void X86DAGToDAGISel::EmitFunctionEntryCode() {
916 emitSpecialCodeForMain();
926 return isInt<31>(Val);
929 bool X86DAGToDAGISel::foldOffsetIntoAddress(uint64_t
Offset,
930 X86ISelAddressMode &AM) {
936 if (AM.ES || AM.MCSym)
939 int64_t Val = AM.Disp +
Offset;
941 if (Subtarget->is64Bit()) {
943 AM.hasSymbolicDisplacement()))
947 if (AM.BaseType == X86ISelAddressMode::FrameIndexBase &&
956 bool X86DAGToDAGISel::matchLoadInAddress(
LoadSDNode *N, X86ISelAddressMode &AM){
966 if (
C->getSExtValue() == 0 && AM.Segment.getNode() ==
nullptr &&
967 (Subtarget->isTargetGlibc() || Subtarget->isTargetAndroid() ||
968 Subtarget->isTargetFuchsia()))
971 AM.Segment = CurDAG->getRegister(X86::GS,
MVT::i16);
974 AM.Segment = CurDAG->getRegister(X86::FS,
MVT::i16);
986 bool X86DAGToDAGISel::matchWrapper(
SDValue N, X86ISelAddressMode &AM) {
989 if (AM.hasSymbolicDisplacement())
999 if (Subtarget->is64Bit() &&
1004 if (IsRIPRel && AM.hasBaseOrIndexReg())
1008 X86ISelAddressMode Backup = AM;
1013 AM.GV =
G->getGlobal();
1014 AM.SymbolFlags =
G->getTargetFlags();
1015 Offset =
G->getOffset();
1017 AM.CP = CP->getConstVal();
1018 AM.Align = CP->getAlignment();
1019 AM.SymbolFlags = CP->getTargetFlags();
1020 Offset = CP->getOffset();
1022 AM.ES = S->getSymbol();
1023 AM.SymbolFlags = S->getTargetFlags();
1024 }
else if (
auto *S = dyn_cast<MCSymbolSDNode>(N0)) {
1025 AM.MCSym = S->getMCSymbol();
1027 AM.JT = J->getIndex();
1028 AM.SymbolFlags = J->getTargetFlags();
1030 AM.BlockAddr = BA->getBlockAddress();
1031 AM.SymbolFlags = BA->getTargetFlags();
1032 Offset = BA->getOffset();
1036 if (foldOffsetIntoAddress(Offset, AM)) {
1042 AM.setBaseReg(CurDAG->getRegister(X86::RIP,
MVT::i64));
1050 bool X86DAGToDAGISel::matchAddress(
SDValue N, X86ISelAddressMode &AM) {
1051 if (matchAddressRecursively(N, AM, 0))
1056 if (AM.Scale == 2 &&
1057 AM.BaseType == X86ISelAddressMode::RegBase &&
1058 AM.Base_Reg.getNode() ==
nullptr) {
1059 AM.Base_Reg = AM.IndexReg;
1067 Subtarget->is64Bit() &&
1069 AM.BaseType == X86ISelAddressMode::RegBase &&
1070 AM.Base_Reg.getNode() ==
nullptr &&
1071 AM.IndexReg.getNode() ==
nullptr &&
1073 AM.hasSymbolicDisplacement())
1074 AM.Base_Reg = CurDAG->getRegister(X86::RIP,
MVT::i64);
1079 bool X86DAGToDAGISel::matchAdd(
SDValue N, X86ISelAddressMode &AM,
1085 X86ISelAddressMode Backup = AM;
1086 if (!matchAddressRecursively(N.
getOperand(0), AM, Depth+1) &&
1100 if (AM.BaseType == X86ISelAddressMode::RegBase &&
1101 !AM.Base_Reg.getNode() &&
1102 !AM.IndexReg.getNode()) {
1139 X86ISelAddressMode &AM) {
1146 if (ScaleLog <= 0 || ScaleLog >= 4 ||
1147 Mask != (0xffu << ScaleLog))
1172 AM.Scale = (1 << ScaleLog);
1182 X86ISelAddressMode &AM) {
1195 if (ShiftAmt != 1 && ShiftAmt != 2 && ShiftAmt != 3)
1214 AM.Scale = 1 << ShiftAmt;
1215 AM.IndexReg = NewAnd;
1249 X86ISelAddressMode &AM) {
1260 unsigned AMShiftAmt = MaskTZ;
1264 if (AMShiftAmt <= 0 || AMShiftAmt > 3)
return true;
1272 if (MaskLZ < ScaleDown)
1274 MaskLZ -= ScaleDown;
1282 bool ReplacingAnyExtend =
false;
1289 MaskLZ = ExtendBits > MaskLZ ? 0 : MaskLZ - ExtendBits;
1290 ReplacingAnyExtend =
true;
1292 APInt MaskedHighBits =
1296 if (MaskedHighBits != Known.Zero)
return true;
1301 if (ReplacingAnyExtend) {
1325 AM.Scale = 1 << AMShiftAmt;
1326 AM.IndexReg = NewSRL;
1330 bool X86DAGToDAGISel::matchAddressRecursively(
SDValue N, X86ISelAddressMode &AM,
1334 dbgs() <<
"MatchAddress: ";
1339 return matchAddressBase(N, AM);
1344 if (AM.isRIPRelative()) {
1348 if (!(AM.ES || AM.MCSym) && AM.JT != -1)
1352 if (!foldOffsetIntoAddress(Cst->getSExtValue(), AM))
1360 if (!AM.hasSymbolicDisplacement() && AM.Disp == 0)
1361 if (
const auto *ESNode = dyn_cast<MCSymbolSDNode>(N.
getOperand(0))) {
1363 AM.MCSym = ESNode->getMCSymbol();
1369 uint64_t Val = cast<ConstantSDNode>(
N)->getSExtValue();
1370 if (!foldOffsetIntoAddress(Val, AM))
1377 if (!matchWrapper(N, AM))
1382 if (!matchLoadInAddress(cast<LoadSDNode>(N), AM))
1387 if (AM.BaseType == X86ISelAddressMode::RegBase &&
1388 AM.Base_Reg.getNode() ==
nullptr &&
1390 AM.BaseType = X86ISelAddressMode::FrameIndexBase;
1391 AM.Base_FrameIndex = cast<FrameIndexSDNode>(
N)->getIndex();
1397 if (AM.IndexReg.getNode() !=
nullptr || AM.Scale != 1)
1401 unsigned Val = CN->getZExtValue();
1406 if (Val == 1 || Val == 2 || Val == 3) {
1407 AM.Scale = 1 << Val;
1413 if (CurDAG->isBaseWithConstantOffset(ShVal)) {
1416 uint64_t Disp = (uint64_t)AddVal->
getSExtValue() << Val;
1417 if (!foldOffsetIntoAddress(Disp, AM))
1421 AM.IndexReg = ShVal;
1429 if (AM.IndexReg.getNode() !=
nullptr || AM.Scale != 1)
break;
1462 if (AM.BaseType == X86ISelAddressMode::RegBase &&
1463 AM.Base_Reg.getNode() ==
nullptr &&
1464 AM.IndexReg.getNode() ==
nullptr) {
1466 if (CN->getZExtValue() == 3 || CN->getZExtValue() == 5 ||
1467 CN->getZExtValue() == 9) {
1468 AM.Scale =
unsigned(CN->getZExtValue())-1;
1476 if (MulVal.getNode()->getOpcode() ==
ISD::ADD && MulVal.hasOneUse() &&
1477 isa<ConstantSDNode>(MulVal.getOperand(1))) {
1480 cast<ConstantSDNode>(MulVal.getOperand(1));
1481 uint64_t Disp = AddVal->
getSExtValue() * CN->getZExtValue();
1482 if (foldOffsetIntoAddress(Disp, AM))
1488 AM.IndexReg = AM.Base_Reg =
Reg;
1507 X86ISelAddressMode Backup = AM;
1508 if (matchAddressRecursively(N.
getOperand(0), AM, Depth+1)) {
1513 if (AM.IndexReg.getNode() || AM.isRIPRelative()) {
1533 if ((AM.BaseType == X86ISelAddressMode::RegBase && AM.Base_Reg.getNode() &&
1535 !AM.Base_Reg.getNode()->hasOneUse()) ||
1536 AM.BaseType == X86ISelAddressMode::FrameIndexBase)
1540 if ((AM.hasSymbolicDisplacement() && !Backup.hasSymbolicDisplacement()) +
1541 ((AM.Disp != 0) && (Backup.Disp == 0)) +
1542 (AM.Segment.getNode() && !Backup.Segment.getNode()) >= 2)
1563 if (!matchAdd(N, AM, Depth))
1575 !matchAdd(N, AM, Depth))
1584 if (AM.IndexReg.getNode() !=
nullptr || AM.Scale != 1)
break;
1614 return matchAddressBase(N, AM);
1619 bool X86DAGToDAGISel::matchAddressBase(
SDValue N, X86ISelAddressMode &AM) {
1621 if (AM.BaseType != X86ISelAddressMode::RegBase || AM.Base_Reg.getNode()) {
1623 if (!AM.IndexReg.getNode()) {
1634 AM.BaseType = X86ISelAddressMode::RegBase;
1642 bool X86DAGToDAGISel::matchVectorAddress(
SDValue N, X86ISelAddressMode &AM) {
1646 uint64_t Val = cast<ConstantSDNode>(
N)->getSExtValue();
1647 if (!foldOffsetIntoAddress(Val, AM))
1652 if (!matchWrapper(N, AM))
1657 return matchAddressBase(N, AM);
1663 X86ISelAddressMode AM;
1664 auto *Mgs = cast<X86MaskedGatherScatterSDNode>(Parent);
1665 AM.IndexReg = Mgs->getIndex();
1666 AM.Scale = cast<ConstantSDNode>(Mgs->getScale())->getZExtValue();
1668 unsigned AddrSpace = cast<MemSDNode>(Parent)->getPointerInfo().getAddrSpace();
1670 if (AddrSpace == 256)
1671 AM.Segment = CurDAG->getRegister(X86::GS,
MVT::i16);
1672 if (AddrSpace == 257)
1673 AM.Segment = CurDAG->getRegister(X86::FS,
MVT::i16);
1674 if (AddrSpace == 258)
1675 AM.Segment = CurDAG->getRegister(X86::SS,
MVT::i16);
1678 if (matchVectorAddress(N, AM))
1682 if (AM.BaseType == X86ISelAddressMode::RegBase) {
1683 if (!AM.Base_Reg.getNode())
1684 AM.Base_Reg = CurDAG->getRegister(0, VT);
1687 getAddressOperands(AM,
SDLoc(N), Base, Scale, Index, Disp, Segment);
1701 X86ISelAddressMode AM;
1711 unsigned AddrSpace =
1712 cast<MemSDNode>(Parent)->getPointerInfo().getAddrSpace();
1714 if (AddrSpace == 256)
1715 AM.Segment = CurDAG->getRegister(X86::GS,
MVT::i16);
1716 if (AddrSpace == 257)
1717 AM.Segment = CurDAG->getRegister(X86::FS,
MVT::i16);
1718 if (AddrSpace == 258)
1719 AM.Segment = CurDAG->getRegister(X86::SS,
MVT::i16);
1722 if (matchAddress(N, AM))
1726 if (AM.BaseType == X86ISelAddressMode::RegBase) {
1727 if (!AM.Base_Reg.getNode())
1728 AM.Base_Reg = CurDAG->getRegister(0, VT);
1731 if (!AM.IndexReg.getNode())
1732 AM.IndexReg = CurDAG->getRegister(0, VT);
1734 getAddressOperands(AM,
SDLoc(N), Base, Scale, Index, Disp, Segment);
1742 while (User != Root) {
1758 bool X86DAGToDAGISel::selectScalarSSELoad(
SDNode *Root,
SDNode *Parent,
1762 SDValue &PatternNodeWithChain) {
1768 PatternNodeWithChain =
N;
1769 if (IsProfitableToFold(PatternNodeWithChain, N.
getNode(), Root) &&
1770 IsLegalToFold(PatternNodeWithChain, Parent, Root, OptLevel)) {
1771 LoadSDNode *
LD = cast<LoadSDNode>(PatternNodeWithChain);
1779 PatternNodeWithChain =
N;
1780 if (IsProfitableToFold(PatternNodeWithChain, N.
getNode(), Root) &&
1781 IsLegalToFold(PatternNodeWithChain, Parent, Root, OptLevel)) {
1782 auto *
MI = cast<MemIntrinsicSDNode>(PatternNodeWithChain);
1783 return selectAddr(
MI,
MI->getBasePtr(), Base, Scale,
Index, Disp,
1794 IsProfitableToFold(PatternNodeWithChain, N.
getNode(), Root) &&
1795 IsLegalToFold(PatternNodeWithChain, N.
getNode(), Root, OptLevel)) {
1796 LoadSDNode *
LD = cast<LoadSDNode>(PatternNodeWithChain);
1810 IsProfitableToFold(PatternNodeWithChain, N.
getNode(), Root) &&
1811 IsLegalToFold(PatternNodeWithChain, N.
getNode(), Root, OptLevel)) {
1813 LoadSDNode *
LD = cast<LoadSDNode>(PatternNodeWithChain);
1823 bool X86DAGToDAGISel::selectMOV64Imm32(
SDValue N,
SDValue &Imm) {
1825 uint64_t ImmVal = CN->getZExtValue();
1829 Imm = CurDAG->getTargetConstant(ImmVal,
SDLoc(N),
MVT::i64);
1850 cast<GlobalAddressSDNode>(
N)->getGlobal()->getAbsoluteSymbolRange();
1857 bool X86DAGToDAGISel::selectLEA64_32Addr(
SDValue N,
SDValue &Base,
1863 if (!selectLEAAddr(N, Base, Scale, Index, Disp, Segment))
1867 if (RN && RN->
getReg() == 0)
1868 Base = CurDAG->getRegister(0,
MVT::i64);
1871 Base =
SDValue(CurDAG->getMachineNode(
1872 TargetOpcode::SUBREG_TO_REG, DL,
MVT::i64,
1873 CurDAG->getTargetConstant(0, DL,
MVT::i64),
1875 CurDAG->getTargetConstant(X86::sub_32bit, DL,
MVT::i32)),
1880 if (RN && RN->
getReg() == 0)
1881 Index = CurDAG->getRegister(0,
MVT::i64);
1884 "Expect to be extending 32-bit registers for use in LEA");
1885 Index =
SDValue(CurDAG->getMachineNode(
1886 TargetOpcode::SUBREG_TO_REG, DL,
MVT::i64,
1887 CurDAG->getTargetConstant(0, DL,
MVT::i64),
1889 CurDAG->getTargetConstant(X86::sub_32bit, DL,
1899 bool X86DAGToDAGISel::selectLEAAddr(
SDValue N,
1903 X86ISelAddressMode AM;
1914 if (matchAddress(N, AM))
1916 assert (T == AM.Segment);
1919 unsigned Complexity = 0;
1920 if (AM.BaseType == X86ISelAddressMode::RegBase)
1921 if (AM.Base_Reg.getNode())
1924 AM.Base_Reg = CurDAG->getRegister(0, VT);
1925 else if (AM.BaseType == X86ISelAddressMode::FrameIndexBase)
1928 if (AM.IndexReg.getNode())
1931 AM.IndexReg = CurDAG->getRegister(0, VT);
1943 if (AM.hasSymbolicDisplacement()) {
1945 if (Subtarget->is64Bit())
1951 if (AM.Disp && (AM.Base_Reg.getNode() || AM.IndexReg.getNode()))
1955 if (Complexity <= 2)
1958 getAddressOperands(AM, DL, Base, Scale, Index, Disp, Segment);
1963 bool X86DAGToDAGISel::selectTLSADDRAddr(
SDValue N,
SDValue &Base,
1969 X86ISelAddressMode AM;
1970 AM.GV = GA->getGlobal();
1971 AM.Disp += GA->getOffset();
1972 AM.Base_Reg = CurDAG->getRegister(0, N.
getValueType());
1973 AM.SymbolFlags = GA->getTargetFlags();
1979 AM.IndexReg = CurDAG->getRegister(0,
MVT::i64);
1982 getAddressOperands(AM,
SDLoc(N), Base, Scale, Index, Disp, Segment);
1987 if (
auto *CN = dyn_cast<ConstantSDNode>(N)) {
1988 Op = CurDAG->getTargetConstant(CN->getAPIntValue(),
SDLoc(CN),
1997 bool WasTruncated =
false;
1999 WasTruncated =
true;
2014 return !WasTruncated;
2018 auto *GA = cast<GlobalAddressSDNode>(N.
getOperand(0));
2020 if (!CR || CR->getUnsignedMax().uge(1ull << VT.
getSizeInBits()))
2024 Op = CurDAG->getTargetGlobalAddress(GA->getGlobal(),
SDLoc(N), VT,
2025 GA->getOffset(), GA->getTargetFlags());
2034 !IsProfitableToFold(N, P, Root) ||
2035 !IsLegalToFold(N, P, Root, OptLevel))
2038 return selectAddr(N.
getNode(),
2047 useNonTemporalLoad(cast<LoadSDNode>(N)) ||
2048 !IsProfitableToFold(N, P, Root) ||
2049 !IsLegalToFold(N, P, Root, OptLevel))
2052 return selectAddr(N.
getNode(),
2059 SDNode *X86DAGToDAGISel::getGlobalBaseReg() {
2060 unsigned GlobalBaseReg = getInstrInfo()->getGlobalBaseReg(MF);
2061 auto &DL = MF->getDataLayout();
2062 return CurDAG->getRegister(GlobalBaseReg, TLI->getPointerTy(DL)).getNode();
2065 bool X86DAGToDAGISel::isSExtAbsoluteSymbolRef(
unsigned Width,
SDNode *N)
const {
2085 UE = N->
use_end(); UI != UE; ++UI) {
2090 if (cast<RegisterSDNode>(UI->getOperand(1))->
getReg() !=
2095 FlagUE = UI->
use_end(); FlagUI != FlagUE; ++FlagUI) {
2097 if (FlagUI.getUse().getResNo() != 1)
continue;
2099 if (!FlagUI->isMachineOpcode())
return false;
2101 switch (FlagUI->getMachineOpcode()) {
2103 case X86::SETAr:
case X86::SETAEr:
case X86::SETBr:
case X86::SETBEr:
2104 case X86::SETEr:
case X86::SETNEr:
case X86::SETPr:
case X86::SETNPr:
2105 case X86::SETAm:
case X86::SETAEm:
case X86::SETBm:
case X86::SETBEm:
2106 case X86::SETEm:
case X86::SETNEm:
case X86::SETPm:
case X86::SETNPm:
2107 case X86::JA_1:
case X86::JAE_1:
case X86::JB_1:
case X86::JBE_1:
2108 case X86::JE_1:
case X86::JNE_1:
case X86::JP_1:
case X86::JNP_1:
2109 case X86::CMOVA16rr:
case X86::CMOVA16rm:
2110 case X86::CMOVA32rr:
case X86::CMOVA32rm:
2111 case X86::CMOVA64rr:
case X86::CMOVA64rm:
2112 case X86::CMOVAE16rr:
case X86::CMOVAE16rm:
2113 case X86::CMOVAE32rr:
case X86::CMOVAE32rm:
2114 case X86::CMOVAE64rr:
case X86::CMOVAE64rm:
2115 case X86::CMOVB16rr:
case X86::CMOVB16rm:
2116 case X86::CMOVB32rr:
case X86::CMOVB32rm:
2117 case X86::CMOVB64rr:
case X86::CMOVB64rm:
2118 case X86::CMOVBE16rr:
case X86::CMOVBE16rm:
2119 case X86::CMOVBE32rr:
case X86::CMOVBE32rm:
2120 case X86::CMOVBE64rr:
case X86::CMOVBE64rm:
2121 case X86::CMOVE16rr:
case X86::CMOVE16rm:
2122 case X86::CMOVE32rr:
case X86::CMOVE32rm:
2123 case X86::CMOVE64rr:
case X86::CMOVE64rm:
2124 case X86::CMOVNE16rr:
case X86::CMOVNE16rm:
2125 case X86::CMOVNE32rr:
case X86::CMOVNE32rm:
2126 case X86::CMOVNE64rr:
case X86::CMOVNE64rm:
2127 case X86::CMOVNP16rr:
case X86::CMOVNP16rm:
2128 case X86::CMOVNP32rr:
case X86::CMOVNP32rm:
2129 case X86::CMOVNP64rr:
case X86::CMOVNP64rm:
2130 case X86::CMOVP16rr:
case X86::CMOVP16rm:
2131 case X86::CMOVP32rr:
case X86::CMOVP32rm:
2132 case X86::CMOVP64rr:
case X86::CMOVP64rm:
2135 default:
return false;
2149 if (UI.getUse().getResNo() != 1)
2155 if (cast<RegisterSDNode>(UI->getOperand(1))->
getReg() != X86::EFLAGS)
2159 FlagUI != FlagUE; ++FlagUI) {
2161 if (FlagUI.getUse().getResNo() != 1)
2164 if (!FlagUI->isMachineOpcode())
2167 switch (FlagUI->getMachineOpcode()) {
2169 case X86::SETOr:
case X86::SETNOr:
case X86::SETEr:
case X86::SETNEr:
2170 case X86::SETSr:
case X86::SETNSr:
case X86::SETPr:
case X86::SETNPr:
2171 case X86::SETLr:
case X86::SETGEr:
case X86::SETLEr:
case X86::SETGr:
2172 case X86::JO_1:
case X86::JNO_1:
case X86::JE_1:
case X86::JNE_1:
2173 case X86::JS_1:
case X86::JNS_1:
case X86::JP_1:
case X86::JNP_1:
2174 case X86::JL_1:
case X86::JGE_1:
case X86::JLE_1:
case X86::JG_1:
2175 case X86::CMOVO16rr:
case X86::CMOVO32rr:
case X86::CMOVO64rr:
2176 case X86::CMOVO16rm:
case X86::CMOVO32rm:
case X86::CMOVO64rm:
2177 case X86::CMOVNO16rr:
case X86::CMOVNO32rr:
case X86::CMOVNO64rr:
2178 case X86::CMOVNO16rm:
case X86::CMOVNO32rm:
case X86::CMOVNO64rm:
2179 case X86::CMOVE16rr:
case X86::CMOVE32rr:
case X86::CMOVE64rr:
2180 case X86::CMOVE16rm:
case X86::CMOVE32rm:
case X86::CMOVE64rm:
2181 case X86::CMOVNE16rr:
case X86::CMOVNE32rr:
case X86::CMOVNE64rr:
2182 case X86::CMOVNE16rm:
case X86::CMOVNE32rm:
case X86::CMOVNE64rm:
2183 case X86::CMOVS16rr:
case X86::CMOVS32rr:
case X86::CMOVS64rr:
2184 case X86::CMOVS16rm:
case X86::CMOVS32rm:
case X86::CMOVS64rm:
2185 case X86::CMOVNS16rr:
case X86::CMOVNS32rr:
case X86::CMOVNS64rr:
2186 case X86::CMOVNS16rm:
case X86::CMOVNS32rm:
case X86::CMOVNS64rm:
2187 case X86::CMOVP16rr:
case X86::CMOVP32rr:
case X86::CMOVP64rr:
2188 case X86::CMOVP16rm:
case X86::CMOVP32rm:
case X86::CMOVP64rm:
2189 case X86::CMOVNP16rr:
case X86::CMOVNP32rr:
case X86::CMOVNP64rr:
2190 case X86::CMOVNP16rm:
case X86::CMOVNP32rm:
case X86::CMOVNP64rm:
2191 case X86::CMOVL16rr:
case X86::CMOVL32rr:
case X86::CMOVL64rr:
2192 case X86::CMOVL16rm:
case X86::CMOVL32rm:
case X86::CMOVL64rm:
2193 case X86::CMOVGE16rr:
case X86::CMOVGE32rr:
case X86::CMOVGE64rr:
2194 case X86::CMOVGE16rm:
case X86::CMOVGE32rm:
case X86::CMOVGE64rm:
2195 case X86::CMOVLE16rr:
case X86::CMOVLE32rr:
case X86::CMOVLE64rr:
2196 case X86::CMOVLE16rm:
case X86::CMOVLE32rm:
case X86::CMOVLE64rm:
2197 case X86::CMOVG16rr:
case X86::CMOVG32rr:
case X86::CMOVG64rr:
2198 case X86::CMOVG16rm:
case X86::CMOVG32rm:
case X86::CMOVG64rm:
2216 if (StoredVal.
getResNo() != 0)
return false;
2230 LoadNode = cast<LoadSDNode>(
Load);
2241 bool FoundLoad =
false;
2245 const unsigned int Max = 1024;
2342 bool X86DAGToDAGISel::foldLoadStoreIntoMemOperand(
SDNode *Node) {
2376 if (!selectAddr(LoadNode, LoadNode->
getBasePtr(), Base, Scale,
Index, Disp,
2380 auto SelectOpcode = [&](
unsigned Opc64,
unsigned Opc32,
unsigned Opc16,
2402 ? SelectOpcode(X86::INC64m, X86::INC32m, X86::INC16m, X86::INC8m)
2403 : SelectOpcode(X86::DEC64m, X86::DEC32m, X86::DEC16m, X86::DEC8m);
2404 const SDValue Ops[] = {Base, Scale,
Index, Disp, Segment, InputChain};
2416 auto SelectRegOpcode = [SelectOpcode](
unsigned Opc) {
2419 return SelectOpcode(X86::ADD64mr, X86::ADD32mr, X86::ADD16mr,
2422 return SelectOpcode(X86::ADC64mr, X86::ADC32mr, X86::ADC16mr,
2425 return SelectOpcode(X86::SUB64mr, X86::SUB32mr, X86::SUB16mr,
2428 return SelectOpcode(X86::SBB64mr, X86::SBB32mr, X86::SBB16mr,
2431 return SelectOpcode(X86::AND64mr, X86::AND32mr, X86::AND16mr,
2434 return SelectOpcode(X86::OR64mr, X86::OR32mr, X86::OR16mr, X86::OR8mr);
2436 return SelectOpcode(X86::XOR64mr, X86::XOR32mr, X86::XOR16mr,
2442 auto SelectImm8Opcode = [SelectOpcode](
unsigned Opc) {
2445 return SelectOpcode(X86::ADD64mi8, X86::ADD32mi8, X86::ADD16mi8, 0);
2447 return SelectOpcode(X86::ADC64mi8, X86::ADC32mi8, X86::ADC16mi8, 0);
2449 return SelectOpcode(X86::SUB64mi8, X86::SUB32mi8, X86::SUB16mi8, 0);
2451 return SelectOpcode(X86::SBB64mi8, X86::SBB32mi8, X86::SBB16mi8, 0);
2453 return SelectOpcode(X86::AND64mi8, X86::AND32mi8, X86::AND16mi8, 0);
2455 return SelectOpcode(X86::OR64mi8, X86::OR32mi8, X86::OR16mi8, 0);
2457 return SelectOpcode(X86::XOR64mi8, X86::XOR32mi8, X86::XOR16mi8, 0);
2462 auto SelectImmOpcode = [SelectOpcode](
unsigned Opc) {
2465 return SelectOpcode(X86::ADD64mi32, X86::ADD32mi, X86::ADD16mi,
2468 return SelectOpcode(X86::ADC64mi32, X86::ADC32mi, X86::ADC16mi,
2471 return SelectOpcode(X86::SUB64mi32, X86::SUB32mi, X86::SUB16mi,
2474 return SelectOpcode(X86::SBB64mi32, X86::SBB32mi, X86::SBB16mi,
2477 return SelectOpcode(X86::AND64mi32, X86::AND32mi, X86::AND16mi,
2480 return SelectOpcode(X86::OR64mi32, X86::OR32mi, X86::OR16mi,
2483 return SelectOpcode(X86::XOR64mi32, X86::XOR32mi, X86::XOR16mi,
2490 unsigned NewOpc = SelectRegOpcode(Opc);
2495 if (
auto *OperandC = dyn_cast<ConstantSDNode>(Operand)) {
2496 auto OperandV = OperandC->getAPIntValue();
2502 ((MemVT !=
MVT::i8 && OperandV.getMinSignedBits() > 8 &&
2503 (-OperandV).getMinSignedBits() <= 8) ||
2504 (MemVT ==
MVT::i64 && OperandV.getMinSignedBits() > 32 &&
2505 (-OperandV).getMinSignedBits() <= 32)) &&
2507 OperandV = -OperandV;
2513 if (MemVT !=
MVT::i8 && OperandV.getMinSignedBits() <= 8) {
2514 Operand = CurDAG->getTargetConstant(OperandV,
SDLoc(Node), MemVT);
2515 NewOpc = SelectImm8Opcode(Opc);
2516 }
else if (OperandV.getActiveBits() <= MemVT.
getSizeInBits() &&
2517 (MemVT !=
MVT::i64 || OperandV.getMinSignedBits() <= 32)) {
2518 Operand = CurDAG->getTargetConstant(OperandV,
SDLoc(Node), MemVT);
2519 NewOpc = SelectImmOpcode(Opc);
2525 CurDAG->getCopyToReg(InputChain,
SDLoc(Node), X86::EFLAGS,
2526 StoredVal.getOperand(2),
SDValue());
2529 Segment, Operand, CopyTo, CopyTo.getValue(1)};
2534 Segment, Operand, InputChain};
2552 ReplaceUses(
SDValue(StoredVal.getNode(), 1),
SDValue(Result, 0));
2553 CurDAG->RemoveDeadNode(Node);
2558 bool X86DAGToDAGISel::matchBEXTRFromAnd(
SDNode *Node) {
2565 if (!Subtarget->hasBMI() && !Subtarget->hasTBM())
2583 if (!MaskCst || !ShiftCst)
2591 uint64_t Shift = ShiftCst->getZExtValue();
2596 if (Shift == 8 && MaskSize == 8)
2605 SDValue C = CurDAG->getConstant(Shift | (MaskSize << 8), dl, NVT);
2608 ReplaceNode(Node, New.
getNode());
2614 MachineSDNode *X86DAGToDAGISel::emitPCMPISTR(
unsigned ROpc,
unsigned MOpc,
2620 const ConstantInt *Val = cast<ConstantSDNode>(Imm)->getConstantIntValue();
2625 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
2630 SDValue Ops[] = { N0, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, Imm,
2633 MachineSDNode *CNode = CurDAG->getMachineNode(MOpc, dl, VTs, Ops);
2638 MemOp[0] = cast<LoadSDNode>(
Load)->getMemOperand();
2643 SDValue Ops[] = { N0, N1, Imm };
2645 MachineSDNode *CNode = CurDAG->getMachineNode(ROpc, dl, VTs, Ops);
2652 MachineSDNode *X86DAGToDAGISel::emitPCMPESTR(
unsigned ROpc,
unsigned MOpc,
2653 bool MayFoldLoad,
const SDLoc &dl,
2659 const ConstantInt *Val = cast<ConstantSDNode>(Imm)->getConstantIntValue();
2664 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
2669 SDValue Ops[] = { N0, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, Imm,
2672 MachineSDNode *CNode = CurDAG->getMachineNode(MOpc, dl, VTs, Ops);
2678 MemOp[0] = cast<LoadSDNode>(
Load)->getMemOperand();
2683 SDValue Ops[] = { N0, N2, Imm, InFlag };
2685 MachineSDNode *CNode = CurDAG->getMachineNode(ROpc, dl, VTs, Ops);
2697 bool X86DAGToDAGISel::shrinkAndImmediate(
SDNode *And) {
2713 APInt MaskVal = And1C->getAPIntValue();
2715 if (!MaskLZ || (VT ==
MVT::i64 && MaskLZ == 32))
2719 if (VT ==
MVT::i64 && MaskLZ >= 32) {
2721 MaskVal = MaskVal.
trunc(32);
2726 APInt NegMaskVal = MaskVal | HighZeros;
2736 NegMaskVal = NegMaskVal.zext(64);
2737 HighZeros = HighZeros.
zext(64);
2742 if (!CurDAG->MaskedValueIsZero(And0, HighZeros))
2747 if (NegMaskVal.isAllOnesValue()) {
2748 ReplaceNode(And, And0.
getNode());
2753 SDValue NewMask = CurDAG->getConstant(NegMaskVal,
SDLoc(And), VT);
2755 ReplaceNode(And, NewAnd.
getNode());
2774 if (Subtarget->isTargetNaCl())
2778 if (Subtarget->isTarget64BitILP32()) {
2787 ReplaceNode(Node, Brind.
getNode());
2788 SelectCode(ZextTarget.getNode());
2795 ReplaceNode(Node, getGlobalBaseReg());
2801 SDValue VSelect = CurDAG->getNode(
2804 ReplaceNode(Node, VSelect.
getNode());
2805 SelectCode(VSelect.
getNode());
2811 if (matchBEXTRFromAnd(Node))
2813 if (shrinkAndImmediate(Node))
2834 if (!Cst || !ShlCst)
2838 uint64_t ShlVal = ShlCst->getZExtValue();
2842 uint64_t RemovedBitsMask = (1ULL << ShlVal) - 1;
2843 if (Opcode !=
ISD::AND && (Val & RemovedBitsMask) != 0)
2846 unsigned ShlOp, AddOp,
Op;
2866 ShlOp = X86::SHL32ri;
2867 AddOp = X86::ADD32rr;
2871 case ISD::AND: Op = X86::AND32ri8;
break;
2872 case ISD::OR: Op = X86::OR32ri8;
break;
2873 case ISD::XOR: Op = X86::XOR32ri8;
break;
2878 ShlOp = X86::SHL64ri;
2879 AddOp = X86::ADD64rr;
2883 case ISD::AND: Op = CstVT==
MVT::i8? X86::AND64ri8 : X86::AND64ri32;
break;
2884 case ISD::OR: Op = CstVT==
MVT::i8? X86::OR64ri8 : X86::OR64ri32;
break;
2885 case ISD::XOR: Op = CstVT==
MVT::i8? X86::XOR64ri8 : X86::XOR64ri32;
break;
2891 SDValue NewCst = CurDAG->getTargetConstant(Val >> ShlVal, dl, CstVT);
2892 SDNode *New = CurDAG->getMachineNode(Op, dl, NVT, N0->
getOperand(0),NewCst);
2894 CurDAG->SelectNodeTo(Node, AddOp, NVT,
SDValue(New, 0),
2897 CurDAG->SelectNodeTo(Node, ShlOp, NVT,
SDValue(New, 0),
2898 getI8Imm(ShlVal, dl));
2906 unsigned Opc = (Opcode ==
X86ISD::SMUL8 ? X86::IMUL8r : X86::MUL8r);
2908 SDValue InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl,
X86::AL,
2913 SDNode *CNode = CurDAG->getMachineNode(Opc, dl, VTs, Ops);
2915 ReplaceNode(Node, CNode);
2923 unsigned LoReg, Opc;
2927 case MVT::i16: LoReg = X86::AX; Opc = X86::MUL16r;
break;
2929 case MVT::i64: LoReg = X86::RAX; Opc = X86::MUL64r;
break;
2932 SDValue InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, LoReg,
2937 SDNode *CNode = CurDAG->getMachineNode(Opc, dl, VTs, Ops);
2939 ReplaceNode(Node, CNode);
2950 bool hasBMI2 = Subtarget->hasBMI2();
2954 case MVT::i32: Opc = hasBMI2 ? X86::MULX32rr : X86::MUL32r;
2955 MOpc = hasBMI2 ? X86::MULX32rm : X86::MUL32m;
break;
2956 case MVT::i64: Opc = hasBMI2 ? X86::MULX64rr : X86::MUL64r;
2957 MOpc = hasBMI2 ? X86::MULX64rm : X86::MUL64m;
break;
2962 case MVT::i32: Opc = X86::IMUL32r; MOpc = X86::IMUL32m;
break;
2963 case MVT::i64: Opc = X86::IMUL64r; MOpc = X86::IMUL64m;
break;
2967 unsigned SrcReg, LoReg, HiReg;
2976 SrcReg = LoReg = X86::RAX; HiReg = X86::RDX;
2979 SrcReg =
X86::EDX; LoReg = HiReg = 0;
2982 SrcReg = X86::RDX; LoReg = HiReg = 0;
2986 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
2987 bool foldedLoad = tryFoldLoad(Node, N1, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4);
2990 foldedLoad = tryFoldLoad(Node, N0, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4);
2995 SDValue InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, SrcReg,
3004 if (MOpc == X86::MULX32rm || MOpc == X86::MULX64rm) {
3006 CNode = CurDAG->getMachineNode(MOpc, dl, VTs, Ops);
3013 CNode = CurDAG->getMachineNode(MOpc, dl, VTs, Ops);
3019 ReplaceUses(N1.
getValue(1), Chain);
3022 MemOp[0] = cast<LoadSDNode>(N1)->getMemOperand();
3025 SDValue Ops[] = { N1, InFlag };
3026 if (Opc == X86::MULX32rr || Opc == X86::MULX64rr) {
3028 SDNode *CNode = CurDAG->getMachineNode(Opc, dl, VTs, Ops);
3034 SDNode *CNode = CurDAG->getMachineNode(Opc, dl, VTs, Ops);
3040 if (!
SDValue(Node, 0).use_empty()) {
3042 assert(LoReg &&
"Register for low half is not defined!");
3043 ResLo = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl, LoReg, NVT,
3047 ReplaceUses(
SDValue(Node, 0), ResLo);
3054 assert(HiReg &&
"Register for high half is not defined!");
3055 ResHi = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl, HiReg, NVT,
3059 ReplaceUses(
SDValue(Node, 1), ResHi);
3064 CurDAG->RemoveDeadNode(Node);
3081 case MVT::i8: Opc = X86::DIV8r; MOpc = X86::DIV8m;
break;
3082 case MVT::i16: Opc = X86::DIV16r; MOpc = X86::DIV16m;
break;
3083 case MVT::i32: Opc = X86::DIV32r; MOpc = X86::DIV32m;
break;
3084 case MVT::i64: Opc = X86::DIV64r; MOpc = X86::DIV64m;
break;
3089 case MVT::i8: Opc = X86::IDIV8r; MOpc = X86::IDIV8m;
break;
3090 case MVT::i16: Opc = X86::IDIV16r; MOpc = X86::IDIV16m;
break;
3091 case MVT::i32: Opc = X86::IDIV32r; MOpc = X86::IDIV32m;
break;
3092 case MVT::i64: Opc = X86::IDIV64r; MOpc = X86::IDIV64m;
break;
3096 unsigned LoReg, HiReg, ClrReg;
3097 unsigned SExtOpcode;
3101 LoReg =
X86::AL; ClrReg = HiReg = X86::AH;
3102 SExtOpcode = X86::CBW;
3105 LoReg = X86::AX; HiReg = X86::DX;
3107 SExtOpcode = X86::CWD;
3111 SExtOpcode = X86::CDQ;
3114 LoReg = X86::RAX; ClrReg = HiReg = X86::RDX;
3115 SExtOpcode = X86::CQO;
3119 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
3120 bool foldedLoad = tryFoldLoad(Node, N1, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4);
3121 bool signBitIsZero = CurDAG->SignBitIsZero(N0);
3124 if (NVT ==
MVT::i8 && (!isSigned || signBitIsZero)) {
3127 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, Move, Chain;
3128 if (tryFoldLoad(Node, N0, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4)) {
3134 ReplaceUses(N0.
getValue(1), Chain);
3138 Chain = CurDAG->getEntryNode();
3144 CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl,
3145 LoReg, N0,
SDValue()).getValue(1);
3146 if (isSigned && !signBitIsZero) {
3152 SDValue ClrNode =
SDValue(CurDAG->getMachineNode(X86::MOV32r0, dl, NVT), 0);
3156 SDValue(CurDAG->getMachineNode(
3157 TargetOpcode::EXTRACT_SUBREG, dl,
MVT::i16, ClrNode,
3158 CurDAG->getTargetConstant(X86::sub_16bit, dl,
3166 SDValue(CurDAG->getMachineNode(
3167 TargetOpcode::SUBREG_TO_REG, dl,
MVT::i64,
3168 CurDAG->getTargetConstant(0, dl,
MVT::i64), ClrNode,
3169 CurDAG->getTargetConstant(X86::sub_32bit, dl,
3177 InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ClrReg,
3178 ClrNode, InFlag).getValue(1);
3192 MemOp[0] = cast<LoadSDNode>(N1)->getMemOperand();
3208 unsigned AHExtOpcode =
3209 isSigned ? X86::MOVSX32rr8_NOREX : X86::MOVZX32rr8_NOREX;
3211 SDNode *RNode = CurDAG->getMachineNode(AHExtOpcode, dl,
MVT::i32,
3221 CurDAG->getTargetExtractSubreg(X86::sub_8bit, dl,
MVT::i8, Result);
3223 ReplaceUses(
SDValue(Node, 1), Result);
3229 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3230 LoReg, NVT, InFlag);
3232 ReplaceUses(
SDValue(Node, 0), Result);
3238 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
3239 HiReg, NVT, InFlag);
3241 ReplaceUses(
SDValue(Node, 1), Result);
3245 CurDAG->RemoveDeadNode(Node);
3276 SubRegOp = X86::sub_8bit;
3278 }
else if (OptForMinSize &&
isUInt<16>(Mask) &&
3285 SubRegOp = X86::sub_16bit;
3295 SubRegOp = X86::sub_32bit;
3302 SDValue Imm = CurDAG->getTargetConstant(Mask, dl, VT);
3307 Reg = CurDAG->getTargetExtractSubreg(SubRegOp, dl, VT, Reg);
3310 SDNode *NewNode = CurDAG->getMachineNode(Op, dl,
MVT::i32, Reg, Imm);
3312 ReplaceNode(Node, NewNode);
3318 if (!Subtarget->hasSSE42())
3324 bool MayFoldLoad = !NeedIndex || !NeedMask;
3328 unsigned ROpc = Subtarget->hasAVX() ? X86::VPCMPISTRMrr : X86::PCMPISTRMrr;
3329 unsigned MOpc = Subtarget->hasAVX() ? X86::VPCMPISTRMrm : X86::PCMPISTRMrm;
3330 CNode = emitPCMPISTR(ROpc, MOpc, MayFoldLoad, dl,
MVT::v16i8, Node);
3333 if (NeedIndex || !NeedMask) {
3334 unsigned ROpc = Subtarget->hasAVX() ? X86::VPCMPISTRIrr : X86::PCMPISTRIrr;
3335 unsigned MOpc = Subtarget->hasAVX() ? X86::VPCMPISTRIrm : X86::PCMPISTRIrm;
3336 CNode = emitPCMPISTR(ROpc, MOpc, MayFoldLoad, dl,
MVT::i32, Node);
3342 CurDAG->RemoveDeadNode(Node);
3346 if (!Subtarget->hasSSE42())
3350 SDValue InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl,
X86::EAX,
3353 InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl,
X86::EDX,
3359 bool MayFoldLoad = !NeedIndex || !NeedMask;
3363 unsigned ROpc = Subtarget->hasAVX() ? X86::VPCMPESTRMrr : X86::PCMPESTRMrr;
3364 unsigned MOpc = Subtarget->hasAVX() ? X86::VPCMPESTRMrm : X86::PCMPESTRMrm;
3365 CNode = emitPCMPESTR(ROpc, MOpc, MayFoldLoad, dl,
MVT::v16i8, Node,
3369 if (NeedIndex || !NeedMask) {
3370 unsigned ROpc = Subtarget->hasAVX() ? X86::VPCMPESTRIrr : X86::PCMPESTRIrr;
3371 unsigned MOpc = Subtarget->hasAVX() ? X86::VPCMPESTRIrm : X86::PCMPESTRIrm;
3372 CNode = emitPCMPESTR(ROpc, MOpc, MayFoldLoad, dl,
MVT::i32, Node, InFlag);
3377 CurDAG->RemoveDeadNode(Node);
3382 if (foldLoadStoreIntoMemOperand(Node))
3390 bool X86DAGToDAGISel::
3391 SelectInlineAsmMemoryOperand(
const SDValue &Op,
unsigned ConstraintID,
3392 std::vector<SDValue> &OutOps) {
3393 SDValue Op0, Op1, Op2, Op3, Op4;
3394 switch (ConstraintID) {
3405 if (!selectAddr(
nullptr, Op, Op0, Op1, Op2, Op3, Op4))
3410 OutOps.push_back(Op0);
3411 OutOps.push_back(Op1);
3412 OutOps.push_back(Op2);
3413 OutOps.push_back(Op3);
3414 OutOps.push_back(Op4);
3422 return new X86DAGToDAGISel(TM, OptLevel);
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
constexpr bool isUInt< 32 >(uint64_t x)
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
static bool isCalleeLoad(SDValue Callee, SDValue &Chain, bool HasCallSeq)
Return true if call address is a load and it can be moved below CALLSEQ_START and the chains leading ...
void push_back(const T &Elt)
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
EVT getValueType() const
Return the ValueType of the referenced return value.
Vector comparison generating mask bits for fp and integer signed and unsigned data types...
static GCMetadataPrinterRegistry::Add< ErlangGCPrinter > X("erlang", "erlang-compatible garbage collector")
const SDValue & getOffset() const
APInt getSignedMax() const
Return the largest signed value contained in the ConstantRange.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
C - The default llvm calling convention, compatible with C.
DELETED_NODE - This is an illegal value that is used to catch errors.
Compute iterated dominance frontiers using a linear time algorithm.
static void insertDAGNode(SelectionDAG &DAG, SDValue Pos, SDValue N)
static bool isLegalMaskCompare(SDNode *N, const X86Subtarget *Subtarget)
void setMemRefs(mmo_iterator NewMemRefs, mmo_iterator NewMemRefsEnd)
Assign this MachineSDNodes's memory reference descriptor list.
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
bool isVector() const
Return true if this is a vector value type.
const SDValue & getBasePtr() const
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
APInt zext(unsigned width) const
Zero extend to a new width.
bool slt(const APInt &RHS) const
Signed less than comparison.
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
const SDValue & getChain() const
constexpr bool isInt< 8 >(int64_t x)
ISD::MemIndexedMode getAddressingMode() const
Return the addressing mode for this load or store: unindexed, pre-inc, pre-dec, post-inc, or post-dec.
TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or anything else with this node...
unsigned getAlignment() const
APInt trunc(unsigned width) const
Truncate to new width.
STATISTIC(NumFunctions, "Total number of functions")
MVT getSimpleValueType(unsigned ResNo) const
Return the type of a specified result as a simple type.
void setNodeId(int Id)
Set unique node id.
SDNode * getNode() const
get the SDNode which holds the desired result
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
INSERT_SUBVECTOR(VECTOR1, VECTOR2, IDX) - Returns a vector with VECTOR2 inserted into VECTOR1 at the ...
std::size_t countLeadingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the most significant bit to the least stopping at the first 1...
static bool MayFoldLoad(SDValue Op)
bool hasOneUse() const
Return true if there is exactly one node using value ResNo of Node.
unsigned getBitWidth() const
Return the number of bits in the APInt.
RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) This node represents a target in...
GlobalBaseReg - On Darwin, this node represents the result of the mflr at function entry...
static bool hasPredecessorHelper(const SDNode *N, SmallPtrSetImpl< const SDNode *> &Visited, SmallVectorImpl< const SDNode *> &Worklist, unsigned int MaxSteps=0, bool TopologicalPrune=false)
Returns true if N is a predecessor of any node in Worklist.
unsigned getAddrSpace() const
Return the LLVM IR address space number that this pointer points into.
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
X86 compare and logical compare instructions.
void dump() const
Support for debugging, callable in GDB: V->dump()
The address of a basic block.
bool hasOneUse() const
Return true if there is exactly one use of this node.
A description of a memory reference used in the backend.
Shift and rotation operations.
bool isNormalStore(const SDNode *N)
Returns true if the specified node is a non-truncating and unindexed store.
std::size_t countTrailingOnes(T Value, ZeroBehavior ZB=ZB_Width)
Count the number of ones from the least significant bit to the first zero bit.
bool isBuildVectorAllZeros(const SDNode *N)
Return true if the specified node is a BUILD_VECTOR where all of the elements are 0 or undef...
CallLoweringInfo & setChain(SDValue InChain)
CopyToReg - This node has three operands: a chain, a register number to set to this value...
op_iterator op_end() const
uint64_t getConstantOperandVal(unsigned i) const
ISD::LoadExtType getExtensionType() const
Return whether this is a plain node, or one of the varieties of value-extending loads.
unsigned getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of a call sequence, and carry arbitrary information that target might want to know.
Position
Position to insert a new instruction relative to an existing instruction.
This class defines information used to lower LLVM code to legal SelectionDAG operators that the targe...
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
unsigned getSizeInBits() const
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
bool hasExternalLinkage() const
int64_t getSExtValue() const
static void InvalidateNodeId(SDNode *N)
unsigned getSizeInBits() const
Return the size of the specified value type in bits.
X86 FP SETCC, similar to above, but with output as an i1 mask and with optional rounding mode...
constexpr bool isMask_64(uint64_t Value)
Return true if the argument is a non-empty sequence of ones starting at the least significant bit wit...
Select with a vector condition (op #0) and two vector operands (ops #1 and #2), returning a vector re...
Simple integer binary arithmetic operators.
op_iterator op_begin() const
ArrayRef< SDUse > ops() const
amdgpu Simplify well known AMD library false Value * Callee
bool use_empty() const
Return true if there are no nodes using value ResNo of Node.
This class is used to represent ISD::STORE nodes.
static bool isFusableLoadOpStorePattern(StoreSDNode *StoreNode, SDValue StoredVal, SelectionDAG *CurDAG, LoadSDNode *&LoadNode, SDValue &InputChain)
Check whether or not the chain ending in StoreNode is suitable for doing the {load; op; store} to mod...
bool isOneConstant(SDValue V)
Returns true if V is a constant integer one.
MVT getSimpleValueType() const
Return the simple ValueType of the referenced return value.
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
const SDValue & getBasePtr() const
bool isNormalLoad(const SDNode *N)
Returns true if the specified node is a non-extending and unindexed load.
OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...) This node represents a target intrin...
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
constexpr bool isUInt< 8 >(uint64_t x)
std::size_t countTrailingZeros(T Val, ZeroBehavior ZB=ZB_Width)
Count number of 0's from the least significant bit to the most stopping at the first 1...
use_iterator use_begin() const
Provide iteration support to walk over all uses of an SDNode.
LOCAL_RECOVER - Represents the llvm.localrecover intrinsic.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
static bool foldMaskedShiftToScaledMask(SelectionDAG &DAG, SDValue N, uint64_t Mask, SDValue Shift, SDValue X, X86ISelAddressMode &AM)
bool hasAnyUseOfValue(unsigned Value) const
Return true if there are any use of the indicated value.
bool isMachineOpcode() const
unsigned getScalarSizeInBits() const
bool ult(const APInt &RHS) const
Unsigned less than comparison.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
const SDValue & getOperand(unsigned Num) const
bool isOperandOf(const SDNode *N) const
Return true if this node is an operand of N.
const SDValue & getOffset() const
APInt getUnsignedMax() const
Return the largest unsigned value contained in the ConstantRange.
static Type * getVoidTy(LLVMContext &C)
This class provides iterator support for SDUse operands that use a specific SDNode.
unsigned getMachineOpcode() const
void RepositionNode(allnodes_iterator Position, SDNode *N)
Move node N in the AllNodes list to be immediately before the given iterator Position.
void ReplaceAllUsesWith(SDValue From, SDValue To)
Modify anything using 'From' to use 'To' instead.
static bool hasNoCarryFlagUses(SDNode *N)
Test whether the given node which sets flags has any uses which require the CF flag to be accurate...
FunctionPass class - This class is used to implement most global optimizations.
On Darwin, this node represents the result of the popl at function entry, used for PIC code...
self_iterator getIterator()
bool hasNUsesOfValue(unsigned NUses, unsigned Value) const
Return true if there are exactly NUSES uses of the indicated value.
static bool foldMaskAndShiftToExtract(SelectionDAG &DAG, SDValue N, uint64_t Mask, SDValue Shift, SDValue X, X86ISelAddressMode &AM)
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
std::vector< ArgListEntry > ArgListTy
This structure contains all information that is necessary for lowering calls.
APInt getSignedMin() const
Return the smallest signed value contained in the ConstantRange.
This class contains a discriminated union of information about pointers in memory operands...
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode...
unsigned getNumOperands() const
Return the number of values used by this operation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
bool use_empty() const
Return true if there are no uses of this node.
These operations represent an abstract X86 call instruction, which includes a bunch of information...
TokenFactor - This node takes multiple tokens as input and produces a single token result...
void dump() const
Dump this node, for debugging.
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
unsigned countPopulation(T Value)
Count the number of set bits in a value.
This is the shared class of boolean and integer constants.
constexpr bool isInt< 32 >(int64_t x)
bool isScalarFPTypeInSSEReg(EVT VT) const
Return true if the specified scalar FP type is computed in an SSE register, not on the X87 floating p...
SDNode * UpdateNodeOperands(SDNode *N, SDValue Op)
Mutate the specified node in-place to have the specified operands.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
An SDNode that represents everything that will be needed to construct a MachineInstr.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
SelectionDAGISel - This is the common base class used for SelectionDAG-based pattern-matching instruc...
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
static bool foldMaskAndShiftToScale(SelectionDAG &DAG, SDValue N, uint64_t Mask, SDValue Shift, SDValue X, X86ISelAddressMode &AM)
EVT getMemoryVT() const
Return the type of the in-memory value.
Target - Wrapper for Target specific information.
Class for arbitrary precision integers.
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
bool sge(const APInt &RHS) const
Signed greater or equal comparison.
static use_iterator use_end()
ZERO_EXTEND - Used for integer types, zeroing the new bits.
ANY_EXTEND - Used for integer types. The high bits are undefined.
void append(in_iter in_start, in_iter in_end)
Add the specified range to the end of the SmallVector.
static bool hasSingleUsesFromRoot(SDNode *Root, SDNode *User)
bool is256BitVector() const
Return true if this is a 256-bit vector type.
int getNodeId() const
Return the unique node id.
static bool isDispSafeForFrameIndex(int64_t Val)
std::pair< SDValue, SDValue > LowerCallTo(CallLoweringInfo &CLI) const
This function lowers an abstract call to a function into an actual call.
const SDValue & getValue() const
Bitwise operators - logical and, logical or, logical xor.
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
bool is128BitVector() const
Return true if this is a 128-bit vector type.
A wrapper node for TargetConstantPool, TargetJumpTable, TargetExternalSymbol, TargetGlobalAddress, TargetGlobalTLSAddress, MCSymbol and TargetBlockAddress.
FunctionPass * createX86ISelDag(X86TargetMachine &TM, CodeGenOpt::Level OptLevel)
This pass converts a legalized DAG into a X86-specific DAG, ready for instruction scheduling...
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.
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
StringRef getName() const
Return a constant reference to the value's name.
static bool isSigned(Value *V)
Can the given value generate sign bits.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool isNON_EXTLoad(const SDNode *N)
Returns true if the specified node is a non-extending load.
unsigned getOpcode() const
SDValue getValue(unsigned R) const
constexpr bool isUInt< 16 >(uint64_t x)
static bool hasNoSignedComparisonUses(SDNode *N)
Test whether the given X86ISD::CMP node has any uses which require the SF or OF bits to be accurate...
CopyFromReg - This node indicates that the input value is a virtual or physical register that is defi...
SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
const MachinePointerInfo & getPointerInfo() const
This class is used to form a handle around another node that is persistent and is updated across invo...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getMinSignedBits() const
Get the minimum bit size for this signed APInt.
uint64_t getConstantOperandVal(unsigned Num) const
Helper method returns the integer value of a ConstantSDNode operand.
unsigned getResNo() const
get the index which selects a specific result in the SDNode
Dynamic (non-constant condition) vector blend where only the sign bits of the condition elements are ...
unsigned getMachineOpcode() const
This may only be called if isMachineOpcode returns true.
bool isNullConstant(SDValue V)
Returns true if V is a constant integer zero.
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.
bool isNonTemporal() const
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
bool isZeroNode(SDValue Elt)
Returns true if Elt is a constant zero or floating point constant +0.0.
StringRef - Represent a constant reference to a string, i.e.
SetCC operator - This evaluates to a true value iff the condition is true.
unsigned countLeadingZeros() const
The APInt version of the countLeadingZeros functions in MathExtras.h.
bool isOffsetSuitableForCodeModel(int64_t Offset, CodeModel::Model M, bool hasSymbolicDisplacement=true)
Returns true of the given offset can be fit into displacement field of the instruction.
unsigned getNumOperands() const
const SDValue & getOperand(unsigned i) const
uint64_t getZExtValue() const
TRUNCATE - Completely drop the high bits.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a scalar value into element 0 of the...
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
static void moveBelowOrigChain(SelectionDAG *CurDAG, SDValue Load, SDValue Call, SDValue OrigChain)
Replace the original chain operand of the call with load's chain operand and move load below the call...
Carry-using nodes for multiple precision addition and subtraction.
Special wrapper used under X86-64 PIC mode for RIP relative displacements.
This class is used to represent ISD::LOAD nodes.
static int getUninvalidatedNodeId(SDNode *N)