23 #define DEBUG_TYPE "systemz-isel" 27 struct SystemZAddressingMode {
62 bool IncludesDynAlloc;
64 SystemZAddressingMode(AddrForm form, DispRange dr)
65 :
Form(form), DR(dr), Base(), Disp(0),
Index(),
66 IncludesDynAlloc(
false) {}
69 bool hasIndexField() {
return Form != FormBD; }
72 bool isDynAlloc() {
return Form == FormBDXDynAlloc; }
75 errs() <<
"SystemZAddressingMode " <<
this <<
'\n';
83 if (hasIndexField()) {
91 errs() <<
" Disp " << Disp;
93 errs() <<
" + ADJDYNALLOC";
99 static uint64_t
allOnes(
unsigned int Count) {
103 return (uint64_t(1) << Count) - 1;
119 struct RxSBGOperands {
122 Mask(
allOnes(BitSize)), Input(N), Start(64 - BitSize), End(63),
138 inline SDValue getImm(
const SDNode *Node, uint64_t Imm)
const {
152 bool expandAddress(SystemZAddressingMode &AM,
bool IsBase)
const;
155 bool selectAddress(
SDValue N, SystemZAddressingMode &AM)
const;
158 void getAddressOperands(
const SystemZAddressingMode &AM,
EVT VT,
160 void getAddressOperands(
const SystemZAddressingMode &AM,
EVT VT,
166 bool selectBDAddr(SystemZAddressingMode::DispRange DR,
SDValue Addr,
172 bool selectMVIAddr(SystemZAddressingMode::DispRange DR,
SDValue Addr,
178 bool selectBDXAddr(SystemZAddressingMode::AddrForm
Form,
179 SystemZAddressingMode::DispRange DR,
SDValue Addr,
193 return selectBDAddr(SystemZAddressingMode::Disp12Only, Addr, Base, Disp);
196 return selectBDAddr(SystemZAddressingMode::Disp12Pair, Addr, Base, Disp);
199 return selectBDAddr(SystemZAddressingMode::Disp20Only, Addr, Base, Disp);
202 return selectBDAddr(SystemZAddressingMode::Disp20Pair, Addr, Base, Disp);
207 return selectMVIAddr(SystemZAddressingMode::Disp12Pair, Addr, Base, Disp);
210 return selectMVIAddr(SystemZAddressingMode::Disp20Pair, Addr, Base, Disp);
216 return selectBDXAddr(SystemZAddressingMode::FormBDXNormal,
217 SystemZAddressingMode::Disp12Only,
218 Addr, Base, Disp, Index);
222 return selectBDXAddr(SystemZAddressingMode::FormBDXNormal,
223 SystemZAddressingMode::Disp12Pair,
224 Addr, Base, Disp, Index);
228 return selectBDXAddr(SystemZAddressingMode::FormBDXDynAlloc,
229 SystemZAddressingMode::Disp12Only,
230 Addr, Base, Disp, Index);
234 return selectBDXAddr(SystemZAddressingMode::FormBDXNormal,
235 SystemZAddressingMode::Disp20Only,
236 Addr, Base, Disp, Index);
240 return selectBDXAddr(SystemZAddressingMode::FormBDXNormal,
241 SystemZAddressingMode::Disp20Only128,
242 Addr, Base, Disp, Index);
246 return selectBDXAddr(SystemZAddressingMode::FormBDXNormal,
247 SystemZAddressingMode::Disp20Pair,
248 Addr, Base, Disp, Index);
252 return selectBDXAddr(SystemZAddressingMode::FormBDXLA,
253 SystemZAddressingMode::Disp12Pair,
254 Addr, Base, Disp, Index);
258 return selectBDXAddr(SystemZAddressingMode::FormBDXLA,
259 SystemZAddressingMode::Disp20Pair,
260 Addr, Base, Disp, Index);
273 bool detectOrAndInsertion(
SDValue &
Op, uint64_t InsertMask)
const;
277 bool refineRxSBGMask(RxSBGOperands &RxSBG, uint64_t
Mask)
const;
281 bool expandRxSBG(RxSBGOperands &RxSBG)
const;
291 bool tryRISBGZero(
SDNode *N);
295 bool tryRxSBG(
SDNode *N,
unsigned Opcode);
304 void splitLargeImmediate(
unsigned Opcode,
SDNode *Node,
SDValue Op0,
305 uint64_t UpperVal, uint64_t LowerVal);
311 bool tryGather(
SDNode *N,
unsigned Opcode);
319 bool tryFoldLoadStoreIntoMemOperand(
SDNode *Node);
334 bool storeLoadCanUseMVC(
SDNode *N)
const;
339 bool storeLoadCanUseBlockBinary(
SDNode *N,
unsigned I)
const;
363 return "SystemZ DAG->DAG Pattern Instruction Selection";
368 bool SelectInlineAsmMemoryOperand(
const SDValue &Op,
unsigned ConstraintID,
369 std::vector<SDValue> &OutOps)
override;
371 void PreprocessISelDAG()
override;
374 #include "SystemZGenDAGISel.inc" 380 return new SystemZDAGToDAGISel(TM, OptLevel);
386 static bool selectDisp(SystemZAddressingMode::DispRange DR, int64_t Val) {
388 case SystemZAddressingMode::Disp12Only:
389 return isUInt<12>(Val);
391 case SystemZAddressingMode::Disp12Pair:
392 case SystemZAddressingMode::Disp20Only:
393 case SystemZAddressingMode::Disp20Pair:
394 return isInt<20>(Val);
396 case SystemZAddressingMode::Disp20Only128:
397 return isInt<20>(Val) && isInt<20>(Val + 8);
417 if (AM.isDynAlloc() && !AM.IncludesDynAlloc) {
419 AM.IncludesDynAlloc =
true;
429 if (AM.hasIndexField() && !AM.Index.getNode()) {
439 static bool expandDisp(SystemZAddressingMode &AM,
bool IsBase,
442 int64_t TestDisp = AM.Disp + Op1;
454 bool SystemZDAGToDAGISel::expandAddress(SystemZAddressingMode &AM,
456 SDValue N = IsBase ? AM.Base : AM.Index;
462 if (Opcode ==
ISD::ADD || CurDAG->isBaseWithConstantOffset(N)) {
476 cast<ConstantSDNode>(Op0)->getSExtValue());
479 cast<ConstantSDNode>(Op1)->getSExtValue());
489 cast<GlobalAddressSDNode>(Anchor)->
getOffset());
497 static bool isValidDisp(SystemZAddressingMode::DispRange DR, int64_t Val) {
500 case SystemZAddressingMode::Disp12Only:
501 case SystemZAddressingMode::Disp20Only:
502 case SystemZAddressingMode::Disp20Only128:
505 case SystemZAddressingMode::Disp12Pair:
507 return isUInt<12>(Val);
509 case SystemZAddressingMode::Disp20Pair:
511 return !isUInt<12>(Val);
535 if (isUInt<12>(Disp))
554 unsigned IndexOpcode = Index->
getOpcode();
569 bool SystemZDAGToDAGISel::selectAddress(
SDValue Addr,
570 SystemZAddressingMode &AM)
const {
578 cast<ConstantSDNode>(Addr)->getSExtValue()))
586 while (expandAddress(AM,
true) ||
587 (AM.Index.getNode() && expandAddress(AM,
false)))
591 if (AM.Form == SystemZAddressingMode::FormBDXLA &&
592 !
shouldUseLA(AM.Base.getNode(), AM.Disp, AM.Index.getNode()))
600 if (AM.isDynAlloc() && !AM.IncludesDynAlloc)
626 void SystemZDAGToDAGISel::getAddressOperands(
const SystemZAddressingMode &AM,
632 Base = CurDAG->getRegister(0, VT);
635 int64_t
FrameIndex = cast<FrameIndexSDNode>(Base)->getIndex();
636 Base = CurDAG->getTargetFrameIndex(FrameIndex, VT);
640 "Unexpected truncation");
648 Disp = CurDAG->getTargetConstant(AM.Disp,
SDLoc(Base), VT);
651 void SystemZDAGToDAGISel::getAddressOperands(
const SystemZAddressingMode &AM,
655 getAddressOperands(AM, VT, Base, Disp);
660 Index = CurDAG->getRegister(0, VT);
663 bool SystemZDAGToDAGISel::selectBDAddr(SystemZAddressingMode::DispRange DR,
666 SystemZAddressingMode AM(SystemZAddressingMode::FormBD, DR);
667 if (!selectAddress(Addr, AM))
670 getAddressOperands(AM, Addr.
getValueType(), Base, Disp);
674 bool SystemZDAGToDAGISel::selectMVIAddr(SystemZAddressingMode::DispRange DR,
677 SystemZAddressingMode AM(SystemZAddressingMode::FormBDXNormal, DR);
678 if (!selectAddress(Addr, AM) || AM.Index.getNode())
681 getAddressOperands(AM, Addr.
getValueType(), Base, Disp);
685 bool SystemZDAGToDAGISel::selectBDXAddr(SystemZAddressingMode::AddrForm
Form,
686 SystemZAddressingMode::DispRange DR,
689 SystemZAddressingMode AM(
Form, DR);
690 if (!selectAddress(Addr, AM))
697 bool SystemZDAGToDAGISel::selectBDVAddr12Only(
SDValue Addr,
SDValue Elem,
702 if (selectBDXAddr12Only(Addr, Regs[0], Disp, Regs[1]) &&
703 Regs[0].getNode() && Regs[1].getNode()) {
704 for (
unsigned int I = 0;
I < 2; ++
I) {
721 bool SystemZDAGToDAGISel::detectOrAndInsertion(
SDValue &
Op,
722 uint64_t InsertMask)
const {
735 if (InsertMask & AndMask)
741 if (Used != (AndMask | InsertMask)) {
751 bool SystemZDAGToDAGISel::refineRxSBGMask(RxSBGOperands &RxSBG,
752 uint64_t
Mask)
const {
754 if (RxSBG.Rotate != 0)
755 Mask = (Mask << RxSBG.Rotate) | (Mask >> (64 - RxSBG.Rotate));
757 if (TII->
isRxSBGMask(Mask, RxSBG.BitSize, RxSBG.Start, RxSBG.End)) {
767 if (RxSBG.Rotate != 0)
768 Mask = ((Mask << RxSBG.Rotate) | (Mask >> (64 - RxSBG.Rotate)));
769 return (Mask & RxSBG.Mask) != 0;
772 bool SystemZDAGToDAGISel::expandRxSBG(RxSBGOperands &RxSBG)
const {
777 if (RxSBG.Opcode == SystemZ::RNSBG)
781 if (!refineRxSBGMask(RxSBG, Mask))
787 if (RxSBG.Opcode == SystemZ::RNSBG)
795 uint64_t
Mask = MaskNode->getZExtValue();
796 if (!refineRxSBGMask(RxSBG, Mask)) {
800 KnownBits Known = CurDAG->computeKnownBits(Input);
802 if (!refineRxSBGMask(RxSBG, Mask))
810 if (RxSBG.Opcode != SystemZ::RNSBG)
818 uint64_t
Mask = ~MaskNode->getZExtValue();
819 if (!refineRxSBGMask(RxSBG, Mask)) {
823 KnownBits Known = CurDAG->computeKnownBits(Input);
825 if (!refineRxSBGMask(RxSBG, Mask))
840 RxSBG.Rotate = (RxSBG.Rotate + CountNode->getZExtValue()) & 63;
851 if (RxSBG.Opcode != SystemZ::RNSBG) {
854 if (!refineRxSBGMask(RxSBG,
allOnes(InnerBitSize)))
870 if (RxSBG.Mask == 1 && RxSBG.Rotate == 1)
871 RxSBG.Rotate += (BitSize - InnerBitSize);
887 if (Count < 1 || Count >= BitSize)
890 if (RxSBG.Opcode == SystemZ::RNSBG) {
897 if (!refineRxSBGMask(RxSBG,
allOnes(BitSize - Count) << Count))
901 RxSBG.Rotate = (RxSBG.Rotate + Count) & 63;
914 if (Count < 1 || Count >= BitSize)
917 if (RxSBG.Opcode == SystemZ::RNSBG || Opcode ==
ISD::SRA) {
925 if (!refineRxSBGMask(RxSBG,
allOnes(BitSize - Count)))
929 RxSBG.Rotate = (RxSBG.Rotate - Count) & 63;
939 SDNode *
N = CurDAG->getMachineNode(TargetOpcode::IMPLICIT_DEF, DL, VT);
946 return CurDAG->getTargetInsertSubreg(SystemZ::subreg_l32,
949 return CurDAG->getTargetExtractSubreg(SystemZ::subreg_l32, DL, VT, N);
954 bool SystemZDAGToDAGISel::tryRISBGZero(
SDNode *N) {
959 RxSBGOperands RISBG(SystemZ::RISBG,
SDValue(N, 0));
961 while (expandRxSBG(RISBG))
979 if (RISBG.Rotate == 0) {
980 bool PreferAnd =
false;
986 else if (RISBG.Mask == 0xff ||
987 RISBG.Mask == 0xffff ||
988 RISBG.Mask == 0x7fffffff ||
994 else if (
auto *
Load = dyn_cast<LoadSDNode>(RISBG.Input)) {
998 RISBG.Mask == 0xffffff00 &&
999 Subtarget->hasLoadAndZeroRightmostByte())
1006 SDValue In = convertTo(DL, VT, RISBG.Input);
1007 SDValue Mask = CurDAG->getConstant(RISBG.Mask, DL, VT);
1012 ReplaceNode(N, New.
getNode());
1022 unsigned Opcode = SystemZ::RISBG;
1024 if (Subtarget->hasMiscellaneousExtensions())
1025 Opcode = SystemZ::RISBGN;
1027 if (VT ==
MVT::i32 && Subtarget->hasHighWord() &&
1032 RISBG.Start >= 32 && RISBG.End >= RISBG.Start &&
1033 ((RISBG.Start + RISBG.Rotate) & 63) >= 32 &&
1034 ((RISBG.End + RISBG.Rotate) & 63) >=
1035 ((RISBG.Start + RISBG.Rotate) & 63)) {
1036 Opcode = SystemZ::RISBMux;
1042 getUNDEF(DL, OpcodeVT),
1043 convertTo(DL, OpcodeVT, RISBG.Input),
1044 CurDAG->getTargetConstant(RISBG.Start, DL,
MVT::i32),
1045 CurDAG->getTargetConstant(RISBG.End | 128, DL,
MVT::i32),
1046 CurDAG->getTargetConstant(RISBG.Rotate, DL,
MVT::i32)
1049 DL, VT,
SDValue(CurDAG->getMachineNode(Opcode, DL, OpcodeVT, Ops), 0));
1050 ReplaceNode(N, New.
getNode());
1054 bool SystemZDAGToDAGISel::tryRxSBG(
SDNode *N,
unsigned Opcode) {
1061 RxSBGOperands RxSBG[] = {
1065 unsigned Count[] = { 0, 0 };
1066 for (
unsigned I = 0;
I < 2; ++
I)
1067 while (expandRxSBG(RxSBG[
I]))
1076 if (Count[0] == 0 && Count[1] == 0)
1080 unsigned I = Count[0] > Count[1] ? 0 : 1;
1084 if (Opcode == SystemZ::ROSBG && (RxSBG[I].
Mask & 0xff) == 0)
1085 if (
auto *
Load = dyn_cast<LoadSDNode>(Op0.
getNode()))
1091 if (Opcode == SystemZ::ROSBG && detectOrAndInsertion(Op0, RxSBG[I].
Mask)) {
1092 Opcode = SystemZ::RISBG;
1094 if (Subtarget->hasMiscellaneousExtensions())
1095 Opcode = SystemZ::RISBGN;
1100 convertTo(DL,
MVT::i64, RxSBG[I].Input),
1101 CurDAG->getTargetConstant(RxSBG[I].Start, DL,
MVT::i32),
1102 CurDAG->getTargetConstant(RxSBG[I].End, DL,
MVT::i32),
1103 CurDAG->getTargetConstant(RxSBG[I].Rotate, DL,
MVT::i32)
1106 DL, VT,
SDValue(CurDAG->getMachineNode(Opcode, DL,
MVT::i64, Ops), 0));
1107 ReplaceNode(N, New.
getNode());
1111 void SystemZDAGToDAGISel::splitLargeImmediate(
unsigned Opcode,
SDNode *Node,
1112 SDValue Op0, uint64_t UpperVal,
1113 uint64_t LowerVal) {
1118 Upper = CurDAG->getNode(Opcode, DL, VT, Op0, Upper);
1139 SDValue Or = CurDAG->getNode(Opcode, DL, VT, Upper, Lower);
1141 ReplaceNode(Node, Or.
getNode());
1146 void SystemZDAGToDAGISel::loadVectorConstant(
1156 for (
unsigned OpVal : VCI.
OpVals)
1160 if (VCI.
VecVT == VT.getSimpleVT())
1161 ReplaceNode(Node, Op.
getNode());
1162 else if (VT.getSizeInBits() == 128) {
1164 ReplaceNode(Node, BitCast.
getNode());
1165 SelectCode(BitCast.
getNode());
1167 unsigned SubRegIdx =
1168 (VT.getSizeInBits() == 32 ? SystemZ::subreg_h32 : SystemZ::subreg_h64);
1170 Node, CurDAG->getTargetExtractSubreg(SubRegIdx, DL, VT, Op).getNode());
1175 bool SystemZDAGToDAGISel::tryGather(
SDNode *N,
unsigned Opcode) {
1181 unsigned Elem = ElemN->getZExtValue();
1187 if (!
Load || !
Load->hasNUsesOfValue(1, 0))
1189 if (
Load->getMemoryVT().getSizeInBits() !=
1190 Load->getValueType(0).getSizeInBits())
1194 if (!selectBDVAddr12Only(
Load->getBasePtr(), ElemV, Base, Disp,
Index) ||
1201 CurDAG->getTargetConstant(Elem, DL,
MVT::i32),
Load->getChain()
1205 ReplaceNode(N, Res);
1209 bool SystemZDAGToDAGISel::tryScatter(
StoreSDNode *
Store,
unsigned Opcode) {
1223 unsigned Elem = ElemN->getZExtValue();
1228 if (!selectBDVAddr12Only(Store->
getBasePtr(), ElemV, Base, Disp,
Index) ||
1234 Vec, Base, Disp,
Index, CurDAG->getTargetConstant(Elem, DL,
MVT::i32),
1237 ReplaceNode(Store, CurDAG->getMachineNode(Opcode, DL,
MVT::Other, Ops));
1265 LoadNode = cast<LoadSDNode>(
Load);
1280 bool ChainCheck =
false;
1288 const unsigned int Max = 1024;
1332 bool SystemZDAGToDAGISel::tryFoldLoadStoreIntoMemOperand(
SDNode *Node) {
1336 SDLoc DL(StoreNode);
1342 unsigned NewOpc = 0;
1343 bool NegateOperand =
false;
1348 NegateOperand =
true;
1352 NewOpc = SystemZ::ASI;
1354 NewOpc = SystemZ::AGSI;
1359 NegateOperand =
true;
1363 NewOpc = SystemZ::ALSI;
1365 NewOpc = SystemZ::ALGSI;
1383 OperandV = -OperandV;
1384 if (OperandV.getMinSignedBits() > 8)
1386 Operand = CurDAG->getTargetConstant(OperandV, DL, MemVT);
1389 if (!selectBDAddr20Only(StoreNode->
getBasePtr(), Base, Disp))
1392 SDValue Ops[] = { Base, Disp, Operand, InputChain };
1395 CurDAG->setNodeMemRefs(
1399 ReplaceUses(
SDValue(StoredVal.getNode(), 1),
SDValue(Result, 0));
1400 CurDAG->RemoveDeadNode(Node);
1404 bool SystemZDAGToDAGISel::canUseBlockOperation(
StoreSDNode *Store,
1428 if (V1 == V2 && End1 == End2)
1435 bool SystemZDAGToDAGISel::storeLoadCanUseMVC(
SDNode *N)
const {
1436 auto *Store = cast<StoreSDNode>(
N);
1437 auto *Load = cast<LoadSDNode>(Store->
getValue());
1441 uint64_t
Size = Load->getMemoryVT().getStoreSize();
1442 if (Size > 1 && Size <= 8) {
1451 return canUseBlockOperation(Store, Load);
1454 bool SystemZDAGToDAGISel::storeLoadCanUseBlockBinary(
SDNode *N,
1456 auto *StoreA = cast<StoreSDNode>(
N);
1457 auto *LoadA = cast<LoadSDNode>(StoreA->getValue().getOperand(1 - I));
1458 auto *LoadB = cast<LoadSDNode>(StoreA->getValue().getOperand(I));
1459 return !LoadA->isVolatile() && canUseBlockOperation(StoreA, LoadB);
1474 if (tryRxSBG(Node, SystemZ::ROSBG))
1480 if (tryRxSBG(Node, SystemZ::RXSBG))
1489 if (
auto *Op1 = dyn_cast<ConstantSDNode>(Node->
getOperand(1))) {
1490 uint64_t Val = Op1->getZExtValue();
1493 if (Subtarget->hasMiscellaneousExtensions3()) {
1496 if (Val == (uint64_t)-1 && Opcode ==
ISD::XOR)
1504 if (
auto *Op0Op1 = dyn_cast<ConstantSDNode>(Op0->
getOperand(1)))
1505 if (Op0Op1->getZExtValue() == (uint64_t)-1)
1510 splitLargeImmediate(Opcode, Node, Node->
getOperand(0),
1519 if (tryRxSBG(Node, SystemZ::RNSBG))
1526 if (tryRISBGZero(Node))
1534 uint64_t Val = cast<ConstantSDNode>(Node)->getZExtValue();
1549 (Subtarget->hasLoadStoreOnCond2() &&
1552 isInt<16>(cast<ConstantSDNode>(Op1)->getSExtValue()) &&
1554 isInt<16>(cast<ConstantSDNode>(Op0)->getSExtValue())))) {
1557 uint64_t ConstCCValid =
1558 cast<ConstantSDNode>(CCValid.
getNode())->getZExtValue();
1559 uint64_t ConstCCMask =
1560 cast<ConstantSDNode>(CCMask.
getNode())->getZExtValue();
1562 CCMask = CurDAG->getTargetConstant(ConstCCValid ^ ConstCCMask,
1566 CurDAG->UpdateNodeOperands(Node, Op1, Op0, CCValid, CCMask, Op4);
1567 if (UpdatedNode != Node) {
1569 ReplaceNode(Node, UpdatedNode);
1579 if (ElemBitSize == 32) {
1580 if (tryGather(Node, SystemZ::VGEF))
1582 }
else if (ElemBitSize == 64) {
1583 if (tryGather(Node, SystemZ::VGEG))
1590 auto *BVN = cast<BuildVectorSDNode>(Node);
1592 if (VCI.isVectorConstantLegal(*Subtarget)) {
1593 loadVectorConstant(VCI, Node);
1600 APFloat Imm = cast<ConstantFPSDNode>(Node)->getValueAPF();
1605 assert(Success &&
"Expected legal FP immediate");
1606 loadVectorConstant(VCI, Node);
1611 if (tryFoldLoadStoreIntoMemOperand(Node))
1613 auto *Store = cast<StoreSDNode>(Node);
1615 if (ElemBitSize == 32) {
1616 if (tryScatter(Store, SystemZ::VSCEF))
1618 }
else if (ElemBitSize == 64) {
1619 if (tryScatter(Store, SystemZ::VSCEG))
1629 bool SystemZDAGToDAGISel::
1630 SelectInlineAsmMemoryOperand(
const SDValue &Op,
1631 unsigned ConstraintID,
1632 std::vector<SDValue> &OutOps) {
1633 SystemZAddressingMode::AddrForm
Form;
1634 SystemZAddressingMode::DispRange DispRange;
1637 switch(ConstraintID) {
1643 Form = SystemZAddressingMode::FormBD;
1644 DispRange = SystemZAddressingMode::Disp12Only;
1648 Form = SystemZAddressingMode::FormBDXNormal;
1649 DispRange = SystemZAddressingMode::Disp12Only;
1653 Form = SystemZAddressingMode::FormBD;
1654 DispRange = SystemZAddressingMode::Disp20Only;
1663 Form = SystemZAddressingMode::FormBDXNormal;
1664 DispRange = SystemZAddressingMode::Disp20Only;
1668 if (selectBDXAddr(Form, DispRange, Op, Base, Disp, Index)) {
1670 Subtarget->getRegisterInfo()->getPointerRegClass(*MF);
1679 SDValue(CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS,
1687 SDValue(CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS,
1692 OutOps.push_back(Base);
1693 OutOps.push_back(Disp);
1694 OutOps.push_back(Index);
1704 SystemZDAGToDAGISel::IsProfitableToFold(
SDValue N,
SDNode *U,
1717 SDNode *CCRegUser =
nullptr;
1720 for (
auto *U : CCUser->
uses()) {
1721 if (CCRegUser ==
nullptr)
1723 else if (CCRegUser != U)
1727 if (CCRegUser ==
nullptr)
1740 if (!IsLegalToFold(N, U, CCRegUser, OptLevel,
false))
1750 struct IPMConversion {
1751 IPMConversion(
unsigned xorValue, int64_t addValue,
unsigned bit)
1752 : XORValue(xorValue), AddValue(addValue),
Bit(bit) {}
1778 uint64_t TopBit = uint64_t(1) << 31;
1783 if (CCMask == (CCValid & (SystemZ::CCMASK_0
1791 | SystemZ::CCMASK_3)))
1803 if (CCMask == (CCValid & (SystemZ::CCMASK_0 | SystemZ::CCMASK_3)))
1814 if (CCMask == (CCValid & (SystemZ::CCMASK_0
1816 | SystemZ::CCMASK_3)))
1818 if (CCMask == (CCValid & (SystemZ::CCMASK_0
1820 | SystemZ::CCMASK_3)))
1827 SDValue SystemZDAGToDAGISel::expandSelectBoolean(
SDNode *Node) {
1830 if (!TrueOp || !FalseOp)
1832 if (FalseOp->getZExtValue() != 0)
1834 if (TrueOp->getSExtValue() != 1 && TrueOp->getSExtValue() != -1)
1839 if (!CCValidOp || !CCMaskOp)
1841 int CCValid = CCValidOp->getZExtValue();
1842 int CCMask = CCMaskOp->getZExtValue();
1851 CurDAG->getConstant(IPM.XORValue, DL,
MVT::i32));
1855 CurDAG->getConstant(IPM.AddValue, DL,
MVT::i32));
1858 if (VT ==
MVT::i32 && IPM.Bit == 31) {
1860 Result = CurDAG->getNode(ShiftOp, DL,
MVT::i32, Result,
1861 CurDAG->getConstant(IPM.Bit, DL,
MVT::i32));
1866 if (TrueOp->getSExtValue() == 1) {
1868 Result = CurDAG->getNode(
ISD::SRL, DL, VT, Result,
1869 CurDAG->getConstant(IPM.Bit, DL,
MVT::i32));
1870 Result = CurDAG->getNode(
ISD::AND, DL, VT, Result,
1871 CurDAG->getConstant(1, DL, VT));
1876 Result = CurDAG->getNode(
ISD::SHL, DL, VT, Result,
1877 CurDAG->getConstant(ShlAmt, DL,
MVT::i32));
1878 Result = CurDAG->getNode(
ISD::SRA, DL, VT, Result,
1879 CurDAG->getConstant(SraAmt, DL,
MVT::i32));
1886 void SystemZDAGToDAGISel::PreprocessISelDAG() {
1889 if (Subtarget->hasLoadStoreOnCond2())
1892 bool MadeChange =
false;
1895 E = CurDAG->allnodes_end();
1905 Res = expandSelectBoolean(N);
1910 LLVM_DEBUG(
dbgs() <<
"SystemZ DAG preprocessing replacing:\nOld: ");
1916 CurDAG->ReplaceAllUsesOfValueWith(
SDValue(N, 0), Res);
1922 CurDAG->RemoveDeadNodes();
static bool isImmHF(uint64_t Val)
BITCAST - This operator converts between integer, vector and FP values, as if the value was stored to...
EVT getValueType() const
Return the ValueType of the referenced return value.
const SDValue & getOffset() const
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
uint64_t getZExtValue() const
Get zero extended value.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
static void insertDAGNode(SelectionDAG *DAG, SDNode *Pos, SDValue N)
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
This class represents lattice values for constants.
static bool isImmLF(uint64_t Val)
const SDValue & getBasePtr() const
void push_back(const T &Elt)
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
const SDValue & getValue() const
static bool maskMatters(RxSBGOperands &RxSBG, uint64_t Mask)
AAMDNodes getAAInfo() const
Returns the AA info that describes the dereference.
const SDValue & getChain() const
bool hasFnAttribute(Attribute::AttrKind Kind) const
Return true if the function has the attribute.
constexpr bool isInt< 16 >(int64_t x)
bool isInteger() const
Return true if this is an integer or a vector integer type.
void setNodeId(int Id)
Set unique node id.
SDNode * getNode() const
get the SDNode which holds the desired result
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
bool hasOneUse() const
Return true if there is exactly one node using value ResNo of Node.
static uint64_t allOnes(unsigned int Count)
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.
bool hasOneUse() const
Return true if there is exactly one use of this node.
const HexagonInstrInfo * TII
Shift and rotation operations.
bool isNormalStore(const SDNode *N)
Returns true if the specified node is a non-truncating and unindexed store.
FunctionPass * createSystemZISelDag(SystemZTargetMachine &TM, CodeGenOpt::Level OptLevel)
CopyToReg - This node has three operands: a chain, a register number to set to this value...
TypeSize getValueSizeInBits() const
Returns the size of the value in bits.
unsigned getID() const
Return the register class ID number.
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
static void InvalidateNodeId(SDNode *N)
Simple integer binary arithmetic operators.
static bool expandAdjDynAlloc(SystemZAddressingMode &AM, bool IsBase, SDValue Value)
static Error getOffset(const SymbolRef &Sym, SectionRef Sec, uint64_t &Result)
ArrayRef< SDUse > ops() const
int64_t getSrcValueOffset() const
static bool shouldUseLA(SDNode *Base, int64_t Disp, SDNode *Index)
This class is used to represent ISD::STORE nodes.
BUILD_VECTOR(ELT0, ELT1, ELT2, ELT3,...) - Return a vector with the specified, possibly variable...
const Value * getValue() const
Return the base address of the memory access.
const SDValue & getBasePtr() const
bool isNormalLoad(const SDNode *N)
Returns true if the specified node is a non-extending and unindexed load.
void dump(const SparseBitVector< ElementSize > &LHS, raw_ostream &out)
use_iterator use_begin() const
Provide iteration support to walk over all uses of an SDNode.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
static bool expandDisp(SystemZAddressingMode &AM, bool IsBase, SDValue Op0, uint64_t Op1)
unsigned getVectorNumElements() const
Given a vector type, return the number of elements it contains.
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
const SDValue & getOperand(unsigned Num) const
INSERT_VECTOR_ELT(VECTOR, VAL, IDX) - Returns VECTOR with the element at IDX replaced with VAL...
const SDValue & getOffset() const
void RepositionNode(allnodes_iterator Position, SDNode *N)
Move node N in the AllNodes list to be immediately before the given iterator Position.
static void changeComponent(SystemZAddressingMode &AM, bool IsBase, SDValue Value)
TypeSize getStoreSize() const
Return the number of bytes overwritten by a store of the specified value type.
const APInt & getAPIntValue() const
FunctionPass class - This class is used to implement most global optimizations.
self_iterator getIterator()
bool isPCREL(unsigned Opcode)
bool hasNUsesOfValue(unsigned NUses, unsigned Value) const
Return true if there are exactly NUSES uses of the indicated value.
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode...
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
const SystemZInstrInfo * getInstrInfo() const override
bool use_empty() const
Return true if there are no uses of this node.
Representation for a specific memory location.
TokenFactor - This node takes multiple tokens as input and produces a single token result...
void dump() const
Dump this node, for debugging.
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
constexpr bool isInt< 32 >(int64_t x)
EXTRACT_VECTOR_ELT(VECTOR, IDX) - Returns a single element from VECTOR identified by the (potentially...
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
EVT changeVectorElementTypeToInteger() const
Return a vector with the same number of elements as this vector, but with the element type converted ...
An SDNode that represents everything that will be needed to construct a MachineInstr.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
SelectionDAGISel - This is the common base class used for SelectionDAG-based pattern-matching instruc...
const Function & getFunction() const
Return the LLVM function that this machine code represents.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
bool isDereferenceable() const
static IPMConversion getIPMConversion(unsigned CCValid, unsigned CCMask)
EVT getMemoryVT() const
Return the type of the in-memory value.
Target - Wrapper for Target specific information.
iterator_range< use_iterator > uses()
static unsigned getReg(const void *D, unsigned RC, unsigned RegNo)
ZERO_EXTEND - Used for integer types, zeroing the new bits.
ANY_EXTEND - Used for integer types. The high bits are undefined.
int getNodeId() const
Return the unique node id.
const SDValue & getValue() const
Bitwise operators - logical and, logical or, logical xor.
StringRef getValueAsString() const
Return the attribute's value as a string.
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
SmallVector< unsigned, 2 > OpVals
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
unsigned getOpcode() const
SDValue getValue(unsigned R) const
static bool selectDisp(SystemZAddressingMode::DispRange DR, int64_t Val)
bool isVectorConstantLegal(const SystemZSubtarget &Subtarget)
This class is used to form a handle around another node that is persistent and is updated across invo...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
bool isPredecessorOf(const SDNode *N) const
Return true if this node is a predecessor of N.
static bool expandIndex(SystemZAddressingMode &AM, SDValue Base, SDValue Index)
TypeSize getScalarSizeInBits() const
LLVM Value Representation.
unsigned getResNo() const
get the index which selects a specific result in the SDNode
unsigned getMachineOpcode() const
This may only be called if isMachineOpcode returns true.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
bool isNonTemporal() const
Attribute getFnAttribute(Attribute::AttrKind Kind) const
Return the attribute for the given attribute kind.
static bool isValidDisp(SystemZAddressingMode::DispRange DR, int64_t Val)
bool isRxSBGMask(uint64_t Mask, unsigned BitSize, unsigned &Start, unsigned &End) const
StringRef - Represent a constant reference to a string, i.e.
unsigned getNumOperands() const
const SDValue & getOperand(unsigned i) const
uint64_t getZExtValue() const
static bool isFusableLoadOpStorePattern(StoreSDNode *StoreNode, SDValue StoredVal, SelectionDAG *CurDAG, LoadSDNode *&LoadNode, SDValue &InputChain)
TRUNCATE - Completely drop the high bits.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
This class is used to represent ISD::LOAD nodes.
static int getUninvalidatedNodeId(SDNode *N)