22#include "llvm/Config/llvm-config.h"
27#include "llvm/IR/IntrinsicsX86.h"
39#define DEBUG_TYPE "x86-isel"
40#define PASS_NAME "X86 DAG->DAG Instruction Selection"
42STATISTIC(NumLoadMoved,
"Number of loads moved below TokenFactor");
51 struct X86ISelAddressMode {
59 int Base_FrameIndex = 0;
65 const GlobalValue *GV =
nullptr;
68 const char *ES =
nullptr;
73 bool NegateIndex =
false;
78 bool IsForLEA =
false;
80 X86ISelAddressMode() =
default;
82 bool hasSymbolicDisplacement()
const {
83 return GV !=
nullptr || CP !=
nullptr || ES !=
nullptr ||
84 MCSym !=
nullptr || JT != -1 || BlockAddr !=
nullptr;
87 bool hasBaseOrIndexReg()
const {
88 return BaseType == FrameIndexBase ||
89 IndexReg.getNode() !=
nullptr || Base_Reg.getNode() !=
nullptr;
94 if (BaseType != RegBase)
return false;
95 if (RegisterSDNode *RegNode =
97 return RegNode->getReg() == X86::RIP;
106#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
107 void dump(SelectionDAG *DAG =
nullptr) {
108 dbgs() <<
"X86ISelAddressMode " <<
this <<
'\n';
109 dbgs() <<
"Base_Reg ";
110 if (Base_Reg.getNode())
111 Base_Reg.getNode()->dump(DAG);
114 if (BaseType == FrameIndexBase)
115 dbgs() <<
" Base.FrameIndex " << Base_FrameIndex <<
'\n';
116 dbgs() <<
" Scale " << Scale <<
'\n'
120 if (IndexReg.getNode())
121 IndexReg.getNode()->dump(DAG);
124 dbgs() <<
" Disp " << Disp <<
'\n'
146 dbgs() <<
" JT" << JT <<
" Align" << Alignment.value() <<
'\n';
160 const X86Subtarget *Subtarget;
166 bool IndirectTlsSegRefs;
169 X86DAGToDAGISel() =
delete;
171 explicit X86DAGToDAGISel(X86TargetMachine &tm,
CodeGenOptLevel OptLevel)
172 : SelectionDAGISel(tm, OptLevel), Subtarget(nullptr),
173 OptForMinSize(
false), IndirectTlsSegRefs(
false) {}
179 "indirect-tls-seg-refs");
186 const X86MachineFunctionInfo *MFI = MF.
getInfo<X86MachineFunctionInfo>();
189 if ((MFI->
getAMXProgModel() == AMXProgModelEnum::ManagedRA && HasACE) ||
192 MF.
getName() +
": Failed to config tile register, AMX and ACE "
193 "tiles need different configurations");
197 void emitFunctionEntryCode()
override;
199 bool IsProfitableToFold(
SDValue N, SDNode *U, SDNode *Root)
const override;
201 void PreprocessISelDAG()
override;
202 void PostprocessISelDAG()
override;
205#include "X86GenDAGISel.inc"
208 void Select(SDNode *
N)
override;
210 bool foldOffsetIntoAddress(
uint64_t Offset, X86ISelAddressMode &AM);
211 bool matchLoadInAddress(LoadSDNode *
N, X86ISelAddressMode &AM,
212 bool AllowSegmentRegForX32 =
false);
213 bool matchWrapper(
SDValue N, X86ISelAddressMode &AM);
214 bool matchAddress(
SDValue N, X86ISelAddressMode &AM);
215 bool matchVectorAddress(
SDValue N, X86ISelAddressMode &AM);
216 bool matchAdd(
SDValue &
N, X86ISelAddressMode &AM,
unsigned Depth);
217 bool hasMaterializingUse(
SDValue V)
const;
220 bool matchAddressRecursively(
SDValue N, X86ISelAddressMode &AM,
222 bool matchVectorAddressRecursively(
SDValue N, X86ISelAddressMode &AM,
224 bool matchAddressBase(
SDValue N, X86ISelAddressMode &AM);
227 bool AllowNonRIP =
true);
230 bool selectVectorAddr(MemSDNode *Parent,
SDValue BasePtr,
SDValue IndexOp,
244 bool tryFoldLoad(SDNode *Root, SDNode *
P,
SDValue N,
254 return tryFoldLoad(
P,
P,
N,
Base, Scale, Index, Disp, Segment);
257 bool tryFoldBroadcast(SDNode *Root, SDNode *
P,
SDValue N,
262 bool isProfitableToFormMaskedOp(SDNode *
N)
const;
265 bool SelectInlineAsmMemoryOperand(
const SDValue &
Op,
267 std::vector<SDValue> &OutOps)
override;
269 void emitSpecialCodeForMain();
271 inline void getAddressOperands(X86ISelAddressMode &AM,
const SDLoc &
DL,
275 if (AM.BaseType == X86ISelAddressMode::FrameIndexBase)
276 Base = CurDAG->getTargetFrameIndex(
278 else if (AM.Base_Reg.
getNode())
281 Base = CurDAG->getRegister(0, VT);
283 Scale = getI8Imm(AM.Scale,
DL);
285#define GET_ND_IF_ENABLED(OPC) (Subtarget->hasNDD() ? OPC##_ND : OPC)
286#define GET_NDM_IF_ENABLED(OPC) \
287 (Subtarget->hasNDD() && Subtarget->hasNDDM() ? OPC##_ND : OPC)
289 if (AM.NegateIndex) {
315 Index = CurDAG->getRegister(0, VT);
320 Disp = CurDAG->getTargetGlobalAddress(AM.GV, SDLoc(),
324 Disp = CurDAG->getTargetConstantPool(AM.CP, MVT::i32, AM.Alignment,
325 AM.Disp, AM.SymbolFlags);
327 assert(!AM.Disp &&
"Non-zero displacement is ignored with ES.");
328 Disp = CurDAG->getTargetExternalSymbol(AM.ES, MVT::i32, AM.SymbolFlags);
329 }
else if (AM.MCSym) {
330 assert(!AM.Disp &&
"Non-zero displacement is ignored with MCSym.");
331 assert(AM.SymbolFlags == 0 &&
"oo");
332 Disp = CurDAG->getMCSymbol(AM.MCSym, MVT::i32);
333 }
else if (AM.JT != -1) {
334 assert(!AM.Disp &&
"Non-zero displacement is ignored with JT.");
335 Disp = CurDAG->getTargetJumpTable(AM.JT, MVT::i32, AM.SymbolFlags);
336 }
else if (AM.BlockAddr)
337 Disp = CurDAG->getTargetBlockAddress(AM.BlockAddr, MVT::i32, AM.Disp,
340 Disp = CurDAG->getSignedTargetConstant(AM.Disp,
DL, MVT::i32);
343 Segment = AM.Segment;
345 Segment = CurDAG->getRegister(0, MVT::i16);
350 bool isAMXSDNode(SDNode *
N)
const {
354 for (
unsigned Idx = 0,
E =
N->getNumValues(); Idx !=
E; ++Idx) {
355 if (
N->getValueType(Idx) == MVT::x86amx)
358 for (
unsigned Idx = 0,
E =
N->getNumOperands(); Idx !=
E; ++Idx) {
360 if (
Op.getValueType() == MVT::x86amx)
372 bool shouldAvoidImmediateInstFormsForSize(SDNode *
N)
const {
373 uint32_t UseCount = 0;
378 if (!CurDAG->shouldOptForSize())
382 for (
const SDNode *User :
N->users()) {
388 if (
User->isMachineOpcode()) {
395 User->getOperand(1).getNode() ==
N) {
406 if (
User->getNumOperands() != 2)
419 if (
User->getOpcode() == X86ISD::ADD ||
421 User->getOpcode() == X86ISD::SUB ||
427 OtherOp =
User->getOperand(1);
430 RegisterSDNode *RegNode;
434 if ((RegNode->
getReg() == X86::ESP) ||
435 (RegNode->
getReg() == X86::RSP))
444 return (UseCount > 1);
448 inline SDValue getI8Imm(
unsigned Imm,
const SDLoc &
DL) {
449 return CurDAG->getTargetConstant(
Imm,
DL, MVT::i8);
453 inline SDValue getI32Imm(
unsigned Imm,
const SDLoc &
DL) {
454 return CurDAG->getTargetConstant(
Imm,
DL, MVT::i32);
459 return CurDAG->getTargetConstant(
Imm,
DL, MVT::i64);
462 SDValue getExtractVEXTRACTImmediate(SDNode *
N,
unsigned VecWidth,
464 assert((VecWidth == 128 || VecWidth == 256) &&
"Unexpected vector width");
466 MVT VecVT =
N->getOperand(0).getSimpleValueType();
470 SDValue getInsertVINSERTImmediate(SDNode *
N,
unsigned VecWidth,
472 assert((VecWidth == 128 || VecWidth == 256) &&
"Unexpected vector width");
474 MVT VecVT =
N->getSimpleValueType(0);
478 SDValue getPermuteVINSERTCommutedImmediate(SDNode *
N,
unsigned VecWidth,
480 assert(VecWidth == 128 &&
"Unexpected vector width");
482 MVT VecVT =
N->getSimpleValueType(0);
484 assert((InsertIdx == 0 || InsertIdx == 1) &&
"Bad insertf128 index");
487 return getI8Imm(InsertIdx ? 0x02 : 0x30,
DL);
492 MVT VT =
N->getSimpleValueType(0);
495 SDVTList VTs = CurDAG->getVTList(MVT::i32, MVT::i32);
497 SDValue(CurDAG->getMachineNode(X86::MOV32r0, dl, VTs, {}), 0);
498 if (VT == MVT::i64) {
500 CurDAG->getMachineNode(
501 TargetOpcode::SUBREG_TO_REG, dl, MVT::i64,
Zero,
502 CurDAG->getTargetConstant(X86::sub_32bit, dl, MVT::i32)),
507 unsigned Opcode =
N->getOpcode();
508 assert((Opcode == X86ISD::SBB || Opcode == X86ISD::SETCC_CARRY) &&
509 "Unexpected opcode for SBB materialization");
510 unsigned FlagOpIndex = Opcode == X86ISD::SBB ? 2 : 1;
512 CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, X86::EFLAGS,
513 N->getOperand(FlagOpIndex),
SDValue());
517 unsigned Opc = VT == MVT::i64 ? X86::SBB64rr : X86::SBB32rr;
518 MVT SBBVT = VT == MVT::i64 ? MVT::i64 : MVT::i32;
519 VTs = CurDAG->getVTList(SBBVT, MVT::i32);
521 CurDAG->getMachineNode(
Opc, dl, VTs,
522 {Zero, Zero, EFLAGS, EFLAGS.getValue(1)}),
528 bool isUnneededShiftMask(SDNode *
N,
unsigned Width)
const {
530 const APInt &Val =
N->getConstantOperandAPInt(1);
535 APInt
Mask = Val | CurDAG->computeKnownBits(
N->getOperand(0)).Zero;
536 return Mask.countr_one() >= Width;
545 bool isDef32(SDNode *
N)
const {
546 unsigned Opc =
N->getOpcode();
551 !((
Opc == X86ISD::BSF ||
Opc == X86ISD::BSR) &&
559 SDNode *getGlobalBaseReg();
563 const X86TargetMachine &getTargetMachine()
const {
564 return static_cast<const X86TargetMachine &
>(TM);
569 const X86InstrInfo *getInstrInfo()
const {
570 return Subtarget->getInstrInfo();
579 bool ComplexPatternFuncMutatesDAG()
const override {
583 bool isSExtAbsoluteSymbolRef(
unsigned Width, SDNode *
N)
const;
586 bool useNonTemporalLoad(LoadSDNode *
N)
const {
587 if (!
N->isNonTemporal())
590 unsigned StoreSize =
N->getMemoryVT().getStoreSize();
592 if (
N->getAlign().value() < StoreSize)
601 return Subtarget->hasSSE41();
603 return Subtarget->hasAVX2();
605 return Subtarget->hasAVX512();
609 bool foldLoadStoreIntoMemOperand(SDNode *Node);
610 MachineSDNode *matchBEXTRFromAndImm(SDNode *Node);
611 bool matchBitExtract(SDNode *Node);
612 bool shrinkAndImmediate(SDNode *
N);
613 bool isMaskZeroExtended(SDNode *
N)
const;
614 bool tryShiftAmountMod(SDNode *
N);
615 bool tryShrinkShlLogicImm(SDNode *
N);
616 bool tryVPTERNLOG(SDNode *
N);
617 bool matchVPTERNLOG(SDNode *Root, SDNode *ParentA, SDNode *ParentB,
621 bool tryMatchBitSelect(SDNode *
N);
623 MachineSDNode *emitPCMPISTR(
unsigned ROpc,
unsigned MOpc,
bool MayFoldLoad,
624 const SDLoc &dl, MVT VT, SDNode *Node);
625 MachineSDNode *emitPCMPESTR(
unsigned ROpc,
unsigned MOpc,
bool MayFoldLoad,
626 const SDLoc &dl, MVT VT, SDNode *Node,
629 bool tryOptimizeRem8Extend(SDNode *
N);
631 bool onlyUsesZeroFlag(
SDValue Flags)
const;
632 bool hasNoSignFlagUses(
SDValue Flags)
const;
633 bool hasNoCarryFlagUses(
SDValue Flags)
const;
634 bool checkTCRetEnoughRegs(SDNode *
N)
const;
640 explicit X86DAGToDAGISelLegacy(X86TargetMachine &tm,
642 : SelectionDAGISelLegacy(
643 ID, std::make_unique<X86DAGToDAGISel>(tm, OptLevel)) {}
647char X86DAGToDAGISelLegacy::ID = 0;
654 unsigned Opcode =
N->getOpcode();
655 if (Opcode == X86ISD::CMPM || Opcode == X86ISD::CMPMM ||
656 Opcode == X86ISD::STRICT_CMPM || Opcode ==
ISD::SETCC ||
657 Opcode == X86ISD::CMPMM_SAE || Opcode == X86ISD::VFPCLASS) {
661 EVT OpVT =
N->getOperand(0).getValueType();
664 if (Opcode == X86ISD::STRICT_CMPM)
665 OpVT =
N->getOperand(1).getValueType();
672 if (Opcode == X86ISD::VFPCLASSS || Opcode == X86ISD::FSETCCM ||
673 Opcode == X86ISD::FSETCCM_SAE)
681bool X86DAGToDAGISel::isMaskZeroExtended(
SDNode *
N)
const {
693X86DAGToDAGISel::IsProfitableToFold(
SDValue N, SDNode *U, SDNode *Root)
const {
694 if (OptLevel == CodeGenOptLevel::None)
709 switch (
U->getOpcode()) {
736 if (
Imm->getAPIntValue().isSignedIntN(8))
745 Imm->getAPIntValue().getBitWidth() == 64 &&
746 Imm->getAPIntValue().isIntN(32))
753 (
Imm->getAPIntValue() == UINT8_MAX ||
754 Imm->getAPIntValue() == UINT16_MAX ||
755 Imm->getAPIntValue() == UINT32_MAX))
761 (-
Imm->getAPIntValue()).isSignedIntN(8))
764 if ((
U->getOpcode() == X86ISD::ADD ||
U->getOpcode() == X86ISD::SUB) &&
765 (-
Imm->getAPIntValue()).isSignedIntN(8) &&
766 hasNoCarryFlagUses(
SDValue(U, 1)))
780 if (Op1.
getOpcode() == X86ISD::Wrapper) {
791 if (
U->getOperand(0).getOpcode() ==
ISD::SHL &&
795 if (
U->getOperand(1).getOpcode() ==
ISD::SHL &&
804 if (
C &&
C->getSExtValue() == -2)
810 if (
C &&
C->getSExtValue() == -2)
845bool X86DAGToDAGISel::isProfitableToFormMaskedOp(SDNode *
N)
const {
847 (
N->getOpcode() ==
ISD::VSELECT ||
N->getOpcode() == X86ISD::SELECTS) &&
848 "Unexpected opcode!");
853 return N->getOperand(1).hasOneUse();
863 Ops.push_back(
Load.getOperand(0));
866 "Unexpected chain operand");
869 Ops.push_back(
Load.getOperand(0));
875 Ops.push_back(NewChain);
880 Load.getOperand(1),
Load.getOperand(2));
898 if (Callee.getNode() == Chain.
getNode() || !Callee.hasOneUse())
910 if (!Callee.getValue(1).hasOneUse())
941 Callee.getValue(1).hasOneUse())
959 const unsigned NumBytes =
BitWidth / 8;
963 const uint8_t OptionalPrefixBytes[] = {0x26, 0x2e, 0x36, 0x3e, 0x64,
964 0x65, 0x66, 0x67, 0xf0, 0xf2};
966 for (
unsigned I = 0;
I != NumBytes; ++
I)
967 Bytes[
I] = (
Imm >> (
I * 8)) & 0xFF;
969 for (
unsigned I = 0;
I + 3 < NumBytes; ++
I) {
970 if (Bytes[
I] != 0xf3)
977 if (J + 2 < NumBytes && Bytes[J] == 0x0f && Bytes[J + 1] == 0x1e &&
978 (Bytes[J + 2] == 0xfa || Bytes[J + 2] == 0xfb))
986 return (VT == MVT::v32i16 || VT == MVT::v32f16 || VT == MVT::v64i8);
1001void X86DAGToDAGISel::PreprocessISelDAG() {
1002 bool MadeChange =
false;
1004 E = CurDAG->allnodes_end();
I !=
E; ) {
1022 MVT VT =
N->getSimpleValueType(0);
1024 "ISD::Constant must have a scalar integer type");
1033 "cf-protection-branch");
1034 if (CFProtectionBranch ||
1040 CurDAG->getConstant(ComplementImm, dl, VT,
false,
true);
1041 Complement = CurDAG->getNOT(dl, Complement, VT);
1043 CurDAG->ReplaceAllUsesOfValueWith(
SDValue(
N, 0), Complement);
1053 if (
N->getOpcode() == X86ISD::AND && !
N->hasAnyUseOfValue(1)) {
1055 N->getOperand(0),
N->getOperand(1));
1057 CurDAG->ReplaceAllUsesOfValueWith(
SDValue(
N, 0), Res);
1081 auto mayPreventLoadFold = [&]() {
1084 !
N->getOperand(1).hasOneUse();
1087 N->getSimpleValueType(0).isVector() && !mayPreventLoadFold()) {
1095 MVT VT =
N->getSimpleValueType(0);
1103 CurDAG->getNode(NewOpcode,
DL, VT,
N->getOperand(0),
AllOnes);
1105 CurDAG->ReplaceAllUsesWith(
N, Res.
getNode());
1112 switch (
N->getOpcode()) {
1113 case X86ISD::VBROADCAST: {
1114 MVT VT =
N->getSimpleValueType(0);
1120 CurDAG->getNode(X86ISD::VBROADCAST, dl, NarrowVT,
N->getOperand(0));
1123 NarrowBCast, CurDAG->getIntPtrConstant(0, dl));
1126 CurDAG->getIntPtrConstant(Index, dl));
1129 CurDAG->ReplaceAllUsesWith(
N, Res.
getNode());
1137 case X86ISD::VBROADCAST_LOAD: {
1138 MVT VT =
N->getSimpleValueType(0);
1144 SDVTList VTs = CurDAG->getVTList(NarrowVT, MVT::Other);
1145 SDValue Ops[] = {MemNode->getChain(), MemNode->getBasePtr()};
1146 SDValue NarrowBCast = CurDAG->getMemIntrinsicNode(
1147 X86ISD::VBROADCAST_LOAD, dl, VTs,
Ops, MemNode->getMemoryVT(),
1148 MemNode->getMemOperand());
1151 NarrowBCast, CurDAG->getIntPtrConstant(0, dl));
1154 CurDAG->getIntPtrConstant(Index, dl));
1158 CurDAG->ReplaceAllUsesWith(
N, To);
1170 MVT VT =
N->getSimpleValueType(0);
1176 SDNode *MaxLd =
nullptr;
1177 SDValue Ptr = Ld->getBasePtr();
1178 SDValue Chain = Ld->getChain();
1179 for (SDNode *User : Ptr->
users()) {
1181 MVT UserVT =
User->getSimpleValueType(0);
1183 UserLd->getBasePtr() == Ptr && UserLd->getChain() == Chain &&
1184 !
User->hasAnyUseOfValue(1) &&
1198 CurDAG->getIntPtrConstant(0, dl));
1199 SDValue Res = CurDAG->getBitcast(VT, Extract);
1203 CurDAG->ReplaceAllUsesWith(
N, To);
1212 EVT EleVT =
N->getOperand(0).getValueType().getVectorElementType();
1213 if (EleVT == MVT::i1)
1217 assert(
N->getValueType(0).getVectorElementType() != MVT::i16 &&
1218 "We can't replace VSELECT with BLENDV in vXi16!");
1220 if (
Subtarget->hasVLX() && CurDAG->ComputeNumSignBits(
N->getOperand(0)) ==
1222 R = CurDAG->getNode(X86ISD::VPTERNLOG, SDLoc(
N),
N->getValueType(0),
1223 N->getOperand(0),
N->getOperand(1),
N->getOperand(2),
1224 CurDAG->getTargetConstant(0xCA, SDLoc(
N), MVT::i8));
1226 R = CurDAG->getNode(X86ISD::BLENDV, SDLoc(
N),
N->getValueType(0),
1227 N->getOperand(0),
N->getOperand(1),
1231 CurDAG->ReplaceAllUsesWith(
N,
R.getNode());
1244 if (!
N->getSimpleValueType(0).isVector())
1248 switch (
N->getOpcode()) {
1258 if (
N->isStrictFPOpcode())
1260 CurDAG->getNode(NewOpc, SDLoc(
N), {
N->getValueType(0), MVT::Other},
1261 {
N->getOperand(0),
N->getOperand(1)});
1264 CurDAG->getNode(NewOpc, SDLoc(
N),
N->getValueType(0),
1267 CurDAG->ReplaceAllUsesWith(
N, Res.
getNode());
1277 if (!
N->getValueType(0).isVector())
1281 switch (
N->getOpcode()) {
1283 case ISD::SHL: NewOpc = X86ISD::VSHLV;
break;
1284 case ISD::SRA: NewOpc = X86ISD::VSRAV;
break;
1285 case ISD::SRL: NewOpc = X86ISD::VSRLV;
break;
1287 SDValue Res = CurDAG->getNode(NewOpc, SDLoc(
N),
N->getValueType(0),
1288 N->getOperand(0),
N->getOperand(1));
1290 CurDAG->ReplaceAllUsesOfValueWith(
SDValue(
N, 0), Res);
1299 if (!
N->getValueType(0).isVector())
1303 if (
N->getOperand(0).getScalarValueSizeInBits() == 1) {
1305 "Unexpected opcode for mask vector!");
1313 SDValue Res = CurDAG->getNode(NewOpc, SDLoc(
N),
N->getValueType(0),
1316 CurDAG->ReplaceAllUsesOfValueWith(
SDValue(
N, 0), Res);
1336 switch (
N->getOpcode()) {
1352 bool IsStrict =
N->isStrictFPOpcode();
1355 Res = CurDAG->getNode(X86ISD::STRICT_VRNDSCALE, dl,
1356 {
N->getValueType(0), MVT::Other},
1357 {
N->getOperand(0),
N->getOperand(1),
1358 CurDAG->getTargetConstant(
Imm, dl, MVT::i32)});
1360 Res = CurDAG->getNode(X86ISD::VRNDSCALE, dl,
N->getValueType(0),
1362 CurDAG->getTargetConstant(
Imm, dl, MVT::i32));
1364 CurDAG->ReplaceAllUsesWith(
N, Res.
getNode());
1372 case X86ISD::FXOR: {
1375 MVT VT =
N->getSimpleValueType(0);
1376 if (VT.
isVector() || VT == MVT::f128)
1379 MVT VecVT = VT == MVT::f64 ? MVT::v2f64
1380 : VT == MVT::f32 ? MVT::v4f32
1391 EVT IntVT = EVT(VecVT).changeVectorElementTypeToInteger();
1395 switch (
N->getOpcode()) {
1397 case X86ISD::FANDN:
Opc = X86ISD::ANDNP;
break;
1402 Res = CurDAG->getNode(
Opc, dl, IntVT, Op0, Op1);
1405 Res = CurDAG->getNode(
N->getOpcode(), dl, VecVT, Op0, Op1);
1408 CurDAG->getIntPtrConstant(0, dl));
1410 CurDAG->ReplaceAllUsesOfValueWith(
SDValue(
N, 0), Res);
1417 MVT VT =
N->getSimpleValueType(0);
1423 if (isMaskZeroExtended(
N))
1435 MVT WideVT =
Cmp.getSimpleValueType();
1436 SDValue ZeroIdx = CurDAG->getIntPtrConstant(0, dl);
1440 V.getOperand(0).getValueType() == WideVT)
1441 return V.getOperand(0);
1443 CurDAG->getUNDEF(WideVT),
V, ZeroIdx);
1450 CurDAG->ReplaceAllUsesOfValueWith(
SDValue(
N, 0), Res);
1457 if (OptLevel != CodeGenOptLevel::None &&
1461 ((
N->getOpcode() == X86ISD::CALL && !
Subtarget->slowTwoMemOps() &&
1463 (
N->getOpcode() == X86ISD::TC_RETURN &&
1465 !getTargetMachine().isPositionIndependent())))) {
1485 bool HasCallSeq =
N->getOpcode() == X86ISD::CALL;
1490 if (
N->getOpcode() == X86ISD::TC_RETURN && !checkTCRetEnoughRegs(
N))
1506 switch (
N->getOpcode()) {
1511 MVT SrcVT =
N->getOperand(0).getSimpleValueType();
1512 MVT DstVT =
N->getSimpleValueType(0);
1520 const X86TargetLowering *X86Lowering =
1521 static_cast<const X86TargetLowering *
>(
TLI);
1524 if (SrcIsSSE && DstIsSSE)
1527 if (!SrcIsSSE && !DstIsSSE) {
1532 if (
N->getConstantOperandVal(1))
1540 SDValue MemTmp = CurDAG->CreateStackTemporary(MemVT);
1542 MachinePointerInfo MPI =
1549 CurDAG->getEntryNode(), dl,
N->getOperand(0), MemTmp, MPI, MemVT);
1551 MemTmp, MPI, MemVT);
1558 CurDAG->ReplaceAllUsesOfValueWith(
SDValue(
N, 0), Result);
1567 MVT SrcVT =
N->getOperand(1).getSimpleValueType();
1568 MVT DstVT =
N->getSimpleValueType(0);
1576 const X86TargetLowering *X86Lowering =
1577 static_cast<const X86TargetLowering *
>(
TLI);
1580 if (SrcIsSSE && DstIsSSE)
1583 if (!SrcIsSSE && !DstIsSSE) {
1588 if (
N->getConstantOperandVal(2))
1596 SDValue MemTmp = CurDAG->CreateStackTemporary(MemVT);
1598 MachinePointerInfo MPI =
1607 SDVTList VTs = CurDAG->getVTList(MVT::Other);
1608 SDValue Ops[] = {
N->getOperand(0),
N->getOperand(1), MemTmp};
1609 Store = CurDAG->getMemIntrinsicNode(X86ISD::FST, dl, VTs,
Ops, MemVT,
1612 if (
N->getFlags().hasNoFPExcept()) {
1614 Flags.setNoFPExcept(
true);
1615 Store->setFlags(Flags);
1618 assert(SrcVT == MemVT &&
"Unexpected VT!");
1619 Store = CurDAG->getStore(
N->getOperand(0), dl,
N->getOperand(1), MemTmp,
1624 SDVTList VTs = CurDAG->getVTList(DstVT, MVT::Other);
1626 Result = CurDAG->getMemIntrinsicNode(
1627 X86ISD::FLD, dl, VTs,
Ops, MemVT, MPI,
1629 if (
N->getFlags().hasNoFPExcept()) {
1631 Flags.setNoFPExcept(
true);
1635 assert(DstVT == MemVT &&
"Unexpected VT!");
1636 Result = CurDAG->getLoad(DstVT, dl,
Store, MemTmp, MPI);
1644 CurDAG->ReplaceAllUsesWith(
N,
Result.getNode());
1658 CurDAG->RemoveDeadNodes();
1662bool X86DAGToDAGISel::tryOptimizeRem8Extend(SDNode *
N) {
1663 unsigned Opc =
N->getMachineOpcode();
1664 if (
Opc != X86::MOVZX32rr8 &&
Opc != X86::MOVSX32rr8 &&
1665 Opc != X86::MOVSX64rr8)
1677 unsigned ExpectedOpc =
Opc == X86::MOVZX32rr8 ? X86::MOVZX32rr8_NOREX
1678 : X86::MOVSX32rr8_NOREX;
1683 if (
Opc == X86::MOVSX64rr8) {
1686 MachineSDNode *Extend = CurDAG->getMachineNode(X86::MOVSX64rr32, SDLoc(
N),
1688 ReplaceUses(
N, Extend);
1697void X86DAGToDAGISel::PostprocessISelDAG() {
1699 if (TM.getOptLevel() == CodeGenOptLevel::None)
1704 bool MadeChange =
false;
1705 while (Position != CurDAG->allnodes_begin()) {
1706 SDNode *
N = &*--Position;
1708 if (
N->use_empty() || !
N->isMachineOpcode())
1711 if (tryOptimizeRem8Extend(
N)) {
1716 unsigned Opc =
N->getMachineOpcode();
1727 case X86::CTEST16rr:
1728 case X86::CTEST32rr:
1729 case X86::CTEST64rr: {
1735#define CASE_ND(OP) \
1738 switch (
And.getMachineOpcode()) {
1745 if (
And->hasAnyUseOfValue(1))
1748 Ops[0] =
And.getOperand(0);
1749 Ops[1] =
And.getOperand(1);
1750 MachineSDNode *
Test =
1751 CurDAG->getMachineNode(
Opc, SDLoc(
N), MVT::i32,
Ops);
1752 ReplaceUses(
N,
Test);
1760 if (
And->hasAnyUseOfValue(1))
1763 bool IsCTESTCC = X86::isCTESTCC(
Opc);
1764#define FROM_TO(A, B) \
1765 CASE_ND(A) NewOpc = IsCTESTCC ? X86::C##B : X86::B; \
1767 switch (
And.getMachineOpcode()) {
1777 And.getOperand(3),
And.getOperand(4),
1778 And.getOperand(5),
And.getOperand(0)};
1781 Ops.push_back(
N->getOperand(2));
1782 Ops.push_back(
N->getOperand(3));
1785 Ops.push_back(
And.getOperand(6));
1788 Ops.push_back(
N->getOperand(4));
1790 MachineSDNode *
Test = CurDAG->getMachineNode(
1791 NewOpc, SDLoc(
N), MVT::i32, MVT::Other,
Ops);
1792 CurDAG->setNodeMemRefs(
1805 case X86::KORTESTBkk:
1806 case X86::KORTESTWkk:
1807 case X86::KORTESTDkk:
1808 case X86::KORTESTQkk: {
1810 if (Op0 !=
N->getOperand(1) || !
N->isOnlyUserOf(Op0.
getNode()) ||
1825#define FROM_TO(A, B) \
1837 if (NewOpc == X86::KTESTWkk && !
Subtarget->hasDQI())
1840 MachineSDNode *KTest = CurDAG->getMachineNode(
1842 ReplaceUses(
N, KTest);
1847 case TargetOpcode::SUBREG_TO_REG: {
1848 unsigned SubRegIdx =
N->getConstantOperandVal(1);
1849 if (SubRegIdx != X86::sub_xmm && SubRegIdx != X86::sub_ymm)
1866 CASE(VMOVAPDZ128rr)
CASE(VMOVUPDZ128rr)
1867 CASE(VMOVAPSZ128rr)
CASE(VMOVUPSZ128rr)
1868 CASE(VMOVDQA32Z128rr)
CASE(VMOVDQU32Z128rr)
1869 CASE(VMOVDQA64Z128rr)
CASE(VMOVDQU64Z128rr)
1870 CASE(VMOVAPDZ256rr)
CASE(VMOVUPDZ256rr)
1871 CASE(VMOVAPSZ256rr)
CASE(VMOVUPSZ256rr)
1872 CASE(VMOVDQA32Z256rr)
CASE(VMOVDQU32Z256rr)
1873 CASE(VMOVDQA64Z256rr)
CASE(VMOVDQU64Z256rr)
1878 if (!
In.isMachineOpcode() ||
1879 In.getMachineOpcode() <= TargetOpcode::GENERIC_OP_END)
1884 uint64_t TSFlags = getInstrInfo()->get(
In.getMachineOpcode()).TSFlags;
1892 CurDAG->UpdateNodeOperands(
N, In,
N->getOperand(1));
1899 CurDAG->RemoveDeadNodes();
1904void X86DAGToDAGISel::emitSpecialCodeForMain() {
1906 TargetLowering::ArgListTy
Args;
1907 auto &
DL = CurDAG->getDataLayout();
1909 TargetLowering::CallLoweringInfo CLI(*CurDAG);
1910 CLI.setChain(CurDAG->getRoot())
1911 .setCallee(CallingConv::C, Type::getVoidTy(*CurDAG->getContext()),
1914 const TargetLowering &
TLI = CurDAG->getTargetLoweringInfo();
1916 CurDAG->setRoot(
Result.second);
1920void X86DAGToDAGISel::emitFunctionEntryCode() {
1923 if (
F.hasExternalLinkage() &&
F.getName() ==
"main")
1924 emitSpecialCodeForMain();
1938 X86ISelAddressMode &AM) {
1943 int64_t Val = AM.Disp +
Offset;
1946 if (Val != 0 && (AM.ES || AM.MCSym))
1953 AM.hasSymbolicDisplacement()))
1957 if (AM.BaseType == X86ISelAddressMode::FrameIndexBase &&
1978 !AM.hasBaseOrIndexReg())
1983 if (Val < -(int64_t)UINT16_MAX || Val > (int64_t)UINT16_MAX)
1993bool X86DAGToDAGISel::matchLoadInAddress(LoadSDNode *
N, X86ISelAddressMode &AM,
1994 bool AllowSegmentRegForX32) {
2007 !IndirectTlsSegRefs &&
2010 if (
Subtarget->isTarget64BitILP32() && !AllowSegmentRegForX32)
2012 switch (
N->getPointerInfo().getAddrSpace()) {
2014 AM.Segment = CurDAG->getRegister(X86::GS, MVT::i16);
2017 AM.Segment = CurDAG->getRegister(X86::FS, MVT::i16);
2030bool X86DAGToDAGISel::matchWrapper(
SDValue N, X86ISelAddressMode &AM) {
2033 if (AM.hasSymbolicDisplacement())
2036 bool IsRIPRelTLS =
false;
2037 bool IsRIPRel =
N.getOpcode() == X86ISD::WrapperRIP;
2054 if (IsRIPRel && AM.hasBaseOrIndexReg())
2058 X86ISelAddressMode Backup = AM;
2063 AM.GV =
G->getGlobal();
2064 AM.SymbolFlags =
G->getTargetFlags();
2067 AM.CP = CP->getConstVal();
2068 AM.Alignment = CP->getAlign();
2069 AM.SymbolFlags = CP->getTargetFlags();
2070 Offset = CP->getOffset();
2072 AM.ES = S->getSymbol();
2073 AM.SymbolFlags = S->getTargetFlags();
2075 AM.MCSym = S->getMCSymbol();
2077 AM.JT = J->getIndex();
2078 AM.SymbolFlags = J->getTargetFlags();
2080 AM.BlockAddr = BA->getBlockAddress();
2081 AM.SymbolFlags = BA->getTargetFlags();
2082 Offset = BA->getOffset();
2087 if (
Subtarget->is64Bit() && !IsRIPRel && AM.GV &&
2088 TM.isLargeGlobalValue(AM.GV)) {
2093 if (foldOffsetIntoAddress(
Offset, AM)) {
2099 AM.setBaseReg(CurDAG->getRegister(X86::RIP, MVT::i64));
2107bool X86DAGToDAGISel::matchAddress(
SDValue N, X86ISelAddressMode &AM) {
2108 if (matchAddressRecursively(
N, AM, 0))
2116 AM.BaseType == X86ISelAddressMode::RegBase &&
2117 AM.Base_Reg.
getNode() !=
nullptr && AM.IndexReg.
getNode() ==
nullptr) {
2118 SDValue Save_Base_Reg = AM.Base_Reg;
2121 if (matchLoadInAddress(LoadN, AM,
true))
2122 AM.Base_Reg = Save_Base_Reg;
2131 if (AM.Scale == 2 && !AM.NegateIndex &&
2132 AM.BaseType == X86ISelAddressMode::RegBase &&
2133 AM.Base_Reg.
getNode() ==
nullptr) {
2134 AM.Base_Reg = AM.IndexReg;
2141 (!AM.GV || !TM.isLargeGlobalValue(AM.GV)) &&
Subtarget->is64Bit() &&
2142 AM.Scale == 1 && AM.BaseType == X86ISelAddressMode::RegBase &&
2143 AM.Base_Reg.
getNode() ==
nullptr && AM.IndexReg.
getNode() ==
nullptr &&
2155 AM.Base_Reg = CurDAG->getRegister(X86::RIP, MVT::i64);
2168bool X86DAGToDAGISel::hasMaterializingUse(
SDValue V)
const {
2170 for (SDUse &U :
V->uses()) {
2171 if (
U.getResNo() !=
V.getResNo())
2173 SDNode *
User =
U.getUser();
2179 if (St->getValue() ==
V)
2190 if (!
User->isMachineOpcode())
2192 const MCInstrDesc &
Desc =
TII->get(
User->getMachineOpcode());
2193 if (!
Desc.mayStore())
2196 if (MemRefBegin < 0)
2199 for (
unsigned I = 0,
E =
User->getNumOperands();
I !=
E; ++
I) {
2200 if (
I >=
static_cast<unsigned>(MemRefBegin) &&
I < MemRefEnd)
2212bool X86DAGToDAGISel::matchAdd(
SDValue &
N, X86ISelAddressMode &AM,
2216 HandleSDNode Handle(
N);
2218 auto IsAddOrAddLike = [&](
SDValue V) {
2219 return V.getOpcode() ==
ISD::ADD || CurDAG->isADDLike(
V);
2228 auto SplitsMaterializedValue = [&](
SDValue Op) {
2229 if (!AM.IsForLEA || !hasMaterializingUse(
Op))
2233 if (IsAddOrAddLike(
Op))
2234 return IsAddOrAddLike(
Op.getOperand(0)) ||
2235 IsAddOrAddLike(
Op.getOperand(1));
2240 return C->getZExtValue() >= 1 &&
C->getZExtValue() <= 3 &&
2241 IsAddOrAddLike(
Op.getOperand(0));
2261 if (SplitsMaterializedValue(
Op) && !AM.isRIPRelative())
2262 return matchAddressBase(
Op, AM);
2263 return matchAddressRecursively(
Op, AM,
Depth + 1);
2266 X86ISelAddressMode Backup = AM;
2267 if (!MatchOperand(
N.getOperand(0)) &&
2268 !MatchOperand(Handle.getValue().getOperand(1)))
2273 if (!MatchOperand(Handle.getValue().getOperand(1)) &&
2274 !MatchOperand(Handle.getValue().getOperand(0)))
2281 if (AM.BaseType == X86ISelAddressMode::RegBase &&
2284 N = Handle.getValue();
2290 N = Handle.getValue();
2300 if (
N->getNodeId() == -1 ||
2320 X86ISelAddressMode &AM) {
2327 if (ScaleLog <= 0 || ScaleLog >= 4 ||
2328 Mask != (0xffu << ScaleLog))
2331 MVT XVT =
X.getSimpleValueType();
2332 MVT VT =
N.getSimpleValueType();
2357 AM.Scale = (1 << ScaleLog);
2365 X86ISelAddressMode &AM) {
2376 bool FoundAnyExtend =
false;
2380 FoundAnyExtend =
true;
2398 if (ShiftAmt != 1 && ShiftAmt != 2 && ShiftAmt != 3)
2401 MVT VT =
N.getSimpleValueType();
2403 if (FoundAnyExtend) {
2424 AM.Scale = 1 << ShiftAmt;
2425 AM.IndexReg = NewAnd;
2459 X86ISelAddressMode &AM) {
2465 unsigned MaskIdx, MaskLen;
2468 unsigned MaskLZ = 64 - (MaskIdx + MaskLen);
2474 unsigned AMShiftAmt = MaskIdx;
2478 if (AMShiftAmt == 0 || AMShiftAmt > 3)
return true;
2482 unsigned ScaleDown = (64 -
X.getSimpleValueType().getSizeInBits()) + ShiftAmt;
2483 if (MaskLZ < ScaleDown)
2485 MaskLZ -= ScaleDown;
2493 bool ReplacingAnyExtend =
false;
2495 unsigned ExtendBits =
X.getSimpleValueType().getSizeInBits() -
2496 X.getOperand(0).getSimpleValueType().getSizeInBits();
2499 X =
X.getOperand(0);
2500 MaskLZ = ExtendBits > MaskLZ ? 0 : MaskLZ - ExtendBits;
2501 ReplacingAnyExtend =
true;
2503 APInt MaskedHighBits =
2510 MVT VT =
N.getSimpleValueType();
2511 if (ReplacingAnyExtend) {
2512 assert(
X.getValueType() != VT);
2519 MVT XVT =
X.getSimpleValueType();
2540 AM.Scale = 1 << AMShiftAmt;
2541 AM.IndexReg = NewExt;
2551 X86ISelAddressMode &AM,
2564 unsigned MaskIdx, MaskLen;
2572 unsigned AMShiftAmt = MaskIdx;
2576 if (AMShiftAmt == 0 || AMShiftAmt > 3)
return true;
2578 MVT XVT =
X.getSimpleValueType();
2579 MVT VT =
N.getSimpleValueType();
2604 AM.Scale = 1 << AMShiftAmt;
2605 AM.IndexReg = NewExt;
2612 X86ISelAddressMode &AM,
2614 assert(AM.IndexReg.
getNode() ==
nullptr &&
"IndexReg already matched");
2615 assert((AM.Scale == 1 || AM.Scale == 2 || AM.Scale == 4 || AM.Scale == 8) &&
2616 "Illegal index scale");
2622 EVT VT =
N.getValueType();
2623 unsigned Opc =
N.getOpcode();
2626 if (CurDAG->isBaseWithConstantOffset(
N)) {
2629 if (!foldOffsetIntoAddress(
Offset, AM))
2630 return matchIndexRecursively(
N.getOperand(0), AM,
Depth + 1);
2634 if (
Opc ==
ISD::ADD &&
N.getOperand(0) ==
N.getOperand(1)) {
2635 if (AM.Scale <= 4) {
2637 return matchIndexRecursively(
N.getOperand(0), AM,
Depth + 1);
2642 if (
Opc == X86ISD::VSHLI) {
2643 uint64_t ShiftAmt =
N.getConstantOperandVal(1);
2644 uint64_t ScaleAmt = 1ULL << ShiftAmt;
2645 if ((AM.Scale * ScaleAmt) <= 8) {
2646 AM.Scale *= ScaleAmt;
2647 return matchIndexRecursively(
N.getOperand(0), AM,
Depth + 1);
2655 if (Src.getOpcode() ==
ISD::ADD && Src->getFlags().hasNoSignedWrap() &&
2657 if (CurDAG->isBaseWithConstantOffset(Src)) {
2658 SDValue AddSrc = Src.getOperand(0);
2660 int64_t
Offset = AddVal->getSExtValue();
2669 CurDAG->ReplaceAllUsesWith(
N, ExtAdd);
2670 CurDAG->RemoveDeadNode(
N.getNode());
2682 unsigned SrcOpc = Src.getOpcode();
2683 if (((SrcOpc ==
ISD::ADD && Src->getFlags().hasNoUnsignedWrap()) ||
2684 CurDAG->isADDLike(Src,
true)) &&
2686 if (CurDAG->isBaseWithConstantOffset(Src)) {
2687 SDValue AddSrc = Src.getOperand(0);
2689 if (!foldOffsetIntoAddress(
Offset * AM.Scale, AM)) {
2700 if ((AM.Scale * ScaleAmt) <= 8 &&
2702 CurDAG->MaskedValueIsZero(ShVal, HiBits))) {
2703 AM.Scale *= ScaleAmt;
2704 SDValue ExtShVal = CurDAG->getNode(
Opc,
DL, VT, ShVal);
2715 SDValue ExtAdd = CurDAG->getNode(SrcOpc,
DL, VT, ExtSrc, ExtVal);
2719 CurDAG->ReplaceAllUsesWith(
N, ExtAdd);
2720 CurDAG->RemoveDeadNode(
N.getNode());
2721 return Res ? Res : ExtSrc;
2731bool X86DAGToDAGISel::matchAddressRecursively(
SDValue N, X86ISelAddressMode &AM,
2734 dbgs() <<
"MatchAddress: ";
2739 return matchAddressBase(
N, AM);
2744 if (AM.isRIPRelative()) {
2748 if (!(AM.ES || AM.MCSym) && AM.JT != -1)
2752 if (!foldOffsetIntoAddress(Cst->getSExtValue(), AM))
2757 switch (
N.getOpcode()) {
2760 if (!AM.hasSymbolicDisplacement() && AM.Disp == 0)
2763 AM.MCSym = ESNode->getMCSymbol();
2770 if (!foldOffsetIntoAddress(Val, AM))
2775 case X86ISD::Wrapper:
2776 case X86ISD::WrapperRIP:
2777 if (!matchWrapper(
N, AM))
2787 if (AM.BaseType == X86ISelAddressMode::RegBase &&
2788 AM.Base_Reg.
getNode() ==
nullptr &&
2790 AM.BaseType = X86ISelAddressMode::FrameIndexBase;
2797 if (AM.IndexReg.
getNode() !=
nullptr || AM.Scale != 1)
2801 unsigned Val = CN->getZExtValue();
2806 if (Val == 1 || Val == 2 || Val == 3) {
2808 AM.Scale = 1 << Val;
2809 AM.IndexReg = matchIndexRecursively(ShVal, AM,
Depth + 1);
2817 if (AM.IndexReg.
getNode() !=
nullptr || AM.Scale != 1)
break;
2821 assert(
N.getSimpleValueType().getSizeInBits() <= 64 &&
2822 "Unexpected value size!");
2834 uint64_t Mask =
And.getConstantOperandVal(1) >>
N.getConstantOperandVal(1);
2846 if (
N.getResNo() != 0)
break;
2849 case X86ISD::MUL_IMM:
2851 if (AM.BaseType == X86ISelAddressMode::RegBase &&
2852 AM.Base_Reg.
getNode() ==
nullptr &&
2853 AM.IndexReg.
getNode() ==
nullptr) {
2855 if (CN->getZExtValue() == 3 || CN->getZExtValue() == 5 ||
2856 CN->getZExtValue() == 9) {
2857 AM.Scale = unsigned(CN->getZExtValue())-1;
2869 uint64_t Disp = AddVal->getSExtValue() * CN->getZExtValue();
2870 if (foldOffsetIntoAddress(Disp, AM))
2871 Reg =
N.getOperand(0);
2873 Reg =
N.getOperand(0);
2876 AM.IndexReg = AM.Base_Reg =
Reg;
2894 HandleSDNode Handle(
N);
2897 X86ISelAddressMode Backup = AM;
2898 if (matchAddressRecursively(
N.getOperand(0), AM,
Depth+1)) {
2899 N = Handle.getValue();
2903 N = Handle.getValue();
2905 if (AM.IndexReg.
getNode() || AM.isRIPRelative()) {
2924 std::optional<unsigned> NegScale;
2927 uint64_t ShVal = ShAmt->getZExtValue();
2928 if (ShVal >= 1 && ShVal <= 3) {
2929 NegScale = 1u << ShVal;
2947 RHS.getOperand(0).getValueType() == MVT::i32))
2950 bool BaseIsNegatedValue = NegScale &&
2951 AM.BaseType == X86ISelAddressMode::RegBase &&
2958 if (((AM.BaseType == X86ISelAddressMode::RegBase && AM.Base_Reg.
getNode() &&
2960 AM.BaseType == X86ISelAddressMode::FrameIndexBase) &&
2961 !BaseIsNegatedValue)
2965 if ((AM.hasSymbolicDisplacement() && !Backup.hasSymbolicDisplacement()) +
2966 ((AM.Disp != 0) && (Backup.Disp == 0)) +
2979 AM.NegateIndex =
true;
2980 AM.Scale = NegScale.value_or(1);
2987 if (!CurDAG->isADDLike(
N))
2991 if (!matchAdd(
N, AM,
Depth))
3000 if (AM.IndexReg.
getNode() !=
nullptr || AM.Scale != 1)
break;
3004 assert(
N.getSimpleValueType().getSizeInBits() <= 64 &&
3005 "Unexpected value size!");
3010 if (
N.getOperand(0).getOpcode() ==
ISD::SRL) {
3039 if (AM.IndexReg.
getNode() !=
nullptr || AM.Scale != 1)
3047 if (
SDValue Index = matchIndexRecursively(
N, AM,
Depth + 1))
3049 AM.IndexReg =
Index;
3055 if (Src.getOpcode() ==
ISD::AND && Src.hasOneUse())
3057 Mask = MaskC->getAPIntValue();
3058 Src = Src.getOperand(0);
3061 if (Src.getOpcode() ==
ISD::SHL && Src.hasOneUse() &&
N->hasOneUse()) {
3063 SDValue ShlSrc = Src.getOperand(0);
3064 SDValue ShlAmt = Src.getOperand(1);
3068 unsigned ShAmtV = ShAmtC->getZExtValue();
3076 if (!Src->getFlags().hasNoUnsignedWrap() &&
3077 !CurDAG->MaskedValueIsZero(ShlSrc, HighZeros & Mask))
3085 MVT VT =
N.getSimpleValueType();
3089 if (!
Mask.isAllOnes()) {
3090 Res = CurDAG->getConstant(
Mask.lshr(ShAmtV),
DL, SrcVT);
3092 Res = CurDAG->getNode(
ISD::AND,
DL, SrcVT, ShlSrc, Res);
3099 CurDAG->ReplaceAllUsesWith(
N, NewShl);
3100 CurDAG->RemoveDeadNode(
N.getNode());
3103 AM.Scale = 1 << ShAmtV;
3107 AM.IndexReg = matchIndexRecursively(Zext, AM,
Depth + 1);
3111 if (Src.getOpcode() ==
ISD::SRL && !
Mask.isAllOnes()) {
3114 Src.getOperand(0), AM))
3119 Src.getOperand(0), AM))
3132 return matchAddressBase(
N, AM);
3137bool X86DAGToDAGISel::matchAddressBase(
SDValue N, X86ISelAddressMode &AM) {
3139 if (AM.BaseType != X86ISelAddressMode::RegBase || AM.Base_Reg.
getNode()) {
3152 AM.BaseType = X86ISelAddressMode::RegBase;
3157bool X86DAGToDAGISel::matchVectorAddressRecursively(
SDValue N,
3158 X86ISelAddressMode &AM,
3161 dbgs() <<
"MatchVectorAddress: ";
3166 return matchAddressBase(
N, AM);
3169 switch (
N.getOpcode()) {
3172 if (!foldOffsetIntoAddress(Val, AM))
3176 case X86ISD::Wrapper:
3177 if (!matchWrapper(
N, AM))
3183 HandleSDNode Handle(
N);
3185 X86ISelAddressMode Backup = AM;
3186 if (!matchVectorAddressRecursively(
N.getOperand(0), AM,
Depth + 1) &&
3187 !matchVectorAddressRecursively(Handle.getValue().getOperand(1), AM,
3193 if (!matchVectorAddressRecursively(Handle.getValue().getOperand(1), AM,
3195 !matchVectorAddressRecursively(Handle.getValue().getOperand(0), AM,
3200 N = Handle.getValue();
3205 return matchAddressBase(
N, AM);
3211bool X86DAGToDAGISel::matchVectorAddress(
SDValue N, X86ISelAddressMode &AM) {
3212 return matchVectorAddressRecursively(
N, AM, 0);
3215bool X86DAGToDAGISel::selectVectorAddr(MemSDNode *Parent,
SDValue BasePtr,
3220 X86ISelAddressMode AM;
3226 AM.IndexReg = matchIndexRecursively(IndexOp, AM, 0);
3228 AM.IndexReg = IndexOp;
3232 AM.Segment = CurDAG->getRegister(X86::GS, MVT::i16);
3234 AM.Segment = CurDAG->getRegister(X86::FS, MVT::i16);
3236 AM.Segment = CurDAG->getRegister(X86::SS, MVT::i16);
3239 MVT VT =
BasePtr.getSimpleValueType();
3242 if (matchVectorAddress(BasePtr, AM))
3245 getAddressOperands(AM,
DL, VT,
Base, Scale, Index, Disp, Segment);
3258 SDValue &Segment,
bool AllowNonRIP) {
3259 X86ISelAddressMode AM;
3266 Parent->
getOpcode() != X86ISD::TLSCALL &&
3267 Parent->
getOpcode() != X86ISD::ENQCMD &&
3268 Parent->
getOpcode() != X86ISD::ENQCMDS &&
3269 Parent->
getOpcode() != X86ISD::EH_SJLJ_SETJMP &&
3270 Parent->
getOpcode() != X86ISD::EH_SJLJ_LONGJMP) {
3271 unsigned AddrSpace =
3274 AM.Segment = CurDAG->getRegister(X86::GS, MVT::i16);
3276 AM.Segment = CurDAG->getRegister(X86::FS, MVT::i16);
3278 AM.Segment = CurDAG->getRegister(X86::SS, MVT::i16);
3283 MVT VT =
N.getSimpleValueType();
3285 if (matchAddress(
N, AM))
3288 if (!AllowNonRIP && !AM.isRIPRelative())
3291 getAddressOperands(AM,
DL, VT,
Base, Scale, Index, Disp, Segment);
3300 bool AllowNonRIP =
Subtarget->hasNDDM();
3303 return U->getOpcode() == X86ISD::CMOV;
3305 return selectAddr(Parent,
N,
Base, Scale, Index, Disp, Segment, AllowNonRIP);
3317 if (
N->getOpcode() != X86ISD::Wrapper)
3320 N =
N.getOperand(0);
3337 return CR->getUnsignedMax().ult(1ull << 32);
3339 return !TM.isLargeGlobalValue(GV);
3348 if (!selectLEAAddr(
N,
Base, Scale, Index, Disp, Segment))
3354 SubReg = X86::sub_8bit;
3356 SubReg = X86::sub_16bit;
3358 SubReg = X86::sub_32bit;
3361 if (RN &&
RN->getReg() == 0)
3362 Base = CurDAG->getRegister(0, MVT::i64);
3369 Base = CurDAG->getTargetInsertSubreg(SubReg,
DL, MVT::i64, ImplDef,
Base);
3372 [[maybe_unused]] EVT IndexType =
Index.getValueType();
3374 if (RN &&
RN->getReg() == 0)
3375 Index = CurDAG->getRegister(0, MVT::i64);
3378 "Expect to be extending 8/16/32-bit registers for use in LEA");
3381 Index = CurDAG->getTargetInsertSubreg(SubReg,
DL, MVT::i64, ImplDef, Index);
3389bool X86DAGToDAGISel::selectLEAAddr(
SDValue N,
3393 X86ISelAddressMode AM;
3398 MVT VT =
N.getSimpleValueType();
3403 SDValue T = CurDAG->getRegister(0, MVT::i32);
3405 if (matchAddress(
N, AM))
3410 unsigned Complexity = 0;
3411 if (AM.BaseType == X86ISelAddressMode::RegBase && AM.Base_Reg.
getNode())
3413 else if (AM.BaseType == X86ISelAddressMode::FrameIndexBase)
3429 if (AM.hasSymbolicDisplacement()) {
3441 auto isMathWithFlags = [](
SDValue V) {
3442 switch (
V.getOpcode()) {
3456 return !
SDValue(
V.getNode(), 1).use_empty();
3463 if (isMathWithFlags(
N.getOperand(0)) || isMathWithFlags(
N.getOperand(1)))
3471 if (Complexity <= 2)
3474 getAddressOperands(AM,
DL, VT,
Base, Scale, Index, Disp, Segment);
3485 X86ISelAddressMode AM;
3487 AM.GV = GA->getGlobal();
3488 AM.Disp += GA->getOffset();
3489 AM.SymbolFlags = GA->getTargetFlags();
3492 AM.ES = SA->getSymbol();
3493 AM.SymbolFlags = SA->getTargetFlags();
3498 AM.IndexReg = CurDAG->getRegister(X86::EBX, MVT::i32);
3501 MVT VT =
N.getSimpleValueType();
3502 getAddressOperands(AM, SDLoc(
N), VT,
Base, Scale, Index, Disp, Segment);
3510 EVT VT =
N.getValueType();
3511 bool WasTruncated =
false;
3513 WasTruncated =
true;
3514 N =
N.getOperand(0);
3517 if (
N.getOpcode() != X86ISD::Wrapper)
3523 unsigned Opc =
N.getOperand(0)->getOpcode();
3525 Op =
N.getOperand(0);
3528 return !WasTruncated;
3533 std::optional<ConstantRange> CR = GA->getGlobal()->getAbsoluteSymbolRange();
3534 if (!CR || CR->getUnsignedMax().uge(1ull << VT.
getSizeInBits()))
3538 Op = CurDAG->getTargetGlobalAddress(GA->getGlobal(), SDLoc(
N), VT,
3539 GA->getOffset(), GA->getTargetFlags());
3543bool X86DAGToDAGISel::tryFoldLoad(SDNode *Root, SDNode *
P,
SDValue N,
3547 assert(Root &&
P &&
"Unknown root/parent nodes");
3549 !IsProfitableToFold(
N,
P, Root) ||
3550 !IsLegalToFold(
N,
P, Root, OptLevel))
3553 return selectAddr(
N.getNode(),
3554 N.getOperand(1),
Base, Scale, Index, Disp, Segment);
3557bool X86DAGToDAGISel::tryFoldBroadcast(SDNode *Root, SDNode *
P,
SDValue N,
3561 assert(Root &&
P &&
"Unknown root/parent nodes");
3562 if (
N->getOpcode() != X86ISD::VBROADCAST_LOAD ||
3563 !IsProfitableToFold(
N,
P, Root) ||
3564 !IsLegalToFold(
N,
P, Root, OptLevel))
3567 return selectAddr(
N.getNode(),
3568 N.getOperand(1),
Base, Scale, Index, Disp, Segment);
3574SDNode *X86DAGToDAGISel::getGlobalBaseReg() {
3580bool X86DAGToDAGISel::isSExtAbsoluteSymbolRef(
unsigned Width, SDNode *
N)
const {
3582 N =
N->getOperand(0).getNode();
3583 if (
N->getOpcode() != X86ISD::Wrapper)
3590 auto *GV = GA->getGlobal();
3593 return CR->getSignedMin().sge(-1ull << Width) &&
3594 CR->getSignedMax().slt(1ull << Width);
3600 !TM.isLargeGlobalValue(GV);
3604 assert(
N->isMachineOpcode() &&
"Unexpected node");
3605 unsigned Opc =
N->getMachineOpcode();
3606 const MCInstrDesc &MCID = getInstrInfo()->get(
Opc);
3611 return static_cast<X86::CondCode>(
N->getConstantOperandVal(CondNo));
3616bool X86DAGToDAGISel::onlyUsesZeroFlag(
SDValue Flags)
const {
3618 for (SDUse &Use :
Flags->uses()) {
3620 if (
Use.getResNo() !=
Flags.getResNo())
3628 for (SDUse &FlagUse :
User->uses()) {
3630 if (FlagUse.getResNo() != 1)
3633 if (!FlagUse.getUser()->isMachineOpcode())
3653bool X86DAGToDAGISel::hasNoSignFlagUses(
SDValue Flags)
const {
3655 for (SDUse &Use :
Flags->uses()) {
3657 if (
Use.getResNo() !=
Flags.getResNo())
3665 for (SDUse &FlagUse :
User->uses()) {
3667 if (FlagUse.getResNo() != 1)
3670 if (!FlagUse.getUser()->isMachineOpcode())
3710 bool X86DAGToDAGISel::hasNoCarryFlagUses(
SDValue Flags)
const {
3712 for (SDUse &Use :
Flags->uses()) {
3714 if (
Use.getResNo() !=
Flags.getResNo())
3718 unsigned UserOpc =
User->getOpcode();
3725 for (SDUse &FlagUse :
User->uses()) {
3727 if (FlagUse.getResNo() != 1)
3730 if (!FlagUse.getUser()->isMachineOpcode())
3750 case X86ISD::SETCC: CCOpNo = 0;
break;
3751 case X86ISD::SETCC_CARRY: CCOpNo = 0;
break;
3752 case X86ISD::CMOV: CCOpNo = 2;
break;
3753 case X86ISD::BRCOND: CCOpNo = 2;
break;
3766 unsigned Depth = 0) {
3787bool X86DAGToDAGISel::checkTCRetEnoughRegs(SDNode *
N)
const {
3788 assert(
N->getOpcode() == X86ISD::TC_RETURN);
3806 ? &X86::GR64_TCW64RegClass
3807 : &X86::GR64_TCRegClass;
3815 ? &X86::GR32RegClass
3816 : &X86::GR32_TCRegClass;
3823 unsigned LoadGPRs = 2;
3830 }
else if (
BasePtr.getOpcode() == X86ISD::Wrapper &&
3832 if (getTargetMachine().isPositionIndependent())
3840 for (
unsigned I = 3,
E =
N->getNumOperands();
I !=
E; ++
I) {
3842 if (!RI->isGeneralPurposeRegister(*MF,
RN->getReg()))
3844 if (++
ArgGPRs + LoadGPRs > AvailGPRs)
3860 if (StoredVal.
getResNo() != 0)
return false;
3877 if (!
Load.hasOneUse())
3885 bool FoundLoad =
false;
3889 const unsigned int Max = 1024;
3931 if (Chain ==
Load.getValue(1)) {
3937 if (
Op ==
Load.getValue(1)) {
3953 if (
Op.getNode() != LoadNode)
3985bool X86DAGToDAGISel::foldLoadStoreIntoMemOperand(SDNode *Node) {
3987 SDValue StoredVal = StoreNode->getOperand(1);
3993 EVT MemVT = StoreNode->getMemoryVT();
3994 if (MemVT != MVT::i64 && MemVT != MVT::i32 && MemVT != MVT::i16 &&
3998 bool IsCommutable =
false;
3999 bool IsNegate =
false;
4013 IsCommutable =
true;
4017 unsigned LoadOpNo = IsNegate ? 1 : 0;
4018 LoadSDNode *LoadNode =
nullptr;
4021 LoadNode, InputChain)) {
4028 LoadNode, InputChain))
4033 if (!selectAddr(LoadNode, LoadNode->
getBasePtr(),
Base, Scale, Index, Disp,
4037 auto SelectOpcode = [&](
unsigned Opc64,
unsigned Opc32,
unsigned Opc16,
4058 unsigned NewOpc = SelectOpcode(X86::NEG64m, X86::NEG32m, X86::NEG16m,
4061 Result = CurDAG->getMachineNode(NewOpc, SDLoc(Node), MVT::i32,
4068 if (!
Subtarget->slowIncDec() || CurDAG->shouldOptForSize()) {
4072 if ((IsOne || IsNegOne) && hasNoCarryFlagUses(StoredVal.
getValue(1))) {
4074 ((
Opc == X86ISD::ADD) == IsOne)
4075 ? SelectOpcode(X86::INC64m, X86::INC32m, X86::INC16m, X86::INC8m)
4076 : SelectOpcode(X86::DEC64m, X86::DEC32m, X86::DEC16m, X86::DEC8m);
4078 Result = CurDAG->getMachineNode(NewOpc, SDLoc(Node), MVT::i32,
4089 auto SelectRegOpcode = [SelectOpcode](
unsigned Opc) {
4092 return SelectOpcode(X86::ADD64mr, X86::ADD32mr, X86::ADD16mr,
4095 return SelectOpcode(X86::ADC64mr, X86::ADC32mr, X86::ADC16mr,
4098 return SelectOpcode(X86::SUB64mr, X86::SUB32mr, X86::SUB16mr,
4101 return SelectOpcode(X86::SBB64mr, X86::SBB32mr, X86::SBB16mr,
4104 return SelectOpcode(X86::AND64mr, X86::AND32mr, X86::AND16mr,
4107 return SelectOpcode(X86::OR64mr, X86::OR32mr, X86::OR16mr, X86::OR8mr);
4109 return SelectOpcode(X86::XOR64mr, X86::XOR32mr, X86::XOR16mr,
4115 auto SelectImmOpcode = [SelectOpcode](
unsigned Opc) {
4118 return SelectOpcode(X86::ADD64mi32, X86::ADD32mi, X86::ADD16mi,
4121 return SelectOpcode(X86::ADC64mi32, X86::ADC32mi, X86::ADC16mi,
4124 return SelectOpcode(X86::SUB64mi32, X86::SUB32mi, X86::SUB16mi,
4127 return SelectOpcode(X86::SBB64mi32, X86::SBB32mi, X86::SBB16mi,
4130 return SelectOpcode(X86::AND64mi32, X86::AND32mi, X86::AND16mi,
4133 return SelectOpcode(X86::OR64mi32, X86::OR32mi, X86::OR16mi,
4136 return SelectOpcode(X86::XOR64mi32, X86::XOR32mi, X86::XOR16mi,
4143 unsigned NewOpc = SelectRegOpcode(
Opc);
4149 int64_t OperandV = OperandC->getSExtValue();
4154 if ((
Opc == X86ISD::ADD ||
Opc == X86ISD::SUB) &&
4156 (MemVT == MVT::i64 && !
isInt<32>(OperandV) &&
4158 hasNoCarryFlagUses(StoredVal.
getValue(1))) {
4159 OperandV = -OperandV;
4160 Opc =
Opc == X86ISD::ADD ? X86ISD::SUB : X86ISD::ADD;
4163 if (MemVT != MVT::i64 ||
isInt<32>(OperandV)) {
4164 Operand = CurDAG->getSignedTargetConstant(OperandV, SDLoc(Node), MemVT);
4165 NewOpc = SelectImmOpcode(
Opc);
4169 if (
Opc == X86ISD::ADC ||
Opc == X86ISD::SBB) {
4171 CurDAG->getCopyToReg(InputChain, SDLoc(Node), X86::EFLAGS,
4175 Segment, Operand, CopyTo, CopyTo.
getValue(1)};
4176 Result = CurDAG->getMachineNode(NewOpc, SDLoc(Node), MVT::i32, MVT::Other,
4180 Segment, Operand, InputChain};
4181 Result = CurDAG->getMachineNode(NewOpc, SDLoc(Node), MVT::i32, MVT::Other,
4190 MachineMemOperand *MemOps[] = {StoreNode->getMemOperand(),
4192 CurDAG->setNodeMemRefs(Result, MemOps);
4198 CurDAG->RemoveDeadNode(Node);
4210bool X86DAGToDAGISel::matchBitExtract(SDNode *Node) {
4213 "Should be either an and-mask, a standalone low-bits mask, or "
4214 "right-shift after clearing high bits.");
4220 MVT NVT =
Node->getSimpleValueType(0);
4223 if (NVT != MVT::i32 && NVT != MVT::i64)
4231 const bool AllowExtraUsesByDefault =
Subtarget->hasBMI2();
4232 auto checkUses = [AllowExtraUsesByDefault](
4234 std::optional<bool> AllowExtraUses) {
4235 return AllowExtraUses.value_or(AllowExtraUsesByDefault) ||
4236 Op.getNode()->hasNUsesOfValue(NUses,
Op.getResNo());
4238 auto checkOneUse = [checkUses](
SDValue Op,
4239 std::optional<bool> AllowExtraUses =
4241 return checkUses(
Op, 1, AllowExtraUses);
4243 auto checkTwoUse = [checkUses](
SDValue Op,
4244 std::optional<bool> AllowExtraUses =
4246 return checkUses(
Op, 2, AllowExtraUses);
4249 auto peekThroughOneUseTruncation = [checkOneUse](
SDValue V) {
4251 assert(
V.getSimpleValueType() == MVT::i32 &&
4252 V.getOperand(0).getSimpleValueType() == MVT::i64 &&
4253 "Expected i64 -> i32 truncation");
4254 V =
V.getOperand(0);
4260 auto matchPatternA = [checkOneUse, peekThroughOneUseTruncation, &NBits,
4263 if (
Mask->getOpcode() !=
ISD::ADD || !checkOneUse(Mask))
4269 SDValue M0 = peekThroughOneUseTruncation(
Mask->getOperand(0));
4274 NBits =
M0->getOperand(1);
4275 NegateNBits =
false;
4279 auto isAllOnes = [
this, peekThroughOneUseTruncation, NVT](
SDValue V) {
4280 V = peekThroughOneUseTruncation(
V);
4281 return CurDAG->MaskedValueIsAllOnes(
4287 auto matchPatternB = [checkOneUse, isAllOnes, peekThroughOneUseTruncation,
4290 if (
Mask.getOpcode() !=
ISD::XOR || !checkOneUse(Mask))
4293 if (!isAllOnes(
Mask->getOperand(1)))
4296 SDValue M0 = peekThroughOneUseTruncation(
Mask->getOperand(0));
4300 if (!isAllOnes(
M0->getOperand(0)))
4302 NBits =
M0->getOperand(1);
4303 NegateNBits =
false;
4309 auto canonicalizeShiftAmt = [&NBits, &NegateNBits](
SDValue ShiftAmt,
4310 unsigned Bitwidth) {
4315 NBits = NBits.getOperand(0);
4321 if (!V0 ||
V0->getZExtValue() != Bitwidth)
4323 NBits = NBits.getOperand(1);
4324 NegateNBits =
false;
4330 auto matchPatternC = [checkOneUse, peekThroughOneUseTruncation, &NegateNBits,
4333 Mask = peekThroughOneUseTruncation(Mask);
4334 unsigned Bitwidth =
Mask.getSimpleValueType().getSizeInBits();
4336 if (
Mask.getOpcode() !=
ISD::SRL || !checkOneUse(Mask))
4343 if (!checkOneUse(
M1))
4345 canonicalizeShiftAmt(
M1, Bitwidth);
4350 return !NegateNBits;
4358 auto matchPatternD = [checkOneUse, checkTwoUse, canonicalizeShiftAmt,
4359 AllowExtraUsesByDefault, &NegateNBits,
4360 &
X](SDNode *
Node) ->
bool {
4372 canonicalizeShiftAmt(N1, Bitwidth);
4376 const bool AllowExtraUses = AllowExtraUsesByDefault && !NegateNBits;
4377 if (!checkOneUse(N0, AllowExtraUses) || !checkTwoUse(N1, AllowExtraUses))
4383 auto matchLowBitMask = [matchPatternA, matchPatternB,
4385 return matchPatternA(Mask) || matchPatternB(Mask) || matchPatternC(Mask);
4389 X =
Node->getOperand(0);
4392 if (matchLowBitMask(Mask)) {
4396 if (!matchLowBitMask(Mask))
4399 }
else if (matchLowBitMask(
SDValue(Node, 0))) {
4400 X = CurDAG->getAllOnesConstant(SDLoc(Node), NVT);
4401 }
else if (!matchPatternD(Node))
4406 if (NegateNBits && !
Subtarget->hasBMI2())
4411 if (NBits.getSimpleValueType() != MVT::i8) {
4418 ConstantSDNode *
Imm =
nullptr;
4419 if (NBits->getOpcode() ==
ISD::AND)
4421 NBits = NBits->getOperand(0);
4426 CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF,
DL, MVT::i32), 0);
4429 SDValue SRIdxVal = CurDAG->getTargetConstant(X86::sub_8bit,
DL, MVT::i32);
4431 NBits =
SDValue(CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG,
DL,
4432 MVT::i32, ImplDef, NBits, SRIdxVal),
4438 CurDAG->getNode(
ISD::AND,
DL, MVT::i32, NBits,
4439 CurDAG->getConstant(
Imm->getZExtValue(),
DL, MVT::i32));
4449 NBits = CurDAG->getNode(
ISD::SUB,
DL, MVT::i32, BitWidthC, NBits);
4455 if (NVT != MVT::i32) {
4461 SDValue Extract = CurDAG->getNode(X86ISD::BZHI,
DL, NVT,
X, NBits);
4462 ReplaceNode(Node, Extract.
getNode());
4463 SelectCode(Extract.
getNode());
4472 SDValue RealX = peekThroughOneUseTruncation(
X);
4478 MVT XVT =
X.getSimpleValueType();
4488 SDValue C8 = CurDAG->getConstant(8,
DL, MVT::i8);
4496 SDValue ShiftAmt =
X.getOperand(1);
4497 X =
X.getOperand(0);
4500 "Expected shift amount to be i8");
4504 SDValue OrigShiftAmt = ShiftAmt;
4509 Control = CurDAG->getNode(
ISD::OR,
DL, MVT::i32, Control, ShiftAmt);
4514 if (XVT != MVT::i32) {
4520 SDValue Extract = CurDAG->getNode(X86ISD::BEXTR,
DL, XVT,
X, Control);
4528 ReplaceNode(Node, Extract.
getNode());
4529 SelectCode(Extract.
getNode());
4535MachineSDNode *X86DAGToDAGISel::matchBEXTRFromAndImm(SDNode *Node) {
4536 MVT NVT =
Node->getSimpleValueType(0);
4550 if (!PreferBEXTR && !
Subtarget->hasBMI2())
4562 if (NVT != MVT::i32 && NVT != MVT::i64)
4568 if (!MaskCst || !ShiftCst)
4576 uint64_t Shift = ShiftCst->getZExtValue();
4581 if (Shift == 8 && MaskSize == 8)
4592 if (!PreferBEXTR && MaskSize <= 32)
4596 unsigned ROpc, MOpc;
4598#define GET_EGPR_IF_ENABLED(OPC) (Subtarget->hasEGPR() ? OPC##_EVEX : OPC)
4604 Control = CurDAG->getTargetConstant(Shift + MaskSize, dl, NVT);
4609 unsigned NewOpc = NVT == MVT::i64 ? X86::MOV32ri64 : X86::MOV32ri;
4610 Control =
SDValue(CurDAG->getMachineNode(NewOpc, dl, NVT, Control), 0);
4616 Control = CurDAG->getTargetConstant(Shift | (MaskSize << 8), dl, NVT);
4618 ROpc = NVT == MVT::i64 ? X86::BEXTRI64ri : X86::BEXTRI32ri;
4619 MOpc = NVT == MVT::i64 ? X86::BEXTRI64mi : X86::BEXTRI32mi;
4627 unsigned NewOpc = NVT == MVT::i64 ? X86::MOV32ri64 : X86::MOV32ri;
4628 Control =
SDValue(CurDAG->getMachineNode(NewOpc, dl, NVT, Control), 0);
4632 MachineSDNode *NewNode;
4634 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
4635 if (tryFoldLoad(Node, N0.
getNode(), Input, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4)) {
4637 Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, Control,
Input.getOperand(0)};
4638 SDVTList VTs = CurDAG->getVTList(NVT, MVT::i32, MVT::Other);
4639 NewNode = CurDAG->getMachineNode(MOpc, dl, VTs,
Ops);
4643 CurDAG->setNodeMemRefs(NewNode, {
cast<LoadSDNode>(Input)->getMemOperand()});
4645 NewNode = CurDAG->getMachineNode(ROpc, dl, NVT, MVT::i32, Input, Control);
4650 SDValue ShAmt = CurDAG->getTargetConstant(Shift, dl, NVT);
4654 CurDAG->getMachineNode(NewOpc, dl, NVT,
SDValue(NewNode, 0), ShAmt);
4661MachineSDNode *X86DAGToDAGISel::emitPCMPISTR(
unsigned ROpc,
unsigned MOpc,
4662 bool MayFoldLoad,
const SDLoc &dl,
4663 MVT VT, SDNode *Node) {
4668 Imm = CurDAG->getTargetConstant(*Val, SDLoc(Node),
Imm.getValueType());
4671 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
4672 if (MayFoldLoad && tryFoldLoad(Node, N1, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4)) {
4675 SDVTList VTs = CurDAG->getVTList(VT, MVT::i32, MVT::Other);
4676 MachineSDNode *CNode = CurDAG->getMachineNode(MOpc, dl, VTs,
Ops);
4685 SDVTList VTs = CurDAG->getVTList(VT, MVT::i32);
4686 MachineSDNode *CNode = CurDAG->getMachineNode(ROpc, dl, VTs,
Ops);
4693MachineSDNode *X86DAGToDAGISel::emitPCMPESTR(
unsigned ROpc,
unsigned MOpc,
4694 bool MayFoldLoad,
const SDLoc &dl,
4695 MVT VT, SDNode *Node,
4701 Imm = CurDAG->getTargetConstant(*Val, SDLoc(Node),
Imm.getValueType());
4704 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
4705 if (MayFoldLoad && tryFoldLoad(Node, N2, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4)) {
4708 SDVTList VTs = CurDAG->getVTList(VT, MVT::i32, MVT::Other, MVT::Glue);
4709 MachineSDNode *CNode = CurDAG->getMachineNode(MOpc, dl, VTs,
Ops);
4719 SDVTList VTs = CurDAG->getVTList(VT, MVT::i32, MVT::Glue);
4720 MachineSDNode *CNode = CurDAG->getMachineNode(ROpc, dl, VTs,
Ops);
4725bool X86DAGToDAGISel::tryShiftAmountMod(SDNode *
N) {
4726 EVT VT =
N->getValueType(0);
4733 unsigned Size = VT == MVT::i64 ? 64 : 32;
4736 SDValue ShiftAmt = OrigShiftAmt;
4755 if (Add1C && Add1C->getAPIntValue().urem(
Size) == 0) {
4759 ((Add0C && Add0C->getAPIntValue().urem(
Size) ==
Size - 1) ||
4760 (Add1C && Add1C->getAPIntValue().urem(
Size) ==
Size - 1))) {
4764 assert(Add0C ==
nullptr || Add1C ==
nullptr);
4773 NewShiftAmt = CurDAG->getNode(
ISD::XOR,
DL, OpVT,
4774 Add0C ==
nullptr ? Add0 : Add1,
AllOnes);
4780 Add0C->getZExtValue() != 0) {
4783 if (Add0C->getZExtValue() %
Size == 0)
4786 Add0C->getZExtValue() % 32 == 0) {
4794 Add0 = CurDAG->getZExtOrTrunc(Add0,
DL, SubVT);
4798 X = CurDAG->getNode(
ISD::ADD,
DL, SubVT, Add1, Add0);
4820 NewShiftAmt = CurDAG->getNode(
ISD::TRUNCATE,
DL, MVT::i8, NewShiftAmt);
4827 NewShiftAmt = CurDAG->getNode(
ISD::AND,
DL, MVT::i8, NewShiftAmt,
4828 CurDAG->getConstant(
Size - 1,
DL, MVT::i8));
4832 SDNode *UpdatedNode = CurDAG->UpdateNodeOperands(
N,
N->getOperand(0),
4834 if (UpdatedNode !=
N) {
4837 ReplaceNode(
N, UpdatedNode);
4844 CurDAG->RemoveDeadNode(OrigShiftAmt.
getNode());
4852bool X86DAGToDAGISel::tryShrinkShlLogicImm(SDNode *
N) {
4853 MVT NVT =
N->getSimpleValueType(0);
4854 unsigned Opcode =
N->getOpcode();
4866 int64_t Val = Cst->getSExtValue();
4871 bool FoundAnyExtend =
false;
4875 FoundAnyExtend =
true;
4883 if (NVT != MVT::i32 && NVT != MVT::i64)
4890 uint64_t ShAmt = ShlCst->getZExtValue();
4894 uint64_t RemovedBitsMask = (1ULL << ShAmt) - 1;
4895 if (Opcode !=
ISD::AND && (Val & RemovedBitsMask) != 0)
4900 auto CanShrinkImmediate = [&](int64_t &ShiftedVal) {
4904 ShiftedVal = (
uint64_t)Val >> ShAmt;
4908 if (ShiftedVal == UINT8_MAX || ShiftedVal == UINT16_MAX)
4911 ShiftedVal = Val >> ShAmt;
4917 ShiftedVal = (
uint64_t)Val >> ShAmt;
4925 if (!CanShrinkImmediate(ShiftedVal))
4935 unsigned ZExtWidth = Cst->getAPIntValue().getActiveBits();
4941 NeededMask &= ~Cst->getAPIntValue();
4943 if (CurDAG->MaskedValueIsZero(
N->getOperand(0), NeededMask))
4948 if (FoundAnyExtend) {
4954 SDValue NewCst = CurDAG->getSignedConstant(ShiftedVal, dl, NVT);
4956 SDValue NewBinOp = CurDAG->getNode(Opcode, dl, NVT,
X, NewCst);
4965bool X86DAGToDAGISel::matchVPTERNLOG(SDNode *Root, SDNode *ParentA,
4966 SDNode *ParentB, SDNode *ParentC,
4969 assert(
A.isOperandOf(ParentA) &&
B.isOperandOf(ParentB) &&
4970 C.isOperandOf(ParentC) &&
"Incorrect parent node");
4972 auto tryFoldLoadOrBCast =
4975 if (tryFoldLoad(Root,
P, L,
Base, Scale, Index, Disp, Segment))
4981 L =
L.getOperand(0);
4984 if (
L.getOpcode() != X86ISD::VBROADCAST_LOAD)
4989 unsigned Size = MemIntr->getMemoryVT().getSizeInBits();
4993 return tryFoldBroadcast(Root,
P, L,
Base, Scale, Index, Disp, Segment);
4996 bool FoldedLoad =
false;
4997 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
4998 if (tryFoldLoadOrBCast(Root, ParentC,
C, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4)) {
5000 }
else if (tryFoldLoadOrBCast(Root, ParentA,
A, Tmp0, Tmp1, Tmp2, Tmp3,
5005 uint8_t OldImm =
Imm;
5006 Imm = OldImm & 0xa5;
5007 if (OldImm & 0x02)
Imm |= 0x10;
5008 if (OldImm & 0x10)
Imm |= 0x02;
5009 if (OldImm & 0x08)
Imm |= 0x40;
5010 if (OldImm & 0x40)
Imm |= 0x08;
5011 }
else if (tryFoldLoadOrBCast(Root, ParentB,
B, Tmp0, Tmp1, Tmp2, Tmp3,
5016 uint8_t OldImm =
Imm;
5017 Imm = OldImm & 0x99;
5018 if (OldImm & 0x02)
Imm |= 0x04;
5019 if (OldImm & 0x04)
Imm |= 0x02;
5020 if (OldImm & 0x20)
Imm |= 0x40;
5021 if (OldImm & 0x40)
Imm |= 0x20;
5026 SDValue TImm = CurDAG->getTargetConstant(
Imm,
DL, MVT::i8);
5030 MachineSDNode *MNode;
5032 SDVTList VTs = CurDAG->getVTList(NVT, MVT::Other);
5035 if (
C.getOpcode() == X86ISD::VBROADCAST_LOAD) {
5037 unsigned EltSize = MemIntr->getMemoryVT().getSizeInBits();
5038 assert((EltSize == 32 || EltSize == 64) &&
"Unexpected broadcast size!");
5040 bool UseD = EltSize == 32;
5042 Opc = UseD ? X86::VPTERNLOGDZ128rmbi : X86::VPTERNLOGQZ128rmbi;
5044 Opc = UseD ? X86::VPTERNLOGDZ256rmbi : X86::VPTERNLOGQZ256rmbi;
5046 Opc = UseD ? X86::VPTERNLOGDZrmbi : X86::VPTERNLOGQZrmbi;
5052 Opc = UseD ? X86::VPTERNLOGDZ128rmi : X86::VPTERNLOGQZ128rmi;
5054 Opc = UseD ? X86::VPTERNLOGDZ256rmi : X86::VPTERNLOGQZ256rmi;
5056 Opc = UseD ? X86::VPTERNLOGDZrmi : X86::VPTERNLOGQZrmi;
5062 MNode = CurDAG->getMachineNode(
Opc,
DL, VTs,
Ops);
5065 ReplaceUses(
C.getValue(1),
SDValue(MNode, 1));
5072 Opc = UseD ? X86::VPTERNLOGDZ128rri : X86::VPTERNLOGQZ128rri;
5074 Opc = UseD ? X86::VPTERNLOGDZ256rri : X86::VPTERNLOGQZ256rri;
5076 Opc = UseD ? X86::VPTERNLOGDZrri : X86::VPTERNLOGQZrri;
5080 MNode = CurDAG->getMachineNode(
Opc,
DL, NVT, {
A,
B,
C, TImm});
5084 CurDAG->RemoveDeadNode(Root);
5090bool X86DAGToDAGISel::tryVPTERNLOG(SDNode *
N) {
5091 MVT NVT =
N->getSimpleValueType(0);
5102 auto getFoldableLogicOp = [](
SDValue Op) {
5105 Op =
Op.getOperand(0);
5107 if (!
Op.hasOneUse())
5110 unsigned Opc =
Op.getOpcode();
5112 Opc == X86ISD::ANDNP)
5121 auto tryPeelOuterNotWrappingLogic = [&](SDNode *
Op) {
5124 SDValue InnerOp = getFoldableLogicOp(
Op->getOperand(0));
5131 if ((FoldableOp = getFoldableLogicOp(N1))) {
5135 if ((FoldableOp = getFoldableLogicOp(N0))) {
5143 bool PeeledOuterNot =
false;
5145 if (
SDValue InnerOp = tryPeelOuterNotWrappingLogic(
N)) {
5146 PeeledOuterNot =
true;
5152 if ((FoldableOp = getFoldableLogicOp(N1)))
5154 else if ((FoldableOp = getFoldableLogicOp(N0)))
5162 SDNode *ParentA =
N;
5163 SDNode *ParentB = FoldableOp.
getNode();
5164 SDNode *ParentC = FoldableOp.
getNode();
5168 uint8_t TernlogMagicA = 0xf0;
5169 uint8_t TernlogMagicB = 0xcc;
5170 uint8_t TernlogMagicC = 0xaa;
5175 auto PeekThroughNot = [](
SDValue &
Op, SDNode *&Parent, uint8_t &
Magic) {
5179 Parent =
Op.getNode();
5180 Op =
Op.getOperand(0);
5184 PeekThroughNot(
A, ParentA, TernlogMagicA);
5185 PeekThroughNot(
B, ParentB, TernlogMagicB);
5186 PeekThroughNot(
C, ParentC, TernlogMagicC);
5191 case ISD::AND:
Imm = TernlogMagicB & TernlogMagicC;
break;
5192 case ISD::OR:
Imm = TernlogMagicB | TernlogMagicC;
break;
5193 case ISD::XOR:
Imm = TernlogMagicB ^ TernlogMagicC;
break;
5194 case X86ISD::ANDNP:
Imm = ~(TernlogMagicB) & TernlogMagicC;
break;
5197 switch (
N->getOpcode()) {
5201 Imm &= ~TernlogMagicA;
5203 Imm = ~(
Imm) & TernlogMagicA;
5213 return matchVPTERNLOG(OriN, ParentA, ParentB, ParentC,
A,
B,
C,
Imm);
5223bool X86DAGToDAGISel::shrinkAndImmediate(SDNode *
And) {
5226 MVT VT =
And->getSimpleValueType(0);
5227 if (VT != MVT::i32 && VT != MVT::i64)
5239 APInt MaskVal = And1C->getAPIntValue();
5241 if (!MaskLZ || (VT == MVT::i64 && MaskLZ == 32))
5245 if (VT == MVT::i64 && MaskLZ >= 32) {
5247 MaskVal = MaskVal.
trunc(32);
5252 APInt NegMaskVal = MaskVal | HighZeros;
5261 if (VT == MVT::i64 && MaskVal.
getBitWidth() < 64) {
5262 NegMaskVal = NegMaskVal.
zext(64);
5263 HighZeros = HighZeros.
zext(64);
5269 KnownBits Known0 = CurDAG->computeKnownBits(And0);
5278 if (VT == MVT::i32 && !isDef32(And0.
getNode()))
5285 SDValue NewMask = CurDAG->getConstant(NegMaskVal, SDLoc(
And), VT);
5294 bool FoldedBCast,
bool Masked) {
5295#define VPTESTM_CASE(VT, SUFFIX) \
5298 return IsTestN ? X86::VPTESTNM##SUFFIX##k: X86::VPTESTM##SUFFIX##k; \
5299 return IsTestN ? X86::VPTESTNM##SUFFIX : X86::VPTESTM##SUFFIX;
5302#define VPTESTM_BROADCAST_CASES(SUFFIX) \
5303default: llvm_unreachable("Unexpected VT!"); \
5304VPTESTM_CASE(v4i32, DZ128##SUFFIX) \
5305VPTESTM_CASE(v2i64, QZ128##SUFFIX) \
5306VPTESTM_CASE(v8i32, DZ256##SUFFIX) \
5307VPTESTM_CASE(v4i64, QZ256##SUFFIX) \
5308VPTESTM_CASE(v16i32, DZ##SUFFIX) \
5309VPTESTM_CASE(v8i64, QZ##SUFFIX)
5311#define VPTESTM_FULL_CASES(SUFFIX) \
5312VPTESTM_BROADCAST_CASES(SUFFIX) \
5313VPTESTM_CASE(v16i8, BZ128##SUFFIX) \
5314VPTESTM_CASE(v8i16, WZ128##SUFFIX) \
5315VPTESTM_CASE(v32i8, BZ256##SUFFIX) \
5316VPTESTM_CASE(v16i16, WZ256##SUFFIX) \
5317VPTESTM_CASE(v64i8, BZ##SUFFIX) \
5318VPTESTM_CASE(v32i16, WZ##SUFFIX)
5336#undef VPTESTM_FULL_CASES
5337#undef VPTESTM_BROADCAST_CASES
5347 if (
Reg.isVirtual())
5348 return MRI.getLiveInPhysReg(
Reg);
5352 if (GetPhysReg(N1) == LoReg && GetPhysReg(N0) != LoReg)
5358bool X86DAGToDAGISel::tryVPTESTM(SDNode *Root,
SDValue Setcc,
5405 auto tryFoldLoadOrBCast = [&](SDNode *Root, SDNode *
P,
SDValue &
L,
5410 if (tryFoldLoad(Root,
P, L,
Base, Scale, Index, Disp, Segment))
5415 if (CmpSVT != MVT::i32 && CmpSVT != MVT::i64)
5421 L =
L.getOperand(0);
5424 if (
L.getOpcode() != X86ISD::VBROADCAST_LOAD)
5428 if (MemIntr->getMemoryVT().getSizeInBits() != CmpSVT.
getSizeInBits())
5431 return tryFoldBroadcast(Root,
P, L,
Base, Scale, Index, Disp, Segment);
5437 bool FoldedLoad =
false;
5438 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
5440 FoldedLoad = tryFoldLoadOrBCast(Root, N0.
getNode(), Src1, Tmp0, Tmp1, Tmp2,
5444 FoldedLoad = tryFoldLoadOrBCast(Root, N0.
getNode(), Src0, Tmp0, Tmp1,
5451 bool FoldedBCast = FoldedLoad &&
Src1.getOpcode() == X86ISD::VBROADCAST_LOAD;
5453 bool IsMasked = InMask.
getNode() !=
nullptr;
5462 unsigned SubReg = CmpVT.
is128BitVector() ? X86::sub_xmm : X86::sub_ymm;
5466 SDValue ImplDef =
SDValue(CurDAG->getMachineNode(X86::IMPLICIT_DEF, dl,
5468 Src0 = CurDAG->getTargetInsertSubreg(SubReg, dl, CmpVT, ImplDef, Src0);
5471 Src1 = CurDAG->getTargetInsertSubreg(SubReg, dl, CmpVT, ImplDef, Src1);
5476 SDValue RC = CurDAG->getTargetConstant(RegClass, dl, MVT::i32);
5477 InMask =
SDValue(CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS,
5478 dl, MaskVT, InMask, RC), 0);
5486 MachineSDNode *CNode;
5488 SDVTList VTs = CurDAG->getVTList(MaskVT, MVT::Other);
5492 Src1.getOperand(0) };
5493 CNode = CurDAG->getMachineNode(
Opc, dl, VTs,
Ops);
5496 Src1.getOperand(0) };
5497 CNode = CurDAG->getMachineNode(
Opc, dl, VTs,
Ops);
5503 CurDAG->setNodeMemRefs(CNode, {
cast<MemSDNode>(Src1)->getMemOperand()});
5506 CNode = CurDAG->getMachineNode(
Opc, dl, MaskVT, InMask, Src0, Src1);
5508 CNode = CurDAG->getMachineNode(
Opc, dl, MaskVT, Src0, Src1);
5514 SDValue RC = CurDAG->getTargetConstant(RegClass, dl, MVT::i32);
5515 CNode = CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS,
5516 dl, ResVT,
SDValue(CNode, 0), RC);
5520 CurDAG->RemoveDeadNode(Root);
5526bool X86DAGToDAGISel::tryMatchBitSelect(SDNode *
N) {
5529 MVT NVT =
N->getSimpleValueType(0);
5566 SDValue Imm = CurDAG->getTargetConstant(0xCA, dl, MVT::i8);
5567 SDValue Ternlog = CurDAG->getNode(X86ISD::VPTERNLOG, dl, NVT,
A,
B,
C,
Imm);
5581 case Intrinsic::x86_acev1_tilezero:
5582 case Intrinsic::x86_acev1_tilemovrowextract:
5583 case Intrinsic::x86_acev1_tcvtrowd2ps:
5584 case Intrinsic::x86_acev1_tcvtrowps2bf16h:
5585 case Intrinsic::x86_acev1_tcvtrowps2bf16l:
5586 case Intrinsic::x86_acev1_tcvtrowps2phh:
5587 case Intrinsic::x86_acev1_tcvtrowps2phl:
5590 case Intrinsic::x86_acev1_top2bf16ps:
5591 case Intrinsic::x86_acev1_top4buud:
5592 case Intrinsic::x86_acev1_top4busd:
5593 case Intrinsic::x86_acev1_top4bssd:
5594 case Intrinsic::x86_acev1_top4bsud:
5595 case Intrinsic::x86_acev1_top4mxhf8ps:
5596 case Intrinsic::x86_acev1_top4mxbhf8ps:
5597 case Intrinsic::x86_acev1_top4mxhbf8ps:
5598 case Intrinsic::x86_acev1_top4mxbf8ps:
5599 case Intrinsic::x86_acev1_top4mxbssps:
5602 case Intrinsic::x86_acev1_tilezero_internal:
5603 case Intrinsic::x86_acev1_tilemovrowextract_internal:
5604 case Intrinsic::x86_acev1_tcvtrowd2ps_internal:
5605 case Intrinsic::x86_acev1_tcvtrowps2bf16h_internal:
5606 case Intrinsic::x86_acev1_tcvtrowps2bf16l_internal:
5607 case Intrinsic::x86_acev1_tcvtrowps2phh_internal:
5608 case Intrinsic::x86_acev1_tcvtrowps2phl_internal:
5609 case Intrinsic::x86_acev1_tilemovcolinsert_internal:
5610 case Intrinsic::x86_acev1_tilemovrowinsert_internal:
5611 case Intrinsic::x86_acev1_top2bf16ps_internal:
5612 case Intrinsic::x86_acev1_top4buud_internal:
5613 case Intrinsic::x86_acev1_top4busd_internal:
5614 case Intrinsic::x86_acev1_top4bssd_internal:
5615 case Intrinsic::x86_acev1_top4bsud_internal:
5616 case Intrinsic::x86_acev1_top4mxhf8ps_internal:
5617 case Intrinsic::x86_acev1_top4mxbhf8ps_internal:
5618 case Intrinsic::x86_acev1_top4mxhbf8ps_internal:
5619 case Intrinsic::x86_acev1_top4mxbf8ps_internal:
5620 case Intrinsic::x86_acev1_top4mxbssps_internal:
5628void X86DAGToDAGISel::Select(SDNode *Node) {
5629 MVT NVT =
Node->getSimpleValueType(0);
5630 unsigned Opcode =
Node->getOpcode();
5633 if (
Node->isMachineOpcode()) {
5635 Node->setNodeId(-1);
5642 unsigned IntNo =
Node->getConstantOperandVal(1);
5646 case Intrinsic::x86_encodekey128:
5647 case Intrinsic::x86_encodekey256: {
5654 case Intrinsic::x86_encodekey128:
5655 Opcode = X86::ENCODEKEY128;
5657 case Intrinsic::x86_encodekey256:
5658 Opcode = X86::ENCODEKEY256;
5663 Chain = CurDAG->getCopyToReg(Chain, dl, X86::XMM0,
Node->getOperand(3),
5665 if (Opcode == X86::ENCODEKEY256)
5666 Chain = CurDAG->getCopyToReg(Chain, dl, X86::XMM1,
Node->getOperand(4),
5669 MachineSDNode *Res = CurDAG->getMachineNode(
5670 Opcode, dl,
Node->getVTList(),
5671 {Node->getOperand(2), Chain, Chain.getValue(1)});
5672 ReplaceNode(Node, Res);
5675 case Intrinsic::x86_tileloaddrs64_internal:
5676 case Intrinsic::x86_tileloaddrst164_internal:
5680 case Intrinsic::x86_tileloadd64_internal:
5681 case Intrinsic::x86_tileloaddt164_internal: {
5685 CurDAG->getMachineFunction().getInfo<X86MachineFunctionInfo>();
5691 case Intrinsic::x86_tileloaddrs64_internal:
5692 Opc = X86::PTILELOADDRSV;
5694 case Intrinsic::x86_tileloaddrst164_internal:
5695 Opc = X86::PTILELOADDRST1V;
5697 case Intrinsic::x86_tileloadd64_internal:
5698 Opc = X86::PTILELOADDV;
5700 case Intrinsic::x86_tileloaddt164_internal:
5701 Opc = X86::PTILELOADDT1V;
5706 SDValue Scale = getI8Imm(1, dl);
5708 SDValue Disp = CurDAG->getTargetConstant(0, dl, MVT::i32);
5709 SDValue Segment = CurDAG->getRegister(0, MVT::i16);
5711 MachineSDNode *CNode;
5713 Node->getOperand(3),
5720 CNode = CurDAG->getMachineNode(
Opc, dl, {MVT::x86amx, MVT::Other},
Ops);
5721 ReplaceNode(Node, CNode);
5728 unsigned IntNo =
Node->getConstantOperandVal(1);
5732 case Intrinsic::x86_sse3_monitor:
5733 case Intrinsic::x86_monitorx:
5734 case Intrinsic::x86_clzero: {
5735 bool Use64BitPtr =
Node->getOperand(2).getValueType() == MVT::i64;
5740 case Intrinsic::x86_sse3_monitor:
5743 Opc = Use64BitPtr ? X86::MONITOR64rrr : X86::MONITOR32rrr;
5745 case Intrinsic::x86_monitorx:
5748 Opc = Use64BitPtr ? X86::MONITORX64rrr : X86::MONITORX32rrr;
5750 case Intrinsic::x86_clzero:
5753 Opc = Use64BitPtr ? X86::CLZERO64r : X86::CLZERO32r;
5758 unsigned PtrReg = Use64BitPtr ? X86::RAX : X86::EAX;
5759 SDValue Chain = CurDAG->getCopyToReg(
Node->getOperand(0), dl, PtrReg,
5763 if (IntNo == Intrinsic::x86_sse3_monitor ||
5764 IntNo == Intrinsic::x86_monitorx) {
5766 Chain = CurDAG->getCopyToReg(Chain, dl, X86::ECX,
Node->getOperand(3),
5769 Chain = CurDAG->getCopyToReg(Chain, dl, X86::EDX,
Node->getOperand(4),
5774 MachineSDNode *CNode = CurDAG->getMachineNode(
Opc, dl, MVT::Other,
5776 ReplaceNode(Node, CNode);
5782 case Intrinsic::x86_tilestored64_internal: {
5784 CurDAG->getMachineFunction().getInfo<X86MachineFunctionInfo>();
5786 unsigned Opc = X86::PTILESTOREDV;
5789 SDValue Scale = getI8Imm(1, dl);
5791 SDValue Disp = CurDAG->getTargetConstant(0, dl, MVT::i32);
5792 SDValue Segment = CurDAG->getRegister(0, MVT::i16);
5794 MachineSDNode *CNode;
5796 Node->getOperand(3),
5802 Node->getOperand(6),
5804 CNode = CurDAG->getMachineNode(
Opc, dl, MVT::Other,
Ops);
5805 ReplaceNode(Node, CNode);
5808 case Intrinsic::x86_tileloaddrs64:
5809 case Intrinsic::x86_tileloaddrst164:
5813 case Intrinsic::x86_tileloadd64:
5814 case Intrinsic::x86_tileloaddt164:
5815 case Intrinsic::x86_tilestored64: {
5819 CurDAG->getMachineFunction().getInfo<X86MachineFunctionInfo>();
5824 case Intrinsic::x86_tileloadd64:
Opc = X86::PTILELOADD;
break;
5825 case Intrinsic::x86_tileloaddrs64:
5826 Opc = X86::PTILELOADDRS;
5828 case Intrinsic::x86_tileloaddt164:
Opc = X86::PTILELOADDT1;
break;
5829 case Intrinsic::x86_tileloaddrst164:
5830 Opc = X86::PTILELOADDRST1;
5832 case Intrinsic::x86_tilestored64:
Opc = X86::PTILESTORED;
break;
5835 unsigned TIndex =
Node->getConstantOperandVal(2);
5838 SDValue Scale = getI8Imm(1, dl);
5840 SDValue Disp = CurDAG->getTargetConstant(0, dl, MVT::i32);
5841 SDValue Segment = CurDAG->getRegister(0, MVT::i16);
5843 MachineSDNode *CNode;
5844 if (
Opc == X86::PTILESTORED) {
5846 CNode = CurDAG->getMachineNode(
Opc, dl, MVT::Other,
Ops);
5849 CNode = CurDAG->getMachineNode(
Opc, dl, MVT::Other,
Ops);
5851 ReplaceNode(Node, CNode);
5858 case X86ISD::NT_BRIND: {
5864 assert(
Target.getValueType() == MVT::i32 &&
"Unexpected VT!");
5865 SDValue ZextTarget = CurDAG->getZExtOrTrunc(Target, dl, MVT::i64);
5868 unsigned Opc = Opcode == X86ISD::NT_BRIND ? X86::JMP64r_NT : X86::JMP64r;
5869 SDNode *Res = CurDAG->getMachineNode(
Opc, dl, MVT::Other, ZextTarget,
5870 Node->getOperand(0));
5871 ReplaceNode(Node, Res);
5877 ReplaceNode(Node, getGlobalBaseReg());
5884 ReplaceUses(
SDValue(Node, 0),
Node->getOperand(0));
5885 CurDAG->RemoveDeadNode(Node);
5891 if (matchBitExtract(Node))
5896 if (tryShiftAmountMod(Node))
5900 case X86ISD::VPTERNLOG: {
5901 uint8_t
Imm =
Node->getConstantOperandVal(3);
5902 if (matchVPTERNLOG(Node, Node, Node, Node,
Node->getOperand(0),
5909 if (tryVPTERNLOG(Node))
5919 tryVPTESTM(Node, N0, N1))
5922 tryVPTESTM(Node, N1, N0))
5926 if (MachineSDNode *NewNode = matchBEXTRFromAndImm(Node)) {
5928 CurDAG->RemoveDeadNode(Node);
5931 if (matchBitExtract(Node))
5944 if (tryShrinkShlLogicImm(Node))
5946 if (Opcode ==
ISD::OR && tryMatchBitSelect(Node))
5948 if (tryVPTERNLOG(Node))
5953 if (Opcode ==
ISD::ADD && matchBitExtract(Node))
5963 if (!CurDAG->shouldOptForSize())
5967 if (NVT != MVT::i8 && NVT != MVT::i16 && NVT != MVT::i32 && NVT != MVT::i64)
5977 int64_t Val = Cst->getSExtValue();
5985 if (Opcode ==
ISD::ADD && (Val == 1 || Val == -1))
5989 if (!shouldAvoidImmediateInstFormsForSize(N1.
getNode()))
5993 unsigned ROpc, MOpc;
6102 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
6103 if (tryFoldLoad(Node, N0, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4)) {
6105 SDVTList VTs = CurDAG->getVTList(NVT, MVT::i32, MVT::Other);
6106 MachineSDNode *CNode = CurDAG->getMachineNode(MOpc, dl, VTs,
Ops);
6112 CurDAG->RemoveDeadNode(Node);
6117 CurDAG->SelectNodeTo(Node, ROpc, NVT, MVT::i32, N0, N1);
6126 case X86ISD::UMUL: {
6130 unsigned LoReg, ROpc, MOpc;
6135 ROpc = Opcode == X86ISD::SMUL ? X86::IMUL8r : X86::MUL8r;
6136 MOpc = Opcode == X86ISD::SMUL ? X86::IMUL8m : X86::MUL8m;
6155 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
6156 bool FoldedLoad = tryFoldLoad(Node, N1, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4);
6159 FoldedLoad = tryFoldLoad(Node, N0, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4);
6167 orderRegForMul(N0, N1, LoReg, CurDAG->getMachineFunction().getRegInfo());
6169 SDValue InGlue = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, LoReg,
6172 MachineSDNode *CNode;
6178 VTs = CurDAG->getVTList(NVT, MVT::i32, MVT::Other);
6180 VTs = CurDAG->getVTList(NVT, NVT, MVT::i32, MVT::Other);
6184 CNode = CurDAG->getMachineNode(MOpc, dl, VTs,
Ops);
6195 VTs = CurDAG->getVTList(NVT, MVT::i32);
6197 VTs = CurDAG->getVTList(NVT, NVT, MVT::i32);
6199 CNode = CurDAG->getMachineNode(ROpc, dl, VTs, {N1, InGlue});
6203 ReplaceUses(
SDValue(Node, 1),
SDValue(CNode, NVT == MVT::i8 ? 1 : 2));
6204 CurDAG->RemoveDeadNode(Node);
6214 unsigned LoReg, HiReg;
6216 bool UseMULX = !IsSigned &&
Subtarget->hasBMI2();
6217 bool UseMULXHi = UseMULX &&
SDValue(Node, 0).use_empty();
6221 Opc = UseMULXHi ? X86::MULX32Hrr
6223 : IsSigned ?
X86::IMUL32r
6225 MOpc = UseMULXHi ? X86::MULX32Hrm
6227 : IsSigned ?
X86::IMUL32m
6229 LoReg = UseMULX ? X86::EDX : X86::EAX;
6233 Opc = UseMULXHi ? X86::MULX64Hrr
6235 : IsSigned ?
X86::IMUL64r
6237 MOpc = UseMULXHi ? X86::MULX64Hrm
6239 : IsSigned ?
X86::IMUL64m
6241 LoReg = UseMULX ? X86::RDX : X86::RAX;
6246 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
6247 bool foldedLoad = tryFoldLoad(Node, N1, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4);
6250 foldedLoad = tryFoldLoad(Node, N0, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4);
6258 orderRegForMul(N0, N1, LoReg, CurDAG->getMachineFunction().getRegInfo());
6260 SDValue InGlue = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, LoReg,
6265 MachineSDNode *CNode =
nullptr;
6269 SDVTList VTs = CurDAG->getVTList(NVT, MVT::Other);
6270 CNode = CurDAG->getMachineNode(MOpc, dl, VTs,
Ops);
6273 }
else if (UseMULX) {
6274 SDVTList VTs = CurDAG->getVTList(NVT, NVT, MVT::Other);
6275 CNode = CurDAG->getMachineNode(MOpc, dl, VTs,
Ops);
6280 SDVTList VTs = CurDAG->getVTList(MVT::Other, MVT::Glue);
6281 CNode = CurDAG->getMachineNode(MOpc, dl, VTs,
Ops);
6287 ReplaceUses(N1.
getValue(1), Chain);
6293 SDVTList VTs = CurDAG->getVTList(NVT);
6294 SDNode *CNode = CurDAG->getMachineNode(
Opc, dl, VTs,
Ops);
6296 }
else if (UseMULX) {
6297 SDVTList VTs = CurDAG->getVTList(NVT, NVT);
6298 SDNode *CNode = CurDAG->getMachineNode(
Opc, dl, VTs,
Ops);
6302 SDVTList VTs = CurDAG->getVTList(MVT::Glue);
6303 SDNode *CNode = CurDAG->getMachineNode(
Opc, dl, VTs,
Ops);
6309 if (!
SDValue(Node, 0).use_empty()) {
6311 assert(LoReg &&
"Register for low half is not defined!");
6312 ResLo = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl, LoReg,
6316 ReplaceUses(
SDValue(Node, 0), ResLo);
6321 if (!
SDValue(Node, 1).use_empty()) {
6323 assert(HiReg &&
"Register for high half is not defined!");
6324 ResHi = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl, HiReg,
6328 ReplaceUses(
SDValue(Node, 1), ResHi);
6333 CurDAG->RemoveDeadNode(Node);
6342 unsigned ROpc, MOpc;
6347 case MVT::i8: ROpc = X86::DIV8r; MOpc = X86::DIV8m;
break;
6348 case MVT::i16: ROpc = X86::DIV16r; MOpc = X86::DIV16m;
break;
6349 case MVT::i32: ROpc = X86::DIV32r; MOpc = X86::DIV32m;
break;
6350 case MVT::i64: ROpc = X86::DIV64r; MOpc = X86::DIV64m;
break;
6355 case MVT::i8: ROpc = X86::IDIV8r; MOpc = X86::IDIV8m;
break;
6356 case MVT::i16: ROpc = X86::IDIV16r; MOpc = X86::IDIV16m;
break;
6357 case MVT::i32: ROpc = X86::IDIV32r; MOpc = X86::IDIV32m;
break;
6358 case MVT::i64: ROpc = X86::IDIV64r; MOpc = X86::IDIV64m;
break;
6362 unsigned LoReg, HiReg, ClrReg;
6363 unsigned SExtOpcode;
6367 LoReg = X86::AL; ClrReg = HiReg = X86::AH;
6371 LoReg = X86::AX; HiReg = X86::DX;
6373 SExtOpcode = X86::CWD;
6376 LoReg = X86::EAX; ClrReg = HiReg = X86::EDX;
6377 SExtOpcode = X86::CDQ;
6380 LoReg = X86::RAX; ClrReg = HiReg = X86::RDX;
6381 SExtOpcode = X86::CQO;
6385 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
6386 bool foldedLoad = tryFoldLoad(Node, N1, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4);
6387 bool signBitIsZero = CurDAG->SignBitIsZero(N0);
6390 if (NVT == MVT::i8) {
6393 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4, Chain;
6394 MachineSDNode *Move;
6395 if (tryFoldLoad(Node, N0, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4)) {
6397 unsigned Opc = (
isSigned && !signBitIsZero) ? X86::MOVSX16rm8
6399 Move = CurDAG->getMachineNode(
Opc, dl, MVT::i16, MVT::Other,
Ops);
6401 ReplaceUses(N0.
getValue(1), Chain);
6405 unsigned Opc = (
isSigned && !signBitIsZero) ? X86::MOVSX16rr8
6407 Move = CurDAG->getMachineNode(
Opc, dl, MVT::i16, N0);
6408 Chain = CurDAG->getEntryNode();
6410 Chain = CurDAG->getCopyToReg(Chain, dl, X86::AX,
SDValue(Move, 0),
6415 CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl,
6416 LoReg, N0,
SDValue()).getValue(1);
6420 SDValue(CurDAG->getMachineNode(SExtOpcode, dl, MVT::Glue, InGlue),0);
6423 SDVTList VTs = CurDAG->getVTList(MVT::i32, MVT::i32);
6425 SDValue(CurDAG->getMachineNode(X86::MOV32r0, dl, VTs, {}), 0);
6429 SDValue(CurDAG->getMachineNode(
6430 TargetOpcode::EXTRACT_SUBREG, dl, MVT::i16, ClrNode,
6431 CurDAG->getTargetConstant(X86::sub_16bit, dl,
6439 CurDAG->getMachineNode(
6440 TargetOpcode::SUBREG_TO_REG, dl, MVT::i64, ClrNode,
6441 CurDAG->getTargetConstant(X86::sub_32bit, dl, MVT::i32)),
6448 InGlue = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, ClrReg,
6449 ClrNode, InGlue).getValue(1);
6456 MachineSDNode *CNode =
6457 CurDAG->getMachineNode(MOpc, dl, MVT::Other, MVT::Glue,
Ops);
6465 SDValue(CurDAG->getMachineNode(ROpc, dl, MVT::Glue, N1, InGlue), 0);
6475 if (HiReg == X86::AH && !
SDValue(Node, 1).use_empty()) {
6476 SDValue AHCopy = CurDAG->getRegister(X86::AH, MVT::i8);
6477 unsigned AHExtOpcode =
6478 isSigned ? X86::MOVSX32rr8_NOREX : X86::MOVZX32rr8_NOREX;
6480 SDNode *RNode = CurDAG->getMachineNode(AHExtOpcode, dl, MVT::i32,
6481 MVT::Glue, AHCopy, InGlue);
6486 CurDAG->getTargetExtractSubreg(X86::sub_8bit, dl, MVT::i8, Result);
6488 ReplaceUses(
SDValue(Node, 1), Result);
6493 if (!
SDValue(Node, 0).use_empty()) {
6494 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
6495 LoReg, NVT, InGlue);
6496 InGlue =
Result.getValue(2);
6497 ReplaceUses(
SDValue(Node, 0), Result);
6502 if (!
SDValue(Node, 1).use_empty()) {
6503 SDValue Result = CurDAG->getCopyFromReg(CurDAG->getEntryNode(), dl,
6504 HiReg, NVT, InGlue);
6505 InGlue =
Result.getValue(2);
6506 ReplaceUses(
SDValue(Node, 1), Result);
6510 CurDAG->RemoveDeadNode(Node);
6515 case X86ISD::STRICT_FCMP:
6516 case X86ISD::STRICT_FCMPS: {
6517 bool IsStrictCmp =
Node->getOpcode() == X86ISD::STRICT_FCMP ||
6518 Node->getOpcode() == X86ISD::STRICT_FCMPS;
6519 SDValue N0 =
Node->getOperand(IsStrictCmp ? 1 : 0);
6520 SDValue N1 =
Node->getOperand(IsStrictCmp ? 2 : 1);
6529 bool IsSignaling =
Node->getOpcode() == X86ISD::STRICT_FCMPS;
6535 Opc = IsSignaling ? X86::COM_Fpr32 : X86::UCOM_Fpr32;
6538 Opc = IsSignaling ? X86::COM_Fpr64 : X86::UCOM_Fpr64;
6541 Opc = IsSignaling ? X86::COM_Fpr80 : X86::UCOM_Fpr80;
6546 IsStrictCmp ?
Node->getOperand(0) : CurDAG->getEntryNode();
6549 SDVTList VTs = CurDAG->getVTList(MVT::Other, MVT::Glue);
6550 Chain =
SDValue(CurDAG->getMachineNode(
Opc, dl, VTs, {N0, N1, Chain}), 0);
6553 Glue =
SDValue(CurDAG->getMachineNode(
Opc, dl, MVT::Glue, N0, N1), 0);
6558 SDValue(CurDAG->getMachineNode(X86::FNSTSW16r, dl, MVT::i16, Glue), 0);
6562 CurDAG->getTargetExtractSubreg(X86::sub_8bit_hi, dl, MVT::i8, FNSTSW);
6567 "Target doesn't support SAHF or FCOMI?");
6568 SDValue AH = CurDAG->getCopyToReg(Chain, dl, X86::AH, Extract,
SDValue());
6571 CurDAG->getMachineNode(X86::SAHF, dl, MVT::i32, AH.
getValue(1)), 0);
6574 ReplaceUses(
SDValue(Node, 1), Chain);
6576 ReplaceUses(
SDValue(Node, 0), SAHF);
6577 CurDAG->RemoveDeadNode(Node);
6597 if (MachineSDNode *NewNode = matchBEXTRFromAndImm(N0.
getNode())) {
6598 unsigned TestOpc = CmpVT == MVT::i64 ? X86::TEST64rr
6601 NewNode = CurDAG->getMachineNode(TestOpc, dl, MVT::i32, BEXTR, BEXTR);
6603 CurDAG->RemoveDeadNode(Node);
6630 onlyUsesZeroFlag(
SDValue(Node, 0))) {
6635 unsigned TestOpcode;
6643 if (LeadingZeros == 0 && SavesBytes) {
6648 ShiftAmt = TrailingZeros;
6650 TestOpcode = X86::TEST64rr;
6651 }
else if (TrailingZeros == 0 && SavesBytes) {
6657 if (LeadingZeros == 1) {
6661 MachineSDNode *
Add = CurDAG->getMachineNode(
6664 MachineSDNode *
Test = CurDAG->getMachineNode(
6666 ReplaceNode(Node,
Test);
6670 ShiftAmt = LeadingZeros;
6672 TestOpcode = X86::TEST64rr;
6673 }
else if (MaskC->hasOneUse() && !
isInt<32>(Mask)) {
6676 unsigned PopCount = 64 - LeadingZeros - TrailingZeros;
6677 if (PopCount == 8) {
6679 ShiftAmt = TrailingZeros;
6680 SubRegIdx = X86::sub_8bit;
6682 TestOpcode = X86::TEST8rr;
6683 }
else if (PopCount == 16) {
6685 ShiftAmt = TrailingZeros;
6686 SubRegIdx = X86::sub_16bit;
6687 SubRegVT = MVT::i16;
6688 TestOpcode = X86::TEST16rr;
6689 }
else if (PopCount == 32) {
6691 ShiftAmt = TrailingZeros;
6692 SubRegIdx = X86::sub_32bit;
6693 SubRegVT = MVT::i32;
6694 TestOpcode = X86::TEST32rr;
6698 SDValue ShiftC = CurDAG->getTargetConstant(ShiftAmt, dl, MVT::i64);
6700 CurDAG->getMachineNode(ShiftOpcode, dl, MVT::i64, MVT::i32,
6703 if (SubRegIdx != 0) {
6705 CurDAG->getTargetExtractSubreg(SubRegIdx, dl, SubRegVT, Shift);
6707 MachineSDNode *
Test =
6708 CurDAG->getMachineNode(TestOpcode, dl, MVT::i32, Shift, Shift);
6709 ReplaceNode(Node,
Test);
6716 unsigned ROpc, MOpc;
6724 (!(Mask & 0x80) || CmpVT == MVT::i8 ||
6725 hasNoSignFlagUses(
SDValue(Node, 0)))) {
6728 SubRegOp = X86::sub_8bit;
6729 ROpc = X86::TEST8ri;
6730 MOpc = X86::TEST8mi;
6731 }
else if (OptForMinSize &&
isUInt<16>(Mask) &&
6732 (!(Mask & 0x8000) || CmpVT == MVT::i16 ||
6733 hasNoSignFlagUses(
SDValue(Node, 0)))) {
6739 SubRegOp = X86::sub_16bit;
6740 ROpc = X86::TEST16ri;
6741 MOpc = X86::TEST16mi;
6743 ((!(Mask & 0x80000000) &&
6746 (CmpVT != MVT::i16 || !(Mask & 0x8000))) ||
6747 CmpVT == MVT::i32 ||
6748 hasNoSignFlagUses(
SDValue(Node, 0)))) {
6755 SubRegOp = X86::sub_32bit;
6756 ROpc = X86::TEST32ri;
6757 MOpc = X86::TEST32mi;
6763 SDValue Imm = CurDAG->getTargetConstant(Mask, dl, VT);
6767 MachineSDNode *NewNode;
6768 SDValue Tmp0, Tmp1, Tmp2, Tmp3, Tmp4;
6769 if (tryFoldLoad(Node, N0.
getNode(),
Reg, Tmp0, Tmp1, Tmp2, Tmp3, Tmp4)) {
6771 if (!LoadN->isSimple()) {
6772 unsigned NumVolBits = LoadN->getValueType(0).getSizeInBits();
6773 if ((MOpc == X86::TEST8mi && NumVolBits != 8) ||
6774 (MOpc == X86::TEST16mi && NumVolBits != 16) ||
6775 (MOpc == X86::TEST32mi && NumVolBits != 32))
6780 Reg.getOperand(0) };
6781 NewNode = CurDAG->getMachineNode(MOpc, dl, MVT::i32, MVT::Other,
Ops);
6783 ReplaceUses(
Reg.getValue(1),
SDValue(NewNode, 1));
6785 CurDAG->setNodeMemRefs(NewNode,
6790 Reg = CurDAG->getTargetExtractSubreg(SubRegOp, dl, VT,
Reg);
6792 NewNode = CurDAG->getMachineNode(ROpc, dl, MVT::i32,
Reg,
Imm);
6795 ReplaceNode(Node, NewNode);
6804 bool NeedIndex = !
SDValue(Node, 0).use_empty();
6807 bool MayFoldLoad = !NeedIndex || !
NeedMask;
6809 MachineSDNode *CNode;
6812 Subtarget->hasAVX() ? X86::VPCMPISTRMrri : X86::PCMPISTRMrri;
6814 Subtarget->hasAVX() ? X86::VPCMPISTRMrmi : X86::PCMPISTRMrmi;
6815 CNode = emitPCMPISTR(ROpc, MOpc, MayFoldLoad, dl, MVT::v16i8, Node);
6818 if (NeedIndex || !NeedMask) {
6820 Subtarget->hasAVX() ? X86::VPCMPISTRIrri : X86::PCMPISTRIrri;
6822 Subtarget->hasAVX() ? X86::VPCMPISTRIrmi : X86::PCMPISTRIrmi;
6823 CNode = emitPCMPISTR(ROpc, MOpc, MayFoldLoad, dl, MVT::i32, Node);
6829 CurDAG->RemoveDeadNode(Node);
6837 SDValue InGlue = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, X86::EAX,
6838 Node->getOperand(1),
6840 InGlue = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, X86::EDX,
6841 Node->getOperand(3), InGlue).getValue(1);
6843 bool NeedIndex = !
SDValue(Node, 0).use_empty();
6846 bool MayFoldLoad = !NeedIndex || !
NeedMask;
6848 MachineSDNode *CNode;
6851 Subtarget->hasAVX() ? X86::VPCMPESTRMrri : X86::PCMPESTRMrri;
6853 Subtarget->hasAVX() ? X86::VPCMPESTRMrmi : X86::PCMPESTRMrmi;
6855 emitPCMPESTR(ROpc, MOpc, MayFoldLoad, dl, MVT::v16i8, Node, InGlue);
6858 if (NeedIndex || !NeedMask) {
6860 Subtarget->hasAVX() ? X86::VPCMPESTRIrri : X86::PCMPESTRIrri;
6862 Subtarget->hasAVX() ? X86::VPCMPESTRIrmi : X86::PCMPESTRIrmi;
6863 CNode = emitPCMPESTR(ROpc, MOpc, MayFoldLoad, dl, MVT::i32, Node, InGlue);
6868 CurDAG->RemoveDeadNode(Node);
6880 if (foldLoadStoreIntoMemOperand(Node))
6884 case X86ISD::SETCC_CARRY: {
6885 MVT VT =
Node->getSimpleValueType(0);
6892 CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, X86::EFLAGS,
6897 unsigned Opc = VT == MVT::i64 ? X86::SETB_C64r : X86::SETB_C32r;
6898 MVT SetVT = VT == MVT::i64 ? MVT::i64 : MVT::i32;
6900 CurDAG->getMachineNode(
Opc, dl, SetVT, EFLAGS, EFLAGS.
getValue(1)),
6905 Result = getSBBZero(Node);
6909 if (VT == MVT::i8 || VT == MVT::i16) {
6910 int SubIndex = VT == MVT::i16 ? X86::sub_16bit : X86::sub_8bit;
6911 Result = CurDAG->getTargetExtractSubreg(SubIndex, dl, VT, Result);
6914 ReplaceUses(
SDValue(Node, 0), Result);
6915 CurDAG->RemoveDeadNode(Node);
6927 if (!
SDValue(Node, 0).use_empty()) {
6929 MVT VT =
Node->getSimpleValueType(0);
6930 if (VT == MVT::i8 || VT == MVT::i16) {
6931 int SubIndex = VT == MVT::i16 ? X86::sub_16bit : X86::sub_8bit;
6932 Result = CurDAG->getTargetExtractSubreg(SubIndex, dl, VT, Result);
6934 ReplaceUses(
SDValue(Node, 0), Result);
6937 CurDAG->RemoveDeadNode(Node);
6944 SDValue IndexOp = Mgt->getIndex();
6947 MVT ValueVT =
Node->getSimpleValueType(0);
6948 MVT MaskVT =
Mask.getSimpleValueType();
6965 if (IndexVT == MVT::v4i32 && NumElts == 4 && EltSize == 32)
6966 Opc = IsFP ? X86::VGATHERDPSZ128rm : X86::VPGATHERDDZ128rm;
6967 else if (IndexVT == MVT::v8i32 && NumElts == 8 && EltSize == 32)
6968 Opc = IsFP ? X86::VGATHERDPSZ256rm : X86::VPGATHERDDZ256rm;
6969 else if (IndexVT == MVT::v16i32 && NumElts == 16 && EltSize == 32)
6970 Opc = IsFP ? X86::VGATHERDPSZrm : X86::VPGATHERDDZrm;
6971 else if (IndexVT == MVT::v4i32 && NumElts == 2 && EltSize == 64)
6972 Opc = IsFP ? X86::VGATHERDPDZ128rm : X86::VPGATHERDQZ128rm;
6973 else if (IndexVT == MVT::v4i32 && NumElts == 4 && EltSize == 64)
6974 Opc = IsFP ? X86::VGATHERDPDZ256rm : X86::VPGATHERDQZ256rm;
6975 else if (IndexVT == MVT::v8i32 && NumElts == 8 && EltSize == 64)
6976 Opc = IsFP ? X86::VGATHERDPDZrm : X86::VPGATHERDQZrm;
6977 else if (IndexVT == MVT::v2i64 && NumElts == 4 && EltSize == 32)
6978 Opc = IsFP ? X86::VGATHERQPSZ128rm : X86::VPGATHERQDZ128rm;
6979 else if (IndexVT == MVT::v4i64 && NumElts == 4 && EltSize == 32)
6980 Opc = IsFP ? X86::VGATHERQPSZ256rm : X86::VPGATHERQDZ256rm;
6981 else if (IndexVT == MVT::v8i64 && NumElts == 8 && EltSize == 32)
6982 Opc = IsFP ? X86::VGATHERQPSZrm : X86::VPGATHERQDZrm;
6983 else if (IndexVT == MVT::v2i64 && NumElts == 2 && EltSize == 64)
6984 Opc = IsFP ? X86::VGATHERQPDZ128rm : X86::VPGATHERQQZ128rm;
6985 else if (IndexVT == MVT::v4i64 && NumElts == 4 && EltSize == 64)
6986 Opc = IsFP ? X86::VGATHERQPDZ256rm : X86::VPGATHERQQZ256rm;
6987 else if (IndexVT == MVT::v8i64 && NumElts == 8 && EltSize == 64)
6988 Opc = IsFP ? X86::VGATHERQPDZrm : X86::VPGATHERQQZrm;
6990 assert(EVT(MaskVT) == EVT(ValueVT).changeVectorElementTypeToInteger() &&
6991 "Unexpected mask VT!");
6992 if (IndexVT == MVT::v4i32 && NumElts == 4 && EltSize == 32)
6993 Opc = IsFP ? X86::VGATHERDPSrm : X86::VPGATHERDDrm;
6994 else if (IndexVT == MVT::v8i32 && NumElts == 8 && EltSize == 32)
6995 Opc = IsFP ? X86::VGATHERDPSYrm : X86::VPGATHERDDYrm;
6996 else if (IndexVT == MVT::v4i32 && NumElts == 2 && EltSize == 64)
6997 Opc = IsFP ? X86::VGATHERDPDrm : X86::VPGATHERDQrm;
6998 else if (IndexVT == MVT::v4i32 && NumElts == 4 && EltSize == 64)
6999 Opc = IsFP ? X86::VGATHERDPDYrm : X86::VPGATHERDQYrm;
7000 else if (IndexVT == MVT::v2i64 && NumElts == 4 && EltSize == 32)
7001 Opc = IsFP ? X86::VGATHERQPSrm : X86::VPGATHERQDrm;
7002 else if (IndexVT == MVT::v4i64 && NumElts == 4 && EltSize == 32)
7003 Opc = IsFP ? X86::VGATHERQPSYrm : X86::VPGATHERQDYrm;
7004 else if (IndexVT == MVT::v2i64 && NumElts == 2 && EltSize == 64)
7005 Opc = IsFP ? X86::VGATHERQPDrm : X86::VPGATHERQQrm;
7006 else if (IndexVT == MVT::v4i64 && NumElts == 4 && EltSize == 64)
7007 Opc = IsFP ? X86::VGATHERQPDYrm : X86::VPGATHERQQYrm;
7014 if (!selectVectorAddr(Mgt, Mgt->getBasePtr(), IndexOp, Mgt->getScale(),
7015 Base, Scale, Index, Disp, Segment))
7018 SDValue PassThru = Mgt->getPassThru();
7019 SDValue Chain = Mgt->getChain();
7021 SDVTList VTs = CurDAG->getVTList(ValueVT, MaskVT, MVT::Other);
7023 MachineSDNode *NewNode;
7026 Index, Disp, Segment, Chain};
7027 NewNode = CurDAG->getMachineNode(
Opc, SDLoc(dl), VTs,
Ops);
7030 Disp, Segment,
Mask, Chain};
7031 NewNode = CurDAG->getMachineNode(
Opc, SDLoc(dl), VTs,
Ops);
7033 CurDAG->setNodeMemRefs(NewNode, {Mgt->getMemOperand()});
7036 CurDAG->RemoveDeadNode(Node);
7042 SDValue IndexOp = Sc->getIndex();
7044 MVT ValueVT =
Value.getSimpleValueType();
7059 if (IndexVT == MVT::v4i32 && NumElts == 4 && EltSize == 32)
7060 Opc = IsFP ? X86::VSCATTERDPSZ128mr : X86::VPSCATTERDDZ128mr;
7061 else if (IndexVT == MVT::v8i32 && NumElts == 8 && EltSize == 32)
7062 Opc = IsFP ? X86::VSCATTERDPSZ256mr : X86::VPSCATTERDDZ256mr;
7063 else if (IndexVT == MVT::v16i32 && NumElts == 16 && EltSize == 32)
7064 Opc = IsFP ? X86::VSCATTERDPSZmr : X86::VPSCATTERDDZmr;
7065 else if (IndexVT == MVT::v4i32 && NumElts == 2 && EltSize == 64)
7066 Opc = IsFP ? X86::VSCATTERDPDZ128mr : X86::VPSCATTERDQZ128mr;
7067 else if (IndexVT == MVT::v4i32 && NumElts == 4 && EltSize == 64)
7068 Opc = IsFP ? X86::VSCATTERDPDZ256mr : X86::VPSCATTERDQZ256mr;
7069 else if (IndexVT == MVT::v8i32 && NumElts == 8 && EltSize == 64)
7070 Opc = IsFP ? X86::VSCATTERDPDZmr : X86::VPSCATTERDQZmr;
7071 else if (IndexVT == MVT::v2i64 && NumElts == 4 && EltSize == 32)
7072 Opc = IsFP ? X86::VSCATTERQPSZ128mr : X86::VPSCATTERQDZ128mr;
7073 else if (IndexVT == MVT::v4i64 && NumElts == 4 && EltSize == 32)
7074 Opc = IsFP ? X86::VSCATTERQPSZ256mr : X86::VPSCATTERQDZ256mr;
7075 else if (IndexVT == MVT::v8i64 && NumElts == 8 && EltSize == 32)
7076 Opc = IsFP ? X86::VSCATTERQPSZmr : X86::VPSCATTERQDZmr;
7077 else if (IndexVT == MVT::v2i64 && NumElts == 2 && EltSize == 64)
7078 Opc = IsFP ? X86::VSCATTERQPDZ128mr : X86::VPSCATTERQQZ128mr;
7079 else if (IndexVT == MVT::v4i64 && NumElts == 4 && EltSize == 64)
7080 Opc = IsFP ? X86::VSCATTERQPDZ256mr : X86::VPSCATTERQQZ256mr;
7081 else if (IndexVT == MVT::v8i64 && NumElts == 8 && EltSize == 64)
7082 Opc = IsFP ? X86::VSCATTERQPDZmr : X86::VPSCATTERQQZmr;
7087 if (!selectVectorAddr(Sc, Sc->getBasePtr(), IndexOp, Sc->getScale(),
7088 Base, Scale, Index, Disp, Segment))
7092 SDValue Chain = Sc->getChain();
7094 SDVTList VTs = CurDAG->getVTList(
Mask.getValueType(), MVT::Other);
7097 MachineSDNode *NewNode = CurDAG->getMachineNode(
Opc, SDLoc(dl), VTs,
Ops);
7098 CurDAG->setNodeMemRefs(NewNode, {Sc->getMemOperand()});
7100 CurDAG->RemoveDeadNode(Node);
7104 auto *MFI = CurDAG->getMachineFunction().getInfo<X86MachineFunctionInfo>();
7108 SDValue CallIdValue = CurDAG->getTargetConstant(CallId, dl, MVT::i32);
7109 MachineSDNode *
New = CurDAG->getMachineNode(
7110 TargetOpcode::PREALLOCATED_SETUP, dl, MVT::Other, CallIdValue, Chain);
7112 CurDAG->RemoveDeadNode(Node);
7116 auto *MFI = CurDAG->getMachineFunction().getInfo<X86MachineFunctionInfo>();
7120 SDValue CallIdValue = CurDAG->getTargetConstant(CallId, dl, MVT::i32);
7123 Ops[0] = CallIdValue;
7126 MachineSDNode *
New = CurDAG->getMachineNode(
7127 TargetOpcode::PREALLOCATED_ARG, dl,
7133 CurDAG->RemoveDeadNode(Node);
7144 switch (
Node->getOpcode()) {
7148 Opcode = X86::AESENCWIDE128KL;
7151 Opcode = X86::AESDECWIDE128KL;
7154 Opcode = X86::AESENCWIDE256KL;
7157 Opcode = X86::AESDECWIDE256KL;
7165 if (!selectAddr(Node, Addr,
Base, Scale, Index, Disp, Segment))
7168 Chain = CurDAG->getCopyToReg(Chain, dl, X86::XMM0,
Node->getOperand(2),
7170 Chain = CurDAG->getCopyToReg(Chain, dl, X86::XMM1,
Node->getOperand(3),
7172 Chain = CurDAG->getCopyToReg(Chain, dl, X86::XMM2,
Node->getOperand(4),
7174 Chain = CurDAG->getCopyToReg(Chain, dl, X86::XMM3,
Node->getOperand(5),
7176 Chain = CurDAG->getCopyToReg(Chain, dl, X86::XMM4,
Node->getOperand(6),
7178 Chain = CurDAG->getCopyToReg(Chain, dl, X86::XMM5,
Node->getOperand(7),
7180 Chain = CurDAG->getCopyToReg(Chain, dl, X86::XMM6,
Node->getOperand(8),
7182 Chain = CurDAG->getCopyToReg(Chain, dl, X86::XMM7,
Node->getOperand(9),
7185 MachineSDNode *Res = CurDAG->getMachineNode(
7186 Opcode, dl,
Node->getVTList(),
7187 {Base, Scale, Index, Disp, Segment, Chain, Chain.getValue(1)});
7189 ReplaceNode(Node, Res);
7196 if (
Node->getNumValues() == 3)
7197 Glue =
Node->getOperand(2);
7199 CurDAG->getCopyFromReg(Chain, dl,
Reg,
Node->getValueType(0), Glue);
7200 ReplaceNode(Node,
Copy.getNode());
7208bool X86DAGToDAGISel::SelectInlineAsmMemoryOperand(
7210 std::vector<SDValue> &OutOps) {
7211 SDValue Op0, Op1, Op2, Op3, Op4;
7212 switch (ConstraintID) {
7215 case InlineAsm::ConstraintCode::o:
7216 case InlineAsm::ConstraintCode::v:
7217 case InlineAsm::ConstraintCode::m:
7218 case InlineAsm::ConstraintCode::X:
7219 case InlineAsm::ConstraintCode::p:
7220 if (!selectAddr(
nullptr,
Op, Op0, Op1, Op2, Op3, Op4))
7225 OutOps.push_back(Op0);
7226 OutOps.push_back(Op1);
7227 OutOps.push_back(Op2);
7228 OutOps.push_back(Op3);
7229 OutOps.push_back(Op4);
7235 std::make_unique<X86DAGToDAGISel>(TM, TM.getOptLevel())) {}
7241 return new X86DAGToDAGISelLegacy(TM, OptLevel);
static SDValue Widen(SelectionDAG *CurDAG, SDValue N)
const AArch64Subtarget & Subtarget
const TargetLowering & TLI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
AMDGPU Register Bank Select
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
Function Alias Analysis false
#define CASE(ATTRNAME, AANAME,...)
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static bool isSigned(unsigned Opcode)
const HexagonInstrInfo * TII
Module.h This file contains the declarations for the Module class.
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
const MCPhysReg ArgGPRs[]
static bool isUndef(const MachineInstr &MI)
Promote Memory to Register
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
MachineRegisterInfo & MRI
BaseType
A given derived pointer can have multiple base pointers through phi/selects.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static bool isFusableLoadOpStorePattern(StoreSDNode *StoreNode, SDValue StoredVal, SelectionDAG *CurDAG, LoadSDNode *&LoadNode, SDValue &InputChain)
static void insertDAGNode(SelectionDAG *DAG, SDNode *Pos, SDValue N)
static bool isRIPRelative(const MCInst &MI, const MCInstrInfo &MCII)
Check if the instruction uses RIP relative addressing.
#define FROM_TO(FROM, TO)
#define GET_EGPR_IF_ENABLED(OPC)
static bool isLegalMaskCompare(SDNode *N, const X86Subtarget *Subtarget)
static bool foldMaskAndShiftToScale(SelectionDAG &DAG, SDValue N, uint64_t Mask, SDValue Shift, SDValue X, X86ISelAddressMode &AM)
static bool foldMaskAndShiftToExtract(SelectionDAG &DAG, SDValue N, uint64_t Mask, SDValue Shift, SDValue X, X86ISelAddressMode &AM)
static bool addrMayUseNonFixedFrameIndex(SDValue Addr, const MachineFrameInfo &MFI, unsigned Depth=0)
Return true if Addr may be matched with a non-fixed frame index as base.
static bool needBWI(MVT VT)
static unsigned getVPTESTMOpc(MVT TestVT, bool IsTestN, bool FoldedLoad, bool FoldedBCast, bool Masked)
#define GET_NDM_IF_ENABLED(OPC)
static bool foldMaskedShiftToBEXTR(SelectionDAG &DAG, SDValue N, uint64_t Mask, SDValue Shift, SDValue X, X86ISelAddressMode &AM, const X86Subtarget &Subtarget)
static bool mayUseCarryFlag(X86::CondCode CC)
static bool isEndbrImm(uint64_t Imm, unsigned BitWidth)
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...
#define GET_ND_IF_ENABLED(OPC)
static void recordACEProgModel(SelectionDAG *DAG, unsigned IntNo)
#define VPTESTM_BROADCAST_CASES(SUFFIX)
static SDValue getLowSubvectorMaskCompare(SDValue V, const X86Subtarget *Subtarget)
static bool foldMaskedShiftToScaledMask(SelectionDAG &DAG, SDValue N, X86ISelAddressMode &AM)
#define VPTESTM_FULL_CASES(SUFFIX)
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 ...
static bool isDispSafeForFrameIndexOrRegBase(int64_t Val)
static void orderRegForMul(SDValue &N0, SDValue &N1, const unsigned LoReg, const MachineRegisterInfo &MRI)
#define GET_ND_IF_ENABLED(OPC)
const AArch64RegisterInfo * getRegisterInfo() const override
const AArch64InstrInfo * getInstrInfo() const override
const AArch64Options & getCLOpts() const
bool isTargetAndroid() const
bool isTargetFuchsia() const
bool isCallingConvWin64(CallingConv::ID CC, bool IsVarArg) const
Class for arbitrary precision integers.
static APInt getAllOnes(unsigned numBits)
Return an APInt of a specified width with all bits set.
LLVM_ABI APInt zext(unsigned width) const
Zero extend to a new width.
LLVM_ABI APInt trunc(unsigned width) const
Truncate to new width.
bool isAllOnes() const
Determine if all bits are set. This is true for zero-width values.
unsigned getBitWidth() const
Return the number of bits in the APInt.
unsigned countl_zero() const
The APInt version of std::countl_zero.
unsigned getSignificantBits() const
Get the minimum bit size for this signed APInt.
bool isSubsetOf(const APInt &RHS) const
This operation checks that all bits set in this APInt are also set in RHS.
static APInt getLowBitsSet(unsigned numBits, unsigned loBitsSet)
Constructs an APInt value that has the bottom loBitsSet bits set.
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Constructs an APInt value that has the top hiBitsSet bits set.
bool isOne() const
Determine if this is a value of 1.
unsigned countr_one() const
Count the number of trailing one bits.
FunctionPass class - This class is used to implement most global optimizations.
bool hasMinSize() const
Optimize this function for minimum size (-Oz).
CallingConv::ID getCallingConv() const
getCallingConv()/setCallingConv(CC) - These method get and set the calling convention of this functio...
LLVMContext & getContext() const
getContext - Return a reference to the LLVMContext associated with this function.
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
Module * getParent()
Get the module that this global value is contained inside of...
LLVM_ABI std::optional< ConstantRange > getAbsoluteSymbolRange() const
If this is an absolute symbol reference, returns the range of the symbol, otherwise returns std::null...
LLVM_ABI void emitError(const Instruction *I, const Twine &ErrorStr)
emitError - Emit an error message to the currently installed error handler with optional location inf...
This class is used to represent ISD::LOAD nodes.
const SDValue & getBasePtr() const
const SDValue & getOffset() const
unsigned getID() const
getID() - Return the register class ID number.
unsigned getNumRegs() const
getNumRegs - Return the number of registers in this class.
bool contains(MCRegister Reg) const
contains - Return true if the specified register is included in this register class.
bool isVectorOf(MVT EltVT) const
Return true if this is a vector with matching element type.
bool is128BitVector() const
Return true if this is a 128-bit vector type.
unsigned getVectorMinNumElements() const
Given a vector type, return the minimum number of elements it contains.
uint64_t getScalarSizeInBits() const
unsigned getVectorNumElements() const
bool isVector() const
Return true if this is a vector value type.
bool is512BitVector() const
Return true if this is a 512-bit vector type.
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
bool is256BitVector() const
Return true if this is a 256-bit vector type.
bool isScalarInteger() const
Return true if this is an integer, not including vectors.
static MVT getVectorVT(MVT VT, unsigned NumElements)
MVT getVectorElementType() const
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
MVT getHalfNumVectorElementsVT() const
Return a VT for a vector type with the same element type but half the number of elements.
MVT getScalarType() const
If this is a vector, return the element type, otherwise return this.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted.
bool isFixedObjectIndex(int ObjectIdx) const
Returns true if the specified index corresponds to a fixed stack object.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
StringRef getName() const
getName - Return the name of the corresponding LLVM function.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
const DataLayout & getDataLayout() const
Return the DataLayout attached to the Module associated to this MF.
Function & getFunction()
Return the LLVM function that this machine code represents.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
@ MOLoad
The memory access reads data.
@ MOStore
The memory access writes data.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
MachineMemOperand * getMemOperand() const
Return the unique MachineMemOperand object describing the memory reference performed by operation.
const MachinePointerInfo & getPointerInfo() const
const SDValue & getChain() const
bool isNonTemporal() const
Metadata * getModuleFlag(StringRef Key) const
Return the corresponding value if Key appears in module flags, otherwise return null.
Wrapper class representing virtual and physical registers.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
ArrayRef< SDUse > ops() const
int getNodeId() const
Return the unique node id.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
bool hasOneUse() const
Return true if there is exactly one use of this node.
SDNodeFlags getFlags() const
MVT getSimpleValueType(unsigned ResNo) const
Return the type of a specified result as a simple type.
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.
uint64_t getAsZExtVal() const
Helper method returns the zero-extended integer value of a ConstantSDNode.
bool use_empty() const
Return true if there are no uses of this node.
const SDValue & getOperand(unsigned Num) const
bool hasNUsesOfValue(unsigned NUses, unsigned Value) const
Return true if there are exactly NUSES uses of the indicated value.
iterator_range< user_iterator > users()
op_iterator op_end() const
op_iterator op_begin() const
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation.
SDNode * getNode() const
get the SDNode which holds the desired result
bool hasOneUse() const
Return true if there is exactly one node using value ResNo of Node, in exactly one operand.
SDValue getValue(unsigned R) const
EVT getValueType() const
Return the ValueType of the referenced return value.
bool isMachineOpcode() const
TypeSize getValueSizeInBits() const
Returns the size of the value in bits.
const SDValue & getOperand(unsigned i) const
ISD::CondCode getOperandCondCode(unsigned i) const
uint64_t getScalarValueSizeInBits() const
unsigned getResNo() const
get the index which selects a specific result in the SDNode
uint64_t getConstantOperandVal(unsigned i) const
MVT getSimpleValueType() const
Return the simple ValueType of the referenced return value.
unsigned getMachineOpcode() const
unsigned getOpcode() const
unsigned getNumOperands() const
SelectionDAGISelPass(std::unique_ptr< SelectionDAGISel > Selector)
SelectionDAGISel - This is the common base class used for SelectionDAG-based pattern-matching instruc...
static int getUninvalidatedNodeId(SDNode *N)
virtual bool runOnMachineFunction(MachineFunction &mf)
static void InvalidateNodeId(SDNode *N)
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
static constexpr unsigned MaxRecursionDepth
LLVM_ABI SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
LLVM_ABI void ReplaceAllUsesWith(SDValue From, SDValue To)
Modify anything using 'From' to use 'To' instead.
LLVM_ABI SDValue getSignedConstant(int64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
LLVM_ABI void RemoveDeadNode(SDNode *N)
Remove the specified node from the system.
LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
MachineFunction & getMachineFunction() const
LLVM_ABI SDValue getZExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either zero-extending or trunca...
LLVM_ABI bool MaskedValueIsZero(SDValue Op, const APInt &Mask, unsigned Depth=0) const
Return true if 'Op & Mask' is known to be zero.
LLVM_ABI SDNode * UpdateNodeOperands(SDNode *N, SDValue Op)
Mutate the specified node in-place to have the specified operands.
void RepositionNode(allnodes_iterator Position, SDNode *N)
Move node N in the AllNodes list to be immediately before the given iterator Position.
ilist< SDNode >::iterator allnodes_iterator
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void push_back(const T &Elt)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
This class is used to represent ISD::STORE nodes.
const SDValue & getBasePtr() const
const SDValue & getOffset() const
virtual const TargetRegisterClass * getRegClassFor(MVT VT, bool isDivergent=false) const
Return the register class that should be used for the specified value type.
virtual MVT getPointerTy(const DataLayout &DL, uint32_t AS=0) const
Return the pointer type for the given address space, defaults to the pointer type from the data layou...
std::pair< SDValue, SDValue > LowerCallTo(CallLoweringInfo &CLI) const
This function lowers an abstract call to a function into an actual call.
bool hasOneUse() const
Return true if there is exactly one use of this value.
X86ISelDAGToDAGPass(X86TargetMachine &TM)
X86MachineFunctionInfo - This class is derived from MachineFunction and contains private X86 target-s...
void setAMXProgModel(AMXProgModelEnum Model)
ACEProgModelEnum getACEProgModel() const
AMXProgModelEnum getAMXProgModel() const
size_t getPreallocatedIdForCallSite(const Value *CS)
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...
self_iterator getIterator()
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
constexpr char Align[]
Key for Kernel::Arg::Metadata::mAlign.
constexpr char Args[]
Key for Kernel::Metadata::mArgs.
constexpr std::underlying_type_t< E > Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
bool isNON_EXTLoad(const SDNode *N)
Returns true if the specified node is a non-extending load.
@ SETCC
SetCC operator - This evaluates to a true value iff the condition is true.
@ DELETED_NODE
DELETED_NODE - This is an illegal value that is used to catch errors.
@ SMUL_LOHI
SMUL_LOHI/UMUL_LOHI - Multiply two integers of type iN, producing a signed/unsigned value of type i[2...
@ INSERT_SUBVECTOR
INSERT_SUBVECTOR(VECTOR1, VECTOR2, IDX) - Returns a vector with VECTOR2 inserted into VECTOR1.
@ ADD
Simple integer binary arithmetic operators.
@ LOAD
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
@ ANY_EXTEND
ANY_EXTEND - Used for integer types. The high bits are undefined.
@ INTRINSIC_VOID
OUTCHAIN = INTRINSIC_VOID(INCHAIN, INTRINSICID, arg1, arg2, ...) This node represents a target intrin...
@ SDIVREM
SDIVREM/UDIVREM - Divide two integers and produce both a quotient and remainder result.
@ BITCAST
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
@ SIGN_EXTEND
Conversion operators.
@ SCALAR_TO_VECTOR
SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a scalar value into element 0 of the...
@ PREALLOCATED_SETUP
PREALLOCATED_SETUP - This has 2 operands: an input chain and a SRCVALUE with the preallocated call Va...
@ PREALLOCATED_ARG
PREALLOCATED_ARG - This has 3 operands: an input chain, a SRCVALUE with the preallocated call Value,...
@ BRIND
BRIND - Indirect branch.
@ AssertAlign
AssertAlign - These nodes record if a register contains a value that has a known alignment and the tr...
@ CopyFromReg
CopyFromReg - This node indicates that the input value is a virtual or physical register that is defi...
@ TargetGlobalAddress
TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or anything else with this node...
@ SHL
Shift and rotation operations.
@ EXTRACT_SUBVECTOR
EXTRACT_SUBVECTOR(VECTOR, IDX) - Returns a subvector from VECTOR.
@ EXTRACT_VECTOR_ELT
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
@ CopyToReg
CopyToReg - This node has three operands: a chain, a register number to set to this value,...
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
@ LOCAL_RECOVER
LOCAL_RECOVER - Represents the llvm.localrecover intrinsic.
@ ANY_EXTEND_VECTOR_INREG
ANY_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register any-extension of the low la...
@ FP_EXTEND
X = FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
@ VSELECT
Select with a vector condition (op #0) and two vector operands (ops #1 and #2), returning a vector re...
@ UADDO_CARRY
Carry-using nodes for multiple precision addition and subtraction.
@ STRICT_FP_ROUND
X = STRICT_FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision ...
@ STRICT_FP_TO_SINT
STRICT_FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
@ FP_TO_SINT
FP_TO_[US]INT - Convert a floating point value to a signed or unsigned integer.
@ STRICT_FP_EXTEND
X = STRICT_FP_EXTEND(Y) - Extend a smaller FP type into a larger FP type.
@ AND
Bitwise operators - logical and, logical or, logical xor.
@ FREEZE
FREEZE - FREEZE(VAL) returns an arbitrary value if VAL is UNDEF (or is evaluated to UNDEF),...
@ TokenFactor
TokenFactor - This node takes multiple tokens as input and produces a single token result.
@ FP_ROUND
X = FP_ROUND(Y, TRUNC) - Rounding 'Y' from a larger floating point type down to the precision of the ...
@ ZERO_EXTEND_VECTOR_INREG
ZERO_EXTEND_VECTOR_INREG(Vector) - This operator represents an in-register zero-extension of the low ...
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
@ AssertSext
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
@ CALLSEQ_START
CALLSEQ_START/CALLSEQ_END - These operators mark the beginning and end of a call sequence,...
@ INTRINSIC_W_CHAIN
RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) This node represents a target in...
bool isNormalStore(const SDNode *N)
Returns true if the specified node is a non-truncating and unindexed store.
LLVM_ABI bool isBuildVectorAllOnes(SDValue V)
Return true if the specified value is a BUILD_VECTOR where all of the elements are ~0 or undef.
LLVM_ABI bool isBuildVectorAllZeros(SDValue V)
Return true if the specified value is a BUILD_VECTOR where all of the elements are 0 or undef.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out,...
LLVM_ABI bool isBuildVectorOfConstantSDNodes(SDValue V)
Return true if the specified value is a BUILD_VECTOR node of all ConstantSDNode or undef.
bool isNormalLoad(const SDNode *N)
Returns true if the specified node is a non-extending and unindexed load.
@ GlobalBaseReg
The result of the mflr at function entry, used for PIC code.
@ X86
Windows x64, Windows Itanium (IA-64)
@ MO_NO_FLAG
MO_NO_FLAG - No flag for the operand.
@ EVEX
EVEX - Specifies that this instruction use EVEX form which provides syntax support up to 32 512-bit r...
@ VEX
VEX - encoding using 0xC4/0xC5.
@ XOP
XOP - Opcode prefix used by XOP instructions.
int getMemoryOperandNo(uint64_t TSFlags)
@ GlobalBaseReg
On Darwin, this node represents the result of the popl at function entry, used for PIC code.
@ POP_FROM_X87_REG
The same as ISD::CopyFromReg except that this node makes it explicit that it may lower to an x87 FPU ...
bool foldNDDCmovLoads(const X86Subtarget &STI, const TargetMachine &TM)
Return true if ISel folds non-RIP-relative loads into NDD CMOVs so that X86CmovConversion converts th...
int getCondSrcNoFromDesc(const MCInstrDesc &MCID)
Return the source operand # for condition code by MCID.
bool mayFoldLoad(SDValue Op, const X86Subtarget &Subtarget, bool AssumeSingleUse=false, bool IgnoreAlignment=false)
Check if Op is a load operation that could be folded into some other x86 instruction as a memory oper...
bool isOffsetSuitableForCodeModel(int64_t Offset, CodeModel::Model M, bool hasSymbolicDisplacement)
Returns true of the given offset can be fit into displacement field of the instruction.
bool isConstantSplat(SDValue Op, APInt &SplatVal, bool AllowPartialUndefs)
If Op is a constant whose elements are all the same constant or undefined, return true and return the...
@ User
could "use" a pointer
NodeAddr< UseNode * > Use
NodeAddr< NodeBase * > Node
This is an optimization pass for GlobalISel generic memory operations.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
constexpr bool isInt(int64_t x)
Checks if an integer fits into the given bit width.
LLVM_ABI bool isNullConstant(SDValue V)
Returns true if V is a constant integer zero.
LLVM_ABI SDValue peekThroughBitcasts(SDValue V)
Return the non-bitcasted source operand of V if it exists.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
@ Load
The value being inserted comes from a load (InsertElement only).
@ Store
The extracted value is stored (ExtractElement only).
bool isa_and_nonnull(const Y &Val)
T bit_ceil(T Value)
Returns the smallest integral power of two no smaller than Value if Value is nonzero.
constexpr int popcount(T Value) noexcept
Count the number of set bits in a value.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
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...
unsigned M1(unsigned Val)
auto dyn_cast_or_null(const Y &Val)
bool any_of(R &&range, UnaryPredicate P)
Provide wrappers to std::any_of which take ranges instead of having to pass begin/end explicitly.
int countl_zero(T Val)
Count number of 0's from the most significant bit to the least stopping at the first 1.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
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...
FunctionPass * createX86ISelDag(X86TargetMachine &TM, CodeGenOptLevel OptLevel)
This pass converts a legalized DAG into a X86-specific DAG, ready for instruction scheduling.
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
CodeGenOptLevel
Code generation optimization level.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
@ And
Bitwise or logical AND of integers.
DWARFExpression::Operation Op
unsigned M0(unsigned Val)
constexpr unsigned BitWidth
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
LLVM_ABI bool isOneConstant(SDValue V)
Returns true if V is a constant integer one.
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
constexpr T maskTrailingOnes(unsigned N)
Create a bitmask with the N right-most bits set to 1, and all other bits set to 0.
LLVM_ABI bool isAllOnesConstant(SDValue V)
Returns true if V is an integer constant with all bits set.
MCRegisterClass TargetRegisterClass
Implement std::hash so that hash_code can be used in STL containers.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
bool is128BitVector() const
Return true if this is a 128-bit vector type.
bool isVector() const
Return true if this is a vector value type.
bool is256BitVector() const
Return true if this is a 256-bit vector type.
bool isConstant() const
Returns true if we know the value of all bits.
LLVM_ABI unsigned getAddrSpace() const
Return the LLVM IR address space number that this pointer points into.
static LLVM_ABI MachinePointerInfo getFixedStack(MachineFunction &MF, int FI, int64_t Offset=0)
Return a MachinePointerInfo record that refers to the specified FrameIndex.
bool hasNoUnsignedWrap() const