49#include "llvm/IR/IntrinsicsPowerPC.h"
71#define DEBUG_TYPE "ppc-isel"
72#define PASS_NAME "PowerPC DAG->DAG Pattern Instruction Selection"
75 "Number of (sext(setcc)) nodes expanded into GPR sequence.");
77 "Number of (zext(setcc)) nodes expanded into GPR sequence.");
79 "Number of sign extensions for compare inputs added.");
81 "Number of zero extensions for compare inputs added.");
83 "Number of logical ops on i1 values calculated in GPR.");
85 "Number of compares not eliminated as they have non-extending uses.");
87 "Number of compares lowered to setb.");
99 unsigned GlobalBaseReg = 0;
102 PPCDAGToDAGISel() =
delete;
112 if (Subtarget->hasROPProtect()) {
117 PPCFunctionInfo *FI = MF.
getInfo<PPCFunctionInfo>();
126 void PreprocessISelDAG()
override;
127 void PostprocessISelDAG()
override;
131 inline SDValue getI16Imm(
unsigned Imm,
const SDLoc &dl) {
132 return CurDAG->getTargetConstant(
Imm, dl, MVT::i16);
137 inline SDValue getI32Imm(
unsigned Imm,
const SDLoc &dl) {
138 return CurDAG->getTargetConstant(
Imm, dl, MVT::i32);
144 return CurDAG->getTargetConstant(
Imm, dl, MVT::i64);
148 inline SDValue getSmallIPtrImm(int64_t
Imm,
const SDLoc &dl) {
149 return CurDAG->getSignedTargetConstant(
150 Imm, dl, PPCLowering->getPointerTy(CurDAG->getDataLayout()));
155 static bool isRotateAndMask(SDNode *
N,
unsigned Mask,
bool isShiftMask,
156 unsigned &SH,
unsigned &MB,
unsigned &ME);
160 SDNode *getGlobalBaseReg();
162 void selectFrameIndex(SDNode *SN, SDNode *
N, int64_t
Offset = 0);
166 void Select(SDNode *
N)
override;
168 bool tryBitfieldInsert(SDNode *
N);
169 bool tryBitPermutation(SDNode *
N);
170 bool tryIntCompareInGPR(SDNode *
N);
175 bool tryTLSXFormLoad(LoadSDNode *
N);
179 bool tryTLSXFormStore(StoreSDNode *
N);
202 return PPCLowering->SelectOptimalAddrMode(Parent,
N, Disp,
Base, *CurDAG,
210 return PPCLowering->SelectOptimalAddrMode(Parent,
N, Disp,
Base, *CurDAG,
218 return PPCLowering->SelectOptimalAddrMode(Parent,
N, Disp,
Base, *CurDAG,
226 return PPCLowering->SelectOptimalAddrMode(Parent,
N, Disp,
Base, *CurDAG,
233 return PPCLowering->SelectOptimalAddrMode(Parent,
N, Disp,
Base, *CurDAG,
241 return PPCLowering->SelectOptimalAddrMode(Parent,
N, Disp,
Base, *CurDAG,
249 return PPCLowering->SelectForceXFormMode(
N, Disp,
Base, *CurDAG) ==
260 return PPCLowering->SelectAddressRegReg(
N,
Base, Index, *CurDAG,
271 return PPCLowering->SelectAddressRegReg(
N,
Base, Index, *CurDAG,
282 return PPCLowering->SelectAddressRegReg(
N,
Base, Index, *CurDAG,
289 return PPCLowering->SelectAddressRegRegOnly(
N,
Base, Index, *CurDAG);
298 return PPCLowering->SelectAddressRegImm(
N, Disp,
Base, *CurDAG,
306 return PPCLowering->SelectAddressRegImm(
N, Disp,
Base, *CurDAG,
Align(4));
313 return PPCLowering->SelectAddressRegImm(
N, Disp,
Base, *CurDAG,
321 return PPCLowering->SelectAddressRegImm34(
N, Disp,
Base, *CurDAG);
331 return PPCLowering->SelectAddressPCRel(
N,
Base);
339 bool SelectInlineAsmMemoryOperand(
const SDValue &
Op,
341 std::vector<SDValue> &OutOps)
override {
342 switch(ConstraintID) {
344 errs() <<
"ConstraintID: "
347 case InlineAsm::ConstraintCode::es:
348 case InlineAsm::ConstraintCode::m:
349 case InlineAsm::ConstraintCode::o:
350 case InlineAsm::ConstraintCode::Q:
351 case InlineAsm::ConstraintCode::Z:
352 case InlineAsm::ConstraintCode::Zy:
355 const TargetInstrInfo *
TII = Subtarget->getInstrInfo();
359 SDValue RC = CurDAG->getTargetConstant(TRC->
getID(), dl, MVT::i32);
361 SDValue(CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS,
362 dl,
Op.getValueType(),
365 OutOps.push_back(NewOp);
372#include "PPCGenDAGISel.inc"
375 bool trySETCC(SDNode *
N);
376 bool tryFoldSWTestBRCC(SDNode *
N);
377 bool trySelectLoopCountIntrinsic(SDNode *
N);
378 bool tryAsSingleRLDICL(SDNode *
N);
379 bool tryAsSingleRLDCL(SDNode *
N);
380 bool tryAsSingleRLDICR(SDNode *
N);
381 bool tryAsSingleRLWINM(SDNode *
N);
382 bool tryAsSingleRLWINM8(SDNode *
N);
383 bool tryAsSingleRLWIMI(SDNode *
N);
384 bool tryAsPairOfRLDICL(SDNode *
N);
385 bool tryAsSingleRLDIMI(SDNode *
N);
387 void PeepholePPC64();
388 void PeepholePPC64ZExt();
389 void PeepholeCROps();
392 void foldBoolExts(
SDValue &Res, SDNode *&
N);
394 bool AllUsersSelectZero(SDNode *
N);
395 void SwapAllSelectUsers(SDNode *
N);
397 bool isOffsetMultipleOf(SDNode *
N,
unsigned Val)
const;
398 void transferMemOperands(SDNode *
N, SDNode *Result);
404 explicit PPCDAGToDAGISelLegacy(PPCTargetMachine &tm,
406 : SelectionDAGISelLegacy(
407 ID, std::make_unique<PPCDAGToDAGISel>(tm, OptLevel)) {}
411char PPCDAGToDAGISelLegacy::ID = 0;
418SDNode *PPCDAGToDAGISel::getGlobalBaseReg() {
419 if (!GlobalBaseReg) {
427 if (PPCLowering->getPointerTy(CurDAG->getDataLayout()) == MVT::i32) {
440 TII.get(PPC::UpdateGBR), GlobalBaseReg)
446 RegInfo->createVirtualRegister(&PPC::GPRC_and_GPRC_NOR0RegClass);
466 return CurDAG->getRegister(GlobalBaseReg,
467 PPCLowering->getPointerTy(CurDAG->getDataLayout()))
507 if (
N->getOpcode() ==
ISD::Constant &&
N->getValueType(0) == MVT::i32) {
508 Imm =
N->getAsZExtVal();
517 if (
N->getOpcode() ==
ISD::Constant &&
N->getValueType(0) == MVT::i64) {
518 Imm =
N->getAsZExtVal();
569 if (std::max(TProb, FProb) / Threshold < std::min(TProb, FProb))
573 <<
"::" << BB->
getName() <<
"'\n"
574 <<
" -> " <<
TBB->getName() <<
": " << TProb <<
"\n"
575 <<
" -> " << FBB->
getName() <<
": " << FProb <<
"\n");
591 return N->getOpcode() ==
Opc
598 SDValue TFI = CurDAG->getTargetFrameIndex(FI,
N->getValueType(0));
599 unsigned Opc =
N->getValueType(0) == MVT::i32 ? PPC::ADDI : PPC::ADDI8;
601 CurDAG->SelectNodeTo(SN,
Opc,
N->getValueType(0), TFI,
602 getSmallIPtrImm(
Offset, dl));
604 ReplaceNode(SN, CurDAG->getMachineNode(
Opc, dl,
N->getValueType(0), TFI,
605 getSmallIPtrImm(
Offset, dl)));
608bool PPCDAGToDAGISel::isRotateAndMask(SDNode *
N,
unsigned Mask,
609 bool isShiftMask,
unsigned &SH,
610 unsigned &MB,
unsigned &ME) {
613 if (
N->getValueType(0) != MVT::i32)
617 unsigned Indeterminant = ~0;
618 unsigned Opcode =
N->getOpcode();
619 if (
N->getNumOperands() != 2 ||
625 if (isShiftMask)
Mask =
Mask << Shift;
627 Indeterminant = ~(0xFFFFFFFFu << Shift);
630 if (isShiftMask)
Mask =
Mask >> Shift;
632 Indeterminant = ~(0xFFFFFFFFu >> Shift);
642 if (Mask && !(Mask & Indeterminant)) {
654 Base.getOpcode() == PPCISD::ADD_TLS &&
655 "Only expecting the ADD_TLS instruction to acquire the thread pointer!");
659 unsigned ADDTLSOp1Opcode = ADDTLSOp1.getOpcode();
668 if (ADDTLSOp1Opcode == PPCISD::LD_GOT_TPREL_L)
673 if (LD && LD->getBasePtr().getOpcode() == PPCISD::MAT_PCREL_ADDR)
679 if (ADDTLSOp1Opcode == PPCISD::GET_TPOINTER)
704 if (
Base.getOpcode() != PPCISD::ADD_TLS)
706 for (
auto *ADDTLSUse :
Base.getNode()->users()) {
711 if (LD->getSrcValueOffset() != 0 || !LD->getOffset().isUndef())
714 if (ST->getSrcValueOffset() != 0 || !ST->getOffset().isUndef())
720 if (
Base.getOperand(1).getOpcode() == PPCISD::TLS_LOCAL_EXEC_MAT_ADDR)
729bool PPCDAGToDAGISel::tryTLSXFormStore(StoreSDNode *ST) {
735 EVT MemVT =
ST->getMemoryVT();
736 EVT RegVT =
ST->getValue().getValueType();
743 Opcode = (RegVT == MVT::i32) ? PPC::STBXTLS_32 : PPC::STBXTLS;
747 Opcode = (RegVT == MVT::i32) ? PPC::STHXTLS_32 : PPC::STHXTLS;
751 Opcode = (RegVT == MVT::i32) ? PPC::STWXTLS_32 : PPC::STWXTLS;
755 Opcode = PPC::STDXTLS;
759 Opcode = PPC::STFSXTLS;
763 Opcode = PPC::STFDXTLS;
768 SDVTList VTs =
ST->getVTList();
771 SDNode *MN = CurDAG->getMachineNode(Opcode, dl, VTs,
Ops);
772 transferMemOperands(ST, MN);
777bool PPCDAGToDAGISel::tryTLSXFormLoad(LoadSDNode *LD) {
783 EVT MemVT =
LD->getMemoryVT();
784 EVT RegVT =
LD->getValueType(0);
791 Opcode = (RegVT == MVT::i32) ? PPC::LBZXTLS_32 : PPC::LBZXTLS;
795 if (RegVT == MVT::i32)
796 Opcode = isSExt ? PPC::LHAXTLS_32 : PPC::LHZXTLS_32;
798 Opcode = isSExt ? PPC::LHAXTLS : PPC::LHZXTLS;
802 if (RegVT == MVT::i32)
803 Opcode = isSExt ? PPC::LWAXTLS_32 : PPC::LWZXTLS_32;
805 Opcode = isSExt ? PPC::LWAXTLS : PPC::LWZXTLS;
809 Opcode = PPC::LDXTLS;
813 Opcode = PPC::LFSXTLS;
817 Opcode = PPC::LFDXTLS;
822 SDVTList VTs =
LD->getVTList();
824 SDNode *MN = CurDAG->getMachineNode(Opcode, dl, VTs,
Ops);
825 transferMemOperands(LD, MN);
832bool PPCDAGToDAGISel::tryBitfieldInsert(SDNode *
N) {
843 KnownBits LKnown = CurDAG->computeKnownBits(Op0);
844 KnownBits RKnown = CurDAG->computeKnownBits(Op1);
849 if ((TargetMask | InsertMask) == 0xFFFFFFFF) {
852 unsigned Value, SH = 0;
853 TargetMask = ~TargetMask;
854 InsertMask = ~InsertMask;
888 KnownBits MKnown = CurDAG->computeKnownBits(Op1.
getOperand(1));
902 SDValue Ops[] = { Op0, Op1, getI32Imm(SH, dl), getI32Imm(MB, dl),
904 ReplaceNode(
N, CurDAG->getMachineNode(PPC::RLWIMI, dl, MVT::i32,
Ops));
912 unsigned MaxTruncation = 0;
919 User->isMachineOpcode() ?
User->getMachineOpcode() :
User->getOpcode();
923 if (
User->isMachineOpcode())
925 MaxTruncation = std::max(MaxTruncation,
926 (
unsigned)
User->getValueType(0).getSizeInBits());
929 if (
User->isMachineOpcode())
935 MaxTruncation = std::max(MaxTruncation, MemVTSize);
944 MaxTruncation = std::max(MaxTruncation, 32u);
952 MaxTruncation = std::max(MaxTruncation, 16u);
960 MaxTruncation = std::max(MaxTruncation, 8u);
964 return MaxTruncation;
972 if ((HiTZ + LoLZ) >= Num)
989 auto getI32Imm = [CurDAG, dl](
unsigned Imm) {
1003 if (TZ > 15 && (LZ > 32 || LO > 32))
1005 getI32Imm((
Imm >> 16) & 0xffff));
1009 assert(LZ < 64 &&
"Unexpected leading zeros here.");
1016 unsigned Opcode = ImmHi16 ? PPC::LIS8 : PPC::LI8;
1017 Result = CurDAG->
getMachineNode(Opcode, dl, MVT::i64, getI32Imm(ImmHi16));
1019 getI32Imm(
Imm & 0xffff));
1027 if ((LZ + FO + TZ) > 48) {
1029 getI32Imm((
Imm >> TZ) & 0xffff));
1031 getI32Imm(TZ), getI32Imm(LZ));
1048 if ((LZ + TO) > 48) {
1052 assert(LZ <= 32 &&
"Unexpected shift value.");
1054 getI32Imm((
Imm >> (48 - LZ) & 0xffff)));
1056 getI32Imm(48 - LZ), getI32Imm(LZ));
1074 if ((LZ + FO + TO) > 48) {
1076 getI32Imm((
Imm >> TO) & 0xffff));
1078 getI32Imm(TO), getI32Imm(LZ));
1084 if (LZ == 32 && ((Lo32 & 0x8000) == 0)) {
1086 getI32Imm(Lo32 & 0xffff));
1088 getI32Imm(Lo32 >> 16));
1112 getI32Imm(RotImm & 0xffff));
1114 getI32Imm(Shift), getI32Imm(0));
1121 uint64_t ImmHi16 = (Lo32 >> 16) & 0xffff;
1125 CurDAG->
getMachineNode(PPC::LI8, dl, MVT::i64, getI32Imm(ImmLo16));
1128 CurDAG->
getMachineNode(PPC::LIS8, dl, MVT::i64, getI32Imm(ImmHi16));
1132 CurDAG->
getMachineNode(PPC::LIS8, dl, MVT::i64, getI32Imm(ImmHi16));
1134 SDValue(Result, 0), getI32Imm(ImmLo16));
1151 if ((LZ + FO + TZ) > 32) {
1153 unsigned Opcode = ImmHi16 ? PPC::LIS8 : PPC::LI8;
1154 Result = CurDAG->
getMachineNode(Opcode, dl, MVT::i64, getI32Imm(ImmHi16));
1156 getI32Imm((
Imm >> TZ) & 0xffff));
1158 getI32Imm(TZ), getI32Imm(LZ));
1165 if ((LZ + TO) > 32) {
1169 assert(LZ <= 32 &&
"Unexpected shift value.");
1171 getI32Imm((
Imm >> (48 - LZ)) & 0xffff));
1173 getI32Imm((
Imm >> (32 - LZ)) & 0xffff));
1175 getI32Imm(32 - LZ), getI32Imm(LZ));
1183 if ((LZ + FO + TO) > 32) {
1185 getI32Imm((
Imm >> (TO + 16)) & 0xffff));
1187 getI32Imm((
Imm >> TO) & 0xffff));
1189 getI32Imm(TO), getI32Imm(LZ));
1201 uint64_t ImmHi16 = (RotImm >> 16) & 0xffff;
1202 unsigned Opcode = ImmHi16 ? PPC::LIS8 : PPC::LI8;
1203 Result = CurDAG->
getMachineNode(Opcode, dl, MVT::i64, getI32Imm(ImmHi16));
1205 getI32Imm(RotImm & 0xffff));
1207 getI32Imm(Shift), getI32Imm(0));
1228 auto getI32Imm = [CurDAG, dl](
unsigned Imm) {
1247 SDNode *Result =
nullptr;
1254 if ((LZ + FO + TZ) > 30) {
1258 getI64Imm(Extended.getZExtValue()));
1260 getI32Imm(TZ), getI32Imm(LZ));
1276 if ((LZ + TO) > 30) {
1277 APInt SignedInt34 =
APInt(34, (
Imm >> (30 - LZ)) & 0x3ffffffff);
1280 getI64Imm(Extended.getZExtValue()));
1282 getI32Imm(30 - LZ), getI32Imm(LZ));
1289 if ((LZ + FO + TO) > 30) {
1293 getI64Imm(Extended.getZExtValue()));
1295 getI32Imm(TO), getI32Imm(LZ));
1307 for (
unsigned Shift = 0; Shift < 63; ++Shift) {
1311 CurDAG->
getMachineNode(PPC::PLI8, dl, MVT::i64, getI64Imm(RotImm));
1313 SDValue(Result, 0), getI32Imm(Shift),
1321 Result = CurDAG->
getMachineNode(PPC::PLI8, dl, MVT::i64, getI64Imm(Hi32));
1331 CurDAG->
getMachineNode(PPC::PLI8, dl, MVT::i64, getI64Imm(Hi32));
1333 CurDAG->
getMachineNode(PPC::PLI8, dl, MVT::i64, getI64Imm(Lo32));
1340 unsigned *InstCnt =
nullptr) {
1341 unsigned InstCntDirect = 0;
1352 if (
Subtarget.hasPrefixInstrs() && InstCntDirect != 1) {
1353 unsigned InstCntDirectP = 0;
1360 if (ResultP && (!Result || InstCntDirectP < InstCntDirect)) {
1362 *InstCnt = InstCntDirectP;
1369 *InstCnt = InstCntDirect;
1372 auto getI32Imm = [CurDAG, dl](
unsigned Imm) {
1381 if (Hi16OfLo32 && Lo16OfLo32) {
1384 bool IsSelected =
false;
1388 CurDAG->
getMachineNode(PPC::LIS8, dl, MVT::i64, getI32Imm(Hi16));
1390 SDValue(Result, 0), getI32Imm(Lo16));
1396 if (Hi16OfHi32 == Lo16OfHi32 && Lo16OfHi32 == Lo16OfLo32) {
1398 Result = getSplat(Hi16OfLo32, Lo16OfLo32);
1403 }
else if (Hi16OfHi32 == Hi16OfLo32 && Hi16OfLo32 == Lo16OfLo32) {
1405 Result = getSplat(Hi16OfHi32, Lo16OfHi32);
1408 getI32Imm(16), getI32Imm(31)};
1410 }
else if (Lo16OfHi32 == Lo16OfLo32 && Hi16OfLo32 == Lo16OfLo32) {
1412 Result = getSplat(Hi16OfHi32, Lo16OfHi32);
1415 getI32Imm(0), getI32Imm(15)};
1418 if (IsSelected ==
true) {
1431 SDValue(Result, 0), getI32Imm(Hi16OfLo32));
1436 getI32Imm(Lo16OfLo32));
1440 *InstCnt = InstCntDirect;
1449 int64_t
Imm =
N->getAsZExtVal();
1461class BitPermutationSelector {
1476 VariableKnownToBeZero
1479 ValueBit(
SDValue V,
unsigned I, Kind K = Variable)
1481 ValueBit(Kind K = Variable) :
Idx(UINT32_MAX), K(K) {}
1484 return K == ConstZero || K == VariableKnownToBeZero;
1487 bool hasValue()
const {
1488 return K == Variable || K == VariableKnownToBeZero;
1492 assert(hasValue() &&
"Cannot get the value of a constant bit");
1496 unsigned getValueBitIndex()
const {
1497 assert(hasValue() &&
"Cannot get the value bit index of a constant bit");
1506 unsigned StartIdx, EndIdx;
1516 bool Repl32Coalesced;
1518 BitGroup(
SDValue V,
unsigned R,
unsigned S,
unsigned E)
1519 :
V(
V), RLAmt(
R), StartIdx(S), EndIdx(
E), Repl32(
false), Repl32CR(
false),
1520 Repl32Coalesced(
false) {
1521 LLVM_DEBUG(
dbgs() <<
"\tbit group for " <<
V.getNode() <<
" RLAmt = " << R
1522 <<
" [" << S <<
", " <<
E <<
"]\n");
1528 struct ValueRotInfo {
1530 unsigned RLAmt = std::numeric_limits<unsigned>::max();
1531 unsigned NumGroups = 0;
1532 unsigned FirstGroupStartIdx = std::numeric_limits<unsigned>::max();
1533 bool Repl32 =
false;
1535 ValueRotInfo() =
default;
1543 if (Repl32 <
Other.Repl32)
1545 else if (Repl32 >
Other.Repl32)
1547 else if (NumGroups >
Other.NumGroups)
1549 else if (NumGroups <
Other.NumGroups)
1551 else if (RLAmt == 0 &&
Other.RLAmt != 0)
1553 else if (RLAmt != 0 &&
Other.RLAmt == 0)
1555 else if (FirstGroupStartIdx <
Other.FirstGroupStartIdx)
1561 using ValueBitsMemoizedValue = std::pair<bool, SmallVector<ValueBit, 64>>;
1562 using ValueBitsMemoizer =
1563 DenseMap<SDValue, std::unique_ptr<ValueBitsMemoizedValue>>;
1564 ValueBitsMemoizer Memoizer;
1570 std::pair<bool, SmallVector<ValueBit, 64> *> getValueBits(
SDValue V,
1572 auto &ValueEntry = Memoizer[
V];
1574 return std::make_pair(ValueEntry->first, &ValueEntry->second);
1575 ValueEntry.reset(
new ValueBitsMemoizedValue());
1576 bool &Interesting = ValueEntry->first;
1578 Bits.resize(NumBits);
1580 switch (
V.getOpcode()) {
1585 unsigned RotAmt =
V.getConstantOperandVal(1) & (NumBits - 1);
1587 const auto &LHSBits = *getValueBits(
V.getOperand(0), NumBits).second;
1589 for (
unsigned i = 0; i < NumBits; ++i)
1590 Bits[i] = LHSBits[i < RotAmt ? i + (NumBits - RotAmt) : i - RotAmt];
1592 return std::make_pair(Interesting =
true, &Bits);
1599 unsigned ShiftAmt =
V.getConstantOperandVal(1) & ((NumBits << 1) - 1);
1601 const auto &LHSBits = *getValueBits(
V.getOperand(0), NumBits).second;
1603 if (ShiftAmt >= NumBits) {
1604 for (
unsigned i = 0; i < NumBits; ++i)
1605 Bits[i] = ValueBit(ValueBit::ConstZero);
1607 for (
unsigned i = ShiftAmt; i < NumBits; ++i)
1608 Bits[i] = LHSBits[i - ShiftAmt];
1609 for (
unsigned i = 0; i < ShiftAmt; ++i)
1610 Bits[i] = ValueBit(ValueBit::ConstZero);
1613 return std::make_pair(Interesting =
true, &Bits);
1620 unsigned ShiftAmt =
V.getConstantOperandVal(1) & ((NumBits << 1) - 1);
1622 const auto &LHSBits = *getValueBits(
V.getOperand(0), NumBits).second;
1624 if (ShiftAmt >= NumBits) {
1625 for (
unsigned i = 0; i < NumBits; ++i)
1626 Bits[i] = ValueBit(ValueBit::ConstZero);
1628 for (
unsigned i = 0; i < NumBits - ShiftAmt; ++i)
1629 Bits[i] = LHSBits[i + ShiftAmt];
1630 for (
unsigned i = NumBits - ShiftAmt; i < NumBits; ++i)
1631 Bits[i] = ValueBit(ValueBit::ConstZero);
1634 return std::make_pair(Interesting =
true, &Bits);
1646 std::tie(Interesting, LHSBits) = getValueBits(
V.getOperand(0), NumBits);
1648 for (
unsigned i = 0; i < NumBits; ++i)
1649 if (((Mask >> i) & 1) == 1)
1650 Bits[i] = (*LHSBits)[i];
1654 if ((*LHSBits)[i].
isZero())
1655 Bits[i] = (*LHSBits)[i];
1657 Bits[i] = ValueBit(ValueBit::ConstZero);
1660 return std::make_pair(Interesting, &Bits);
1664 const auto &LHSBits = *getValueBits(
V.getOperand(0), NumBits).second;
1665 const auto &RHSBits = *getValueBits(
V.getOperand(1), NumBits).second;
1667 bool AllDisjoint =
true;
1669 unsigned LastIdx = 0;
1670 for (
unsigned i = 0; i < NumBits; ++i) {
1678 if (LHSBits[i].hasValue() && LHSBits[i].
getValue() == LastVal &&
1679 LHSBits[i].getValueBitIndex() == LastIdx + 1)
1680 Bits[i] = LHSBits[i];
1681 else if (RHSBits[i].hasValue() && RHSBits[i].
getValue() == LastVal &&
1682 RHSBits[i].getValueBitIndex() == LastIdx + 1)
1683 Bits[i] = RHSBits[i];
1685 Bits[i] = ValueBit(ValueBit::ConstZero);
1687 else if (LHSBits[i].
isZero())
1688 Bits[i] = RHSBits[i];
1689 else if (RHSBits[i].
isZero())
1690 Bits[i] = LHSBits[i];
1692 AllDisjoint =
false;
1696 if (Bits[i].hasValue()) {
1697 LastVal =
Bits[i].getValue();
1698 LastIdx =
Bits[i].getValueBitIndex();
1701 if (LastVal) LastVal =
SDValue();
1709 return std::make_pair(Interesting =
true, &Bits);
1713 if (
V.getValueType() != MVT::i64 ||
1714 V.getOperand(0).getValueType() != MVT::i32)
1718 const unsigned NumOperandBits = 32;
1719 std::tie(Interesting, LHSBits) = getValueBits(
V.getOperand(0),
1722 for (
unsigned i = 0; i < NumOperandBits; ++i)
1723 Bits[i] = (*LHSBits)[i];
1725 for (
unsigned i = NumOperandBits; i < NumBits; ++i)
1726 Bits[i] = ValueBit(ValueBit::ConstZero);
1728 return std::make_pair(Interesting, &Bits);
1731 EVT
FromType =
V.getOperand(0).getValueType();
1732 EVT ToType =
V.getValueType();
1734 if (FromType != MVT::i64 || ToType != MVT::i32)
1736 const unsigned NumAllBits =
FromType.getSizeInBits();
1738 std::tie(Interesting, InBits) = getValueBits(
V.getOperand(0),
1744 bool UseUpper32bit =
false;
1745 for (
unsigned i = 0; i < NumValidBits; ++i)
1746 if ((*InBits)[i].hasValue() && (*InBits)[i].getValueBitIndex() >= 32) {
1747 UseUpper32bit =
true;
1753 for (
unsigned i = 0; i < NumValidBits; ++i)
1754 Bits[i] = (*InBits)[i];
1756 return std::make_pair(Interesting, &Bits);
1762 std::tie(Interesting, LHSBits) = getValueBits(
V.getOperand(0),
1766 const unsigned NumValidBits =
FromType.getSizeInBits();
1767 for (
unsigned i = 0; i < NumValidBits; ++i)
1768 Bits[i] = (*LHSBits)[i];
1772 for (
unsigned i = NumValidBits; i < NumBits; ++i)
1773 Bits[i] = (*LHSBits)[i].hasValue()
1774 ? ValueBit((*LHSBits)[i].
getValue(),
1775 (*LHSBits)[i].getValueBitIndex(),
1776 ValueBit::VariableKnownToBeZero)
1777 : ValueBit(ValueBit::ConstZero);
1779 return std::make_pair(Interesting, &Bits);
1784 EVT VT =
LD->getMemoryVT();
1787 for (
unsigned i = 0; i < NumValidBits; ++i)
1788 Bits[i] = ValueBit(
V, i);
1791 for (
unsigned i = NumValidBits; i < NumBits; ++i)
1792 Bits[i] = ValueBit(
V, i, ValueBit::VariableKnownToBeZero);
1796 return std::make_pair(Interesting =
false, &Bits);
1801 for (
unsigned i = 0; i < NumBits; ++i)
1802 Bits[i] = ValueBit(
V, i);
1804 return std::make_pair(Interesting =
false, &Bits);
1809 void computeRotationAmounts() {
1811 RLAmt.resize(
Bits.size());
1812 for (
unsigned i = 0; i <
Bits.size(); ++i)
1813 if (Bits[i].hasValue()) {
1814 unsigned VBI =
Bits[i].getValueBitIndex();
1818 RLAmt[i] =
Bits.size() - (VBI - i);
1819 }
else if (Bits[i].
isZero()) {
1821 RLAmt[i] = UINT32_MAX;
1830 void collectBitGroups(
bool LateMask) {
1833 unsigned LastRLAmt = RLAmt[0];
1835 unsigned LastGroupStartIdx = 0;
1836 bool IsGroupOfZeros = !
Bits[LastGroupStartIdx].hasValue();
1837 for (
unsigned i = 1; i <
Bits.size(); ++i) {
1838 unsigned ThisRLAmt = RLAmt[i];
1840 if (LateMask && !ThisValue) {
1841 ThisValue = LastValue;
1842 ThisRLAmt = LastRLAmt;
1845 if (BitGroups.empty())
1846 LastGroupStartIdx = 0;
1853 if (IsGroupOfZeros && Bits[i].
isZero())
1858 if (ThisRLAmt == LastRLAmt && ThisValue == LastValue)
1861 if (!(IsGroupOfZeros && ThisValue && !Bits[i].
isZero()))
1865 BitGroups.push_back(BitGroup(LastValue, LastRLAmt, LastGroupStartIdx,
1867 LastRLAmt = ThisRLAmt;
1868 LastValue = ThisValue;
1869 LastGroupStartIdx = i;
1870 IsGroupOfZeros = !
Bits[LastGroupStartIdx].hasValue();
1873 BitGroups.push_back(BitGroup(LastValue, LastRLAmt, LastGroupStartIdx,
1876 if (BitGroups.empty())
1880 if (BitGroups.size() > 1) {
1884 if (BitGroups[0].StartIdx == 0 &&
1885 BitGroups[BitGroups.size()-1].EndIdx ==
Bits.size()-1 &&
1886 BitGroups[0].V == BitGroups[BitGroups.size()-1].V &&
1887 BitGroups[0].RLAmt == BitGroups[BitGroups.size()-1].RLAmt) {
1888 LLVM_DEBUG(
dbgs() <<
"\tcombining final bit group with initial one\n");
1889 BitGroups[BitGroups.size()-1].EndIdx = BitGroups[0].EndIdx;
1890 BitGroups.erase(BitGroups.begin());
1900 void collectValueRotInfo() {
1903 for (
auto &BG : BitGroups) {
1904 unsigned RLAmtKey = BG.RLAmt + (BG.Repl32 ? 64 : 0);
1905 ValueRotInfo &VRI = ValueRots[std::make_pair(BG.V, RLAmtKey)];
1907 VRI.RLAmt = BG.RLAmt;
1908 VRI.Repl32 = BG.Repl32;
1910 VRI.FirstGroupStartIdx = std::min(VRI.FirstGroupStartIdx, BG.StartIdx);
1915 ValueRotsVec.clear();
1916 for (
auto &
I : ValueRots) {
1917 ValueRotsVec.push_back(
I.second);
1930 void assignRepl32BitGroups() {
1941 auto IsAllLow32 = [
this](BitGroup & BG) {
1942 if (BG.StartIdx <= BG.EndIdx) {
1943 for (
unsigned i = BG.StartIdx; i <= BG.EndIdx; ++i) {
1944 if (!Bits[i].hasValue())
1946 if (Bits[i].getValueBitIndex() >= 32)
1950 for (
unsigned i = BG.StartIdx; i <
Bits.size(); ++i) {
1951 if (!Bits[i].hasValue())
1953 if (Bits[i].getValueBitIndex() >= 32)
1956 for (
unsigned i = 0; i <= BG.EndIdx; ++i) {
1957 if (!Bits[i].hasValue())
1959 if (Bits[i].getValueBitIndex() >= 32)
1967 for (
auto &BG : BitGroups) {
1971 if (BG.RLAmt == 0) {
1972 auto PotentiallyMerged = [
this](BitGroup & BG) {
1973 for (
auto &BG2 : BitGroups)
1974 if (&BG != &BG2 && BG.V == BG2.V &&
1975 (BG2.RLAmt == 0 || BG2.RLAmt == 32))
1979 if (!PotentiallyMerged(BG))
1982 if (BG.StartIdx < 32 && BG.EndIdx < 32) {
1983 if (IsAllLow32(BG)) {
1984 if (BG.RLAmt >= 32) {
1992 << BG.V.getNode() <<
" RLAmt = " << BG.RLAmt <<
" ["
1993 << BG.StartIdx <<
", " << BG.EndIdx <<
"]\n");
1999 for (
auto I = BitGroups.begin();
I != BitGroups.end();) {
2002 auto IP = (
I == BitGroups.begin()) ?
2003 std::prev(BitGroups.end()) : std::prev(
I);
2004 if (
I->Repl32 && IP->Repl32 &&
I->V == IP->V &&
I->RLAmt == IP->RLAmt &&
2005 I->StartIdx == (IP->EndIdx + 1) % 64 &&
I != IP) {
2007 LLVM_DEBUG(dbgs() <<
"\tcombining 32-bit replicated bit group for "
2008 << I->V.getNode() <<
" RLAmt = " << I->RLAmt <<
" ["
2009 << I->StartIdx <<
", " << I->EndIdx
2010 <<
"] with group with range [" << IP->StartIdx <<
", "
2011 << IP->EndIdx <<
"]\n");
2013 IP->EndIdx = I->EndIdx;
2014 IP->Repl32CR = IP->Repl32CR || I->Repl32CR;
2015 IP->Repl32Coalesced = true;
2016 I = BitGroups.erase(I);
2025 if (I->StartIdx == 32 && I->EndIdx == 63) {
2026 assert(std::next(I) == BitGroups.end() &&
2027 "bit group ends at index 63 but there is another?");
2028 auto IN = BitGroups.begin();
2030 if (IP->Repl32 && IN->Repl32 && I->V == IP->V && I->V == IN->V &&
2031 (I->RLAmt % 32) == IP->RLAmt && (I->RLAmt % 32) == IN->RLAmt &&
2032 IP->EndIdx == 31 && IN->StartIdx == 0 && I != IP &&
2035 LLVM_DEBUG(dbgs() <<
"\tcombining bit group for " << I->V.getNode()
2036 <<
" RLAmt = " << I->RLAmt <<
" [" << I->StartIdx
2037 <<
", " << I->EndIdx
2038 <<
"] with 32-bit replicated groups with ranges ["
2039 << IP->StartIdx <<
", " << IP->EndIdx <<
"] and ["
2040 << IN->StartIdx <<
", " << IN->EndIdx <<
"]\n");
2048 IP->Repl32CR = IP->Repl32CR || I->RLAmt >= 32;
2049 IP->Repl32Coalesced = true;
2050 I = BitGroups.erase(I);
2055 IP->EndIdx = IN->EndIdx;
2056 IP->Repl32CR = IP->Repl32CR || IN->Repl32CR || I->RLAmt >= 32;
2057 IP->Repl32Coalesced = true;
2058 I = BitGroups.erase(I);
2059 BitGroups.erase(BitGroups.begin());
2073 SDValue getI32Imm(
unsigned Imm,
const SDLoc &dl) {
2074 return CurDAG->getTargetConstant(
Imm, dl, MVT::i32);
2079 for (
unsigned i = 0; i <
Bits.size(); ++i) {
2080 if (Bits[i].hasValue())
2082 Mask |= (UINT64_C(1) << i);
2093 if (
V.getValueSizeInBits() == 64)
2096 assert(
V.getValueSizeInBits() == 32);
2097 SDValue SubRegIdx = CurDAG->getTargetConstant(PPC::sub_32, dl, MVT::i32);
2098 SDValue ImDef =
SDValue(CurDAG->getMachineNode(PPC::IMPLICIT_DEF, dl,
2100 SDValue ExtVal =
SDValue(CurDAG->getMachineNode(PPC::INSERT_SUBREG, dl,
2107 if (
V.getValueSizeInBits() == 32)
2110 assert(
V.getValueSizeInBits() == 64);
2111 SDValue SubRegIdx = CurDAG->getTargetConstant(PPC::sub_32, dl, MVT::i32);
2112 SDValue SubVal =
SDValue(CurDAG->getMachineNode(PPC::EXTRACT_SUBREG, dl,
2113 MVT::i32,
V, SubRegIdx), 0);
2120 void SelectAndParts32(
const SDLoc &dl,
SDValue &Res,
unsigned *InstCnt) {
2124 for (ValueRotInfo &VRI : ValueRotsVec) {
2126 for (
unsigned i = 0; i <
Bits.size(); ++i) {
2127 if (!Bits[i].hasValue() || Bits[i].
getValue() != VRI.V)
2129 if (RLAmt[i] != VRI.RLAmt)
2135 unsigned ANDIMask = (
Mask & UINT16_MAX), ANDISMask = Mask >> 16;
2136 assert((ANDIMask != 0 || ANDISMask != 0) &&
2137 "No set bits in mask for value bit groups");
2138 bool NeedsRotate = VRI.RLAmt != 0;
2154 unsigned NumAndInsts = (unsigned) NeedsRotate +
2155 (
unsigned) (ANDIMask != 0) +
2156 (
unsigned) (ANDISMask != 0) +
2157 (
unsigned) (ANDIMask != 0 && ANDISMask != 0) +
2158 (
unsigned) (bool) Res;
2160 LLVM_DEBUG(
dbgs() <<
"\t\trotation groups for " << VRI.V.getNode()
2161 <<
" RL: " << VRI.RLAmt <<
":"
2162 <<
"\n\t\t\tisel using masking: " << NumAndInsts
2163 <<
" using rotates: " << VRI.NumGroups <<
"\n");
2165 if (NumAndInsts >= VRI.NumGroups)
2170 if (InstCnt) *InstCnt += NumAndInsts;
2175 { TruncateToInt32(VRI.V, dl), getI32Imm(VRI.RLAmt, dl),
2176 getI32Imm(0, dl), getI32Imm(31, dl) };
2177 VRot =
SDValue(CurDAG->getMachineNode(PPC::RLWINM, dl, MVT::i32,
2180 VRot = TruncateToInt32(VRI.V, dl);
2185 ANDIVal =
SDValue(CurDAG->getMachineNode(PPC::ANDI_rec, dl, MVT::i32,
2186 VRot, getI32Imm(ANDIMask, dl)),
2190 SDValue(CurDAG->getMachineNode(PPC::ANDIS_rec, dl, MVT::i32, VRot,
2191 getI32Imm(ANDISMask, dl)),
2196 TotalVal = ANDISVal;
2200 TotalVal =
SDValue(CurDAG->getMachineNode(PPC::OR, dl, MVT::i32,
2201 ANDIVal, ANDISVal), 0);
2206 Res =
SDValue(CurDAG->getMachineNode(PPC::OR, dl, MVT::i32,
2211 eraseMatchingBitGroups([VRI](
const BitGroup &BG) {
2212 return BG.V == VRI.V && BG.RLAmt == VRI.RLAmt;
2218 SDNode *Select32(SDNode *
N,
bool LateMask,
unsigned *InstCnt) {
2222 if (InstCnt) *InstCnt = 0;
2225 SelectAndParts32(dl, Res, InstCnt);
2230 if ((!NeedMask || LateMask) && !Res) {
2231 ValueRotInfo &VRI = ValueRotsVec[0];
2233 if (InstCnt) *InstCnt += 1;
2235 { TruncateToInt32(VRI.V, dl), getI32Imm(VRI.RLAmt, dl),
2236 getI32Imm(0, dl), getI32Imm(31, dl) };
2237 Res =
SDValue(CurDAG->getMachineNode(PPC::RLWINM, dl, MVT::i32,
Ops),
2240 Res = TruncateToInt32(VRI.V, dl);
2244 eraseMatchingBitGroups([VRI](
const BitGroup &BG) {
2245 return BG.V == VRI.V && BG.RLAmt == VRI.RLAmt;
2249 if (InstCnt) *InstCnt += BitGroups.size();
2252 for (
auto &BG : BitGroups) {
2255 { TruncateToInt32(BG.V, dl), getI32Imm(BG.RLAmt, dl),
2256 getI32Imm(
Bits.size() - BG.EndIdx - 1, dl),
2257 getI32Imm(
Bits.size() - BG.StartIdx - 1, dl) };
2258 Res =
SDValue(CurDAG->getMachineNode(PPC::RLWINM, dl, MVT::i32,
Ops), 0);
2261 { Res, TruncateToInt32(BG.V, dl), getI32Imm(BG.RLAmt, dl),
2262 getI32Imm(
Bits.size() - BG.EndIdx - 1, dl),
2263 getI32Imm(
Bits.size() - BG.StartIdx - 1, dl) };
2264 Res =
SDValue(CurDAG->getMachineNode(PPC::RLWIMI, dl, MVT::i32,
Ops), 0);
2269 unsigned Mask = (unsigned) getZerosMask();
2271 unsigned ANDIMask = (
Mask & UINT16_MAX), ANDISMask = Mask >> 16;
2272 assert((ANDIMask != 0 || ANDISMask != 0) &&
2273 "No set bits in zeros mask?");
2275 if (InstCnt) *InstCnt += (unsigned) (ANDIMask != 0) +
2276 (unsigned) (ANDISMask != 0) +
2277 (unsigned) (ANDIMask != 0 && ANDISMask != 0);
2281 ANDIVal =
SDValue(CurDAG->getMachineNode(PPC::ANDI_rec, dl, MVT::i32,
2282 Res, getI32Imm(ANDIMask, dl)),
2286 SDValue(CurDAG->getMachineNode(PPC::ANDIS_rec, dl, MVT::i32, Res,
2287 getI32Imm(ANDISMask, dl)),
2295 Res =
SDValue(CurDAG->getMachineNode(PPC::OR, dl, MVT::i32,
2296 ANDIVal, ANDISVal), 0);
2302 unsigned SelectRotMask64Count(
unsigned RLAmt,
bool Repl32,
2303 unsigned MaskStart,
unsigned MaskEnd,
2307 unsigned InstMaskStart = 64 - MaskEnd - 1,
2308 InstMaskEnd = 64 - MaskStart - 1;
2313 if ((!IsIns && (InstMaskEnd == 63 || InstMaskStart == 0)) ||
2314 InstMaskEnd == 63 - RLAmt)
2323 bool Repl32,
unsigned MaskStart,
unsigned MaskEnd,
2324 unsigned *InstCnt =
nullptr) {
2327 unsigned InstMaskStart = 64 - MaskEnd - 1,
2328 InstMaskEnd = 64 - MaskStart - 1;
2330 if (InstCnt) *InstCnt += 1;
2336 assert(InstMaskStart >= 32 &&
"Mask cannot start out of range");
2337 assert(InstMaskEnd >= 32 &&
"Mask cannot end out of range");
2339 { ExtendToInt64(
V, dl), getI32Imm(RLAmt, dl),
2340 getI32Imm(InstMaskStart - 32, dl), getI32Imm(InstMaskEnd - 32, dl) };
2341 return SDValue(CurDAG->getMachineNode(PPC::RLWINM8, dl, MVT::i64,
2345 if (InstMaskEnd == 63) {
2347 { ExtendToInt64(
V, dl), getI32Imm(RLAmt, dl),
2348 getI32Imm(InstMaskStart, dl) };
2349 return SDValue(CurDAG->getMachineNode(PPC::RLDICL, dl, MVT::i64,
Ops), 0);
2352 if (InstMaskStart == 0) {
2354 { ExtendToInt64(
V, dl), getI32Imm(RLAmt, dl),
2355 getI32Imm(InstMaskEnd, dl) };
2356 return SDValue(CurDAG->getMachineNode(PPC::RLDICR, dl, MVT::i64,
Ops), 0);
2359 if (InstMaskEnd == 63 - RLAmt) {
2361 { ExtendToInt64(
V, dl), getI32Imm(RLAmt, dl),
2362 getI32Imm(InstMaskStart, dl) };
2363 return SDValue(CurDAG->getMachineNode(PPC::RLDIC, dl, MVT::i64,
Ops), 0);
2372 if (InstCnt) *InstCnt += 1;
2375 unsigned RLAmt2 = MaskStart;
2378 unsigned RLAmt1 = (64 + RLAmt - RLAmt2) % 64;
2380 V = SelectRotMask64(
V, dl, RLAmt1,
false, 0, 63);
2381 return SelectRotMask64(
V, dl, RLAmt2,
false, MaskStart, MaskEnd);
2387 unsigned RLAmt,
bool Repl32,
unsigned MaskStart,
2388 unsigned MaskEnd,
unsigned *InstCnt =
nullptr) {
2391 unsigned InstMaskStart = 64 - MaskEnd - 1,
2392 InstMaskEnd = 64 - MaskStart - 1;
2394 if (InstCnt) *InstCnt += 1;
2400 assert(InstMaskStart >= 32 &&
"Mask cannot start out of range");
2401 assert(InstMaskEnd >= 32 &&
"Mask cannot end out of range");
2403 { ExtendToInt64(
Base, dl), ExtendToInt64(
V, dl), getI32Imm(RLAmt, dl),
2404 getI32Imm(InstMaskStart - 32, dl), getI32Imm(InstMaskEnd - 32, dl) };
2405 return SDValue(CurDAG->getMachineNode(PPC::RLWIMI8, dl, MVT::i64,
2409 if (InstMaskEnd == 63 - RLAmt) {
2411 { ExtendToInt64(
Base, dl), ExtendToInt64(
V, dl), getI32Imm(RLAmt, dl),
2412 getI32Imm(InstMaskStart, dl) };
2413 return SDValue(CurDAG->getMachineNode(PPC::RLDIMI, dl, MVT::i64,
Ops), 0);
2422 if (InstCnt) *InstCnt += 1;
2425 unsigned RLAmt2 = MaskStart;
2428 unsigned RLAmt1 = (64 + RLAmt - RLAmt2) % 64;
2430 V = SelectRotMask64(
V, dl, RLAmt1,
false, 0, 63);
2431 return SelectRotMaskIns64(
Base,
V, dl, RLAmt2,
false, MaskStart, MaskEnd);
2434 void SelectAndParts64(
const SDLoc &dl,
SDValue &Res,
unsigned *InstCnt) {
2447 for (ValueRotInfo &VRI : ValueRotsVec) {
2455 auto MatchingBG = [VRI](
const BitGroup &BG) {
2459 unsigned EffRLAmt = BG.RLAmt;
2460 if (!VRI.Repl32 && BG.Repl32) {
2461 if (BG.StartIdx < 32 && BG.EndIdx < 32 && BG.StartIdx <= BG.EndIdx &&
2462 !BG.Repl32Coalesced) {
2468 }
else if (VRI.Repl32 != BG.Repl32) {
2472 return VRI.RLAmt == EffRLAmt;
2475 for (
auto &BG : BitGroups) {
2476 if (!MatchingBG(BG))
2479 if (BG.StartIdx <= BG.EndIdx) {
2480 for (
unsigned i = BG.StartIdx; i <= BG.EndIdx; ++i)
2481 Mask |= (UINT64_C(1) << i);
2483 for (
unsigned i = BG.StartIdx; i <
Bits.size(); ++i)
2484 Mask |= (UINT64_C(1) << i);
2485 for (
unsigned i = 0; i <= BG.EndIdx; ++i)
2486 Mask |= (UINT64_C(1) << i);
2495 unsigned ANDIMask = (
Mask & UINT16_MAX),
2496 ANDISMask = (Mask >> 16) & UINT16_MAX;
2498 bool NeedsRotate = VRI.RLAmt || (VRI.Repl32 && !
isUInt<32>(Mask));
2500 unsigned NumAndInsts = (unsigned) NeedsRotate +
2501 (
unsigned) (bool) Res;
2502 unsigned NumOfSelectInsts = 0;
2504 assert(NumOfSelectInsts > 0 &&
"Failed to select an i64 constant.");
2506 NumAndInsts += (unsigned) (ANDIMask != 0) + (unsigned) (ANDISMask != 0) +
2507 (unsigned) (ANDIMask != 0 && ANDISMask != 0);
2509 NumAndInsts += NumOfSelectInsts + 1;
2511 unsigned NumRLInsts = 0;
2512 bool FirstBG =
true;
2513 bool MoreBG =
false;
2514 for (
auto &BG : BitGroups) {
2515 if (!MatchingBG(BG)) {
2520 SelectRotMask64Count(BG.RLAmt, BG.Repl32, BG.StartIdx, BG.EndIdx,
2525 LLVM_DEBUG(
dbgs() <<
"\t\trotation groups for " << VRI.V.getNode()
2526 <<
" RL: " << VRI.RLAmt << (VRI.Repl32 ?
" (32):" :
":")
2527 <<
"\n\t\t\tisel using masking: " << NumAndInsts
2528 <<
" using rotates: " << NumRLInsts <<
"\n");
2534 if (NumAndInsts > NumRLInsts)
2539 if ((Use32BitInsts || MoreBG) && NumAndInsts == NumRLInsts)
2544 if (InstCnt) *InstCnt += NumAndInsts;
2551 if (VRI.RLAmt || (VRI.Repl32 && !
isUInt<32>(Mask)))
2552 VRot = SelectRotMask64(VRI.V, dl, VRI.RLAmt, VRI.Repl32,
2553 VRI.Repl32 ? 31 : 0, VRI.Repl32 ? 30 : 63);
2558 if (Use32BitInsts) {
2559 assert((ANDIMask != 0 || ANDISMask != 0) &&
2560 "No set bits in mask when using 32-bit ands for 64-bit value");
2564 ANDIVal =
SDValue(CurDAG->getMachineNode(PPC::ANDI8_rec, dl, MVT::i64,
2565 ExtendToInt64(VRot, dl),
2566 getI32Imm(ANDIMask, dl)),
2570 SDValue(CurDAG->getMachineNode(PPC::ANDIS8_rec, dl, MVT::i64,
2571 ExtendToInt64(VRot, dl),
2572 getI32Imm(ANDISMask, dl)),
2576 TotalVal = ANDISVal;
2580 TotalVal =
SDValue(CurDAG->getMachineNode(PPC::OR8, dl, MVT::i64,
2581 ExtendToInt64(ANDIVal, dl), ANDISVal), 0);
2585 SDValue(CurDAG->getMachineNode(PPC::AND8, dl, MVT::i64,
2586 ExtendToInt64(VRot, dl), TotalVal),
2593 Res =
SDValue(CurDAG->getMachineNode(PPC::OR8, dl, MVT::i64,
2594 ExtendToInt64(Res, dl), TotalVal),
2599 eraseMatchingBitGroups(MatchingBG);
2604 SDNode *Select64(SDNode *
N,
bool LateMask,
unsigned *InstCnt) {
2608 if (InstCnt) *InstCnt = 0;
2611 SelectAndParts64(dl, Res, InstCnt);
2616 if ((!NeedMask || LateMask) && !Res) {
2620 unsigned MaxGroupsIdx = 0;
2621 if (!ValueRotsVec[0].Repl32) {
2622 for (
unsigned i = 0, ie = ValueRotsVec.size(); i < ie; ++i)
2623 if (ValueRotsVec[i].Repl32) {
2624 if (ValueRotsVec[i].NumGroups > ValueRotsVec[0].NumGroups)
2630 ValueRotInfo &VRI = ValueRotsVec[MaxGroupsIdx];
2631 bool NeedsRotate =
false;
2634 }
else if (VRI.Repl32) {
2635 for (
auto &BG : BitGroups) {
2636 if (BG.V != VRI.V || BG.RLAmt != VRI.RLAmt ||
2637 BG.Repl32 != VRI.Repl32)
2642 if (BG.StartIdx < 32 && BG.EndIdx < 32 && BG.StartIdx < BG.EndIdx)
2651 Res = SelectRotMask64(VRI.V, dl, VRI.RLAmt, VRI.Repl32,
2652 VRI.Repl32 ? 31 : 0, VRI.Repl32 ? 30 : 63,
2659 eraseMatchingBitGroups([VRI](
const BitGroup &BG) {
2660 return BG.V == VRI.V && BG.RLAmt == VRI.RLAmt &&
2661 BG.Repl32 == VRI.Repl32;
2668 for (
auto I = BitGroups.begin(), IE = BitGroups.end();
I != IE; ++
I) {
2669 if (SelectRotMask64Count(
I->RLAmt,
I->Repl32,
I->StartIdx,
I->EndIdx,
2671 SelectRotMask64Count(
I->RLAmt,
I->Repl32,
I->StartIdx,
I->EndIdx,
2673 if (
I != BitGroups.begin()) {
2676 BitGroups.insert(BitGroups.begin(), BG);
2684 for (
auto &BG : BitGroups) {
2686 Res = SelectRotMask64(BG.V, dl, BG.RLAmt, BG.Repl32, BG.StartIdx,
2687 BG.EndIdx, InstCnt);
2689 Res = SelectRotMaskIns64(Res, BG.V, dl, BG.RLAmt, BG.Repl32,
2690 BG.StartIdx, BG.EndIdx, InstCnt);
2701 unsigned ANDIMask = (
Mask & UINT16_MAX),
2702 ANDISMask = (Mask >> 16) & UINT16_MAX;
2704 if (Use32BitInsts) {
2705 assert((ANDIMask != 0 || ANDISMask != 0) &&
2706 "No set bits in mask when using 32-bit ands for 64-bit value");
2708 if (InstCnt) *InstCnt += (unsigned) (ANDIMask != 0) +
2709 (unsigned) (ANDISMask != 0) +
2710 (unsigned) (ANDIMask != 0 && ANDISMask != 0);
2714 ANDIVal =
SDValue(CurDAG->getMachineNode(PPC::ANDI8_rec, dl, MVT::i64,
2715 ExtendToInt64(Res, dl),
2716 getI32Imm(ANDIMask, dl)),
2720 SDValue(CurDAG->getMachineNode(PPC::ANDIS8_rec, dl, MVT::i64,
2721 ExtendToInt64(Res, dl),
2722 getI32Imm(ANDISMask, dl)),
2730 Res =
SDValue(CurDAG->getMachineNode(PPC::OR8, dl, MVT::i64,
2731 ExtendToInt64(ANDIVal, dl), ANDISVal), 0);
2733 unsigned NumOfSelectInsts = 0;
2736 Res =
SDValue(CurDAG->getMachineNode(PPC::AND8, dl, MVT::i64,
2737 ExtendToInt64(Res, dl), MaskVal),
2740 *InstCnt += NumOfSelectInsts + 1;
2747 SDNode *
Select(SDNode *
N,
bool LateMask,
unsigned *InstCnt =
nullptr) {
2749 collectBitGroups(LateMask);
2750 if (BitGroups.empty())
2754 if (
Bits.size() == 64)
2755 assignRepl32BitGroups();
2758 collectValueRotInfo();
2760 if (
Bits.size() == 32) {
2761 return Select32(
N, LateMask, InstCnt);
2763 assert(
Bits.size() == 64 &&
"Not 64 bits here?");
2764 return Select64(
N, LateMask, InstCnt);
2770 void eraseMatchingBitGroups(function_ref<
bool(
const BitGroup &)>
F) {
2781 DenseMap<std::pair<SDValue, unsigned>, ValueRotInfo> ValueRots;
2784 SelectionDAG *CurDAG =
nullptr;
2788 BitPermutationSelector(SelectionDAG *DAG,
bool StressRotates)
2789 : CurDAG(DAG), StressRotates(StressRotates) {}
2797 getValueBits(
SDValue(
N, 0),
N->getValueType(0).getSizeInBits());
2802 LLVM_DEBUG(
dbgs() <<
"Considering bit-permutation-based instruction"
2803 " selection for: ");
2807 computeRotationAmounts();
2820 unsigned InstCnt = 0, InstCntLateMask = 0;
2822 SDNode *
RN =
Select(
N,
false, &InstCnt);
2823 LLVM_DEBUG(
dbgs() <<
"\t\tisel would use " << InstCnt <<
" instructions\n");
2826 SDNode *RNLM =
Select(
N,
true, &InstCntLateMask);
2828 <<
" instructions\n");
2830 if (InstCnt <= InstCntLateMask) {
2840class IntegerCompareEliminator {
2841 SelectionDAG *CurDAG;
2846 enum ExtOrTruncConversion { Ext,
Trunc };
2854 enum SetccInGPROpts { ZExtOrig, ZExtInvert, SExtOrig, SExtInvert };
2864 enum ZeroCompare { GEZExt, GESExt, LEZExt, LESExt };
2866 SDNode *tryEXTEND(SDNode *
N);
2867 SDNode *tryLogicOpOfCompares(SDNode *
N);
2871 SDValue addExtOrTrunc(
SDValue NatWidthRes, ExtOrTruncConversion Conv);
2875 int64_t RHSValue, SDLoc dl);
2877 int64_t RHSValue, SDLoc dl);
2879 int64_t RHSValue, SDLoc dl);
2881 int64_t RHSValue, SDLoc dl);
2885 IntegerCompareEliminator(SelectionDAG *DAG, PPCDAGToDAGISel *Sel,
2887 : CurDAG(DAG), S(Sel), CmpInGPR(CmpInGPR) {
2890 "Only expecting to use this on 64 bit targets.");
2893 if (CmpInGPR == PPC::ICmpInGPRType::None)
2895 switch (
N->getOpcode()) {
2898 if (CmpInGPR == PPC::ICmpInGPRType::Sext ||
2899 CmpInGPR == PPC::ICmpInGPRType::SextI32 ||
2900 CmpInGPR == PPC::ICmpInGPRType::SextI64)
2904 if (CmpInGPR == PPC::ICmpInGPRType::Zext ||
2905 CmpInGPR == PPC::ICmpInGPRType::ZextI32 ||
2906 CmpInGPR == PPC::ICmpInGPRType::ZextI64)
2908 return tryEXTEND(
N);
2912 return tryLogicOpOfCompares(
N);
2920SDNode *IntegerCompareEliminator::tryEXTEND(SDNode *
N) {
2923 "Expecting a zero/sign extend node!");
2928 N->getOperand(0).getValueType() == MVT::i1 &&
2930 WideRes = computeLogicOpInGPR(
N->getOperand(0));
2931 else if (
N->getOperand(0).getOpcode() !=
ISD::SETCC)
2935 getSETCCInGPR(
N->getOperand(0),
2937 SetccInGPROpts::SExtOrig : SetccInGPROpts::ZExtOrig);
2943 bool Output32Bit =
N->getValueType(0) == MVT::i32;
2949 if (Input32Bit != Output32Bit)
2950 ConvOp = addExtOrTrunc(WideRes, Input32Bit ? ExtOrTruncConversion::Ext :
2951 ExtOrTruncConversion::Trunc);
2959SDNode *IntegerCompareEliminator::tryLogicOpOfCompares(SDNode *
N) {
2960 if (
N->getValueType(0) != MVT::i1)
2963 "Expected a logic operation on setcc results.");
2965 if (!LoweredLogical)
2970 unsigned SubRegToExtract = IsBitwiseNegate ? PPC::sub_eq : PPC::sub_gt;
2979 if (IsBitwiseNegate &&
2982 else if (IsBitwiseNegate)
2984 OpToConvToRecForm = LoweredLogical.
getOperand(0);
2988 OpToConvToRecForm = LoweredLogical;
2998 if (NewOpc != -1 && IsBitwiseNegate) {
3001 "Expected a PPC::XORI8 only for bitwise negation.");
3003 std::vector<SDValue>
Ops;
3004 for (
int i = 0, e = OpToConvToRecForm.
getNumOperands(); i < e; i++)
3010 MVT::Glue,
Ops), 0);
3012 assert((NewOpc != -1 || !IsBitwiseNegate) &&
3013 "No record form available for AND8/OR8/XOR8?");
3016 dl, MVT::i64, MVT::Glue,
LHS,
RHS),
3028 MVT::i1, CR0Reg, SRIdxVal,
3041SDValue IntegerCompareEliminator::computeLogicOpInGPR(
SDValue LogicOp) {
3043 "Can only handle logic operations here.");
3045 "Can only handle logic operations on i1 values here.");
3057 unsigned OperandOpcode = Operand.getOpcode();
3059 return getSETCCInGPR(Operand, SetccInGPROpts::ZExtOrig);
3061 SDValue InputOp = Operand.getOperand(0);
3064 PPC::RLDICL, dl, InVT, InputOp,
3065 S->getI64Imm(0, dl),
3066 S->getI64Imm(63, dl)), 0);
3068 return computeLogicOpInGPR(Operand);
3077 if (!
LHS || (!
RHS && !IsBitwiseNegation))
3080 NumLogicOpsOnComparison++;
3083 if (
LHS.getValueType() == MVT::i32)
3084 LHS = addExtOrTrunc(
LHS, ExtOrTruncConversion::Ext);
3085 if (!IsBitwiseNegation &&
RHS.getValueType() == MVT::i32)
3086 RHS = addExtOrTrunc(
RHS, ExtOrTruncConversion::Ext);
3091 case ISD::AND: NewOpc = PPC::AND8;
break;
3092 case ISD::OR: NewOpc = PPC::OR8;
break;
3093 case ISD::XOR: NewOpc = PPC::XOR8;
break;
3096 if (IsBitwiseNegation) {
3097 RHS = S->getI64Imm(1, dl);
3098 NewOpc = PPC::XORI8;
3109SDValue IntegerCompareEliminator::signExtendInputIfNeeded(
SDValue Input) {
3111 "Can only sign-extend 32-bit values here.");
3119 return addExtOrTrunc(Input, ExtOrTruncConversion::Ext);
3125 return addExtOrTrunc(Input, ExtOrTruncConversion::Ext);
3130 return addExtOrTrunc(Input, ExtOrTruncConversion::Ext);
3133 SignExtensionsAdded++;
3135 MVT::i64, Input), 0);
3142SDValue IntegerCompareEliminator::zeroExtendInputIfNeeded(
SDValue Input) {
3144 "Can only zero-extend 32-bit values here.");
3154 if (IsTruncateOfZExt)
3155 return addExtOrTrunc(Input, ExtOrTruncConversion::Ext);
3159 return addExtOrTrunc(Input, ExtOrTruncConversion::Ext);
3164 return addExtOrTrunc(Input, ExtOrTruncConversion::Ext);
3168 ZeroExtensionsAdded++;
3170 S->getI64Imm(0, dl),
3171 S->getI64Imm(32, dl)), 0);
3178SDValue IntegerCompareEliminator::addExtOrTrunc(
SDValue NatWidthRes,
3179 ExtOrTruncConversion Conv) {
3180 SDLoc dl(NatWidthRes);
3184 if (Conv == ExtOrTruncConversion::Ext) {
3189 ImDef, NatWidthRes, SubRegIdx), 0);
3192 assert(Conv == ExtOrTruncConversion::Trunc &&
3193 "Unknown convertion between 32 and 64 bit values.");
3199 NatWidthRes, SubRegIdx), 0);
3205IntegerCompareEliminator::getCompoundZeroComparisonInGPR(
SDValue LHS, SDLoc dl,
3206 ZeroCompare CmpTy) {
3207 EVT InVT =
LHS.getValueType();
3208 bool Is32Bit = InVT == MVT::i32;
3213 case ZeroCompare::GEZExt:
3214 case ZeroCompare::GESExt:
3218 case ZeroCompare::LEZExt:
3219 case ZeroCompare::LESExt: {
3222 LHS = signExtendInputIfNeeded(
LHS);
3227 Neg, S->getI64Imm(1, dl),
3228 S->getI64Imm(63, dl)), 0);
3232 S->getI64Imm(~0ULL, dl)), 0);
3242 (CmpTy == ZeroCompare::GEZExt || CmpTy == ZeroCompare::LEZExt))
3244 ToExtend, S->getI64Imm(1, dl),
3245 S->getI64Imm(63, dl)), 0);
3247 (CmpTy == ZeroCompare::GESExt || CmpTy == ZeroCompare::LESExt))
3249 S->getI64Imm(63, dl)), 0);
3251 assert(Is32Bit &&
"Should have handled the 32-bit sequences above.");
3254 case ZeroCompare::GEZExt: {
3255 SDValue ShiftOps[] = { ToExtend, S->getI32Imm(1, dl), S->getI32Imm(31, dl),
3256 S->getI32Imm(31, dl) };
3260 case ZeroCompare::GESExt:
3262 S->getI32Imm(31, dl)), 0);
3263 case ZeroCompare::LEZExt:
3265 S->getI32Imm(1, dl)), 0);
3266 case ZeroCompare::LESExt:
3268 S->getI32Imm(-1, dl)), 0);
3281 int64_t RHSValue, SDLoc dl) {
3282 if (CmpInGPR == PPC::ICmpInGPRType::I64 ||
3283 CmpInGPR == PPC::ICmpInGPRType::SextI64 ||
3284 CmpInGPR == PPC::ICmpInGPRType::ZextI64 ||
3285 CmpInGPR == PPC::ICmpInGPRType::Sext)
3287 bool IsRHSZero = RHSValue == 0;
3288 bool IsRHSOne = RHSValue == 1;
3289 bool IsRHSNegOne = RHSValue == -1LL;
3299 SDValue ShiftOps[] = { Clz, S->getI32Imm(27, dl), S->getI32Imm(5, dl),
3300 S->getI32Imm(31, dl) };
3311 SDValue ShiftOps[] = { Clz, S->getI32Imm(27, dl), S->getI32Imm(5, dl),
3312 S->getI32Imm(31, dl) };
3316 S->getI32Imm(1, dl)), 0);
3322 return getCompoundZeroComparisonInGPR(
LHS, dl, ZeroCompare::GEZExt);
3328 IsRHSZero = RHSConst && RHSConst->
isZero();
3332 if (CmpInGPR == PPC::ICmpInGPRType::NonExtIn)
3337 if (CmpInGPR == PPC::ICmpInGPRType::NonExtIn)
3339 return getCompoundZeroComparisonInGPR(
LHS, dl, ZeroCompare::LEZExt);
3343 LHS = signExtendInputIfNeeded(
LHS);
3344 RHS = signExtendInputIfNeeded(
RHS);
3349 S->getI64Imm(1, dl), S->getI64Imm(63, dl)),
3353 MVT::i64, Shift, S->getI32Imm(1, dl)), 0);
3361 return getCompoundZeroComparisonInGPR(
LHS, dl, ZeroCompare::GEZExt);
3364 if (CmpInGPR == PPC::ICmpInGPRType::NonExtIn)
3367 LHS = signExtendInputIfNeeded(
LHS);
3368 RHS = signExtendInputIfNeeded(
RHS);
3372 Neg, S->getI32Imm(1, dl), S->getI32Imm(63, dl)), 0);
3378 IsRHSZero = RHSConst && RHSConst->
isZero();
3388 if (CmpInGPR == PPC::ICmpInGPRType::NonExtIn)
3390 return getCompoundZeroComparisonInGPR(
LHS, dl, ZeroCompare::LEZExt);
3394 SDValue ShiftOps[] = {
LHS, S->getI32Imm(1, dl), S->getI32Imm(31, dl),
3395 S->getI32Imm(31, dl) };
3400 if (CmpInGPR == PPC::ICmpInGPRType::NonExtIn)
3403 LHS = signExtendInputIfNeeded(
LHS);
3404 RHS = signExtendInputIfNeeded(
RHS);
3408 SUBFNode, S->getI64Imm(1, dl),
3409 S->getI64Imm(63, dl)), 0);
3417 if (CmpInGPR == PPC::ICmpInGPRType::NonExtIn)
3420 LHS = zeroExtendInputIfNeeded(
LHS);
3421 RHS = zeroExtendInputIfNeeded(
RHS);
3426 Subtract, S->getI64Imm(1, dl),
3427 S->getI64Imm(63, dl)), 0);
3429 S->getI32Imm(1, dl)), 0);
3437 if (CmpInGPR == PPC::ICmpInGPRType::NonExtIn)
3440 LHS = zeroExtendInputIfNeeded(
LHS);
3441 RHS = zeroExtendInputIfNeeded(
RHS);
3445 Subtract, S->getI64Imm(1, dl),
3446 S->getI64Imm(63, dl)), 0);
3456 int64_t RHSValue, SDLoc dl) {
3457 if (CmpInGPR == PPC::ICmpInGPRType::I64 ||
3458 CmpInGPR == PPC::ICmpInGPRType::SextI64 ||
3459 CmpInGPR == PPC::ICmpInGPRType::ZextI64 ||
3460 CmpInGPR == PPC::ICmpInGPRType::Zext)
3462 bool IsRHSZero = RHSValue == 0;
3463 bool IsRHSOne = RHSValue == 1;
3464 bool IsRHSNegOne = RHSValue == -1LL;
3477 SDValue SHLOps[] = { Cntlzw, S->getI32Imm(27, dl),
3478 S->getI32Imm(5, dl), S->getI32Imm(31, dl) };
3496 { Clz, S->getI32Imm(27, dl), S->getI32Imm(5, dl), S->getI32Imm(31, dl) };
3501 S->getI32Imm(1, dl)), 0);
3508 return getCompoundZeroComparisonInGPR(
LHS, dl, ZeroCompare::GESExt);
3514 IsRHSZero = RHSConst && RHSConst->
isZero();
3518 if (CmpInGPR == PPC::ICmpInGPRType::NonExtIn)
3523 return getCompoundZeroComparisonInGPR(
LHS, dl, ZeroCompare::LESExt);
3526 LHS = signExtendInputIfNeeded(
LHS);
3527 RHS = signExtendInputIfNeeded(
RHS);
3533 SUBFNode, S->getI64Imm(1, dl),
3534 S->getI64Imm(63, dl)), 0);
3536 S->getI32Imm(-1, dl)), 0);
3543 return getCompoundZeroComparisonInGPR(
LHS, dl, ZeroCompare::GESExt);
3545 if (CmpInGPR == PPC::ICmpInGPRType::NonExtIn)
3548 LHS = signExtendInputIfNeeded(
LHS);
3549 RHS = signExtendInputIfNeeded(
RHS);
3553 S->getI64Imm(63, dl)), 0);
3559 IsRHSZero = RHSConst && RHSConst->
isZero();
3568 if (CmpInGPR == PPC::ICmpInGPRType::NonExtIn)
3570 return getCompoundZeroComparisonInGPR(
LHS, dl, ZeroCompare::LESExt);
3574 S->getI32Imm(31, dl)), 0);
3576 if (CmpInGPR == PPC::ICmpInGPRType::NonExtIn)
3579 LHS = signExtendInputIfNeeded(
LHS);
3580 RHS = signExtendInputIfNeeded(
RHS);
3584 SUBFNode, S->getI64Imm(63, dl)), 0);
3592 if (CmpInGPR == PPC::ICmpInGPRType::NonExtIn)
3595 LHS = zeroExtendInputIfNeeded(
LHS);
3596 RHS = zeroExtendInputIfNeeded(
RHS);
3601 S->getI32Imm(1, dl), S->getI32Imm(63,dl)),
3604 S->getI32Imm(-1, dl)), 0);
3612 if (CmpInGPR == PPC::ICmpInGPRType::NonExtIn)
3615 LHS = zeroExtendInputIfNeeded(
LHS);
3616 RHS = zeroExtendInputIfNeeded(
RHS);
3620 Subtract, S->getI64Imm(63, dl)), 0);
3630 int64_t RHSValue, SDLoc dl) {
3631 if (CmpInGPR == PPC::ICmpInGPRType::I32 ||
3632 CmpInGPR == PPC::ICmpInGPRType::SextI32 ||
3633 CmpInGPR == PPC::ICmpInGPRType::ZextI32 ||
3634 CmpInGPR == PPC::ICmpInGPRType::Sext)
3636 bool IsRHSZero = RHSValue == 0;
3637 bool IsRHSOne = RHSValue == 1;
3638 bool IsRHSNegOne = RHSValue == -1LL;
3649 S->getI64Imm(58, dl),
3650 S->getI64Imm(63, dl)), 0);
3661 Xor, S->getI32Imm(~0U, dl)), 0);
3671 return getCompoundZeroComparisonInGPR(
LHS, dl, ZeroCompare::GEZExt);
3674 IsRHSZero = RHSConst && RHSConst->
isZero();
3683 return getCompoundZeroComparisonInGPR(
LHS, dl, ZeroCompare::LEZExt);
3686 S->getI64Imm(1, dl),
3687 S->getI64Imm(63, dl)), 0);
3690 S->getI64Imm(63, dl)), 0);
3695 ShiftR, ShiftL, SubtractCarry), 0);
3703 return getCompoundZeroComparisonInGPR(
LHS, dl, ZeroCompare::GEZExt);
3707 S->getI64Imm(~0ULL, dl)), 0);
3711 S->getI64Imm(1, dl),
3712 S->getI64Imm(63, dl)), 0);
3716 IsRHSZero = RHSConst && RHSConst->
isZero();
3726 return getCompoundZeroComparisonInGPR(
LHS, dl, ZeroCompare::LEZExt);
3729 S->getI64Imm(1, dl),
3730 S->getI64Imm(63, dl)), 0);
3733 LHS, S->getI64Imm(63, dl)), 0);
3736 RHS, S->getI64Imm(1, dl),
3737 S->getI64Imm(63, dl)), 0);
3743 SRDINode, SRADINode, SUBFC8Carry), 0);
3745 ADDE8Node, S->getI64Imm(1, dl)), 0);
3760 LHS,
LHS, SUBFC8Carry), 0);
3762 SUBFE8Node, S->getI64Imm(1, dl)), 0);
3777 LHS,
LHS, SubtractCarry), 0);
3789 int64_t RHSValue, SDLoc dl) {
3790 if (CmpInGPR == PPC::ICmpInGPRType::I32 ||
3791 CmpInGPR == PPC::ICmpInGPRType::SextI32 ||
3792 CmpInGPR == PPC::ICmpInGPRType::ZextI32 ||
3793 CmpInGPR == PPC::ICmpInGPRType::Zext)
3795 bool IsRHSZero = RHSValue == 0;
3796 bool IsRHSOne = RHSValue == 1;
3797 bool IsRHSNegOne = RHSValue == -1LL;
3809 AddInput, S->getI32Imm(~0U, dl)), 0);
3822 Xor, S->getI32Imm(0, dl)), 0);
3832 return getCompoundZeroComparisonInGPR(
LHS, dl, ZeroCompare::GESExt);
3835 IsRHSZero = RHSConst && RHSConst->
isZero();
3844 return getCompoundZeroComparisonInGPR(
LHS, dl, ZeroCompare::LESExt);
3847 S->getI64Imm(63, dl)), 0);
3850 S->getI64Imm(1, dl),
3851 S->getI64Imm(63, dl)), 0);
3857 ShiftR, ShiftL, SubtractCarry), 0);
3866 return getCompoundZeroComparisonInGPR(
LHS, dl, ZeroCompare::GESExt);
3870 S->getI64Imm(-1, dl)), 0);
3874 S->getI64Imm(63, dl)), 0);
3878 IsRHSZero = RHSConst && RHSConst->
isZero();
3888 return getCompoundZeroComparisonInGPR(
LHS, dl, ZeroCompare::LESExt);
3891 S->getI64Imm(63, dl)), 0);
3895 LHS, S->getI64Imm(63, dl)), 0);
3898 RHS, S->getI64Imm(1, dl),
3899 S->getI64Imm(63, dl)), 0);
3905 SRDINode, SRADINode, SUBFC8Carry), 0);
3908 ADDE8Node, S->getI64Imm(1, dl)), 0);
3925 LHS, SubtractCarry), 0);
3927 ExtSub, ExtSub), 0);
3950static bool allUsesExtend(
SDValue Compare, SelectionDAG *CurDAG) {
3952 "An ISD::SETCC node required here.");
3960 for (
auto *CompareUse :
Compare.getNode()->users())
3965 OmittedForNonExtendUses++;
3975 SetccInGPROpts ConvOpts) {
3978 "An ISD::SETCC node required here.");
3991 EVT InputVT =
LHS.getValueType();
3992 if (InputVT != MVT::i32 && InputVT != MVT::i64)
3995 if (ConvOpts == SetccInGPROpts::ZExtInvert ||
3996 ConvOpts == SetccInGPROpts::SExtInvert)
3999 bool Inputs32Bit = InputVT == MVT::i32;
4004 bool IsSext = ConvOpts == SetccInGPROpts::SExtOrig ||
4005 ConvOpts == SetccInGPROpts::SExtInvert;
4007 if (IsSext && Inputs32Bit)
4008 return get32BitSExtCompare(
LHS,
RHS,
CC, RHSValue, dl);
4009 else if (Inputs32Bit)
4010 return get32BitZExtCompare(
LHS,
RHS,
CC, RHSValue, dl);
4012 return get64BitSExtCompare(
LHS,
RHS,
CC, RHSValue, dl);
4013 return get64BitZExtCompare(
LHS,
RHS,
CC, RHSValue, dl);
4018bool PPCDAGToDAGISel::tryIntCompareInGPR(SDNode *
N) {
4019 if (
N->getValueType(0) != MVT::i32 &&
4020 N->getValueType(0) != MVT::i64)
4036 switch (
N->getOpcode()) {
4043 IntegerCompareEliminator ICmpElim(
4044 CurDAG,
this, CmpInGPR.value_or(PPC::ICmpInGPRType::All));
4045 if (SDNode *New = ICmpElim.Select(
N)) {
4046 ReplaceNode(
N, New);
4054bool PPCDAGToDAGISel::tryBitPermutation(SDNode *
N) {
4055 if (
N->getValueType(0) != MVT::i32 &&
4056 N->getValueType(0) != MVT::i64)
4062 switch (
N->getOpcode()) {
4067 if (
Subtarget->isISA3_1() &&
N->getValueType(0) == MVT::i32 &&
4069 auto &OpRight =
N->getOperand(1);
4079 BitPermutationSelector BPS(
4081 if (SDNode *New = BPS.Select(
N)) {
4082 ReplaceNode(
N, New);
4095 const SDLoc &dl,
SDValue Chain) {
4099 if (
LHS.getValueType() == MVT::i32) {
4106 getI32Imm(
Imm & 0xFFFF, dl)),
4111 getI32Imm(
Imm & 0xFFFF, dl)),
4124 getI32Imm(
Imm >> 16, dl)), 0);
4126 getI32Imm(
Imm & 0xFFFF, dl)), 0);
4132 getI32Imm(
Imm & 0xFFFF, dl)), 0);
4138 getI32Imm((
int)SImm & 0xFFFF,
4143 }
else if (
LHS.getValueType() == MVT::i64) {
4150 getI32Imm(
Imm & 0xFFFF, dl)),
4155 getI32Imm(
Imm & 0xFFFF, dl)),
4169 getI64Imm(
Imm >> 16, dl)), 0);
4171 getI64Imm(
Imm & 0xFFFF, dl)),
4179 getI64Imm(
Imm & 0xFFFF, dl)), 0);
4185 getI64Imm(SImm & 0xFFFF, dl)),
4189 }
else if (
LHS.getValueType() == MVT::f32) {
4195 Opc = PPC::EFSCMPEQ;
4203 Opc = PPC::EFSCMPLT;
4211 Opc = PPC::EFSCMPGT;
4216 }
else if (
LHS.getValueType() == MVT::f64) {
4222 Opc = PPC::EFDCMPEQ;
4230 Opc = PPC::EFDCMPLT;
4238 Opc = PPC::EFDCMPGT;
4242 Opc =
Subtarget->hasVSX() ? PPC::XSCMPUDP : PPC::FCMPUD;
4244 assert(
LHS.getValueType() == MVT::f128 &&
"Unknown vt!");
4245 assert(
Subtarget->hasP9Vector() &&
"XSCMPUQP requires Power9 Vector");
4246 Opc = PPC::XSCMPUQP;
4314 case ISD::SETO: Invert =
true;
return 3;
4331 bool HasVSX,
bool &
Swap,
bool &Negate) {
4358 if (VecVT == MVT::v4f32)
4359 return HasVSX ? PPC::XVCMPEQSP : PPC::VCMPEQFP;
4360 else if (VecVT == MVT::v2f64)
4361 return PPC::XVCMPEQDP;
4365 if (VecVT == MVT::v4f32)
4366 return HasVSX ? PPC::XVCMPGTSP : PPC::VCMPGTFP;
4367 else if (VecVT == MVT::v2f64)
4368 return PPC::XVCMPGTDP;
4372 if (VecVT == MVT::v4f32)
4373 return HasVSX ? PPC::XVCMPGESP : PPC::VCMPGEFP;
4374 else if (VecVT == MVT::v2f64)
4375 return PPC::XVCMPGEDP;
4402 if (VecVT == MVT::v16i8)
4403 return PPC::VCMPEQUB;
4404 else if (VecVT == MVT::v8i16)
4405 return PPC::VCMPEQUH;
4406 else if (VecVT == MVT::v4i32)
4407 return PPC::VCMPEQUW;
4408 else if (VecVT == MVT::v2i64)
4409 return PPC::VCMPEQUD;
4410 else if (VecVT == MVT::v1i128)
4411 return PPC::VCMPEQUQ;
4414 if (VecVT == MVT::v16i8)
4415 return PPC::VCMPGTSB;
4416 else if (VecVT == MVT::v8i16)
4417 return PPC::VCMPGTSH;
4418 else if (VecVT == MVT::v4i32)
4419 return PPC::VCMPGTSW;
4420 else if (VecVT == MVT::v2i64)
4421 return PPC::VCMPGTSD;
4422 else if (VecVT == MVT::v1i128)
4423 return PPC::VCMPGTSQ;
4426 if (VecVT == MVT::v16i8)
4427 return PPC::VCMPGTUB;
4428 else if (VecVT == MVT::v8i16)
4429 return PPC::VCMPGTUH;
4430 else if (VecVT == MVT::v4i32)
4431 return PPC::VCMPGTUW;
4432 else if (VecVT == MVT::v2i64)
4433 return PPC::VCMPGTUD;
4434 else if (VecVT == MVT::v1i128)
4435 return PPC::VCMPGTUQ;
4444bool PPCDAGToDAGISel::trySETCC(SDNode *
N) {
4447 bool IsStrict =
N->isStrictFPOpcode();
4451 bool isPPC64 = (PtrVT == MVT::i64);
4467 SDValue Ops[] = {
Op, getI32Imm(27, dl), getI32Imm(5, dl),
4468 getI32Imm(31, dl) };
4476 Op, getI32Imm(~0U, dl)), 0);
4481 SDValue Ops[] = {
Op, getI32Imm(1, dl), getI32Imm(31, dl),
4482 getI32Imm(31, dl) };
4490 SDValue Ops[] = {
T, getI32Imm(1, dl), getI32Imm(31, dl),
4491 getI32Imm(31, dl) };
4496 }
else if (
Imm == ~0U) {
4503 Op, getI32Imm(1, dl)), 0);
4508 0),
Op.getValue(1));
4513 SDNode *AD = CurDAG->
getMachineNode(PPC::ADDIC, dl, MVT::i32, MVT::Glue,
4514 Op, getI32Imm(~0U, dl));
4521 getI32Imm(1, dl)), 0);
4524 SDValue Ops[] = { AN, getI32Imm(1, dl), getI32Imm(31, dl),
4525 getI32Imm(31, dl) };
4530 SDValue Ops[] = {
Op, getI32Imm(1, dl), getI32Imm(31, dl),
4531 getI32Imm(31, dl) };
4542 if (!IsStrict &&
LHS.getValueType().isVector()) {
4546 EVT VecVT =
LHS.getValueType();
4562 unsigned int VCmpInst =
4591 if (
Subtarget->hasSPE() &&
LHS.getValueType().isFloatingPoint()) {
4605 SDValue Ops[] = { IntCR, getI32Imm((32 - (3 - Idx)) & 31, dl),
4606 getI32Imm(31, dl), getI32Imm(31, dl) };
4615 CurDAG->
SelectNodeTo(
N, PPC::XORI, MVT::i32, Tmp, getI32Imm(1, dl));
4621bool PPCDAGToDAGISel::isOffsetMultipleOf(SDNode *
N,
unsigned Val)
const {
4626 if (LDN || (MIN &&
MIN->getOpcode() == PPCISD::LD_SPLAT))
4642 if ((SlotAlign % Val) != 0)
4657void PPCDAGToDAGISel::transferMemOperands(SDNode *
N, SDNode *Result) {
4664 bool &NeedSwapOps,
bool &IsUnCmp) {
4670 SDValue TrueRes =
N->getOperand(2);
4671 SDValue FalseRes =
N->getOperand(3);
4673 if (!TrueConst || (
N->getSimpleValueType(0) != MVT::i64 &&
4674 N->getSimpleValueType(0) != MVT::i32))
4683 if ((TrueResVal < -1 || TrueResVal > 1) ||
4719 if (!SelCCTrueConst || !SelCCFalseConst)
4724 if (SelCCTVal == -1 && SelCCFVal == 1) {
4726 }
else if (SelCCTVal != 1 || SelCCFVal != -1)
4736 bool InnerSwapped =
false;
4737 if (
LHS == InnerRHS &&
RHS == InnerLHS)
4738 InnerSwapped =
true;
4739 else if (
LHS != InnerLHS ||
RHS != InnerRHS)
4750 NeedSwapOps = (InnerCC ==
ISD::SETGT) ? InnerSwapped : !InnerSwapped;
4767 NeedSwapOps = (TrueResVal == 1);
4786 NeedSwapOps = (TrueResVal == -1);
4795 LLVM_DEBUG(
dbgs() <<
"Found a node that can be lowered to a SETB: ");
4803 if (
N.getOpcode() == PPCISD::FTSQRT)
4808 switch (
N.getConstantOperandVal(0)) {
4809 case Intrinsic::ppc_vsx_xvtdivdp:
4810 case Intrinsic::ppc_vsx_xvtdivsp:
4811 case Intrinsic::ppc_vsx_xvtsqrtdp:
4812 case Intrinsic::ppc_vsx_xvtsqrtsp:
4818bool PPCDAGToDAGISel::tryFoldSWTestBRCC(SDNode *
N) {
4876bool PPCDAGToDAGISel::trySelectLoopCountIntrinsic(SDNode *
N) {
4888 LHS.getOperand(0).getConstantOperandVal(1) != Intrinsic::loop_decrement)
4895 "Counter decrement comparison is not EQ or NE");
4898 assert(OldDecrement.
hasOneUse() &&
"loop decrement has more than one use!");
4900 SDLoc DecrementLoc(OldDecrement);
4902 SDValue DecrementOps[] = {
Subtarget->isPPC64() ? getI64Imm(1, DecrementLoc)
4903 : getI32Imm(1, DecrementLoc)};
4904 unsigned DecrementOpcode =
4905 Subtarget->isPPC64() ? PPC::DecreaseCTR8loop : PPC::DecreaseCTRloop;
4906 SDNode *NewDecrement = CurDAG->
getMachineNode(DecrementOpcode, DecrementLoc,
4907 MVT::i1, DecrementOps);
4909 unsigned Val =
RHS->getAsZExtVal();
4911 unsigned Opcode = IsBranchOnTrue ? PPC::BC : PPC::BCn;
4913 ReplaceUses(
LHS.getValue(0),
LHS.getOperand(1));
4917 ReplaceUses(OldDecrement.
getValue(1), ChainInput);
4921 ChainInput,
N->getOperand(0));
4924 N->getOperand(4), Chain);
4928bool PPCDAGToDAGISel::tryAsSingleRLWINM(SDNode *
N) {
4936 unsigned SH, MB, ME;
4939 if (isRotateAndMask(Val.
getNode(),
Imm,
false, SH, MB, ME)) {
4941 SDValue Ops[] = {Val, getI32Imm(SH, dl), getI32Imm(MB, dl),
4952 unsigned AlreadyCleared = 0;
4955 if (IntrinsicID == Intrinsic::ppc_lbarx)
4956 AlreadyCleared = 24;
4957 else if (IntrinsicID == Intrinsic::ppc_lharx)
4958 AlreadyCleared = 16;
4959 if (AlreadyCleared != 0 && AlreadyCleared == MB && ME == 31) {
4960 ReplaceUses(
SDValue(
N, 0),
N->getOperand(0));
4965 SDValue Ops[] = {Val, getI32Imm(0, dl), getI32Imm(MB, dl),
4973 ReplaceUses(
SDValue(
N, 0),
N->getOperand(1));
4980bool PPCDAGToDAGISel::tryAsSingleRLWINM8(SDNode *
N) {
4997 SDValue Ops[] = {
N->getOperand(0), getI64Imm(0, dl), getI64Imm(MB - 32, dl),
4998 getI64Imm(ME - 32, dl)};
5006bool PPCDAGToDAGISel::tryAsPairOfRLDICL(SDNode *
N) {
5026 if (NumOfLeadingZeros != 0)
5039 unsigned OnesOnLeft = ME + 1;
5040 unsigned ZerosInBetween = (MB - ME + 63) & 63;
5044 getI64Imm(OnesOnLeft, Loc),
5045 getI64Imm(ZerosInBetween, Loc)),
5054 SDValue Ops[] = {Val, getI64Imm(64 - OnesOnLeft, Loc),
5055 getI64Imm(NumOfLeadingZeros, Loc)};
5060bool PPCDAGToDAGISel::tryAsSingleRLWIMI(SDNode *
N) {
5090 getI32Imm(MB, dl), getI32Imm(ME, dl)};
5098bool PPCDAGToDAGISel::tryAsSingleRLDCL(SDNode *
N) {
5127bool PPCDAGToDAGISel::tryAsSingleRLDICL(SDNode *
N) {
5146 auto ImDef = CurDAG->
getMachineNode(PPC::IMPLICIT_DEF, dl, ResultType);
5151 getI32Imm(PPC::sub_32, dl)),
5164 assert(
Imm < 64 &&
"Illegal shift amount");
5169 SDValue Ops[] = {Val, getI32Imm(SH, dl), getI32Imm(MB, dl)};
5174bool PPCDAGToDAGISel::tryAsSingleRLDICR(SDNode *
N) {
5187 SDValue Ops[] = {
N->getOperand(0), getI32Imm(SH, dl), getI32Imm(MB, dl)};
5192bool PPCDAGToDAGISel::tryAsSingleRLDIMI(SDNode *
N) {
5206 unsigned SH = 63 - ME;
5212 getI32Imm(SH, Dl), getI32Imm(MB, Dl)};
5219void PPCDAGToDAGISel::Select(SDNode *
N) {
5221 if (
N->isMachineOpcode()) {
5234 if (tryBitPermutation(
N))
5238 if (tryIntCompareInGPR(
N))
5241 switch (
N->getOpcode()) {
5245 if (
N->getValueType(0) == MVT::i64) {
5252 auto IntrinsicID =
N->getConstantOperandVal(1);
5253 if (IntrinsicID != Intrinsic::ppc_tdw && IntrinsicID != Intrinsic::ppc_tw &&
5254 IntrinsicID != Intrinsic::ppc_trapd &&
5255 IntrinsicID != Intrinsic::ppc_trap)
5257 unsigned Opcode = (IntrinsicID == Intrinsic::ppc_tdw ||
5258 IntrinsicID == Intrinsic::ppc_trapd)
5263 if (IntrinsicID == Intrinsic::ppc_tdw ||
5264 IntrinsicID == Intrinsic::ppc_tw) {
5265 SDValue Ops[] = {
N->getOperand(4),
N->getOperand(2),
N->getOperand(3)};
5266 int16_t SImmOperand2;
5267 int16_t SImmOperand3;
5268 int16_t SImmOperand4;
5269 bool isOperand2IntS16Immediate =
5271 bool isOperand3IntS16Immediate =
5276 if (isOperand2IntS16Immediate == isOperand3IntS16Immediate)
5277 Opcode = IntrinsicID == Intrinsic::ppc_tdw ? PPC::TD : PPC::TW;
5278 else if (isOperand3IntS16Immediate)
5280 Ops[2] = getI32Imm(
int(SImmOperand3) & 0xFFFF, dl);
5283 bool isOperand4IntS16Immediate =
5285 (void)isOperand4IntS16Immediate;
5286 assert(isOperand4IntS16Immediate &&
5287 "The 4th operand is not an Immediate");
5289 int16_t TO = int(SImmOperand4) & 0x1F;
5291 if ((TO & 0x1) != ((TO & 0x2) >> 1))
5292 TO = (TO & 0x1) ? TO + 1 : TO - 1;
5294 if ((TO & 0x8) != ((TO & 0x10) >> 1))
5295 TO = (TO & 0x8) ? TO + 8 : TO - 8;
5296 Ops[0] = getI32Imm(TO, dl);
5297 Ops[1] =
N->getOperand(3);
5298 Ops[2] = getI32Imm(
int(SImmOperand2) & 0xFFFF, dl);
5303 OpsWithMD = {getI32Imm(24, dl),
N->getOperand(2), getI32Imm(0, dl)};
5307 if (
N->getNumOperands() > MDIndex) {
5308 SDValue MDV =
N->getOperand(MDIndex);
5313 "ppc-trap-reason") &&
5314 "Unsupported annotation data type!");
5317 "Invalid data type for annotation ppc-trap-reason!");
5320 MD->
getOperand(i))->getString().str()), dl));
5335 auto IntID =
N->getConstantOperandVal(0);
5336 if (IntID == Intrinsic::ppc_fsels) {
5337 SDValue Ops[] = {
N->getOperand(1),
N->getOperand(2),
N->getOperand(3)};
5342 if (IntID == Intrinsic::ppc_bcdadd_p || IntID == Intrinsic::ppc_bcdsub_p) {
5345 IntID == Intrinsic::ppc_bcdadd_p ? PPC::BCDADD_rec : PPC::BCDSUB_rec;
5346 unsigned SubReg = 0;
5347 unsigned ShiftVal = 0;
5351 SubReg = PPC::sub_eq;
5355 SubReg = PPC::sub_eq;
5360 SubReg = PPC::sub_lt;
5364 SubReg = PPC::sub_lt;
5369 SubReg = PPC::sub_gt;
5373 SubReg = PPC::sub_gt;
5378 SubReg = PPC::sub_un;
5381 SubReg = PPC::sub_un;
5386 EVT VTs[] = {MVT::v16i8, MVT::Glue};
5396 CurDAG->
getMachineNode(TargetOpcode::EXTRACT_SUBREG, dl, MVT::i1,
5397 CR6Reg, SubRegIdx, BCDOp.
getValue(1)),
5406 SDValue Ops[] = {Move, getI32Imm((32 - (4 + ShiftVal)) & 31, dl),
5407 getI32Imm(31, dl), getI32Imm(31, dl)};
5413 CurDAG->
SelectNodeTo(
N, PPC::XORI, MVT::i32, Shift, getI32Imm(1, dl));
5421 unsigned Opcode = 0;
5425 case Intrinsic::ppc_altivec_vstribr_p:
5426 Opcode = PPC::VSTRIBR_rec;
5428 case Intrinsic::ppc_altivec_vstribl_p:
5429 Opcode = PPC::VSTRIBL_rec;
5431 case Intrinsic::ppc_altivec_vstrihr_p:
5432 Opcode = PPC::VSTRIHR_rec;
5434 case Intrinsic::ppc_altivec_vstrihl_p:
5435 Opcode = PPC::VSTRIHL_rec;
5442 EVT VTs[] = {MVT::v16i8, MVT::Glue};
5450 CurDAG->
getMachineNode(TargetOpcode::EXTRACT_SUBREG, dl, MVT::i1,
5451 CR6Reg, SubRegIdx, VecStrOp.
getValue(1)),
5465 case PPCISD::ADDI_TLSLD_L_ADDR:
5466 case PPCISD::ADDI_TLSGD_L_ADDR: {
5468 if (PPCLowering->getPointerTy(CurDAG->
getDataLayout()) != MVT::i32 ||
5477 case PPCISD::CALL_RM: {
5495 ReplaceNode(
N, getGlobalBaseReg());
5499 selectFrameIndex(
N,
N);
5505 N->getOperand(0), InGlue));
5510 ReplaceNode(
N, CurDAG->
getMachineNode(PPC::ReadTB, dl, MVT::i32, MVT::i32,
5511 MVT::Other,
N->getOperand(0)));
5518 getConstantIntValue(), dl,
5519 N->getValueType(0));
5520 if (
N->getValueType(0) == MVT::i64) {
5528 assert(
N->getValueType(0) == MVT::i32 &&
5529 "Expecting i64 or i32 in PPCISD::SRA_ADDZE");
5546 if (tryTLSXFormStore(ST))
5553 EVT LoadedVT =
LD->getMemoryVT();
5561 if (tryTLSXFormLoad(LD))
5572 if (
LD->getValueType(0) != MVT::i64) {
5574 assert((!isSExt || LoadedVT == MVT::i16) &&
"Invalid sext update load");
5577 case MVT::f64: Opcode = PPC::LFDU;
break;
5578 case MVT::f32: Opcode = PPC::LFSU;
break;
5579 case MVT::i32: Opcode = PPC::LWZU;
break;
5580 case MVT::i16: Opcode = isSExt ? PPC::LHAU : PPC::LHZU;
break;
5582 case MVT::i8: Opcode = PPC::LBZU;
break;
5585 assert(
LD->getValueType(0) == MVT::i64 &&
"Unknown load result type!");
5586 assert((!isSExt || LoadedVT == MVT::i16) &&
"Invalid sext update load");
5589 case MVT::i64: Opcode = PPC::LDU;
break;
5590 case MVT::i32: Opcode = PPC::LWZU8;
break;
5591 case MVT::i16: Opcode = isSExt ? PPC::LHAU8 : PPC::LHZU8;
break;
5593 case MVT::i8: Opcode = PPC::LBZU8;
break;
5601 Opcode, dl,
LD->getValueType(0),
5603 transferMemOperands(
N, MN);
5609 if (
LD->getValueType(0) != MVT::i64) {
5611 assert((!isSExt || LoadedVT == MVT::i16) &&
"Invalid sext update load");
5614 case MVT::f64: Opcode = PPC::LFDUX;
break;
5615 case MVT::f32: Opcode = PPC::LFSUX;
break;
5616 case MVT::i32: Opcode = PPC::LWZUX;
break;
5617 case MVT::i16: Opcode = isSExt ? PPC::LHAUX : PPC::LHZUX;
break;
5619 case MVT::i8: Opcode = PPC::LBZUX;
break;
5622 assert(
LD->getValueType(0) == MVT::i64 &&
"Unknown load result type!");
5623 assert((!isSExt || LoadedVT == MVT::i16 || LoadedVT == MVT::i32) &&
5624 "Invalid sext update load");
5627 case MVT::i64: Opcode = PPC::LDUX;
break;
5628 case MVT::i32: Opcode = isSExt ? PPC::LWAUX : PPC::LWZUX8;
break;
5629 case MVT::i16: Opcode = isSExt ? PPC::LHAUX8 : PPC::LHZUX8;
break;
5631 case MVT::i8: Opcode = PPC::LBZUX8;
break;
5639 Opcode, dl,
LD->getValueType(0),
5641 transferMemOperands(
N, MN);
5649 if (tryAsSingleRLWINM(
N) || tryAsSingleRLWIMI(
N) || tryAsSingleRLDCL(
N) ||
5650 tryAsSingleRLDICL(
N) || tryAsSingleRLDICR(
N) || tryAsSingleRLWINM8(
N) ||
5651 tryAsPairOfRLDICL(
N))
5657 if (
N->getValueType(0) == MVT::i32)
5658 if (tryBitfieldInsert(
N))
5669 selectFrameIndex(
N,
N->getOperand(0).getNode(), (int64_t)
Imm);
5676 if (tryAsSingleRLDIMI(
N))
5684 (Imm64 & ~0xFFFFFFFFuLL) == 0) {
5688 if (ImmHi != 0 && ImmLo != 0) {
5691 getI16Imm(ImmLo, dl));
5707 (Imm64 & ~0xFFFFFFFFuLL) == 0) {
5711 if (ImmHi != 0 && ImmLo != 0) {
5714 getI16Imm(ImmLo, dl));
5727 selectFrameIndex(
N,
N->getOperand(0).getNode(), (int64_t)
Imm);
5734 unsigned Imm, SH, MB, ME;
5736 isRotateAndMask(
N,
Imm,
true, SH, MB, ME)) {
5738 getI32Imm(SH, dl), getI32Imm(MB, dl),
5739 getI32Imm(ME, dl) };
5748 unsigned Imm, SH, MB, ME;
5750 isRotateAndMask(
N,
Imm,
true, SH, MB, ME)) {
5752 getI32Imm(SH, dl), getI32Imm(MB, dl),
5753 getI32Imm(ME, dl) };
5783 SDNode *MulNode = CurDAG->
getMachineNode(PPC::MULLI8, dl, MVT::i64,
5784 N->getOperand(0), SDImm);
5787 getI32Imm(63 - Shift, dl)};
5792 SDNode *MulNode = CurDAG->
getMachineNode(PPC::MULLI, dl, MVT::i32,
5793 N->getOperand(0), SDImm);
5796 getI32Imm(0, dl), getI32Imm(31 - Shift, dl)};
5808 EVT InVT =
N->getOperand(0).getValueType();
5809 assert((InVT == MVT::i64 || InVT == MVT::i32) &&
5810 "Invalid input type for ANDI_rec_1_EQ_BIT");
5812 unsigned Opcode = (InVT == MVT::i64) ? PPC::ANDI8_rec : PPC::ANDI_rec;
5822 CurDAG->
SelectNodeTo(
N, TargetOpcode::EXTRACT_SUBREG, MVT::i1, CR0Reg,
5823 SRIdxVal,
SDValue(AndI.getNode(), 1) );
5830 bool isPPC64 = (PtrVT == MVT::i64);
5833 if (
Subtarget->useCRBits() &&
N->getOperand(0).getValueType() == MVT::i1)
5837 bool NeedSwapOps =
false;
5838 bool IsUnCmp =
false;
5854 N,
N->getSimpleValueType(0) == MVT::i64 ? PPC::SETB8 : PPC::SETB,
5855 N->getValueType(0), GenCC);
5866 N->getValueType(0) == MVT::i32) {
5869 N->getOperand(0), getI32Imm(~0U, dl));
5871 N->getOperand(0),
SDValue(Tmp, 1));
5875 SDValue CCReg = SelectCC(
N->getOperand(0),
N->getOperand(1),
CC, dl);
5877 if (
N->getValueType(0) == MVT::i1) {
5885 case 0: SRI = PPC::sub_lt;
break;
5886 case 1: SRI = PPC::sub_gt;
break;
5887 case 2: SRI = PPC::sub_eq;
break;
5888 case 3: SRI = PPC::sub_un;
break;
5895 SDValue C = Inv ? NotCCBit : CCBit,
5896 NotC = Inv ? CCBit : NotCCBit;
5899 C,
N->getOperand(2)), 0);
5901 NotC,
N->getOperand(3)), 0);
5903 CurDAG->
SelectNodeTo(
N, PPC::CROR, MVT::i1, CAndT, NotCAndF);
5910 unsigned SelectCCOp;
5911 if (
N->getValueType(0) == MVT::i32)
5912 SelectCCOp = PPC::SELECT_CC_I4;
5913 else if (
N->getValueType(0) == MVT::i64)
5914 SelectCCOp = PPC::SELECT_CC_I8;
5915 else if (
N->getValueType(0) == MVT::f32) {
5917 SelectCCOp = PPC::SELECT_CC_VSSRC;
5919 SelectCCOp = PPC::SELECT_CC_SPE4;
5921 SelectCCOp = PPC::SELECT_CC_F4;
5922 }
else if (
N->getValueType(0) == MVT::f64) {
5924 SelectCCOp = PPC::SELECT_CC_VSFRC;
5926 SelectCCOp = PPC::SELECT_CC_SPE;
5928 SelectCCOp = PPC::SELECT_CC_F8;
5929 }
else if (
N->getValueType(0) == MVT::f128)
5930 SelectCCOp = PPC::SELECT_CC_F16;
5932 SelectCCOp = PPC::SELECT_CC_SPE;
5933 else if (
N->getValueType(0) == MVT::v2f64 ||
5934 N->getValueType(0) == MVT::v2i64)
5935 SelectCCOp = PPC::SELECT_CC_VSRC;
5937 SelectCCOp = PPC::SELECT_CC_VRRC;
5940 getI32Imm(BROpc, dl) };
5945 if (
Subtarget->hasVSX() && (
N->getValueType(0) == MVT::v2f64 ||
5946 N->getValueType(0) == MVT::v2i64)) {
5953 for (
int i = 0; i < 2; ++i)
5959 if (Op1 == Op2 &&
DM[0] == 0 &&
DM[1] == 0 &&
5965 if (
LD->isUnindexed() &&
LD->hasOneUse() && Op1.
hasOneUse() &&
5966 (
LD->getMemoryVT() == MVT::f64 ||
5967 LD->getMemoryVT() == MVT::i64) &&
5971 MachineMemOperand *MemOp =
LD->getMemOperand();
5973 N->getValueType(0),
Ops);
5983 unsigned tmp =
DM[0];
5999 SDValue Ops[] = {
N->getOperand(1),
N->getOperand(0) };
6001 ? (IsPPC64 ? PPC::BDNZ8 : PPC::BDNZ)
6002 : (IsPPC64 ? PPC::BDZ8 : PPC::BDZ),
6006 case PPCISD::COND_BRANCH: {
6013 unsigned PCC =
N->getConstantOperandVal(1);
6024 if (tryFoldSWTestBRCC(
N))
6026 if (trySelectLoopCountIntrinsic(
N))
6032 if (
N->getOperand(2).getValueType() == MVT::i1) {
6055 N->getOperand(
Swap ? 3 : 2),
6056 N->getOperand(
Swap ? 2 : 3)), 0);
6057 CurDAG->
SelectNodeTo(
N, PPC::BC, MVT::Other, BitComp,
N->getOperand(4),
6067 N->getOperand(4),
N->getOperand(0) };
6075 unsigned Opc =
Target.getValueType() == MVT::i32 ? PPC::MTCTR : PPC::MTCTR8;
6076 unsigned Reg =
Target.getValueType() == MVT::i32 ? PPC::BCTR : PPC::BCTR8;
6082 case PPCISD::TOC_ENTRY: {
6083 const bool isPPC64 =
Subtarget->isPPC64();
6084 const bool isELFABI =
Subtarget->isSVR4ABI();
6085 const bool isAIXABI =
Subtarget->isAIXABI();
6091 "PowerPC doesn't support tiny or kernel code models.");
6102 auto replaceWith = [
this, &dl](
unsigned OpCode, SDNode *TocEntry,
6104 SDValue GA = TocEntry->getOperand(0);
6105 SDValue TocBase = TocEntry->getOperand(1);
6106 SDNode *MN =
nullptr;
6107 if (OpCode == PPC::ADDItoc || OpCode == PPC::ADDItoc8)
6113 transferMemOperands(TocEntry, MN);
6115 ReplaceNode(TocEntry, MN);
6124 "32-bit ELF can only have TOC entries in position independent"
6127 replaceWith(PPC::LWZtoc,
N, MVT::i32);
6131 assert(isAIXABI &&
"ELF ABI already handled");
6134 replaceWith(PPC::ADDItoc,
N, MVT::i32);
6138 replaceWith(PPC::LWZtoc,
N, MVT::i32);
6143 assert(isAIXABI &&
"ELF ABI handled in common SelectCode");
6146 replaceWith(PPC::ADDItoc8,
N, MVT::i64);
6156 assert((isPPC64 || (isAIXABI && !isPPC64)) &&
"We are dealing with 64-bit"
6157 " ELF/AIX or 32-bit AIX in the following.");
6182 isPPC64 ? PPC::ADDIStocHA8 : PPC::ADDIStocHA, dl, VT, TOCbase, GA);
6189 dl, VT,
SDValue(Tmp, 0), GA));
6193 if (PPCLowering->isAccessedAsGotIndirect(GA)) {
6197 isPPC64 ? PPC::LDtocL : PPC::LWZtocL, dl, VT, GA,
SDValue(Tmp, 0));
6199 transferMemOperands(
N, MN);
6204 assert(isPPC64 &&
"TOC_ENTRY already handled for 32-bit.");
6213 "PPCISD::PPC32_PICGOT is only supported for 32-bit SVR4");
6224 "Invalid operand on VADD_SPLAT!");
6226 int Elt =
N->getConstantOperandVal(0);
6227 int EltSize =
N->getConstantOperandVal(1);
6228 unsigned Opc1, Opc2, Opc3;
6232 Opc1 = PPC::VSPLTISB;
6233 Opc2 = PPC::VADDUBM;
6234 Opc3 = PPC::VSUBUBM;
6236 }
else if (EltSize == 2) {
6237 Opc1 = PPC::VSPLTISH;
6238 Opc2 = PPC::VADDUHM;
6239 Opc3 = PPC::VSUBUHM;
6242 assert(EltSize == 4 &&
"Invalid element size on VADD_SPLAT!");
6243 Opc1 = PPC::VSPLTISW;
6244 Opc2 = PPC::VADDUWM;
6245 Opc3 = PPC::VSUBUWM;
6249 if ((Elt & 1) == 0) {
6256 SDValue EltVal = getI32Imm(Elt >> 1, dl);
6261 }
else if (Elt > 0) {
6268 SDValue EltVal = getI32Imm(Elt - 16, dl);
6270 EltVal = getI32Imm(-16, dl);
6282 SDValue EltVal = getI32Imm(Elt + 16, dl);
6284 EltVal = getI32Imm(-16, dl);
6291 case PPCISD::LD_SPLAT: {
6298 EVT
Type =
N->getValueType(0);
6299 if (
Type != MVT::v16i8 &&
Type != MVT::v8i16)
6308 isOffsetMultipleOf(
N, 16))
6314 unsigned LIOpcode =
Subtarget->isPPC64() ? PPC::LI8 : PPC::LI;
6329 unsigned SplatOp = (
Type == MVT::v16i8) ? PPC::VSPLTB : PPC::VSPLTH;
6330 unsigned SplatElemIndex =
6341 SDNode *LoadHigh = LoadLow;
6342 if (
Type == MVT::v8i16) {
6344 PPC::LVX, dl, MVT::v16i8, MVT::Other,
6346 LIOpcode, dl, MVT::i32,
6349 N->getOperand(1),
SDValue(LoadLow, 1)});
6353 transferMemOperands(
N, LoadHigh);
6374SDValue PPCDAGToDAGISel::combineToCMPB(SDNode *
N) {
6378 "Only OR nodes are supported for CMPB");
6384 if (
N->getValueType(0) != MVT::i32 &&
6385 N->getValueType(0) != MVT::i64)
6388 EVT VT =
N->getValueType(0);
6391 bool BytesFound[8] = {
false,
false,
false,
false,
false,
false,
false,
false};
6394 auto IsByteSelectCC = [
this](
SDValue O,
unsigned &
b,
6404 uint64_t PM =
O.getConstantOperandVal(2);
6405 uint64_t PAlt =
O.getConstantOperandVal(3);
6406 for (b = 0;
b < 8; ++
b) {
6408 if (PM && (PM & Mask) == PM && (PAlt & Mask) == PAlt)
6418 O.getConstantOperandVal(1) != 0) {
6419 SDValue Op0 =
O.getOperand(0), Op1 =
O.getOperand(1);
6451 uint64_t ULim =
O.getConstantOperandVal(1);
6452 if (ULim != (UINT64_C(1) << b*8))
6477 if (
Op.getConstantOperandVal(1) != (UINT64_C(0xFF) << (8*b)))
6492 unsigned Bits =
Op.getValueSizeInBits();
6495 if (
Op.getConstantOperandVal(1) != Bits-8)
6513 while (!
Queue.empty()) {
6516 for (
const SDValue &O :
V.getNode()->ops()) {
6522 }
else if (IsByteSelectCC(O, b, M,
A, OLHS, ORHS)) {
6526 BytesFound[
b] =
true;
6529 }
else if ((
LHS == ORHS &&
RHS == OLHS) ||
6530 (
RHS == ORHS &&
LHS == OLHS)) {
6531 BytesFound[
b] =
true;
6543 unsigned LastB = 0, BCnt = 0;
6544 for (
unsigned i = 0; i < 8; ++i)
6545 if (BytesFound[LastB]) {
6550 if (!LastB || BCnt < 2)
6555 if (
LHS.getValueType() != VT) {
6562 bool NonTrivialMask = ((int64_t)
Mask) != INT64_C(-1);
6563 if (NonTrivialMask && !Alt) {
6590void PPCDAGToDAGISel::foldBoolExts(
SDValue &Res, SDNode *&
N) {
6599 if (
N->getOperand(0).getValueType() != MVT::i1)
6602 if (!
N->hasOneUse())
6606 EVT VT =
N->getValueType(0);
6613 SDNode *
User = *
N->user_begin();
6614 if (
User->getNumOperands() != 2)
6623 User->getValueType(0), {O0, O1});
6628 SDValue TrueRes = TryFold(ConstTrue);
6629 if (!TrueRes || TrueRes.
isUndef())
6631 SDValue FalseRes = TryFold(ConstFalse);
6632 if (!FalseRes || FalseRes.
isUndef())
6645 ConstTrue = TrueRes;
6646 ConstFalse = FalseRes;
6647 }
while (
N->hasOneUse());
6650void PPCDAGToDAGISel::PreprocessISelDAG() {
6653 bool MadeChange =
false;
6655 SDNode *
N = &*--Position;
6660 switch (
N->getOpcode()) {
6663 Res = combineToCMPB(
N);
6668 foldBoolExts(Res,
N);
6688void PPCDAGToDAGISel::PostprocessISelDAG() {
6695 PeepholePPC64ZExt();
6703bool PPCDAGToDAGISel::AllUsersSelectZero(SDNode *
N) {
6704 for (
const SDNode *User :
N->users()) {
6705 if (!
User->isMachineOpcode())
6707 if (
User->getMachineOpcode() != PPC::SELECT_I4 &&
6708 User->getMachineOpcode() != PPC::SELECT_I8)
6711 SDNode *Op1 =
User->getOperand(1).getNode();
6712 SDNode *Op2 =
User->getOperand(2).getNode();
6732void PPCDAGToDAGISel::SwapAllSelectUsers(SDNode *
N) {
6734 for (SDNode *User :
N->users()) {
6735 assert((
User->getMachineOpcode() == PPC::SELECT_I4 ||
6736 User->getMachineOpcode() == PPC::SELECT_I8) &&
6737 "Must have all select users");
6741 for (SDNode *User : ToReplace) {
6744 User->getValueType(0),
User->getOperand(0),
6745 User->getOperand(2),
6746 User->getOperand(1));
6754 ReplaceUses(User, ResNode);
6758void PPCDAGToDAGISel::PeepholeCROps() {
6762 for (SDNode &Node : CurDAG->
allnodes()) {
6764 if (!MachineNode || MachineNode->
use_empty())
6766 SDNode *ResNode = MachineNode;
6768 bool Op1Set =
false, Op1Unset =
false,
6770 Op2Set =
false, Op2Unset =
false,
6785 if (
Op.isMachineOpcode()) {
6786 if (
Op.getMachineOpcode() == PPC::CRSET)
6788 else if (
Op.getMachineOpcode() == PPC::CRUNSET)
6790 else if ((
Op.getMachineOpcode() == PPC::CRNOR &&
6791 Op.getOperand(0) ==
Op.getOperand(1)) ||
6792 Op.getMachineOpcode() == PPC::CRNOT)
6799 case PPC::SELECT_I4:
6800 case PPC::SELECT_I8:
6801 case PPC::SELECT_F4:
6802 case PPC::SELECT_F8:
6803 case PPC::SELECT_SPE:
6804 case PPC::SELECT_SPE4:
6805 case PPC::SELECT_VRRC:
6806 case PPC::SELECT_VSFRC:
6807 case PPC::SELECT_VSSRC:
6808 case PPC::SELECT_VSRC: {
6810 if (
Op.isMachineOpcode()) {
6811 if (
Op.getMachineOpcode() == PPC::CRSET)
6813 else if (
Op.getMachineOpcode() == PPC::CRUNSET)
6815 else if ((
Op.getMachineOpcode() == PPC::CRNOR &&
6816 Op.getOperand(0) ==
Op.getOperand(1)) ||
6817 Op.getMachineOpcode() == PPC::CRNOT)
6824 bool SelectSwap =
false;
6837 else if (Op1Unset || Op2Unset)
6839 ResNode = CurDAG->
getMachineNode(PPC::CRUNSET, SDLoc(MachineNode),
6843 ResNode = CurDAG->
getMachineNode(PPC::CRANDC, SDLoc(MachineNode),
6849 ResNode = CurDAG->
getMachineNode(PPC::CRANDC, SDLoc(MachineNode),
6853 else if (AllUsersSelectZero(MachineNode)) {
6854 ResNode = CurDAG->
getMachineNode(PPC::CRNAND, SDLoc(MachineNode),
6876 else if (Op1Unset || Op2Unset)
6892 else if (AllUsersSelectZero(MachineNode)) {
6903 else if (Op1Set || Op2Set)
6925 else if (AllUsersSelectZero(MachineNode)) {
6935 ResNode = CurDAG->
getMachineNode(PPC::CRUNSET, SDLoc(MachineNode),
6965 else if (AllUsersSelectZero(MachineNode)) {
6973 if (Op1Set || Op2Set)
6975 ResNode = CurDAG->
getMachineNode(PPC::CRUNSET, SDLoc(MachineNode),
6989 ResNode = CurDAG->
getMachineNode(PPC::CRANDC, SDLoc(MachineNode),
6995 ResNode = CurDAG->
getMachineNode(PPC::CRANDC, SDLoc(MachineNode),
6999 else if (AllUsersSelectZero(MachineNode)) {
7039 else if (AllUsersSelectZero(MachineNode)) {
7049 ResNode = CurDAG->
getMachineNode(PPC::CRUNSET, SDLoc(MachineNode),
7056 else if (Op1Unset || Op2Set)
7058 ResNode = CurDAG->
getMachineNode(PPC::CRUNSET, SDLoc(MachineNode),
7075 else if (AllUsersSelectZero(MachineNode)) {
7087 else if (Op1Set || Op2Unset)
7101 ResNode = CurDAG->
getMachineNode(PPC::CRNAND, SDLoc(MachineNode),
7111 else if (AllUsersSelectZero(MachineNode)) {
7112 ResNode = CurDAG->
getMachineNode(PPC::CRANDC, SDLoc(MachineNode),
7118 case PPC::SELECT_I4:
7119 case PPC::SELECT_I8:
7120 case PPC::SELECT_F4:
7121 case PPC::SELECT_F8:
7122 case PPC::SELECT_SPE:
7123 case PPC::SELECT_SPE4:
7124 case PPC::SELECT_VRRC:
7125 case PPC::SELECT_VSFRC:
7126 case PPC::SELECT_VSSRC:
7127 case PPC::SELECT_VSRC:
7159 SwapAllSelectUsers(MachineNode);
7161 if (ResNode != MachineNode) {
7168 ReplaceUses(MachineNode, ResNode);
7174 }
while (IsModified);
7285 if (!Op0OK && !Op1OK)
7308 if (!Op0OK && !Op1OK)
7322void PPCDAGToDAGISel::PeepholePPC64ZExt() {
7337 bool MadeChange =
false;
7339 SDNode *
N = &*--Position;
7341 if (
N->use_empty() || !
N->isMachineOpcode())
7344 if (
N->getMachineOpcode() != PPC::RLDICL)
7347 if (
N->getConstantOperandVal(1) != 0 ||
7348 N->getConstantOperandVal(2) != 32)
7377 SmallPtrSet<SDNode *, 16> ToPromote;
7383 bool OutsideUse =
false;
7384 for (SDNode *PN : ToPromote) {
7385 for (SDNode *UN : PN->users()) {
7386 if (!ToPromote.count(UN) && UN != ISR.
getNode()) {
7404 for (SDNode *PN : ToPromote) {
7406 switch (PN->getMachineOpcode()) {
7409 case PPC::RLWINM: NewOpcode = PPC::RLWINM8;
break;
7410 case PPC::RLWNM: NewOpcode = PPC::RLWNM8;
break;
7411 case PPC::SLW: NewOpcode = PPC::SLW8;
break;
7412 case PPC::SRW: NewOpcode = PPC::SRW8;
break;
7413 case PPC::LI: NewOpcode = PPC::LI8;
break;
7414 case PPC::LIS: NewOpcode = PPC::LIS8;
break;
7415 case PPC::LHBRX: NewOpcode = PPC::LHBRX8;
break;
7416 case PPC::LWBRX: NewOpcode = PPC::LWBRX8;
break;
7417 case PPC::CNTLZW: NewOpcode = PPC::CNTLZW8;
break;
7418 case PPC::CNTTZW: NewOpcode = PPC::CNTTZW8;
break;
7419 case PPC::RLWIMI: NewOpcode = PPC::RLWIMI8;
break;
7420 case PPC::OR: NewOpcode = PPC::OR8;
break;
7421 case PPC::SELECT_I4: NewOpcode = PPC::SELECT_I8;
break;
7422 case PPC::ORI: NewOpcode = PPC::ORI8;
break;
7423 case PPC::ORIS: NewOpcode = PPC::ORIS8;
break;
7424 case PPC::AND: NewOpcode = PPC::AND8;
break;
7426 NewOpcode = PPC::ANDI8_rec;
7428 case PPC::ANDIS_rec:
7429 NewOpcode = PPC::ANDIS8_rec;
7439 for (
const SDValue &
V : PN->ops()) {
7440 if (!ToPromote.count(
V.getNode()) &&
V.getValueType() == MVT::i32 &&
7457 SDVTList VTs = PN->getVTList();
7458 for (
unsigned i = 0, ie = VTs.
NumVTs; i != ie; ++i)
7459 if (VTs.
VTs[i] == MVT::i32)
7492 if (!
N->isMachineOpcode())
7494 unsigned Opc =
N->getMachineOpcode();
7498 if (
Opc == PPC::XXPERMDIs) {
7500 N->getConstantOperandVal(1) == 2;
7501 }
else if (
Opc == PPC::XXPERMDI ||
Opc == PPC::XXSLDWI) {
7502 return N->getOperand(0) ==
N->getOperand(1) &&
7504 N->getConstantOperandVal(2) == 2;
7512 if (!
N->isMachineOpcode())
7514 unsigned Opc =
N->getMachineOpcode();
7564 while (
V->isMachineOpcode() &&
7565 V->getMachineOpcode() == TargetOpcode::COPY_TO_REGCLASS) {
7567 if (
V->use_empty() || !
V->user_begin()->isOnlyUserOf(
V.getNode()))
7569 V =
V->getOperand(0);
7574 SDValue VecOp = SkipRCCopy(
N->getOperand(0));
7594 if (GV->hasAttribute(
"aix-small-tls"))
7615 if (!(
Subtarget.hasAIXSmallLocalDynamicTLS() ||
7632 if (!TPReg || (TPReg->
getReg() !=
Subtarget.getThreadPointerRegister()))
7656 if (
N->getMachineOpcode() != PPC::ADDI8)
7661 SDValue InitialADDI =
N->getOperand(0);
7672 assert(GA &&
"Expecting a valid GlobalAddressSDNode when folding addi into "
7673 "local-[exec|dynamic] accesses!");
7681 int Offset =
N->getConstantOperandVal(1);
7690void PPCDAGToDAGISel::PeepholePPC64() {
7694 SDNode *
N = &*--Position;
7696 if (
N->use_empty() || !
N->isMachineOpcode())
7707 unsigned StorageOpcode =
N->getMachineOpcode();
7708 bool RequiresMod4Offset =
false;
7710 switch (StorageOpcode) {
7715 case PPC::DFLOADf64:
7716 case PPC::DFLOADf32:
7717 RequiresMod4Offset =
true;
7733 case PPC::DFSTOREf64:
7734 case PPC::DFSTOREf32:
7735 RequiresMod4Offset =
true;
7757 if (!
Base.isMachineOpcode())
7761 bool ReplaceFlags =
true;
7773 switch (
Base.getMachineOpcode()) {
7781 ReplaceFlags =
false;
7783 case PPC::ADDIdtprelL:
7786 case PPC::ADDItlsldL:
7789 case PPC::ADDItocL8:
7804 int MaxDisplacement = 7;
7806 const GlobalValue *GV = GA->getGlobal();
7808 MaxDisplacement = std::min((
int)
Alignment.value() - 1, MaxDisplacement);
7811 bool UpdateHBase =
false;
7814 int Offset =
N->getConstantOperandVal(FirstOp);
7820 if (
Base.getMachineOpcode() != PPC::ADDItocL8)
7831 if (HImmOpnd != ImmOpnd)
7839 if (RequiresMod4Offset) {
7840 if (GlobalAddressSDNode *GA =
7842 const GlobalValue *GV = GA->getGlobal();
7857 if (RequiresMod4Offset && (
Offset % 4) != 0)
7865 }
else if (
Offset != 0) {
7873 assert(GA &&
"Expecting a valid GlobalAddressSDNode when folding "
7874 "addi into local-[exec|dynamic] accesses!");
7887 LLVM_DEBUG(
dbgs() <<
"Folding add-immediate into mem-op:\nBase: ");
7898 const GlobalValue *GV = GA->getGlobal();
7902 if (Alignment < 4 && (RequiresMod4Offset || (
Offset % 4) != 0)) {
7903 LLVM_DEBUG(
dbgs() <<
"Rejected this candidate for alignment.\n\n");
7907 }
else if (ConstantPoolSDNode *CP =
7917 Base.getOperand(0),
N->getOperand(3));
7927 if (
Base.getNode()->use_empty())
7937 return new PPCDAGToDAGISelLegacy(TM, OptLevel);
static bool isOpcWithIntImmediate(const SDNode *N, unsigned Opc, uint64_t &Imm)
const AArch64Subtarget & Subtarget
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
static msgpack::DocNode getNode(msgpack::DocNode DN, msgpack::Type Type, MCValue Val)
AMDGPU Register Bank Select
This file implements a class to represent arbitrary precision integral constant values and operations...
static bool isInt32Immediate(SDNode *N, unsigned &Imm)
isInt32Immediate - This method tests to see if the node is a 32-bit constant operand.
MachineBasicBlock MachineBasicBlock::iterator MBBI
Function Alias Analysis false
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 RegisterPass< DebugifyModulePass > DM("debugify", "Attach debug info to everything")
This file defines the DenseMap class.
const HexagonInstrInfo * TII
static MaybeAlign getAlign(Value *Ptr)
Module.h This file contains the declarations for the Module class.
static constexpr Value * getValue(Ty &ValueOrUse)
const AbstractManglingParser< Derived, Alloc >::OperatorInfo AbstractManglingParser< Derived, Alloc >::Ops[]
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
Machine Check Debug Module
static CodeModel::Model getCodeModel(const PPCSubtarget &S, const TargetMachine &TM, const MachineOperand &MO)
static bool isEligibleToFoldADDIForFasterLocalAccesses(SelectionDAG *DAG, SDValue ADDIToFold)
static bool canOptimizeTLSDFormToXForm(SelectionDAG *CurDAG, SDValue Base)
static bool hasTocDataAttr(SDValue Val)
static void foldADDIForFasterLocalAccesses(SDNode *N, SelectionDAG *DAG)
static bool isThreadPointerAcquisitionNode(SDValue Base, SelectionDAG *CurDAG)
static bool PeepholePPC64ZExtGather(SDValue Op32, SmallPtrSetImpl< SDNode * > &ToPromote)
static bool isLaneInsensitive(SDValue N)
static unsigned allUsesTruncate(SelectionDAG *CurDAG, SDNode *N)
static CodeModel::Model getCodeModel(const PPCSubtarget &Subtarget, const TargetMachine &TM, const SDNode *Node)
static void reduceVSXSwap(SDNode *N, SelectionDAG *DAG)
static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned &Imm)
static PPC::Predicate getPredicateForSetCC(ISD::CondCode CC, const EVT &VT, const PPCSubtarget *Subtarget)
static unsigned getCRIdxForSetCC(ISD::CondCode CC, bool &Invert)
getCRIdxForSetCC - Return the index of the condition register field associated with the SetCC conditi...
static bool isInt64Immediate(SDNode *N, uint64_t &Imm)
isInt64Immediate - This method tests to see if the node is a 64-bit constant operand.
static bool isInt32Immediate(SDNode *N, unsigned &Imm)
isInt32Immediate - This method tests to see if the node is a 32-bit constant operand.
static unsigned getBranchHint(unsigned PCC, const FunctionLoweringInfo &FuncInfo, const SDValue &DestMBB)
static bool mayUseP9Setb(SDNode *N, const ISD::CondCode &CC, SelectionDAG *DAG, bool &NeedSwapOps, bool &IsUnCmp)
static unsigned int getVCmpInst(MVT VecVT, ISD::CondCode CC, bool HasVSX, bool &Swap, bool &Negate)
static SDNode * selectI64ImmDirectPrefix(SelectionDAG *CurDAG, const SDLoc &dl, uint64_t Imm, unsigned &InstCnt)
static SDNode * selectI64ImmDirect(SelectionDAG *CurDAG, const SDLoc &dl, uint64_t Imm, unsigned &InstCnt)
static bool hasAIXSmallTLSAttr(SDValue Val)
static bool isSWTestOp(SDValue N)
static SDNode * selectI64Imm(SelectionDAG *CurDAG, const SDLoc &dl, uint64_t Imm, unsigned *InstCnt=nullptr)
static bool isVSXSwap(SDValue N)
static uint32_t findContiguousZerosAtLeast(uint64_t Imm, unsigned Num)
if(auto Err=PB.parsePassPipeline(MPM, Passes)) return wrap(std MPM run * Mod
#define INITIALIZE_PASS(passName, arg, name, cfg, analysis)
SmallVector< MachineOperand, 4 > Cond
const SmallVectorImpl< MachineOperand > MachineBasicBlock * TBB
This file defines the SmallPtrSet class.
This file defines the SmallVector class.
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
const AArch64Options & getCLOpts() const
bool isLittleEndian() const
Class for arbitrary precision integers.
uint64_t getZExtValue() const
Get zero extended value.
LLVM_ABI APInt rotr(unsigned rotateAmt) const
Rotate right by rotateAmt.
LLVM_ABI APInt sext(unsigned width) const
Sign extend to a new width.
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Constructs an APInt value that has the top hiBitsSet bits set.
MachineBasicBlock * getBasicBlock() const
LLVM Basic Block Representation.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction; assumes that the block is well-formed.
LLVM_ABI BranchProbability getEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors) const
Get an edge's probability, relative to other out-edges of the Src.
int64_t getSExtValue() const
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
BranchProbabilityInfo * BPI
MachineBasicBlock * MBB
MBB - The current block.
FunctionPass class - This class is used to implement most global optimizations.
unsigned getTargetFlags() const
const GlobalValue * getGlobal() const
Module * getParent()
Get the module that this global value is contained inside of...
bool hasAttribute(Attribute::AttrKind Kind) const
Return true if the attribute exists.
const TargetRegisterClass * getInlineAsmMemoryOperandRegClass(InlineAsm::ConstraintCode C) const override
static StringRef getMemConstraintName(ConstraintCode C)
LLVM_ABI unsigned getNumSuccessors() const LLVM_READONLY
Return the number of successors that this instruction has.
LLVM_ABI BasicBlock * getSuccessor(unsigned Idx) const LLVM_READONLY
Return the specified successor. This instruction must be a terminator.
This class is used to represent ISD::LOAD nodes.
ISD::LoadExtType getExtensionType() const
Return whether this is a plain node, or one of the varieties of value-extending loads.
unsigned getID() const
getID() - Return the register class ID number.
const MDOperand & getOperand(unsigned I) const
unsigned getNumOperands() const
Return number of MDNode operands.
TypeSize getSizeInBits() const
Returns the size of the specified MVT in bits.
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
MachineInstrBundleIterator< MachineInstr > iterator
LLVM_ABI int CreateStackObject(uint64_t Size, Align Alignment, bool isSpillSlot, const AllocaInst *Alloca=nullptr, uint8_t ID=0)
Create a new statically sized stack object, returning a nonnegative identifier to represent it.
Align getObjectAlign(int ObjectIdx) const
Return the alignment of the specified stack object.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
MachineFrameInfo & getFrameInfo()
getFrameInfo - Return the frame info object for the current function.
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...
const MachineBasicBlock & front() const
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
EVT getMemoryVT() const
Return the type of the in-memory value.
A Module instance is used to store all the information related to an LLVM module.
PPCFunctionInfo - This class is derived from MachineFunction private PowerPC target-specific informat...
void setROPProtectionHashSaveIndex(int Idx)
static int getRecordFormOpcode(unsigned Opcode)
Common code between 32-bit and 64-bit PowerPC targets.
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.
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode.
LLVM_ABI void dump() const
Dump this node, for debugging.
bool hasOneUse() const
Return true if there is exactly one use of this node.
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.
unsigned getMachineOpcode() const
This may only be called if isMachineOpcode returns true.
SDVTList getVTList() const
const SDValue & getOperand(unsigned Num) const
uint64_t getConstantOperandVal(unsigned Num) const
Helper method returns the integer value of a ConstantSDNode operand.
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
Represents a use of a SDNode.
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 getConstantOperandVal(unsigned i) const
unsigned getMachineOpcode() const
unsigned getOpcode() const
unsigned getNumOperands() const
SelectionDAGISel - This is the common base class used for SelectionDAG-based pattern-matching instruc...
virtual bool runOnMachineFunction(MachineFunction &mf)
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
SDValue getTargetGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT, int64_t offset=0, unsigned TargetFlags=0)
SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, Register Reg, SDValue N)
LLVM_ABI SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
LLVM_ABI MachineSDNode * getMachineNode(unsigned Opcode, const SDLoc &dl, EVT VT)
These are used for target selectors to create a new node with specified return type(s),...
LLVM_ABI SDNode * SelectNodeTo(SDNode *N, unsigned MachineOpc, EVT VT)
These are used for target selectors to mutate the specified node to have the specified return type,...
LLVM_ABI SDValue getRegister(Register Reg, EVT VT)
const TargetLowering & getTargetLoweringInfo() const
allnodes_const_iterator allnodes_begin() const
allnodes_const_iterator allnodes_end() const
SDValue getSelect(const SDLoc &DL, EVT VT, SDValue Cond, SDValue LHS, SDValue RHS, SDNodeFlags Flags=SDNodeFlags())
Helper function to make it easier to build Select's if you just have operands and don't want to check...
LLVM_ABI void setNodeMemRefs(MachineSDNode *N, ArrayRef< MachineMemOperand * > NewMemRefs)
Mutate the specified machine node's memory references to the provided list.
const DataLayout & getDataLayout() const
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.
SDValue getSignedTargetConstant(int64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
LLVM_ABI SDValue getSignedConstant(int64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
LLVM_ABI void RemoveDeadNodes()
This method deletes all unreachable nodes in the SelectionDAG.
LLVM_ABI void RemoveDeadNode(SDNode *N)
Remove the specified node from the system.
LLVM_ABI SDValue getTargetExtractSubreg(int SRIdx, const SDLoc &DL, EVT VT, SDValue Operand)
A convenience function for creating TargetInstrInfo::EXTRACT_SUBREG nodes.
LLVM_ABI SDValue FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDValue > Ops, SDNodeFlags Flags=SDNodeFlags())
const TargetMachine & getTarget() const
LLVM_ABI SDValue getAnyExtOrTrunc(SDValue Op, const SDLoc &DL, EVT VT)
Convert Op, which must be of integer type, to the integer type VT, by either any-extending or truncat...
iterator_range< allnodes_iterator > allnodes()
LLVM_ABI SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
LLVM_ABI void ReplaceAllUsesOfValueWith(SDValue From, SDValue To)
Replace any uses of From with To, leaving uses of other values produced by From.getNode() alone.
MachineFunction & getMachineFunction() const
LLVM_ABI KnownBits computeKnownBits(SDValue Op, unsigned Depth=0) const
Determine which bits of Op are known to be either zero or one and return them in Known.
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.
SDValue getTargetConstantPool(const Constant *C, EVT VT, MaybeAlign Align=std::nullopt, int Offset=0, unsigned TargetFlags=0)
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
ilist< SDNode >::iterator allnodes_iterator
int getMaskElt(unsigned Idx) const
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
void insert_range(Range &&R)
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements.
void push_back(const T &Elt)
This class is used to represent ISD::STORE nodes.
TargetInstrInfo - Interface to description of machine instruction set.
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...
Primary interface to the complete machine description for the target machine.
CodeGenOptLevel getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
TLSModel::Model getTLSModel(const GlobalValue *GV) const
Returns the TLS model which should be used for the given global variable.
bool isPositionIndependent() const
CodeModel::Model getCodeModel() const
Returns the code model.
virtual const TargetLowering * getTargetLowering() const
A Use represents the edge between a Value definition and its users.
LLVM_ABI unsigned getOperandNo() const
Return the operand # of this use in its User.
User * getUser() const
Returns the User that contains this Use.
LLVM_ABI Align getPointerAlignment(const DataLayout &DL) const
Returns an alignment of the pointer value.
LLVM_ABI StringRef getName() const
Return a constant reference to the value's name.
#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 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.
@ SETCC
SetCC operator - This evaluates to a true value iff the condition is true.
@ STRICT_FSETCC
STRICT_FSETCC/STRICT_FSETCCS - Constrained versions of SETCC, used for floating-point operands only.
@ BSWAP
Byte Swap and Counting operators.
@ 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...
@ 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...
@ BR_CC
BR_CC - Conditional branch.
@ BRIND
BRIND - Indirect branch.
@ SELECT
Select(COND, TRUEVAL, FALSEVAL).
@ 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.
@ VECTOR_SHUFFLE
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
@ ZERO_EXTEND
ZERO_EXTEND - Used for integer types, zeroing the new bits.
@ SELECT_CC
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
@ TargetConstant
TargetConstant* - Like Constant*, but the DAG does not do any folding, simplification,...
@ AND
Bitwise operators - logical and, logical or, logical xor.
@ INTRINSIC_WO_CHAIN
RESULT = INTRINSIC_WO_CHAIN(INTRINSICID, arg1, arg2, ...) This node represents a target intrinsic fun...
@ TokenFactor
TokenFactor - This node takes multiple tokens as input and produces a single token result.
@ TRUNCATE
TRUNCATE - Completely drop the high bits.
@ AssertSext
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
@ INTRINSIC_W_CHAIN
RESULT,OUTCHAIN = INTRINSIC_W_CHAIN(INCHAIN, INTRINSICID, arg1, ...) This node represents a target in...
bool isZEXTLoad(const SDNode *N)
Returns true if the specified node is a ZEXTLOAD.
LLVM_ABI CondCode getSetCCInverse(CondCode Operation, EVT Type)
Return the operation corresponding to !(X op Y), where 'op' is a valid SetCC operation.
bool isBitwiseLogicOp(unsigned Opcode)
Whether this is bitwise logic opcode.
bool isSignedIntSetCC(CondCode Code)
Return true if this is a setcc instruction that performs a signed comparison when used with integer o...
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,...
bool isUnsignedIntSetCC(CondCode Code)
Return true if this is a setcc instruction that performs an unsigned comparison when used with intege...
@ MO_TLSLD_FLAG
MO_TLSLD_FLAG - If this bit is set the symbol reference is relative to TLS Local Dynamic model.
@ MO_PLT
On PPC, the 12 bits are not enough for all target operand flags.
@ MO_DTPREL_LO
These values identify relocations on immediates folded into memory operations.
@ MO_TPREL_FLAG
MO_TPREL_FLAG - If this bit is set, the symbol reference is relative to the thread pointer and the sy...
@ BDNZ
CHAIN = BDNZ CHAIN, DESTBB - These are used to create counter-based loops.
@ ANDI_rec_1_EQ_BIT
i1 = ANDI_rec_1_[EQ|GT]_BIT(i32 or i64 x) - Represents the result of the eq or gt bit of CR0 after ex...
@ MFOCRF
R32 = MFOCRF(CRREG, INFLAG) - Represents the MFOCRF instruction.
@ VADD_SPLAT
VRRC = VADD_SPLAT Elt, EltSize - Temporary node to be expanded during instruction selection to optimi...
@ PPC32_PICGOT
GPRC = address of GLOBAL_OFFSET_TABLE.
@ GlobalBaseReg
The result of the mflr at function entry, used for PIC code.
@ SRA_ADDZE
The combination of sra[wd]i and addze used to implemented signed integer division by a power of 2.
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
@ User
could "use" a pointer
unsigned getOpcode(const VPValue *V)
Return the instruction opcode for the recipe defining V or 0 for unsupported recipes and VPValues not...
This is an optimization pass for GlobalISel generic memory operations.
bool operator<(int64_t V1, const APSInt &V2)
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
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.
@ Define
Register definition.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
int countr_one(T Value)
Count the number of ones from the least significant bit to the first zero bit.
bool isIntS16Immediate(SDNode *N, int16_t &Imm)
isIntS16Immediate - This method tests to see if the node is either a 32-bit or 64-bit immediate,...
constexpr T maskLeadingOnes(unsigned N)
Create a bitmask with the N left-most bits set to 1, and all other bits set to 0.
@ O1
Optimize quickly without destroying debuggability.
@ O0
Disable as many optimizations as possible.
static bool isRunOfOnes64(uint64_t Val, unsigned &MB, unsigned &ME)
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.
auto dyn_cast_or_null(const Y &Val)
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 bool isBitwiseNot(SDValue V, bool AllowUndefs=false)
Returns true if V is a bitwise not operation.
constexpr bool isPowerOf2_32(uint32_t Value)
Return true if the argument is a power of two > 0.
void sort(IteratorTy Start, IteratorTy End)
constexpr uint32_t Hi_32(uint64_t Value)
Return the high 32 bits of a 64 bit value.
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
LLVM_ABI void report_fatal_error(Error Err, bool gen_crash_diag=true)
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...
constexpr bool isUInt(uint64_t x)
Checks if an unsigned integer fits into the given bit width.
int countl_one(T Value)
Count the number of ones from the most significant bit to the first zero bit.
CodeGenOptLevel
Code generation optimization level.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
constexpr uint32_t Lo_32(uint64_t Value)
Return the low 32 bits of a 64 bit value.
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...
FunctionPass * createPPCISelDag(PPCTargetMachine &TM, CodeGenOptLevel OL)
createPPCISelDag - This pass converts a legalized DAG into a PowerPC-specific DAG,...
LLVM_ABI raw_fd_ostream & errs()
This returns a reference to a raw_ostream for standard error.
@ Xor
Bitwise or logical XOR of integers.
@ Sub
Subtraction of integers.
DWARFExpression::Operation Op
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.
void erase_if(Container &C, UnaryPredicate P)
Provide a container algorithm similar to C++ Library Fundamentals v2's erase_if which is equivalent t...
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
static bool isRunOfOnes(unsigned Val, unsigned &MB, unsigned &ME)
Returns true iff Val consists of one contiguous run of 1s with any number of 0s on either side.
MCRegisterClass TargetRegisterClass
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
constexpr uint64_t value() const
This is a hole in the type system and should not be abused.
EVT changeVectorElementTypeToInteger() const
Return a vector with the same number of elements as this vector, but with the element type converted ...
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
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.
EVT getVectorElementType() const
Given a vector type, return the type of each element.
bool isInteger() const
Return true if this is an integer or a vector integer type.