23 #include "llvm/Config/llvm-config.h" 28 #include "llvm/IR/IntrinsicsX86.h" 40 #define DEBUG_TYPE "x86-isel" 42 STATISTIC(NumLoadMoved,
"Number of loads moved below TokenFactor");
45 cl::desc(
"Enable setting constant bits to reduce size of mask immediates"),
55 struct X86ISelAddressMode {
77 bool NegateIndex =
false;
80 : BaseType(RegBase), Base_FrameIndex(0), Scale(1), IndexReg(), Disp(0),
81 Segment(), GV(nullptr), CP(nullptr), BlockAddr(nullptr), ES(nullptr),
82 MCSym(nullptr), JT(-1), Align(0), SymbolFlags(X86II::
MO_NO_FLAG) {}
84 bool hasSymbolicDisplacement()
const {
85 return GV !=
nullptr || CP !=
nullptr || ES !=
nullptr ||
86 MCSym !=
nullptr || JT != -1 || BlockAddr !=
nullptr;
89 bool hasBaseOrIndexReg()
const {
90 return BaseType == FrameIndexBase ||
96 if (BaseType != RegBase)
return false;
98 dyn_cast_or_null<RegisterSDNode>(Base_Reg.
getNode()))
99 return RegNode->getReg() == X86::RIP;
108 #if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP) 110 dbgs() <<
"X86ISelAddressMode " <<
this <<
'\n';
111 dbgs() <<
"Base_Reg ";
116 if (BaseType == FrameIndexBase)
117 dbgs() <<
" Base.FrameIndex " << Base_FrameIndex <<
'\n';
118 dbgs() <<
" Scale " << Scale <<
'\n' 126 dbgs() <<
" Disp " << Disp <<
'\n' 148 dbgs() <<
" JT" << JT <<
" Align" << Align <<
'\n';
172 bool IndirectTlsSegRefs;
177 OptForMinSize(
false), IndirectTlsSegRefs(
false) {}
180 return "X86 DAG->DAG Instruction Selection";
187 "indirect-tls-seg-refs");
192 assert((!OptForMinSize || OptForSize) &&
193 "OptForMinSize implies OptForSize");
199 void EmitFunctionEntryCode()
override;
203 void PreprocessISelDAG()
override;
204 void PostprocessISelDAG()
override;
207 #include "X86GenDAGISel.inc" 212 bool foldOffsetIntoAddress(uint64_t
Offset, X86ISelAddressMode &AM);
213 bool matchLoadInAddress(
LoadSDNode *
N, X86ISelAddressMode &AM);
214 bool matchWrapper(
SDValue N, X86ISelAddressMode &AM);
215 bool matchAddress(
SDValue N, X86ISelAddressMode &AM);
216 bool matchVectorAddress(
SDValue N, X86ISelAddressMode &AM);
217 bool matchAdd(
SDValue &
N, X86ISelAddressMode &AM,
unsigned Depth);
218 bool matchAddressRecursively(
SDValue N, X86ISelAddressMode &AM,
220 bool matchAddressBase(
SDValue N, X86ISelAddressMode &AM);
254 return tryFoldLoad(P, P, N, Base, Scale, Index, Disp, Segment);
263 bool SelectInlineAsmMemoryOperand(
const SDValue &
Op,
264 unsigned ConstraintID,
265 std::vector<SDValue> &OutOps)
override;
267 void emitSpecialCodeForMain();
269 inline void getAddressOperands(X86ISelAddressMode &AM,
const SDLoc &DL,
273 if (AM.BaseType == X86ISelAddressMode::FrameIndexBase)
274 Base = CurDAG->getTargetFrameIndex(
275 AM.Base_FrameIndex, TLI->getPointerTy(CurDAG->getDataLayout()));
276 else if (AM.Base_Reg.getNode())
279 Base = CurDAG->getRegister(0, VT);
281 Scale = getI8Imm(AM.Scale, DL);
284 if (AM.NegateIndex) {
285 unsigned NegOpc = VT ==
MVT::i64 ? X86::NEG64r : X86::NEG32r;
291 if (AM.IndexReg.getNode())
294 Index = CurDAG->getRegister(0, VT);
299 Disp = CurDAG->getTargetGlobalAddress(AM.GV,
SDLoc(),
303 Disp = CurDAG->getTargetConstantPool(AM.CP,
MVT::i32,
304 AM.Align, AM.Disp, AM.SymbolFlags);
306 assert(!AM.Disp &&
"Non-zero displacement is ignored with ES.");
307 Disp = CurDAG->getTargetExternalSymbol(AM.ES,
MVT::i32, AM.SymbolFlags);
308 }
else if (AM.MCSym) {
309 assert(!AM.Disp &&
"Non-zero displacement is ignored with MCSym.");
310 assert(AM.SymbolFlags == 0 &&
"oo");
311 Disp = CurDAG->getMCSymbol(AM.MCSym,
MVT::i32);
312 }
else if (AM.JT != -1) {
313 assert(!AM.Disp &&
"Non-zero displacement is ignored with JT.");
314 Disp = CurDAG->getTargetJumpTable(AM.JT,
MVT::i32, AM.SymbolFlags);
315 }
else if (AM.BlockAddr)
316 Disp = CurDAG->getTargetBlockAddress(AM.BlockAddr,
MVT::i32, AM.Disp,
319 Disp = CurDAG->getTargetConstant(AM.Disp, DL,
MVT::i32);
321 if (AM.Segment.getNode())
322 Segment = AM.Segment;
324 Segment = CurDAG->getRegister(0,
MVT::i16);
333 bool shouldAvoidImmediateInstFormsForSize(
SDNode *
N)
const {
339 if (!CurDAG->shouldOptForSize())
344 UE = N->
use_end(); (UI != UE) && (UseCount < 2); ++UI) {
393 (RegNode = dyn_cast_or_null<RegisterSDNode>(
395 if ((RegNode->getReg() ==
X86::ESP) ||
396 (RegNode->getReg() == X86::RSP))
405 return (UseCount > 1);
409 inline SDValue getI8Imm(
unsigned Imm,
const SDLoc &DL) {
410 return CurDAG->getTargetConstant(Imm, DL,
MVT::i8);
414 inline SDValue getI32Imm(
unsigned Imm,
const SDLoc &DL) {
415 return CurDAG->getTargetConstant(Imm, DL,
MVT::i32);
419 inline SDValue getI64Imm(uint64_t Imm,
const SDLoc &DL) {
420 return CurDAG->getTargetConstant(Imm, DL,
MVT::i64);
423 SDValue getExtractVEXTRACTImmediate(
SDNode *N,
unsigned VecWidth,
425 assert((VecWidth == 128 || VecWidth == 256) &&
"Unexpected vector width");
431 SDValue getInsertVINSERTImmediate(
SDNode *N,
unsigned VecWidth,
433 assert((VecWidth == 128 || VecWidth == 256) &&
"Unexpected vector width");
441 bool isUnneededShiftMask(
SDNode *N,
unsigned Width)
const {
443 const APInt &Val = cast<ConstantSDNode>(N->
getOperand(1))->getAPIntValue();
445 if (Val.countTrailingOnes() >=
Width)
455 SDNode *getGlobalBaseReg();
466 return Subtarget->getInstrInfo();
472 bool ComplexPatternFuncMutatesDAG()
const override {
476 bool isSExtAbsoluteSymbolRef(
unsigned Width,
SDNode *N)
const;
480 template <
unsigned W
idth>
bool isSExtRelocImm(
SDNode *N)
const {
481 if (
auto *CN = dyn_cast<ConstantSDNode>(N))
482 return isInt<Width>(CN->getSExtValue());
483 return isSExtAbsoluteSymbolRef(Width, N);
487 bool useNonTemporalLoad(
LoadSDNode *N)
const {
502 return Subtarget->hasSSE41();
504 return Subtarget->hasAVX2();
506 return Subtarget->hasAVX512();
510 bool foldLoadStoreIntoMemOperand(
SDNode *Node);
512 bool matchBitExtract(
SDNode *Node);
513 bool shrinkAndImmediate(
SDNode *N);
514 bool isMaskZeroExtended(
SDNode *N)
const;
515 bool tryShiftAmountMod(
SDNode *N);
516 bool combineIncDecVector(
SDNode *Node);
517 bool tryShrinkShlLogicImm(
SDNode *N);
519 bool tryMatchBitSelect(
SDNode *N);
527 bool tryOptimizeRem8Extend(
SDNode *N);
529 bool onlyUsesZeroFlag(
SDValue Flags)
const;
530 bool hasNoSignFlagUses(
SDValue Flags)
const;
531 bool hasNoCarryFlagUses(
SDValue Flags)
const;
552 return Subtarget->
hasVLX();
566 bool X86DAGToDAGISel::isMaskZeroExtended(
SDNode *N)
const {
594 if (useNonTemporalLoad(cast<LoadSDNode>(N)))
626 if (Imm->getAPIntValue().isSignedIntN(8))
635 Imm->getAPIntValue().getBitWidth() == 64 &&
636 Imm->getAPIntValue().isIntN(32))
643 (Imm->getAPIntValue() == UINT8_MAX ||
644 Imm->getAPIntValue() == UINT16_MAX ||
645 Imm->getAPIntValue() == UINT32_MAX))
651 (-Imm->getAPIntValue()).isSignedIntN(8))
689 if (
C &&
C->getSExtValue() == -2)
695 if (
C &&
C->getSExtValue() == -2)
737 "Unexpected chain operand");
789 if (isa<MemSDNode>(Chain.
getNode()) &&
790 cast<MemSDNode>(Chain.
getNode())->writeMem())
801 void X86DAGToDAGISel::PreprocessISelDAG() {
803 E = CurDAG->allnodes_end();
I !=
E; ) {
812 CurDAG->ReplaceAllUsesOfValueWith(
SDValue(N, 0), Res);
814 CurDAG->DeleteNode(N);
850 CurDAG->ReplaceAllUsesWith(N, Res.
getNode());
852 CurDAG->DeleteNode(N);
873 CurDAG->ReplaceAllUsesOfValueWith(
SDValue(N, 0), Res);
875 CurDAG->DeleteNode(N);
893 CurDAG->ReplaceAllUsesOfValueWith(
SDValue(N, 0), Res);
895 CurDAG->DeleteNode(N);
931 CurDAG->getTargetConstant(Imm, dl,
MVT::i8)});
935 CurDAG->getTargetConstant(Imm, dl,
MVT::i8));
937 CurDAG->ReplaceAllUsesWith(N, Res.
getNode());
939 CurDAG->DeleteNode(N);
960 if (Subtarget->hasSSE2()) {
972 Res = CurDAG->getNode(Opc, dl, IntVT, Op0, Op1);
975 Res = CurDAG->getNode(N->
getOpcode(), dl, VecVT, Op0, Op1);
978 CurDAG->getIntPtrConstant(0, dl));
980 CurDAG->ReplaceAllUsesOfValueWith(
SDValue(N, 0), Res);
982 CurDAG->DeleteNode(N);
990 !Subtarget->useRetpolineIndirectCalls() &&
993 (Subtarget->is64Bit() ||
994 !getTargetMachine().isPositionIndependent())))) {
1050 if (SrcIsSSE && DstIsSSE)
1053 if (!SrcIsSSE && !DstIsSSE) {
1066 SDValue MemTmp = CurDAG->CreateStackTemporary(MemVT);
1081 CurDAG->ReplaceAllUsesOfValueWith(
SDValue(N, 0), Result);
1103 if (SrcIsSSE && DstIsSSE)
1106 if (!SrcIsSSE && !DstIsSSE) {
1119 SDValue MemTmp = CurDAG->CreateStackTemporary(MemVT);
1129 Store = CurDAG->getMemIntrinsicNode(
X86ISD::FST, dl, VTs, Ops, MemVT,
1138 assert(SrcVT == MemVT &&
"Unexpected VT!");
1146 Result = CurDAG->getMemIntrinsicNode(
X86ISD::FLD, dl, VTs, Ops, MemVT,
1155 assert(DstVT == MemVT &&
"Unexpected VT!");
1165 CurDAG->ReplaceAllUsesWith(N, Result.
getNode());
1174 CurDAG->DeleteNode(N);
1180 CurDAG->RemoveDeadNodes();
1184 bool X86DAGToDAGISel::tryOptimizeRem8Extend(
SDNode *N) {
1186 if (Opc != X86::MOVZX32rr8 && Opc != X86::MOVSX32rr8 &&
1187 Opc != X86::MOVSX64rr8)
1199 unsigned ExpectedOpc = Opc == X86::MOVZX32rr8 ? X86::MOVZX32rr8_NOREX
1200 : X86::MOVSX32rr8_NOREX;
1205 if (Opc == X86::MOVSX64rr8) {
1210 ReplaceUses(N, Extend);
1213 ReplaceUses(N, N00.
getNode());
1219 void X86DAGToDAGISel::PostprocessISelDAG() {
1226 bool MadeChange =
false;
1227 while (Position != CurDAG->allnodes_begin()) {
1233 if (tryOptimizeRem8Extend(N)) {
1241 if ((Opc == X86::TEST8rr || Opc == X86::TEST16rr ||
1242 Opc == X86::TEST32rr || Opc == X86::TEST64rr) &&
1248 if (N0Opc == X86::AND8rr || N0Opc == X86::AND16rr ||
1249 N0Opc == X86::AND32rr || N0Opc == X86::AND64rr) {
1254 ReplaceUses(N, Test);
1258 if (N0Opc == X86::AND8rm || N0Opc == X86::AND16rm ||
1259 N0Opc == X86::AND32rm || N0Opc == X86::AND64rm) {
1262 case X86::AND8rm: NewOpc = X86::TEST8mr;
break;
1263 case X86::AND16rm: NewOpc = X86::TEST16mr;
break;
1264 case X86::AND32rm: NewOpc = X86::TEST32mr;
break;
1265 case X86::AND64rm: NewOpc = X86::TEST64mr;
break;
1278 ReplaceUses(N, Test);
1288 if ((Opc == X86::KORTESTBrr || Opc == X86::KORTESTWrr ||
1289 Opc == X86::KORTESTDrr || Opc == X86::KORTESTQrr) &&
1293 onlyUsesZeroFlag(
SDValue(N, 0))) {
1298 if (N0Opc == X86::KANDBrr ||
1299 (N0Opc == X86::KANDWrr && Subtarget->hasDQI()) ||
1300 N0Opc == X86::KANDDrr || N0Opc == X86::KANDQrr) {
1304 case X86::KORTESTBrr: NewOpc = X86::KTESTBrr;
break;
1305 case X86::KORTESTWrr: NewOpc = X86::KTESTWrr;
break;
1306 case X86::KORTESTDrr: NewOpc = X86::KTESTDrr;
break;
1307 case X86::KORTESTQrr: NewOpc = X86::KTESTQrr;
break;
1313 ReplaceUses(N, KTest);
1320 if (Opc != TargetOpcode::SUBREG_TO_REG)
1324 if (SubRegIdx != X86::sub_xmm && SubRegIdx != X86::sub_ymm)
1335 case X86::VMOVAPDrr:
case X86::VMOVUPDrr:
1336 case X86::VMOVAPSrr:
case X86::VMOVUPSrr:
1337 case X86::VMOVDQArr:
case X86::VMOVDQUrr:
1338 case X86::VMOVAPDYrr:
case X86::VMOVUPDYrr:
1339 case X86::VMOVAPSYrr:
case X86::VMOVUPSYrr:
1340 case X86::VMOVDQAYrr:
case X86::VMOVDQUYrr:
1341 case X86::VMOVAPDZ128rr:
case X86::VMOVUPDZ128rr:
1342 case X86::VMOVAPSZ128rr:
case X86::VMOVUPSZ128rr:
1343 case X86::VMOVDQA32Z128rr:
case X86::VMOVDQU32Z128rr:
1344 case X86::VMOVDQA64Z128rr:
case X86::VMOVDQU64Z128rr:
1345 case X86::VMOVAPDZ256rr:
case X86::VMOVUPDZ256rr:
1346 case X86::VMOVAPSZ256rr:
case X86::VMOVUPSZ256rr:
1347 case X86::VMOVDQA32Z256rr:
case X86::VMOVDQU32Z256rr:
1348 case X86::VMOVDQA64Z256rr:
case X86::VMOVDQU64Z256rr:
1362 (TSFlags & X86II::EncodingMask) !=
X86II::XOP)
1372 CurDAG->RemoveDeadNodes();
1377 void X86DAGToDAGISel::emitSpecialCodeForMain() {
1378 if (Subtarget->isTargetCygMing()) {
1380 auto &DL = CurDAG->getDataLayout();
1385 CurDAG->getExternalSymbol(
"__main", TLI->getPointerTy(DL)),
1388 std::pair<SDValue, SDValue> Result = TLI.
LowerCallTo(CLI);
1389 CurDAG->setRoot(Result.second);
1393 void X86DAGToDAGISel::EmitFunctionEntryCode() {
1397 emitSpecialCodeForMain();
1407 return isInt<31>(Val);
1410 bool X86DAGToDAGISel::foldOffsetIntoAddress(uint64_t
Offset,
1411 X86ISelAddressMode &AM) {
1417 if (AM.ES || AM.MCSym)
1420 int64_t Val = AM.Disp +
Offset;
1422 if (Subtarget->is64Bit()) {
1424 AM.hasSymbolicDisplacement()))
1428 if (AM.BaseType == X86ISelAddressMode::FrameIndexBase &&
1437 bool X86DAGToDAGISel::matchLoadInAddress(
LoadSDNode *N, X86ISelAddressMode &AM){
1447 if (
C->getSExtValue() == 0 && AM.Segment.getNode() ==
nullptr &&
1448 !IndirectTlsSegRefs &&
1449 (Subtarget->isTargetGlibc() || Subtarget->isTargetAndroid() ||
1450 Subtarget->isTargetFuchsia()))
1468 bool X86DAGToDAGISel::matchWrapper(
SDValue N, X86ISelAddressMode &AM) {
1471 if (AM.hasSymbolicDisplacement())
1474 bool IsRIPRelTLS =
false;
1488 if (Subtarget->is64Bit() &&
1494 if (IsRIPRel && AM.hasBaseOrIndexReg())
1498 X86ISelAddressMode Backup = AM;
1503 AM.GV =
G->getGlobal();
1504 AM.SymbolFlags =
G->getTargetFlags();
1505 Offset =
G->getOffset();
1507 AM.CP = CP->getConstVal();
1508 AM.Align = CP->getAlignment();
1509 AM.SymbolFlags = CP->getTargetFlags();
1510 Offset = CP->getOffset();
1512 AM.ES = S->getSymbol();
1513 AM.SymbolFlags = S->getTargetFlags();
1514 }
else if (
auto *S = dyn_cast<MCSymbolSDNode>(N0)) {
1515 AM.MCSym = S->getMCSymbol();
1517 AM.JT = J->getIndex();
1518 AM.SymbolFlags = J->getTargetFlags();
1520 AM.BlockAddr = BA->getBlockAddress();
1521 AM.SymbolFlags = BA->getTargetFlags();
1522 Offset = BA->getOffset();
1526 if (foldOffsetIntoAddress(Offset, AM)) {
1532 AM.setBaseReg(CurDAG->getRegister(X86::RIP,
MVT::i64));
1540 bool X86DAGToDAGISel::matchAddress(
SDValue N, X86ISelAddressMode &AM) {
1541 if (matchAddressRecursively(N, AM, 0))
1546 if (AM.Scale == 2 &&
1547 AM.BaseType == X86ISelAddressMode::RegBase &&
1548 AM.Base_Reg.getNode() ==
nullptr) {
1549 AM.Base_Reg = AM.IndexReg;
1556 switch (
TM.getCodeModel()) {
1560 if (Subtarget->is64Bit() &&
1562 AM.BaseType == X86ISelAddressMode::RegBase &&
1563 AM.Base_Reg.getNode() ==
nullptr &&
1564 AM.IndexReg.getNode() ==
nullptr &&
1566 AM.hasSymbolicDisplacement())
1567 AM.Base_Reg = CurDAG->getRegister(X86::RIP,
MVT::i64);
1574 bool X86DAGToDAGISel::matchAdd(
SDValue &N, X86ISelAddressMode &AM,
1580 X86ISelAddressMode Backup = AM;
1581 if (!matchAddressRecursively(N.
getOperand(0), AM, Depth+1) &&
1595 if (AM.BaseType == X86ISelAddressMode::RegBase &&
1596 !AM.Base_Reg.getNode() &&
1597 !AM.IndexReg.getNode()) {
1634 X86ISelAddressMode &AM) {
1641 if (ScaleLog <= 0 || ScaleLog >= 4 ||
1642 Mask != (0xffu << ScaleLog))
1668 AM.Scale = (1 << ScaleLog);
1676 X86ISelAddressMode &AM) {
1682 int64_t Mask = cast<ConstantSDNode>(N->
getOperand(1))->getSExtValue();
1687 bool FoundAnyExtend =
false;
1691 FoundAnyExtend =
true;
1709 if (ShiftAmt != 1 && ShiftAmt != 2 && ShiftAmt != 3)
1714 if (FoundAnyExtend) {
1735 AM.Scale = 1 << ShiftAmt;
1736 AM.IndexReg = NewAnd;
1770 X86ISelAddressMode &AM) {
1781 unsigned AMShiftAmt = MaskTZ;
1785 if (AMShiftAmt <= 0 || AMShiftAmt > 3)
return true;
1793 if (MaskLZ < ScaleDown)
1795 MaskLZ -= ScaleDown;
1803 bool ReplacingAnyExtend =
false;
1810 MaskLZ = ExtendBits > MaskLZ ? 0 : MaskLZ - ExtendBits;
1811 ReplacingAnyExtend =
true;
1813 APInt MaskedHighBits =
1816 if (MaskedHighBits != Known.Zero)
return true;
1821 if (ReplacingAnyExtend) {
1846 AM.Scale = 1 << AMShiftAmt;
1847 AM.IndexReg = NewSRL;
1857 X86ISelAddressMode &AM,
1865 if (!Subtarget.
hasTBM() &&
1880 if (AMShiftAmt <= 0 || AMShiftAmt > 3)
return true;
1905 AM.Scale = 1 << AMShiftAmt;
1906 AM.IndexReg = NewAnd;
1910 bool X86DAGToDAGISel::matchAddressRecursively(
SDValue N, X86ISelAddressMode &AM,
1914 dbgs() <<
"MatchAddress: ";
1919 return matchAddressBase(N, AM);
1924 if (AM.isRIPRelative()) {
1928 if (!(AM.ES || AM.MCSym) && AM.JT != -1)
1932 if (!foldOffsetIntoAddress(Cst->getSExtValue(), AM))
1940 if (!AM.hasSymbolicDisplacement() && AM.Disp == 0)
1941 if (
const auto *ESNode = dyn_cast<MCSymbolSDNode>(N.
getOperand(0))) {
1943 AM.MCSym = ESNode->getMCSymbol();
1949 uint64_t Val = cast<ConstantSDNode>(
N)->getSExtValue();
1950 if (!foldOffsetIntoAddress(Val, AM))
1957 if (!matchWrapper(N, AM))
1962 if (!matchLoadInAddress(cast<LoadSDNode>(N), AM))
1967 if (AM.BaseType == X86ISelAddressMode::RegBase &&
1968 AM.Base_Reg.getNode() ==
nullptr &&
1970 AM.BaseType = X86ISelAddressMode::FrameIndexBase;
1971 AM.Base_FrameIndex = cast<FrameIndexSDNode>(
N)->getIndex();
1977 if (AM.IndexReg.getNode() !=
nullptr || AM.Scale != 1)
1981 unsigned Val = CN->getZExtValue();
1986 if (Val == 1 || Val == 2 || Val == 3) {
1987 AM.Scale = 1 << Val;
1993 if (CurDAG->isBaseWithConstantOffset(ShVal)) {
1996 uint64_t Disp = (uint64_t)AddVal->
getSExtValue() << Val;
1997 if (!foldOffsetIntoAddress(Disp, AM))
2001 AM.IndexReg = ShVal;
2009 if (AM.IndexReg.getNode() !=
nullptr || AM.Scale != 1)
break;
2014 "Unexpected value size!");
2017 if (And.getOpcode() !=
ISD::AND)
break;
2024 !isa<ConstantSDNode>(And.getOperand(1)))
2043 if (AM.BaseType == X86ISelAddressMode::RegBase &&
2044 AM.Base_Reg.getNode() ==
nullptr &&
2045 AM.IndexReg.getNode() ==
nullptr) {
2047 if (CN->getZExtValue() == 3 || CN->getZExtValue() == 5 ||
2048 CN->getZExtValue() == 9) {
2049 AM.Scale =
unsigned(CN->getZExtValue())-1;
2057 if (MulVal.getNode()->getOpcode() ==
ISD::ADD && MulVal.hasOneUse() &&
2058 isa<ConstantSDNode>(MulVal.getOperand(1))) {
2061 cast<ConstantSDNode>(MulVal.getOperand(1));
2062 uint64_t Disp = AddVal->
getSExtValue() * CN->getZExtValue();
2063 if (foldOffsetIntoAddress(Disp, AM))
2069 AM.IndexReg = AM.Base_Reg =
Reg;
2088 X86ISelAddressMode Backup = AM;
2089 if (matchAddressRecursively(N.
getOperand(0), AM, Depth+1)) {
2096 if (AM.IndexReg.getNode() || AM.isRIPRelative()) {
2115 if ((AM.BaseType == X86ISelAddressMode::RegBase && AM.Base_Reg.getNode() &&
2116 !AM.Base_Reg.getNode()->hasOneUse()) ||
2117 AM.BaseType == X86ISelAddressMode::FrameIndexBase)
2121 if ((AM.hasSymbolicDisplacement() && !Backup.hasSymbolicDisplacement()) +
2122 ((AM.Disp != 0) && (Backup.Disp == 0)) +
2123 (AM.Segment.getNode() && !Backup.Segment.getNode()) >= 2)
2135 AM.NegateIndex =
true;
2141 if (!matchAdd(N, AM, Depth))
2153 !matchAdd(N, AM, Depth))
2162 if (AM.IndexReg.getNode() !=
nullptr || AM.Scale != 1)
break;
2167 "Unexpected value size!");
2201 if (AM.IndexReg.getNode() !=
nullptr || AM.Scale != 1)
2209 if (!ShAmtC || ShAmtC->getZExtValue() > 3)
2215 ShAmtC->getZExtValue());
2216 if (!CurDAG->MaskedValueIsZero(Shl.
getOperand(0), HighZeros))
2226 AM.Scale = 1 << ShAmtC->getZExtValue();
2231 CurDAG->ReplaceAllUsesWith(N, NewShl);
2232 CurDAG->RemoveDeadNode(N.
getNode());
2237 return matchAddressBase(N, AM);
2242 bool X86DAGToDAGISel::matchAddressBase(
SDValue N, X86ISelAddressMode &AM) {
2244 if (AM.BaseType != X86ISelAddressMode::RegBase || AM.Base_Reg.getNode()) {
2246 if (!AM.IndexReg.getNode()) {
2257 AM.BaseType = X86ISelAddressMode::RegBase;
2265 bool X86DAGToDAGISel::matchVectorAddress(
SDValue N, X86ISelAddressMode &AM) {
2269 uint64_t Val = cast<ConstantSDNode>(
N)->getSExtValue();
2270 if (!foldOffsetIntoAddress(Val, AM))
2275 if (!matchWrapper(N, AM))
2280 return matchAddressBase(N, AM);
2286 X86ISelAddressMode AM;
2287 auto *Mgs = cast<X86MaskedGatherScatterSDNode>(Parent);
2288 AM.IndexReg = Mgs->getIndex();
2289 AM.Scale = cast<ConstantSDNode>(Mgs->getScale())->getZExtValue();
2291 unsigned AddrSpace = cast<MemSDNode>(Parent)->getPointerInfo().getAddrSpace();
2303 if (matchVectorAddress(N, AM))
2306 getAddressOperands(AM, DL, VT, Base, Scale, Index, Disp, Segment);
2320 X86ISelAddressMode AM;
2332 unsigned AddrSpace =
2333 cast<MemSDNode>(Parent)->getPointerInfo().getAddrSpace();
2335 if (AddrSpace == 256)
2337 if (AddrSpace == 257)
2339 if (AddrSpace == 258)
2347 if (matchAddress(N, AM))
2350 getAddressOperands(AM, DL, VT, Base, Scale, Index, Disp, Segment);
2358 while (User != Root) {
2374 bool X86DAGToDAGISel::selectScalarSSELoad(
SDNode *Root,
SDNode *Parent,
2378 SDValue &PatternNodeWithChain) {
2387 IsProfitableToFold(N, LD, Root) &&
2388 IsLegalToFold(N, Parent, Root, OptLevel)) {
2389 PatternNodeWithChain =
N;
2397 PatternNodeWithChain =
N;
2398 if (IsProfitableToFold(PatternNodeWithChain, N.
getNode(), Root) &&
2399 IsLegalToFold(PatternNodeWithChain, Parent, Root, OptLevel)) {
2400 auto *
MI = cast<MemIntrinsicSDNode>(PatternNodeWithChain);
2401 return selectAddr(
MI,
MI->getBasePtr(), Base, Scale,
Index, Disp,
2412 IsProfitableToFold(PatternNodeWithChain, N.
getNode(), Root) &&
2413 IsLegalToFold(PatternNodeWithChain, N.
getNode(), Root, OptLevel)) {
2414 LoadSDNode *
LD = cast<LoadSDNode>(PatternNodeWithChain);
2424 bool X86DAGToDAGISel::selectMOV64Imm32(
SDValue N,
SDValue &Imm) {
2426 uint64_t ImmVal = CN->getZExtValue();
2430 Imm = CurDAG->getTargetConstant(ImmVal,
SDLoc(N),
MVT::i64);
2451 cast<GlobalAddressSDNode>(
N)->getGlobal()->getAbsoluteSymbolRange();
2458 bool X86DAGToDAGISel::selectLEA64_32Addr(
SDValue N,
SDValue &Base,
2464 if (!selectLEAAddr(N, Base, Scale, Index, Disp, Segment))
2468 if (RN && RN->
getReg() == 0)
2469 Base = CurDAG->getRegister(0,
MVT::i64);
2472 SDValue ImplDef =
SDValue(CurDAG->getMachineNode(X86::IMPLICIT_DEF, DL,
2474 Base = CurDAG->getTargetInsertSubreg(X86::sub_32bit, DL,
MVT::i64, ImplDef,
2479 if (RN && RN->
getReg() == 0)
2480 Index = CurDAG->getRegister(0,
MVT::i64);
2483 "Expect to be extending 32-bit registers for use in LEA");
2484 SDValue ImplDef =
SDValue(CurDAG->getMachineNode(X86::IMPLICIT_DEF, DL,
2486 Index = CurDAG->getTargetInsertSubreg(X86::sub_32bit, DL,
MVT::i64, ImplDef,
2495 bool X86DAGToDAGISel::selectLEAAddr(
SDValue N,
2499 X86ISelAddressMode AM;
2510 if (matchAddress(N, AM))
2512 assert (T == AM.Segment);
2515 unsigned Complexity = 0;
2516 if (AM.BaseType == X86ISelAddressMode::RegBase && AM.Base_Reg.getNode())
2518 else if (AM.BaseType == X86ISelAddressMode::FrameIndexBase)
2521 if (AM.IndexReg.getNode())
2534 if (AM.hasSymbolicDisplacement()) {
2536 if (Subtarget->is64Bit())
2546 auto isMathWithFlags = [](
SDValue V) {
2547 switch (V.getOpcode()) {
2561 return !
SDValue(V.getNode(), 1).use_empty();
2577 if (Complexity <= 2)
2580 getAddressOperands(AM, DL, VT, Base, Scale, Index, Disp, Segment);
2585 bool X86DAGToDAGISel::selectTLSADDRAddr(
SDValue N,
SDValue &Base,
2591 X86ISelAddressMode AM;
2592 AM.GV = GA->getGlobal();
2593 AM.Disp += GA->getOffset();
2594 AM.SymbolFlags = GA->getTargetFlags();
2602 getAddressOperands(AM,
SDLoc(N), VT, Base, Scale, Index, Disp, Segment);
2607 if (
auto *CN = dyn_cast<ConstantSDNode>(N)) {
2608 Op = CurDAG->getTargetConstant(CN->getAPIntValue(),
SDLoc(CN),
2617 bool WasTruncated =
false;
2619 WasTruncated =
true;
2634 return !WasTruncated;
2638 auto *GA = cast<GlobalAddressSDNode>(N.
getOperand(0));
2640 if (!CR || CR->getUnsignedMax().uge(1ull << VT.
getSizeInBits()))
2644 Op = CurDAG->getTargetGlobalAddress(GA->getGlobal(),
SDLoc(N), VT,
2645 GA->getOffset(), GA->getTargetFlags());
2653 assert(Root && P &&
"Unknown root/parent nodes");
2655 !IsProfitableToFold(N, P, Root) ||
2656 !IsLegalToFold(N, P, Root, OptLevel))
2659 return selectAddr(N.
getNode(),
2667 assert(Root && P &&
"Unknown root/parent nodes");
2669 !IsProfitableToFold(N, P, Root) ||
2670 !IsLegalToFold(N, P, Root, OptLevel))
2673 return selectAddr(N.
getNode(),
2680 SDNode *X86DAGToDAGISel::getGlobalBaseReg() {
2681 unsigned GlobalBaseReg = getInstrInfo()->getGlobalBaseReg(MF);
2683 return CurDAG->getRegister(GlobalBaseReg, TLI->getPointerTy(DL)).getNode();
2686 bool X86DAGToDAGISel::isSExtAbsoluteSymbolRef(
unsigned Width,
SDNode *N)
const {
2705 if (Opc == X86::JCC_1)
2707 else if (Opc == X86::SETCCr)
2709 else if (Opc == X86::SETCCm)
2711 else if (Opc == X86::CMOV16rr || Opc == X86::CMOV32rr ||
2712 Opc == X86::CMOV64rr)
2714 else if (Opc == X86::CMOV16rm || Opc == X86::CMOV32rm ||
2715 Opc == X86::CMOV64rm)
2723 bool X86DAGToDAGISel::onlyUsesZeroFlag(
SDValue Flags)
const {
2728 if (UI.getUse().getResNo() != Flags.
getResNo())
2732 cast<RegisterSDNode>(UI->getOperand(1))->
getReg() != X86::EFLAGS)
2736 FlagUE = UI->
use_end(); FlagUI != FlagUE; ++FlagUI) {
2738 if (FlagUI.getUse().getResNo() != 1)
continue;
2740 if (!FlagUI->isMachineOpcode())
return false;
2759 bool X86DAGToDAGISel::hasNoSignFlagUses(
SDValue Flags)
const {
2764 if (UI.getUse().getResNo() != Flags.
getResNo())
2768 cast<RegisterSDNode>(UI->getOperand(1))->
getReg() != X86::EFLAGS)
2772 FlagUE = UI->
use_end(); FlagUI != FlagUE; ++FlagUI) {
2774 if (FlagUI.getUse().getResNo() != 1)
continue;
2776 if (!FlagUI->isMachineOpcode())
return false;
2815 bool X86DAGToDAGISel::hasNoCarryFlagUses(
SDValue Flags)
const {
2820 if (UI.getUse().getResNo() != Flags.
getResNo())
2823 unsigned UIOpc = UI->getOpcode();
2827 if (cast<RegisterSDNode>(UI->getOperand(1))->
getReg() != X86::EFLAGS)
2831 FlagUI != FlagUE; ++FlagUI) {
2833 if (FlagUI.getUse().getResNo() != 1)
2836 if (!FlagUI->isMachineOpcode())
2877 if (StoredVal.
getResNo() != 0)
return false;
2891 LoadNode = cast<LoadSDNode>(
Load);
2902 bool FoundLoad =
false;
2906 const unsigned int Max = 1024;
3003 bool X86DAGToDAGISel::foldLoadStoreIntoMemOperand(
SDNode *Node) {
3016 bool IsCommutable =
false;
3017 bool IsNegate =
false;
3031 IsCommutable =
true;
3035 unsigned LoadOpNo = IsNegate ? 1 : 0;
3039 LoadNode, InputChain)) {
3046 LoadNode, InputChain))
3051 if (!selectAddr(LoadNode, LoadNode->
getBasePtr(), Base, Scale,
Index, Disp,
3055 auto SelectOpcode = [&](
unsigned Opc64,
unsigned Opc32,
unsigned Opc16,
3076 unsigned NewOpc = SelectOpcode(X86::NEG64m, X86::NEG32m, X86::NEG16m,
3078 const SDValue Ops[] = {Base, Scale,
Index, Disp, Segment, InputChain};
3079 Result = CurDAG->getMachineNode(NewOpc,
SDLoc(Node),
MVT::i32,
3086 if (!Subtarget->slowIncDec() || CurDAG->shouldOptForSize()) {
3090 if ((IsOne || IsNegOne) && hasNoCarryFlagUses(StoredVal.getValue(1))) {
3093 ? SelectOpcode(X86::INC64m, X86::INC32m, X86::INC16m, X86::INC8m)
3094 : SelectOpcode(X86::DEC64m, X86::DEC32m, X86::DEC16m, X86::DEC8m);
3095 const SDValue Ops[] = {Base, Scale,
Index, Disp, Segment, InputChain};
3096 Result = CurDAG->getMachineNode(NewOpc,
SDLoc(Node),
MVT::i32,
3107 auto SelectRegOpcode = [SelectOpcode](
unsigned Opc) {
3110 return SelectOpcode(X86::ADD64mr, X86::ADD32mr, X86::ADD16mr,
3113 return SelectOpcode(X86::ADC64mr, X86::ADC32mr, X86::ADC16mr,
3116 return SelectOpcode(X86::SUB64mr, X86::SUB32mr, X86::SUB16mr,
3119 return SelectOpcode(X86::SBB64mr, X86::SBB32mr, X86::SBB16mr,
3122 return SelectOpcode(X86::AND64mr, X86::AND32mr, X86::AND16mr,
3125 return SelectOpcode(X86::OR64mr, X86::OR32mr, X86::OR16mr, X86::OR8mr);
3127 return SelectOpcode(X86::XOR64mr, X86::XOR32mr, X86::XOR16mr,
3133 auto SelectImm8Opcode = [SelectOpcode](
unsigned Opc) {
3136 return SelectOpcode(X86::ADD64mi8, X86::ADD32mi8, X86::ADD16mi8, 0);
3138 return SelectOpcode(X86::ADC64mi8, X86::ADC32mi8, X86::ADC16mi8, 0);
3140 return SelectOpcode(X86::SUB64mi8, X86::SUB32mi8, X86::SUB16mi8, 0);
3142 return SelectOpcode(X86::SBB64mi8, X86::SBB32mi8, X86::SBB16mi8, 0);
3144 return SelectOpcode(X86::AND64mi8, X86::AND32mi8, X86::AND16mi8, 0);
3146 return SelectOpcode(X86::OR64mi8, X86::OR32mi8, X86::OR16mi8, 0);
3148 return SelectOpcode(X86::XOR64mi8, X86::XOR32mi8, X86::XOR16mi8, 0);
3153 auto SelectImmOpcode = [SelectOpcode](
unsigned Opc) {
3156 return SelectOpcode(X86::ADD64mi32, X86::ADD32mi, X86::ADD16mi,
3159 return SelectOpcode(X86::ADC64mi32, X86::ADC32mi, X86::ADC16mi,
3162 return SelectOpcode(X86::SUB64mi32, X86::SUB32mi, X86::SUB16mi,
3165 return SelectOpcode(X86::SBB64mi32, X86::SBB32mi, X86::SBB16mi,
3168 return SelectOpcode(X86::AND64mi32, X86::AND32mi, X86::AND16mi,
3171 return SelectOpcode(X86::OR64mi32, X86::OR32mi, X86::OR16mi,
3174 return SelectOpcode(X86::XOR64mi32, X86::XOR32mi, X86::XOR16mi,
3181 unsigned NewOpc = SelectRegOpcode(Opc);
3186 if (
auto *OperandC = dyn_cast<ConstantSDNode>(Operand)) {
3187 int64_t OperandV = OperandC->getSExtValue();
3196 hasNoCarryFlagUses(StoredVal.getValue(1))) {
3197 OperandV = -OperandV;
3204 Operand = CurDAG->getTargetConstant(OperandV,
SDLoc(Node), MemVT);
3205 NewOpc = SelectImm8Opcode(Opc);
3207 Operand = CurDAG->getTargetConstant(OperandV,
SDLoc(Node), MemVT);
3208 NewOpc = SelectImmOpcode(Opc);
3214 CurDAG->getCopyToReg(InputChain,
SDLoc(Node), X86::EFLAGS,
3215 StoredVal.getOperand(2),
SDValue());
3218 Segment, Operand, CopyTo, CopyTo.getValue(1)};
3223 Segment, Operand, InputChain};
3235 CurDAG->setNodeMemRefs(Result, MemOps);
3240 ReplaceUses(
SDValue(StoredVal.getNode(), 1),
SDValue(Result, 0));
3241 CurDAG->RemoveDeadNode(Node);
3251 bool X86DAGToDAGISel::matchBitExtract(
SDNode *Node) {
3254 "Should be either an and-mask, or right-shift after clearing high bits.");
3257 if (!Subtarget->hasBMI() && !Subtarget->hasBMI2())
3270 const bool CanHaveExtraUses = Subtarget->hasBMI2();
3271 auto checkUses = [CanHaveExtraUses](
SDValue Op,
unsigned NUses) {
3272 return CanHaveExtraUses ||
3275 auto checkOneUse = [checkUses](
SDValue Op) {
return checkUses(Op, 1); };
3276 auto checkTwoUse = [checkUses](
SDValue Op) {
return checkUses(Op, 2); };
3278 auto peekThroughOneUseTruncation = [checkOneUse](
SDValue V) {
3281 V.getOperand(0).getSimpleValueType() ==
MVT::i64 &&
3282 "Expected i64 -> i32 truncation");
3283 V = V.getOperand(0);
3289 auto matchPatternA = [checkOneUse, peekThroughOneUseTruncation,
3292 if (Mask->getOpcode() !=
ISD::ADD || !checkOneUse(Mask))
3298 SDValue M0 = peekThroughOneUseTruncation(Mask->getOperand(0));
3307 auto isAllOnes = [
this, peekThroughOneUseTruncation, NVT](
SDValue V) {
3308 V = peekThroughOneUseTruncation(V);
3309 return CurDAG->MaskedValueIsAllOnes(
3315 auto matchPatternB = [checkOneUse, isAllOnes, peekThroughOneUseTruncation,
3318 if (Mask.getOpcode() !=
ISD::XOR || !checkOneUse(Mask))
3321 if (!isAllOnes(Mask->getOperand(1)))
3324 SDValue M0 = peekThroughOneUseTruncation(Mask->getOperand(0));
3335 auto matchShiftAmt = [checkOneUse, &NBits](
SDValue ShiftAmt,
3336 unsigned Bitwidth) {
3341 if (!checkOneUse(ShiftAmt))
3345 if (ShiftAmt.getOpcode() !=
ISD::SUB)
3348 if (!V0 || V0->getZExtValue() != Bitwidth)
3355 auto matchPatternC = [checkOneUse, peekThroughOneUseTruncation,
3358 Mask = peekThroughOneUseTruncation(Mask);
3359 unsigned Bitwidth = Mask.getSimpleValueType().getSizeInBits();
3361 if (Mask.getOpcode() !=
ISD::SRL || !checkOneUse(Mask))
3366 SDValue M1 = Mask.getOperand(1);
3368 if (!checkOneUse(M1))
3370 return matchShiftAmt(M1, Bitwidth);
3376 auto matchPatternD = [checkOneUse, checkTwoUse, matchShiftAmt,
3388 if (N1 != N01 || !checkTwoUse(N1))
3390 if (!matchShiftAmt(N1, Bitwidth))
3396 auto matchLowBitMask = [matchPatternA, matchPatternB,
3398 return matchPatternA(Mask) || matchPatternB(Mask) || matchPatternC(Mask);
3405 if (matchLowBitMask(Mask)) {
3409 if (!matchLowBitMask(Mask))
3412 }
else if (!matchPatternD(Node))
3424 CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, DL,
MVT::i32), 0);
3427 SDValue SRIdxVal = CurDAG->getTargetConstant(X86::sub_8bit, DL,
MVT::i32);
3430 CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG, DL,
MVT::i32, ImplDef,
3431 NBits, SRIdxVal), 0);
3434 if (Subtarget->hasBMI2()) {
3443 ReplaceNode(Node, Extract.
getNode());
3444 SelectCode(Extract.
getNode());
3453 SDValue RealX = peekThroughOneUseTruncation(X);
3480 "Expected shift amount to be i8");
3484 SDValue OrigShiftAmt = ShiftAmt;
3508 ReplaceNode(Node, Extract.
getNode());
3509 SelectCode(Extract.
getNode());
3529 Subtarget->hasTBM() || (Subtarget->hasBMI() && Subtarget->hasFastBEXTR());
3530 if (!PreferBEXTR && !Subtarget->hasBMI2())
3548 if (!MaskCst || !ShiftCst)
3556 uint64_t Shift = ShiftCst->getZExtValue();
3561 if (Shift == 8 && MaskSize == 8)
3572 if (!PreferBEXTR && MaskSize <= 32)
3576 unsigned ROpc, MOpc;
3579 assert(Subtarget->hasBMI2() &&
"We must have BMI2's BZHI then.");
3583 Control = CurDAG->getTargetConstant(Shift + MaskSize, dl, NVT);
3584 ROpc = NVT ==
MVT::i64 ? X86::BZHI64rr : X86::BZHI32rr;
3585 MOpc = NVT ==
MVT::i64 ? X86::BZHI64rm : X86::BZHI32rm;
3586 unsigned NewOpc = NVT ==
MVT::i64 ? X86::MOV32ri64 : X86::MOV32ri;
3587 Control =
SDValue(CurDAG->getMachineNode(NewOpc, dl, NVT, Control), 0);
3593 Control = CurDAG->getTargetConstant(Shift | (MaskSize << 8), dl, NVT);
3594 if (Subtarget->hasTBM()) {
3595 ROpc = NVT ==
MVT::i64 ? X86::BEXTRI64ri : X86::BEXTRI32ri;
3596 MOpc = NVT ==
MVT::i64 ? X86::BEXTRI64mi : X86::BEXTRI32mi;
3598 assert(Subtarget->hasBMI() &&
"We must have BMI1's BEXTR then.");
3600 ROpc = NVT ==
MVT::i64 ? X86::BEXTR64rr : X86::BEXTR32rr;
3601 MOpc = NVT ==
MVT::i64 ? X86::BEXTR64rm : X86::BEXTR32rm;
3602 unsigned NewOpc = NVT ==
MVT::i64 ? X86::MOV32ri64 : X86::MOV32ri;
3603 Control =
SDValue(CurDAG->getMachineNode(NewOpc, dl, NVT, Control), 0);
3609 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
3610 if (tryFoldLoad(Node, N0.
getNode(), Input, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4)) {
3612 Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, Control, Input.
getOperand(0)};
3614 NewNode = CurDAG->getMachineNode(MOpc, dl, VTs, Ops);
3618 CurDAG->setNodeMemRefs(NewNode, {cast<LoadSDNode>(Input)->getMemOperand()});
3620 NewNode = CurDAG->getMachineNode(ROpc, dl, NVT,
MVT::i32, Input, Control);
3625 SDValue ShAmt = CurDAG->getTargetConstant(Shift, dl, NVT);
3626 unsigned NewOpc = NVT ==
MVT::i64 ? X86::SHR64ri : X86::SHR32ri;
3628 CurDAG->getMachineNode(NewOpc, dl, NVT,
SDValue(NewNode, 0), ShAmt);
3635 MachineSDNode *X86DAGToDAGISel::emitPCMPISTR(
unsigned ROpc,
unsigned MOpc,
3641 const ConstantInt *Val = cast<ConstantSDNode>(Imm)->getConstantIntValue();
3645 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
3646 if (MayFoldLoad && tryFoldLoad(Node, N1, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4)) {
3647 SDValue Ops[] = { N0, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, Imm,
3650 MachineSDNode *CNode = CurDAG->getMachineNode(MOpc, dl, VTs, Ops);
3654 CurDAG->setNodeMemRefs(CNode, {cast<LoadSDNode>(N1)->getMemOperand()});
3658 SDValue Ops[] = { N0, N1, Imm };
3660 MachineSDNode *CNode = CurDAG->getMachineNode(ROpc, dl, VTs, Ops);
3667 MachineSDNode *X86DAGToDAGISel::emitPCMPESTR(
unsigned ROpc,
unsigned MOpc,
3668 bool MayFoldLoad,
const SDLoc &dl,
3674 const ConstantInt *Val = cast<ConstantSDNode>(Imm)->getConstantIntValue();
3678 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
3679 if (MayFoldLoad && tryFoldLoad(Node, N2, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4)) {
3680 SDValue Ops[] = { N0, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, Imm,
3683 MachineSDNode *CNode = CurDAG->getMachineNode(MOpc, dl, VTs, Ops);
3688 CurDAG->setNodeMemRefs(CNode, {cast<LoadSDNode>(N2)->getMemOperand()});
3692 SDValue Ops[] = { N0, N2, Imm, InFlag };
3694 MachineSDNode *CNode = CurDAG->getMachineNode(ROpc, dl, VTs, Ops);
3699 bool X86DAGToDAGISel::tryShiftAmountMod(
SDNode *N) {
3710 SDValue ShiftAmt = OrigShiftAmt;
3726 if (isa<ConstantSDNode>(Add1) &&
3727 cast<ConstantSDNode>(Add1)->getZExtValue() % Size == 0) {
3732 isa<ConstantSDNode>(Add0) &&
3733 cast<ConstantSDNode>(Add0)->getZExtValue() != 0 &&
3734 cast<ConstantSDNode>(Add0)->getZExtValue() % Size == 0) {
3739 SDValue Zero = CurDAG->getConstant(0, DL, SubVT);
3762 CurDAG->getConstant(Size - 1, DL,
MVT::i8));
3768 if (UpdatedNode != N) {
3771 ReplaceNode(N, UpdatedNode);
3778 CurDAG->RemoveDeadNode(OrigShiftAmt.
getNode());
3786 bool X86DAGToDAGISel::tryShrinkShlLogicImm(
SDNode *N) {
3805 bool FoundAnyExtend =
false;
3809 FoundAnyExtend =
true;
3828 uint64_t RemovedBitsMask = (1ULL << ShAmt) - 1;
3829 if (Opcode !=
ISD::AND && (Val & RemovedBitsMask) != 0)
3834 auto CanShrinkImmediate = [&](int64_t &ShiftedVal) {
3838 ShiftedVal = (uint64_t)Val >> ShAmt;
3842 if (ShiftedVal == UINT8_MAX || ShiftedVal == UINT16_MAX)
3845 ShiftedVal = Val >> ShAmt;
3851 ShiftedVal = (uint64_t)Val >> ShAmt;
3859 if (!CanShrinkImmediate(ShiftedVal))
3877 if (CurDAG->MaskedValueIsZero(N->
getOperand(0), NeededMask))
3882 if (FoundAnyExtend) {
3888 SDValue NewCst = CurDAG->getConstant(ShiftedVal, dl, NVT);
3890 SDValue NewBinOp = CurDAG->getNode(Opcode, dl, NVT, X, NewCst);
3894 ReplaceNode(N, NewSHL.
getNode());
3905 bool X86DAGToDAGISel::combineIncDecVector(
SDNode *Node) {
3907 "Unexpected opcode for increment/decrement transform");
3920 SDValue OneConstant, AllOnesVec;
3924 "Expected bit count to be a multiple of 32");
3925 OneConstant = CurDAG->getConstant(Ones, DL,
MVT::i32);
3929 assert(NumElts > 0 &&
"Expected to get non-empty vector.");
3934 AllOnesVec = CurDAG->getBitcast(VT, AllOnesVec);
3938 SDValue NewNode = CurDAG->getNode(NewOpcode, DL, VT, X, AllOnesVec);
3940 ReplaceNode(Node, NewNode.
getNode());
3941 SelectCode(NewNode.
getNode());
3952 bool X86DAGToDAGISel::shrinkAndImmediate(
SDNode *And) {
3968 APInt MaskVal = And1C->getAPIntValue();
3970 if (!MaskLZ || (VT ==
MVT::i64 && MaskLZ == 32))
3974 if (VT ==
MVT::i64 && MaskLZ >= 32) {
3976 MaskVal = MaskVal.
trunc(32);
3981 APInt NegMaskVal = MaskVal | HighZeros;
3991 NegMaskVal = NegMaskVal.zext(64);
3992 HighZeros = HighZeros.
zext(64);
3997 if (!CurDAG->MaskedValueIsZero(And0, HighZeros))
4002 if (NegMaskVal.isAllOnesValue()) {
4003 ReplaceNode(And, And0.
getNode());
4008 SDValue NewMask = CurDAG->getConstant(NegMaskVal,
SDLoc(And), VT);
4010 ReplaceNode(And, NewAnd.
getNode());
4016 bool FoldedBCast,
bool Masked) {
4022 return IsTestN ? X86::VPTESTNMBZ128rmk : X86::VPTESTMBZ128rmk;
4024 return IsTestN ? X86::VPTESTNMWZ128rmk : X86::VPTESTMWZ128rmk;
4026 return IsTestN ? X86::VPTESTNMDZ128rmk : X86::VPTESTMDZ128rmk;
4028 return IsTestN ? X86::VPTESTNMQZ128rmk : X86::VPTESTMQZ128rmk;
4030 return IsTestN ? X86::VPTESTNMBZ256rmk : X86::VPTESTMBZ256rmk;
4032 return IsTestN ? X86::VPTESTNMWZ256rmk : X86::VPTESTMWZ256rmk;
4034 return IsTestN ? X86::VPTESTNMDZ256rmk : X86::VPTESTMDZ256rmk;
4036 return IsTestN ? X86::VPTESTNMQZ256rmk : X86::VPTESTMQZ256rmk;
4038 return IsTestN ? X86::VPTESTNMBZrmk : X86::VPTESTMBZrmk;
4040 return IsTestN ? X86::VPTESTNMWZrmk : X86::VPTESTMWZrmk;
4042 return IsTestN ? X86::VPTESTNMDZrmk : X86::VPTESTMDZrmk;
4044 return IsTestN ? X86::VPTESTNMQZrmk : X86::VPTESTMQZrmk;
4052 return IsTestN ? X86::VPTESTNMDZ128rmbk : X86::VPTESTMDZ128rmbk;
4054 return IsTestN ? X86::VPTESTNMQZ128rmbk : X86::VPTESTMQZ128rmbk;
4056 return IsTestN ? X86::VPTESTNMDZ256rmbk : X86::VPTESTMDZ256rmbk;
4058 return IsTestN ? X86::VPTESTNMQZ256rmbk : X86::VPTESTMQZ256rmbk;
4060 return IsTestN ? X86::VPTESTNMDZrmbk : X86::VPTESTMDZrmbk;
4062 return IsTestN ? X86::VPTESTNMQZrmbk : X86::VPTESTMQZrmbk;
4069 return IsTestN ? X86::VPTESTNMBZ128rrk : X86::VPTESTMBZ128rrk;
4071 return IsTestN ? X86::VPTESTNMWZ128rrk : X86::VPTESTMWZ128rrk;
4073 return IsTestN ? X86::VPTESTNMDZ128rrk : X86::VPTESTMDZ128rrk;
4075 return IsTestN ? X86::VPTESTNMQZ128rrk : X86::VPTESTMQZ128rrk;
4077 return IsTestN ? X86::VPTESTNMBZ256rrk : X86::VPTESTMBZ256rrk;
4079 return IsTestN ? X86::VPTESTNMWZ256rrk : X86::VPTESTMWZ256rrk;
4081 return IsTestN ? X86::VPTESTNMDZ256rrk : X86::VPTESTMDZ256rrk;
4083 return IsTestN ? X86::VPTESTNMQZ256rrk : X86::VPTESTMQZ256rrk;
4085 return IsTestN ? X86::VPTESTNMBZrrk : X86::VPTESTMBZrrk;
4087 return IsTestN ? X86::VPTESTNMWZrrk : X86::VPTESTMWZrrk;
4089 return IsTestN ? X86::VPTESTNMDZrrk : X86::VPTESTMDZrrk;
4091 return IsTestN ? X86::VPTESTNMQZrrk : X86::VPTESTMQZrrk;
4099 return IsTestN ? X86::VPTESTNMBZ128rm : X86::VPTESTMBZ128rm;
4101 return IsTestN ? X86::VPTESTNMWZ128rm : X86::VPTESTMWZ128rm;
4103 return IsTestN ? X86::VPTESTNMDZ128rm : X86::VPTESTMDZ128rm;
4105 return IsTestN ? X86::VPTESTNMQZ128rm : X86::VPTESTMQZ128rm;
4107 return IsTestN ? X86::VPTESTNMBZ256rm : X86::VPTESTMBZ256rm;
4109 return IsTestN ? X86::VPTESTNMWZ256rm : X86::VPTESTMWZ256rm;
4111 return IsTestN ? X86::VPTESTNMDZ256rm : X86::VPTESTMDZ256rm;
4113 return IsTestN ? X86::VPTESTNMQZ256rm : X86::VPTESTMQZ256rm;
4115 return IsTestN ? X86::VPTESTNMBZrm : X86::VPTESTMBZrm;
4117 return IsTestN ? X86::VPTESTNMWZrm : X86::VPTESTMWZrm;
4119 return IsTestN ? X86::VPTESTNMDZrm : X86::VPTESTMDZrm;
4121 return IsTestN ? X86::VPTESTNMQZrm : X86::VPTESTMQZrm;
4129 return IsTestN ? X86::VPTESTNMDZ128rmb : X86::VPTESTMDZ128rmb;
4131 return IsTestN ? X86::VPTESTNMQZ128rmb : X86::VPTESTMQZ128rmb;
4133 return IsTestN ? X86::VPTESTNMDZ256rmb : X86::VPTESTMDZ256rmb;
4135 return IsTestN ? X86::VPTESTNMQZ256rmb : X86::VPTESTMQZ256rmb;
4137 return IsTestN ? X86::VPTESTNMDZrmb : X86::VPTESTMDZrmb;
4139 return IsTestN ? X86::VPTESTNMQZrmb : X86::VPTESTMQZrmb;
4146 return IsTestN ? X86::VPTESTNMBZ128rr : X86::VPTESTMBZ128rr;
4148 return IsTestN ? X86::VPTESTNMWZ128rr : X86::VPTESTMWZ128rr;
4150 return IsTestN ? X86::VPTESTNMDZ128rr : X86::VPTESTMDZ128rr;
4152 return IsTestN ? X86::VPTESTNMQZ128rr : X86::VPTESTMQZ128rr;
4154 return IsTestN ? X86::VPTESTNMBZ256rr : X86::VPTESTMBZ256rr;
4156 return IsTestN ? X86::VPTESTNMWZ256rr : X86::VPTESTMWZ256rr;
4158 return IsTestN ? X86::VPTESTNMDZ256rr : X86::VPTESTMDZ256rr;
4160 return IsTestN ? X86::VPTESTNMQZ256rr : X86::VPTESTMQZ256rr;
4162 return IsTestN ? X86::VPTESTNMBZrr : X86::VPTESTMBZrr;
4164 return IsTestN ? X86::VPTESTNMWZrr : X86::VPTESTMWZrr;
4166 return IsTestN ? X86::VPTESTNMDZrr : X86::VPTESTMDZrr;
4168 return IsTestN ? X86::VPTESTNMQZrr : X86::VPTESTMQZrr;
4174 bool X86DAGToDAGISel::tryVPTESTM(
SDNode *Root,
SDValue Setcc,
4176 assert(Subtarget->hasAVX512() &&
"Expected AVX512!");
4222 bool CanFoldLoads = Src0 != Src1;
4225 bool FoldedLoad =
false;
4227 if (!Widen && CanFoldLoads) {
4229 FoldedLoad = tryFoldLoad(Root, N0.
getNode(),
Load, Tmp0, Tmp1, Tmp2, Tmp3,
4234 FoldedLoad = tryFoldLoad(Root, N0.
getNode(),
Load, Tmp0, Tmp1, Tmp2,
4249 auto *MemIntr = cast<MemIntrinsicSDNode>(Src);
4250 if (MemIntr->getMemoryVT().getSizeInBits() == CmpSVT.getSizeInBits())
4259 bool FoldedBCast =
false;
4260 if (!FoldedLoad && CanFoldLoads &&
4263 if ((Load = findBroadcastedOp(Src1, CmpSVT, ParentNode))) {
4264 FoldedBCast = tryFoldBroadcast(Root, ParentNode, Load, Tmp0,
4265 Tmp1, Tmp2, Tmp3, Tmp4);
4271 if ((Load = findBroadcastedOp(Src0, CmpSVT, ParentNode))) {
4272 FoldedBCast = tryFoldBroadcast(Root, ParentNode, Load, Tmp0,
4273 Tmp1, Tmp2, Tmp3, Tmp4);
4280 auto getMaskRC = [](
MVT MaskVT) {
4281 switch (MaskVT.SimpleTy) {
4283 case MVT::v2i1:
return X86::VK2RegClassID;
4284 case MVT::v4i1:
return X86::VK4RegClassID;
4285 case MVT::v8i1:
return X86::VK8RegClassID;
4305 SDValue ImplDef =
SDValue(CurDAG->getMachineNode(X86::IMPLICIT_DEF, dl,
4307 Src0 = CurDAG->getTargetInsertSubreg(SubReg, dl, CmpVT, ImplDef, Src0);
4309 assert(!FoldedLoad &&
"Shouldn't have folded the load");
4311 Src1 = CurDAG->getTargetInsertSubreg(SubReg, dl, CmpVT, ImplDef, Src1);
4315 unsigned RegClass = getMaskRC(MaskVT);
4317 InMask =
SDValue(CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS,
4318 dl, MaskVT, InMask, RC), 0);
4323 unsigned Opc =
getVPTESTMOpc(CmpVT, IsTestN, FoldedLoad, FoldedBCast,
4327 if (FoldedLoad || FoldedBCast) {
4331 SDValue Ops[] = { InMask, Src0, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4,
4333 CNode = CurDAG->getMachineNode(Opc, dl, VTs, Ops);
4335 SDValue Ops[] = { Src0, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4,
4337 CNode = CurDAG->getMachineNode(Opc, dl, VTs, Ops);
4343 CurDAG->setNodeMemRefs(CNode, {cast<MemSDNode>(
Load)->getMemOperand()});
4346 CNode = CurDAG->getMachineNode(Opc, dl, MaskVT, InMask, Src0, Src1);
4348 CNode = CurDAG->getMachineNode(Opc, dl, MaskVT, Src0, Src1);
4353 unsigned RegClass = getMaskRC(ResVT);
4355 CNode = CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS,
4356 dl, ResVT,
SDValue(CNode, 0), RC);
4360 CurDAG->RemoveDeadNode(Root);
4366 bool X86DAGToDAGISel::tryMatchBitSelect(
SDNode *N) {
4372 if (!NVT.isVector() || !Subtarget->hasAVX512())
4376 if (!(Subtarget->hasVLX() || NVT.is512BitVector()))
4408 ReplaceNode(N, Ternlog.
getNode());
4409 SelectCode(Ternlog.
getNode());
4430 case Intrinsic::x86_sse3_monitor:
4431 case Intrinsic::x86_monitorx:
4432 case Intrinsic::x86_clzero: {
4438 case Intrinsic::x86_sse3_monitor:
4439 if (!Subtarget->hasSSE3())
4441 Opc = Use64BitPtr ? X86::MONITOR64rrr : X86::MONITOR32rrr;
4443 case Intrinsic::x86_monitorx:
4444 if (!Subtarget->hasMWAITX())
4446 Opc = Use64BitPtr ? X86::MONITORX64rrr : X86::MONITORX32rrr;
4448 case Intrinsic::x86_clzero:
4449 if (!Subtarget->hasCLZERO())
4451 Opc = Use64BitPtr ? X86::CLZERO64r : X86::CLZERO32r;
4456 unsigned PtrReg = Use64BitPtr ? X86::RAX :
X86::EAX;
4461 if (IntNo == Intrinsic::x86_sse3_monitor ||
4462 IntNo == Intrinsic::x86_monitorx) {
4474 ReplaceNode(Node, CNode);
4485 if (Subtarget->isTargetNaCl())
4489 if (Subtarget->isTarget64BitILP32()) {
4498 ReplaceNode(Node, Brind.
getNode());
4499 SelectCode(ZextTarget.getNode());
4506 ReplaceNode(Node, getGlobalBaseReg());
4514 CurDAG->RemoveDeadNode(Node);
4524 assert(Subtarget->hasSSE41() &&
"Expected SSE4.1 support!");
4525 SDValue Blendv = CurDAG->getNode(
4528 ReplaceNode(Node, Blendv.getNode());
4529 SelectCode(Blendv.getNode());
4535 if (matchBitExtract(Node))
4540 if (tryShiftAmountMod(Node))
4550 tryVPTESTM(Node, N0, N1))
4553 tryVPTESTM(Node, N1, N0))
4559 CurDAG->RemoveDeadNode(Node);
4562 if (matchBitExtract(Node))
4570 if (tryShrinkShlLogicImm(Node))
4573 if (Opcode ==
ISD::OR && tryMatchBitSelect(Node))
4580 combineIncDecVector(Node))
4611 if (Opcode ==
ISD::ADD && (Val == 1 || Val == -1))
4615 if (!shouldAvoidImmediateInstFormsForSize(N1.
getNode()))
4619 unsigned ROpc, MOpc;
4625 case ISD::ADD: ROpc = X86::ADD8rr; MOpc = X86::ADD8rm;
break;
4626 case ISD::SUB: ROpc = X86::SUB8rr; MOpc = X86::SUB8rm;
break;
4627 case ISD::AND: ROpc = X86::AND8rr; MOpc = X86::AND8rm;
break;
4628 case ISD::OR: ROpc = X86::OR8rr; MOpc = X86::OR8rm;
break;
4629 case ISD::XOR: ROpc = X86::XOR8rr; MOpc = X86::XOR8rm;
break;
4635 case ISD::ADD: ROpc = X86::ADD16rr; MOpc = X86::ADD16rm;
break;
4636 case ISD::SUB: ROpc = X86::SUB16rr; MOpc = X86::SUB16rm;
break;
4637 case ISD::AND: ROpc = X86::AND16rr; MOpc = X86::AND16rm;
break;
4638 case ISD::OR: ROpc = X86::OR16rr; MOpc = X86::OR16rm;
break;
4639 case ISD::XOR: ROpc = X86::XOR16rr; MOpc = X86::XOR16rm;
break;
4645 case ISD::ADD: ROpc = X86::ADD32rr; MOpc = X86::ADD32rm;
break;
4646 case ISD::SUB: ROpc = X86::SUB32rr; MOpc = X86::SUB32rm;
break;
4647 case ISD::AND: ROpc = X86::AND32rr; MOpc = X86::AND32rm;
break;
4648 case ISD::OR: ROpc = X86::OR32rr; MOpc = X86::OR32rm;
break;
4649 case ISD::XOR: ROpc = X86::XOR32rr; MOpc = X86::XOR32rm;
break;
4655 case ISD::ADD: ROpc = X86::ADD64rr; MOpc = X86::ADD64rm;
break;
4656 case ISD::SUB: ROpc = X86::SUB64rr; MOpc = X86::SUB64rm;
break;
4657 case ISD::AND: ROpc = X86::AND64rr; MOpc = X86::AND64rm;
break;
4658 case ISD::OR: ROpc = X86::OR64rr; MOpc = X86::OR64rm;
break;
4659 case ISD::XOR: ROpc = X86::XOR64rr; MOpc = X86::XOR64rm;
break;
4668 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
4669 if (tryFoldLoad(Node, N0, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4)) {
4672 MachineSDNode *CNode = CurDAG->getMachineNode(MOpc, dl, VTs, Ops);
4676 CurDAG->setNodeMemRefs(CNode, {cast<LoadSDNode>(N0)->getMemOperand()});
4678 CurDAG->RemoveDeadNode(Node);
4683 CurDAG->SelectNodeTo(Node, ROpc, NVT,
MVT::i32, N0, N1);
4696 unsigned LoReg, ROpc, MOpc;
4701 ROpc = Opcode ==
X86ISD::SMUL ? X86::IMUL8r : X86::MUL8r;
4702 MOpc = Opcode ==
X86ISD::SMUL ? X86::IMUL8m : X86::MUL8m;
4721 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
4722 bool FoldedLoad = tryFoldLoad(Node, N1, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4);
4725 FoldedLoad = tryFoldLoad(Node, N0, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4);
4730 SDValue InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, LoReg,
4745 CNode = CurDAG->getMachineNode(MOpc, dl, VTs, Ops);
4750 CurDAG->setNodeMemRefs(CNode, {cast<LoadSDNode>(N1)->getMemOperand()});
4756 VTs = CurDAG->getVTList(NVT,
MVT::i32);
4758 VTs = CurDAG->getVTList(NVT, NVT,
MVT::i32);
4760 CNode = CurDAG->getMachineNode(ROpc, dl, VTs, {N1, InFlag});
4765 CurDAG->RemoveDeadNode(Node);
4779 case MVT::i32: Opc = X86::MUL32r; MOpc = X86::MUL32m;
break;
4780 case MVT::i64: Opc = X86::MUL64r; MOpc = X86::MUL64m;
break;
4785 case MVT::i32: Opc = X86::IMUL32r; MOpc = X86::IMUL32m;
break;
4786 case MVT::i64: Opc = X86::IMUL64r; MOpc = X86::IMUL64m;
break;
4790 unsigned SrcReg, LoReg, HiReg;
4799 SrcReg = LoReg = X86::RAX; HiReg = X86::RDX;
4803 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
4804 bool foldedLoad = tryFoldLoad(Node, N1, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4);
4807 foldedLoad = tryFoldLoad(Node, N0, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4);
4812 SDValue InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, SrcReg,
4820 CNode = CurDAG->getMachineNode(MOpc, dl, VTs, Ops);
4825 ReplaceUses(N1.
getValue(1), Chain);
4827 CurDAG->setNodeMemRefs(CNode, {cast<LoadSDNode>(N1)->getMemOperand()});
4829 SDValue Ops[] = { N1, InFlag };
4831 SDNode *CNode = CurDAG->getMachineNode(Opc, dl, VTs, Ops);
4836 if (!
SDValue(Node, 0).use_empty()) {
4837 assert(LoReg &&
"Register for low half is not defined!");
4838 SDValue ResLo = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl, LoReg,
4841 ReplaceUses(
SDValue(Node, 0), ResLo);
4847 assert(HiReg &&
"Register for high half is not defined!");
4848 SDValue ResHi = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl, HiReg,
4851 ReplaceUses(
SDValue(Node, 1), ResHi);
4856 CurDAG->RemoveDeadNode(Node);
4870 case MVT::i8: Opc = X86::DIV8r; MOpc = X86::DIV8m;
break;
4871 case MVT::i16: Opc = X86::DIV16r; MOpc = X86::DIV16m;
break;
4872 case MVT::i32: Opc = X86::DIV32r; MOpc = X86::DIV32m;
break;
4873 case MVT::i64: Opc = X86::DIV64r; MOpc = X86::DIV64m;
break;
4878 case MVT::i8: Opc = X86::IDIV8r; MOpc = X86::IDIV8m;
break;
4879 case MVT::i16: Opc = X86::IDIV16r; MOpc = X86::IDIV16m;
break;
4880 case MVT::i32: Opc = X86::IDIV32r; MOpc = X86::IDIV32m;
break;
4881 case MVT::i64: Opc = X86::IDIV64r; MOpc = X86::IDIV64m;
break;
4885 unsigned LoReg, HiReg, ClrReg;
4886 unsigned SExtOpcode;
4890 LoReg =
X86::AL; ClrReg = HiReg = X86::AH;
4894 LoReg = X86::AX; HiReg = X86::DX;
4896 SExtOpcode = X86::CWD;
4900 SExtOpcode = X86::CDQ;
4903 LoReg = X86::RAX; ClrReg = HiReg = X86::RDX;
4904 SExtOpcode = X86::CQO;
4908 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
4909 bool foldedLoad = tryFoldLoad(Node, N1, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4);
4910 bool signBitIsZero = CurDAG->SignBitIsZero(N0);
4916 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, Chain;
4918 if (tryFoldLoad(Node, N0, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4)) {
4920 unsigned Opc = (isSigned && !signBitIsZero) ? X86::MOVSX16rm8
4924 ReplaceUses(N0.
getValue(1), Chain);
4926 CurDAG->setNodeMemRefs(Move, {cast<LoadSDNode>(N0)->getMemOperand()});
4928 unsigned Opc = (isSigned && !signBitIsZero) ? X86::MOVSX16rr8
4930 Move = CurDAG->getMachineNode(Opc, dl,
MVT::i16, N0);
4931 Chain = CurDAG->getEntryNode();
4933 Chain = CurDAG->getCopyToReg(Chain, dl, X86::AX,
SDValue(Move, 0),
4938 CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl,
4939 LoReg, N0,
SDValue()).getValue(1);
4940 if (isSigned && !signBitIsZero) {
4946 SDValue ClrNode =
SDValue(CurDAG->getMachineNode(X86::MOV32r0, dl, NVT), 0);
4950 SDValue(CurDAG->getMachineNode(
4951 TargetOpcode::EXTRACT_SUBREG, dl,
MVT::i16, ClrNode,
4952 CurDAG->getTargetConstant(X86::sub_16bit, dl,
4960 SDValue(CurDAG->getMachineNode(
4961 TargetOpcode::SUBREG_TO_REG, dl,
MVT::i64,
4962 CurDAG->getTargetConstant(0, dl,
MVT::i64), ClrNode,
4963 CurDAG->getTargetConstant(X86::sub_32bit, dl,
4971 InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ClrReg,
4972 ClrNode, InFlag).getValue(1);
4985 CurDAG->setNodeMemRefs(CNode, {cast<LoadSDNode>(N1)->getMemOperand()});
5000 unsigned AHExtOpcode =
5001 isSigned ? X86::MOVSX32rr8_NOREX : X86::MOVZX32rr8_NOREX;
5003 SDNode *RNode = CurDAG->getMachineNode(AHExtOpcode, dl,
MVT::i32,
5009 CurDAG->getTargetExtractSubreg(X86::sub_8bit, dl,
MVT::i8, Result);
5011 ReplaceUses(
SDValue(Node, 1), Result);
5017 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
5018 LoReg, NVT, InFlag);
5020 ReplaceUses(
SDValue(Node, 0), Result);
5026 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
5027 HiReg, NVT, InFlag);
5029 ReplaceUses(
SDValue(Node, 1), Result);
5033 CurDAG->RemoveDeadNode(Node);
5054 unsigned TestOpc = CmpVT ==
MVT::i64 ? X86::TEST64rr
5057 NewNode = CurDAG->getMachineNode(TestOpc, dl,
MVT::i32, BEXTR, BEXTR);
5059 CurDAG->RemoveDeadNode(Node);
5082 onlyUsesZeroFlag(
SDValue(Node, 0))) {
5091 ReplaceNode(Node, Test);
5102 ReplaceNode(Node, Test);
5109 unsigned ROpc, MOpc;
5117 (!(Mask & 0x80) || CmpVT ==
MVT::i8 ||
5118 hasNoSignFlagUses(
SDValue(Node, 0)))) {
5121 SubRegOp = X86::sub_8bit;
5122 ROpc = X86::TEST8ri;
5123 MOpc = X86::TEST8mi;
5124 }
else if (OptForMinSize &&
isUInt<16>(Mask) &&
5125 (!(Mask & 0x8000) || CmpVT ==
MVT::i16 ||
5126 hasNoSignFlagUses(
SDValue(Node, 0)))) {
5132 SubRegOp = X86::sub_16bit;
5133 ROpc = X86::TEST16ri;
5134 MOpc = X86::TEST16mi;
5136 ((!(Mask & 0x80000000) &&
5139 (CmpVT !=
MVT::i16 || !(Mask & 0x8000))) ||
5141 hasNoSignFlagUses(
SDValue(Node, 0)))) {
5148 SubRegOp = X86::sub_32bit;
5149 ROpc = X86::TEST32ri;
5150 MOpc = X86::TEST32mi;
5156 SDValue Imm = CurDAG->getTargetConstant(Mask, dl, VT);
5161 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
5162 if (tryFoldLoad(Node, N0.
getNode(),
Reg, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4)) {
5164 if (!LoadN->isSimple()) {
5166 if (MOpc == X86::TEST8mi && NumVolBits != 8)
5168 else if (MOpc == X86::TEST16mi && NumVolBits != 16)
5170 else if (MOpc == X86::TEST32mi && NumVolBits != 32)
5174 SDValue Ops[] = { Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, Imm,
5180 CurDAG->setNodeMemRefs(NewNode,
5181 {cast<LoadSDNode>(
Reg)->getMemOperand()});
5185 Reg = CurDAG->getTargetExtractSubreg(SubRegOp, dl, VT, Reg);
5187 NewNode = CurDAG->getMachineNode(ROpc, dl,
MVT::i32, Reg, Imm);
5190 ReplaceNode(Node, NewNode);
5196 if (!Subtarget->hasSSE42())
5202 bool MayFoldLoad = !NeedIndex || !NeedMask;
5206 unsigned ROpc = Subtarget->hasAVX() ? X86::VPCMPISTRMrr : X86::PCMPISTRMrr;
5207 unsigned MOpc = Subtarget->hasAVX() ? X86::VPCMPISTRMrm : X86::PCMPISTRMrm;
5208 CNode = emitPCMPISTR(ROpc, MOpc, MayFoldLoad, dl,
MVT::v16i8, Node);
5211 if (NeedIndex || !NeedMask) {
5212 unsigned ROpc = Subtarget->hasAVX() ? X86::VPCMPISTRIrr : X86::PCMPISTRIrr;
5213 unsigned MOpc = Subtarget->hasAVX() ? X86::VPCMPISTRIrm : X86::PCMPISTRIrm;
5214 CNode = emitPCMPISTR(ROpc, MOpc, MayFoldLoad, dl,
MVT::i32, Node);
5220 CurDAG->RemoveDeadNode(Node);
5224 if (!Subtarget->hasSSE42())
5228 SDValue InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl,
X86::EAX,
5231 InFlag = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl,
X86::EDX,
5237 bool MayFoldLoad = !NeedIndex || !NeedMask;
5241 unsigned ROpc = Subtarget->hasAVX() ? X86::VPCMPESTRMrr : X86::PCMPESTRMrr;
5242 unsigned MOpc = Subtarget->hasAVX() ? X86::VPCMPESTRMrm : X86::PCMPESTRMrm;
5243 CNode = emitPCMPESTR(ROpc, MOpc, MayFoldLoad, dl,
MVT::v16i8, Node,
5247 if (NeedIndex || !NeedMask) {
5248 unsigned ROpc = Subtarget->hasAVX() ? X86::VPCMPESTRIrr : X86::PCMPESTRIrr;
5249 unsigned MOpc = Subtarget->hasAVX() ? X86::VPCMPESTRIrm : X86::PCMPESTRIrm;
5250 CNode = emitPCMPESTR(ROpc, MOpc, MayFoldLoad, dl,
MVT::i32, Node, InFlag);
5255 CurDAG->RemoveDeadNode(Node);
5267 if (foldLoadStoreIntoMemOperand(Node))
5275 bool X86DAGToDAGISel::
5276 SelectInlineAsmMemoryOperand(
const SDValue &Op,
unsigned ConstraintID,
5277 std::vector<SDValue> &OutOps) {
5278 SDValue Op0, Op1, Op2, Op3, Op4;
5279 switch (ConstraintID) {
5286 if (!selectAddr(
nullptr, Op, Op0, Op1, Op2, Op3, Op4))
5291 OutOps.push_back(Op0);
5292 OutOps.push_back(Op1);
5293 OutOps.push_back(Op2);
5294 OutOps.push_back(Op3);
5295 OutOps.push_back(Op4);
5303 return new X86DAGToDAGISel(TM, OptLevel);
static bool foldMaskedShiftToScaledMask(SelectionDAG &DAG, SDValue N, X86ISelAddressMode &AM)
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 ...
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
static bool isFusableLoadOpStorePattern(StoreSDNode *StoreNode, SDValue StoredVal, SelectionDAG *CurDAG, unsigned LoadOpNo, LoadSDNode *&LoadNode, SDValue &InputChain)
Check whether or not the chain ending in StoreNode is suitable for doing the {load; op; store} to mod...
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
void setFlags(SDNodeFlags NewFlags)
APInt getSignedMax() const
Return the largest signed value contained in the ConstantRange.
static APInt getAllOnesValue(unsigned numBits)
Get the all-ones value.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
bool isConstantSplat(SDValue Op, APInt &SplatVal)
If Op is a constant whose elements are all the same constant or undefined, return true and return the...
This class represents lattice values for constants.
static void insertDAGNode(SelectionDAG &DAG, SDValue Pos, SDValue N)
static bool IsMasked(Instruction *I)
static bool isLegalMaskCompare(SDNode *N, const X86Subtarget *Subtarget)
static MVT getVectorVT(MVT VT, unsigned NumElements)
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
bool hasOptSize() const
Optimize this function for size (-Os) or minimum size (-Oz).
ZERO_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register zero-extension of the low ...
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.
void push_back(const T &Elt)
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
APInt zext(unsigned width) const
Zero extend to a new width.
bool is256BitVector() const
Return true if this is a 256-bit vector type.
bool slt(const APInt &RHS) const
Signed less than comparison.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Get a value with low bits set.
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
bool hasFastBEXTR() const
unsigned getVectorNumElements() const
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
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
C - The default llvm calling convention, compatible with C.
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.
TypeSize getScalarValueSizeInBits() const
const SDNodeFlags getFlags() const
Bitwise logical ANDNOT of floating point values.
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 ...
static bool isRIPRelative(const MCInst &MI, const MCInstrInfo &MCII)
Check if the instruction uses RIP relative addressing.
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.
unsigned 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...
void dump() const
Support for debugging, callable in GDB: V->dump()
The address of a basic block.
static cl::opt< bool > AndImmShrink("x86-and-imm-shrink", cl::init(true), cl::desc("Enable setting constant bits to reduce size of mask immediates"), cl::Hidden)
bool hasOneUse() const
Return true if there is exactly one use of this node.
A description of a memory reference used in the backend.
bool hasNoFPExcept() const
Dynamic (non-constant condition) vector blend where only the sign bits of the condition elements are ...
Bitwise Logical AND NOT of Packed FP values.
Shift and rotation operations.
bool isNormalStore(const SDNode *N)
Returns true if the specified node is a non-truncating and unindexed store.
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.
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.
TypeSize getValueSizeInBits() const
Returns the size of the value in bits.
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.
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
bool hasExternalLinkage() const
unsigned getActiveBits() const
Compute the number of active bits in the value.
int64_t getSExtValue() const
static void InvalidateNodeId(SDNode *N)
X86 FP SETCC, similar to above, but with output as an i1 mask and and a version with SAE...
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.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out...
op_iterator op_begin() const
X = STRICT_FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
ANY_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register any-extension of the low la...
ArrayRef< SDUse > ops() const
MVT getVectorElementType() const
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
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.
Bitwise logical XOR of floating point values.
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
static unsigned getVPTESTMOpc(MVT TestVT, bool IsTestN, bool FoldedLoad, bool FoldedBCast, bool Masked)
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.
bool is128BitVector() const
Return true if this is a 128-bit vector type.
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
const SDValue & getBasePtr() const
bool isSimple() const
Returns true if the memory operation is neither atomic or volatile.
initializer< Ty > init(const Ty &Val)
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...
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
constexpr bool isUInt< 8 >(uint64_t x)
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.
This instruction implements an extending load to FP stack slots.
bool hasAnyUseOfValue(unsigned Value) const
Return true if there are any use of the indicated value.
bool isMachineOpcode() const
static bool mayUseCarryFlag(X86::CondCode CC)
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 isOneValue() const
Determine if this is a value of 1.
X86 conditional branches.
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.
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
const APInt & getAPIntValue() const
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...
void RemoveDeadNode(SDNode *N)
Remove the specified node from the system.
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
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
unsigned 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...
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.
static SDValue Widen(SelectionDAG *CurDAG, SDValue N)
The memory access writes data.
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
XOP - Opcode prefix used by XOP instructions.
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.
static X86::CondCode getCondFromNode(SDNode *N)
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.
static bool foldMaskedShiftToBEXTR(SelectionDAG &DAG, SDValue N, uint64_t Mask, SDValue Shift, SDValue X, X86ISelAddressMode &AM, const X86Subtarget &Subtarget)
constexpr bool isInt< 32 >(int64_t x)
Align max(MaybeAlign Lhs, Align Rhs)
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...
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
EVT getVectorElementType() const
Given a vector type, return the type of each element.
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...
void setNoFPExcept(bool b)
EVT changeVectorElementTypeToInteger() const
Return a vector with the same number of elements as this vector, but with the element type converted ...
An SDNode that represents everything that will be needed to construct a MachineInstr.
TypeSize getScalarSizeInBits() const
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...
const Function & getFunction() const
Return the LLVM function that this machine code represents.
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.
unsigned countTrailingOnes() const
Count the number of trailing one bits.
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.
The memory access reads data.
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.
These are IR-level optimization flags that may be propagated to SDNodes.
constexpr bool isShiftedMask_64(uint64_t Value)
Return true if the argument contains a non-empty sequence of ones with the remainder zero (64 bit ver...
bool isVector() const
Return true if this is a vector value type.
const SDValue & getValue() const
Bitwise operators - logical and, logical or, logical xor.
bool isOnlyUserOf(const SDNode *N) const
Return true if this node is the only use of N.
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.
Vector comparison generating mask bits for fp and integer signed and unsigned data types...
FunctionPass * createX86ISelDag(X86TargetMachine &TM, CodeGenOpt::Level OptLevel)
This pass converts a legalized DAG into a X86-specific DAG, ready for instruction scheduling...
Bitwise logical AND of floating point values.
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.
bool hasMinSize() const
Optimize this function for minimum size (-Oz).
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 is512BitVector() const
Return true if this is a 512-bit vector type.
X = STRICT_FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision ...
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)
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 instruction implements a truncating store from FP stack slots.
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.
bool isAllOnesConstant(SDValue V)
Returns true if V is an integer constant with all bits set.
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
Bitwise logical OR of floating point values.
unsigned getMachineOpcode() const
This may only be called if isMachineOpcode returns true.
unsigned countTrailingOnes(T Value, ZeroBehavior ZB=ZB_Width)
Count the number of ones from the least significant bit to the first zero bit.
bool isNullConstant(SDValue V)
Returns true if V is a constant integer zero.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
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
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.
KnownBits computeKnownBits(SDValue Op, unsigned Depth=0) const
Determine which bits of Op are known to be either zero or one and return them in Known.
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
bool isStrictFPOpcode()
Test if this node is a strict floating point pseudo-op.
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...
STRICT_FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
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.
uint64_t PowerOf2Ceil(uint64_t A)
Returns the power of two which is greater than or equal to the given value.
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)