69 #define DEBUG_TYPE "ppc-codegen" 72 "Number of (sext(setcc)) nodes expanded into GPR sequence.");
74 "Number of (zext(setcc)) nodes expanded into GPR sequence.");
76 "Number of sign extensions for compare inputs added.");
78 "Number of zero extensions for compare inputs added.");
80 "Number of logical ops on i1 values calculated in GPR.");
82 "Number of compares not eliminated as they have non-extending uses.");
84 "Number of compares lowered to setb.");
92 cl::desc(
"use aggressive ppc isel for bit permutations"),
95 "ppc-bit-perm-rewriter-stress-rotates",
96 cl::desc(
"stress rotate selection in aggressive ppc isel for " 101 "ppc-use-branch-hint",
cl::init(
true),
102 cl::desc(
"Enable static hinting of branches on ppc"),
107 cl::desc(
"Enable tls optimization peephole"),
116 cl::desc(
"Specify the types of comparisons to emit GPR-only code for."),
122 "Only comparisons where inputs don't need [sz]ext."),
125 "Only i32 comparisons with zext result."),
127 "Only i64 comparisons with zext result."),
130 "Only i32 comparisons with sext result."),
132 "Only i64 comparisons with sext result.")));
157 InsertVRSaveCode(MF);
162 void PreprocessISelDAG()
override;
163 void PostprocessISelDAG()
override;
167 inline SDValue getI16Imm(
unsigned Imm,
const SDLoc &dl) {
168 return CurDAG->getTargetConstant(Imm, dl,
MVT::i16);
173 inline SDValue getI32Imm(
unsigned Imm,
const SDLoc &dl) {
174 return CurDAG->getTargetConstant(Imm, dl,
MVT::i32);
179 inline SDValue getI64Imm(uint64_t Imm,
const SDLoc &dl) {
180 return CurDAG->getTargetConstant(Imm, dl,
MVT::i64);
184 inline SDValue getSmallIPtrImm(
unsigned Imm,
const SDLoc &dl) {
185 return CurDAG->getTargetConstant(
186 Imm, dl, PPCLowering->getPointerTy(CurDAG->getDataLayout()));
191 static bool isRotateAndMask(
SDNode *
N,
unsigned Mask,
bool isShiftMask,
192 unsigned &SH,
unsigned &MB,
unsigned &ME);
196 SDNode *getGlobalBaseReg();
204 bool tryBitfieldInsert(
SDNode *
N);
205 bool tryBitPermutation(
SDNode *
N);
206 bool tryIntCompareInGPR(
SDNode *
N);
207 bool tryAndWithMask(
SDNode *
N);
242 return PPCLowering->SelectAddressRegReg(N, Base, Index, *CurDAG, 0);
252 return PPCLowering->SelectAddressRegReg(N, Base, Index, *CurDAG, 4);
262 return PPCLowering->SelectAddressRegReg(N, Base, Index, *CurDAG, 16);
268 return PPCLowering->SelectAddressRegRegOnly(N, Base, Index, *CurDAG);
277 return PPCLowering->SelectAddressRegImm(N, Disp, Base, *CurDAG, 0);
284 return PPCLowering->SelectAddressRegImm(N, Disp, Base, *CurDAG, 4);
291 return PPCLowering->SelectAddressRegImm(N, Disp, Base, *CurDAG, 16);
305 bool SelectInlineAsmMemoryOperand(
const SDValue &
Op,
306 unsigned ConstraintID,
307 std::vector<SDValue> &OutOps)
override {
308 switch(ConstraintID) {
310 errs() <<
"ConstraintID: " << ConstraintID <<
"\n";
325 SDValue(CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS,
329 OutOps.push_back(NewOp);
338 return "PowerPC DAG->DAG Pattern Instruction Selection";
342 #include "PPCGenDAGISel.inc" 347 void PeepholePPC64();
348 void PeepholePPC64ZExt();
349 void PeepholeCROps();
354 bool AllUsersSelectZero(
SDNode *N);
355 void SwapAllSelectUsers(
SDNode *N);
357 bool isOffsetMultipleOf(
SDNode *N,
unsigned Val)
const;
372 bool HasVectorVReg =
false;
373 for (
unsigned i = 0,
e = RegInfo->getNumVirtRegs(); i !=
e; ++i) {
375 if (RegInfo->getRegClass(Reg) == &PPC::VRRCRegClass) {
376 HasVectorVReg =
true;
380 if (!HasVectorVReg)
return;
394 Register InVRSAVE = RegInfo->createVirtualRegister(&PPC::GPRCRegClass);
395 Register UpdatedVRSAVE = RegInfo->createVirtualRegister(&PPC::GPRCRegClass);
405 BuildMI(EntryBB, IP, dl, TII.
get(PPC::MFVRSAVE), InVRSAVE);
406 BuildMI(EntryBB, IP, dl, TII.
get(PPC::UPDATE_VRSAVE),
407 UpdatedVRSAVE).addReg(InVRSAVE);
408 BuildMI(EntryBB, IP, dl, TII.
get(PPC::MTVRSAVE)).addReg(UpdatedVRSAVE);
412 if (BB->isReturnBlock()) {
413 IP = BB->end(); --IP;
418 while (I2 != BB->begin() && (--I2)->isTerminator())
422 BuildMI(*BB, IP, dl, TII.
get(PPC::MTVRSAVE)).addReg(InVRSAVE);
430 SDNode *PPCDAGToDAGISel::getGlobalBaseReg() {
431 if (!GlobalBaseReg) {
439 if (PPCLowering->getPointerTy(CurDAG->getDataLayout()) ==
MVT::i32) {
441 GlobalBaseReg = PPC::R30;
444 BuildMI(FirstMBB, MBBI, dl, TII.
get(PPC::MoveGOTtoLR));
448 BuildMI(FirstMBB, MBBI, dl, TII.
get(PPC::MovePCtoLR));
450 Register TempReg = RegInfo->createVirtualRegister(&PPC::GPRCRegClass);
458 RegInfo->createVirtualRegister(&PPC::GPRC_and_GPRC_NOR0RegClass);
459 BuildMI(FirstMBB, MBBI, dl, TII.
get(PPC::MovePCtoLR));
473 GlobalBaseReg = RegInfo->createVirtualRegister(&PPC::G8RC_and_G8RC_NOX0RegClass);
474 BuildMI(FirstMBB, MBBI, dl, TII.
get(PPC::MovePCtoLR8));
478 return CurDAG->getRegister(GlobalBaseReg,
479 PPCLowering->getPointerTy(CurDAG->getDataLayout()))
487 Imm = cast<ConstantSDNode>(
N)->getZExtValue();
497 Imm = cast<ConstantSDNode>(
N)->getZExtValue();
518 assert(isa<BasicBlockSDNode>(DestMBB));
548 if (
std::max(TProb, FProb) / Threshold < std::min(TProb, FProb))
552 <<
"::" << BB->
getName() <<
"'\n" 553 <<
" -> " << TBB->
getName() <<
": " << TProb <<
"\n" 554 <<
" -> " << FBB->
getName() <<
": " << FProb <<
"\n");
560 if (BBDN->getBasicBlock()->getBasicBlock() != TBB)
576 int FI = cast<FrameIndexSDNode>(
N)->getIndex();
581 getSmallIPtrImm(Offset, dl));
583 ReplaceNode(SN, CurDAG->getMachineNode(Opc, dl, N->
getValueType(0), TFI,
584 getSmallIPtrImm(Offset, dl)));
587 bool PPCDAGToDAGISel::isRotateAndMask(
SDNode *N,
unsigned Mask,
588 bool isShiftMask,
unsigned &SH,
589 unsigned &MB,
unsigned &ME) {
596 unsigned Indeterminant = ~0;
604 if (isShiftMask) Mask = Mask << Shift;
606 Indeterminant = ~(0xFFFFFFFFu << Shift);
609 if (isShiftMask) Mask = Mask >> Shift;
611 Indeterminant = ~(0xFFFFFFFFu >> Shift);
621 if (Mask && !(Mask & Indeterminant)) {
646 Opcode = (RegVT ==
MVT::i32) ? PPC::STBXTLS_32 : PPC::STBXTLS;
650 Opcode = (RegVT ==
MVT::i32) ? PPC::STHXTLS_32 : PPC::STHXTLS;
654 Opcode = (RegVT ==
MVT::i32) ? PPC::STWXTLS_32 : PPC::STWXTLS;
658 Opcode = PPC::STDXTLS;
666 SDNode *MN = CurDAG->getMachineNode(Opcode, dl, VTs, Ops);
667 transferMemOperands(ST, MN);
688 Opcode = (RegVT ==
MVT::i32) ? PPC::LBZXTLS_32 : PPC::LBZXTLS;
692 Opcode = (RegVT ==
MVT::i32) ? PPC::LHZXTLS_32 : PPC::LHZXTLS;
696 Opcode = (RegVT ==
MVT::i32) ? PPC::LWZXTLS_32 : PPC::LWZXTLS;
700 Opcode = PPC::LDXTLS;
707 SDNode *MN = CurDAG->getMachineNode(Opcode, dl, VTs, Ops);
708 transferMemOperands(LD, MN);
715 bool PPCDAGToDAGISel::tryBitfieldInsert(
SDNode *N) {
720 KnownBits LKnown = CurDAG->computeKnownBits(Op0);
721 KnownBits RKnown = CurDAG->computeKnownBits(Op1);
726 if ((TargetMask | InsertMask) == 0xFFFFFFFF) {
729 unsigned Value, SH = 0;
730 TargetMask = ~TargetMask;
731 InsertMask = ~InsertMask;
759 SH = (Op1Opc ==
ISD::SHL) ? Value : 32 - Value;
774 SH = (SHOpc ==
ISD::SHL) ? Value : 32 - Value;
779 SDValue Ops[] = { Op0, Op1, getI32Imm(SH, dl), getI32Imm(MB, dl),
781 ReplaceNode(N, CurDAG->getMachineNode(PPC::RLWIMI, dl,
MVT::i32, Ops));
792 unsigned Remainder = 0;
798 Shift = countTrailingZeros<uint64_t>(Imm);
799 int64_t ImmSh =
static_cast<uint64_t
>(Imm) >> Shift;
817 unsigned Lo = Imm & 0xFFFF;
832 if (!Shift)
return Result;
836 if ((
unsigned)(Imm & 0xFFFFFFFF) == Remainder) {
846 if ((Remainder >> 16) & 0xFFFF)
848 if (Remainder & 0xFFFF)
854 static uint64_t
Rot64(uint64_t Imm,
unsigned R) {
855 return (Imm << R) | (Imm >> (64 - R));
866 for (
unsigned r = 1; r < 63; ++r) {
867 uint64_t RImm =
Rot64(Imm, r);
869 Count = std::min(Count, RCount);
876 uint64_t OnesMask = -(int64_t) (UINT64_C(1) << (LS+1));
877 uint64_t RImmWithOnes = RImm | OnesMask;
880 Count = std::min(Count, RCount);
891 unsigned Remainder = 0;
897 Shift = countTrailingZeros<uint64_t>(Imm);
898 int64_t ImmSh =
static_cast<uint64_t
>(Imm) >> Shift;
916 unsigned Lo = Imm & 0xFFFF;
917 unsigned Hi = (Imm >> 16) & 0xFFFF;
919 auto getI32Imm = [CurDAG, dl](
unsigned Imm) {
931 unsigned OpC = Hi ? PPC::LIS8 : PPC::LI8;
935 SDValue(Result, 0), getI32Imm(Lo));
942 if (!Shift)
return Result;
946 if ((
unsigned)(Imm & 0xFFFFFFFF) == Remainder) {
948 {
SDValue(Result, 0),
SDValue(Result, 0), getI32Imm(Shift), getI32Imm(0)};
957 getI32Imm(63 - Shift));
961 if ((Hi = (Remainder >> 16) & 0xFFFF)) {
963 SDValue(Result, 0), getI32Imm(Hi));
965 if ((Lo = Remainder & 0xFFFF)) {
967 SDValue(Result, 0), getI32Imm(Lo));
987 for (
unsigned r = 1; r < 63; ++r) {
988 uint64_t RImm =
Rot64(Imm, r);
990 if (RCount < Count) {
1009 uint64_t OnesMask = -(int64_t) (UINT64_C(1) << (LS+1));
1010 uint64_t RImmWithOnes = RImm | OnesMask;
1013 if (RCount < Count) {
1016 MatImm = RImmWithOnes;
1024 auto getI32Imm = [CurDAG, dl](
unsigned Imm) {
1030 getI32Imm(64 - RMin), getI32Imm(MaskEnd));
1034 unsigned MaxTruncation = 0;
1041 Use->isMachineOpcode() ?
Use->getMachineOpcode() :
Use->getOpcode();
1045 if (
Use->isMachineOpcode())
1048 std::max(MaxTruncation, (
unsigned)
Use->getValueType(0).getSizeInBits());
1051 if (
Use->isMachineOpcode())
1055 if (MemVTSize == 64 || Use.getOperandNo() != 0)
1057 MaxTruncation =
std::max(MaxTruncation, MemVTSize);
1066 MaxTruncation =
std::max(MaxTruncation, 32u);
1074 MaxTruncation =
std::max(MaxTruncation, 16u);
1082 MaxTruncation =
std::max(MaxTruncation, 8u);
1086 return MaxTruncation;
1094 int64_t Imm = cast<ConstantSDNode>(
N)->getZExtValue();
1106 class BitPermutationSelector {
1121 VariableKnownToBeZero
1125 : V(V), Idx(I), K(K) {}
1126 ValueBit(
Kind K = Variable)
1127 : V(
SDValue(
nullptr, 0)), Idx(UINT32_MAX), K(K) {}
1130 return K == ConstZero || K == VariableKnownToBeZero;
1133 bool hasValue()
const {
1134 return K == Variable || K == VariableKnownToBeZero;
1138 assert(hasValue() &&
"Cannot get the value of a constant bit");
1142 unsigned getValueBitIndex()
const {
1143 assert(hasValue() &&
"Cannot get the value bit index of a constant bit");
1152 unsigned StartIdx, EndIdx;
1162 bool Repl32Coalesced;
1164 BitGroup(
SDValue V,
unsigned R,
unsigned S,
unsigned E)
1165 : V(V), RLAmt(R), StartIdx(S), EndIdx(E), Repl32(
false), Repl32CR(
false),
1166 Repl32Coalesced(
false) {
1168 <<
" [" << S <<
", " << E <<
"]\n");
1174 struct ValueRotInfo {
1177 unsigned NumGroups = 0;
1179 bool Repl32 =
false;
1181 ValueRotInfo() =
default;
1189 if (Repl32 < Other.Repl32)
1191 else if (Repl32 > Other.Repl32)
1193 else if (NumGroups > Other.NumGroups)
1195 else if (NumGroups < Other.NumGroups)
1197 else if (RLAmt == 0 && Other.RLAmt != 0)
1199 else if (RLAmt != 0 && Other.RLAmt == 0)
1201 else if (FirstGroupStartIdx < Other.FirstGroupStartIdx)
1207 using ValueBitsMemoizedValue = std::pair<bool, SmallVector<ValueBit, 64>>;
1208 using ValueBitsMemoizer =
1210 ValueBitsMemoizer Memoizer;
1216 std::pair<bool, SmallVector<ValueBit, 64> *> getValueBits(
SDValue V,
1218 auto &ValueEntry = Memoizer[V];
1220 return std::make_pair(ValueEntry->first, &ValueEntry->second);
1221 ValueEntry.reset(
new ValueBitsMemoizedValue());
1222 bool &Interesting = ValueEntry->first;
1234 for (
unsigned i = 0; i < NumBits; ++i)
1235 Bits[i] = LHSBits[i < RotAmt ? i + (NumBits - RotAmt) : i - RotAmt];
1237 return std::make_pair(Interesting =
true, &Bits);
1246 for (
unsigned i = ShiftAmt; i < NumBits; ++i)
1247 Bits[i] = LHSBits[i - ShiftAmt];
1249 for (
unsigned i = 0; i < ShiftAmt; ++i)
1250 Bits[i] = ValueBit(ValueBit::ConstZero);
1252 return std::make_pair(Interesting =
true, &Bits);
1261 for (
unsigned i = 0; i < NumBits - ShiftAmt; ++i)
1262 Bits[i] = LHSBits[i + ShiftAmt];
1264 for (
unsigned i = NumBits - ShiftAmt; i < NumBits; ++i)
1265 Bits[i] = ValueBit(ValueBit::ConstZero);
1267 return std::make_pair(Interesting =
true, &Bits);
1279 std::tie(Interesting, LHSBits) = getValueBits(V.
getOperand(0), NumBits);
1281 for (
unsigned i = 0; i < NumBits; ++i)
1282 if (((Mask >> i) & 1) == 1)
1283 Bits[i] = (*LHSBits)[i];
1287 if ((*LHSBits)[i].isZero())
1288 Bits[i] = (*LHSBits)[i];
1290 Bits[i] = ValueBit(ValueBit::ConstZero);
1293 return std::make_pair(Interesting, &Bits);
1300 bool AllDisjoint =
true;
1302 unsigned LastIdx = 0;
1303 for (
unsigned i = 0; i < NumBits; ++i) {
1311 if (LHSBits[i].hasValue() && LHSBits[i].getValue() == LastVal &&
1312 LHSBits[i].getValueBitIndex() == LastIdx + 1)
1313 Bits[i] = LHSBits[i];
1314 else if (RHSBits[i].hasValue() && RHSBits[i].getValue() == LastVal &&
1315 RHSBits[i].getValueBitIndex() == LastIdx + 1)
1316 Bits[i] = RHSBits[i];
1318 Bits[i] = ValueBit(ValueBit::ConstZero);
1320 else if (LHSBits[i].
isZero())
1321 Bits[i] = RHSBits[i];
1322 else if (RHSBits[i].
isZero())
1323 Bits[i] = LHSBits[i];
1325 AllDisjoint =
false;
1329 if (Bits[i].hasValue()) {
1330 LastVal = Bits[i].getValue();
1331 LastIdx = Bits[i].getValueBitIndex();
1334 if (LastVal) LastVal =
SDValue();
1342 return std::make_pair(Interesting =
true, &Bits);
1351 const unsigned NumOperandBits = 32;
1352 std::tie(Interesting, LHSBits) = getValueBits(V.
getOperand(0),
1355 for (
unsigned i = 0; i < NumOperandBits; ++i)
1356 Bits[i] = (*LHSBits)[i];
1358 for (
unsigned i = NumOperandBits; i < NumBits; ++i)
1359 Bits[i] = ValueBit(ValueBit::ConstZero);
1361 return std::make_pair(Interesting, &Bits);
1371 std::tie(Interesting, InBits) = getValueBits(V.
getOperand(0),
1377 bool UseUpper32bit =
false;
1378 for (
unsigned i = 0; i < NumValidBits; ++i)
1379 if ((*InBits)[i].hasValue() && (*InBits)[i].getValueBitIndex() >= 32) {
1380 UseUpper32bit =
true;
1386 for (
unsigned i = 0; i < NumValidBits; ++i)
1387 Bits[i] = (*InBits)[i];
1389 return std::make_pair(Interesting, &Bits);
1395 std::tie(Interesting, LHSBits) = getValueBits(V.
getOperand(0),
1399 const unsigned NumValidBits = FromType.getSizeInBits();
1400 for (
unsigned i = 0; i < NumValidBits; ++i)
1401 Bits[i] = (*LHSBits)[i];
1405 for (
unsigned i = NumValidBits; i < NumBits; ++i)
1406 Bits[i] = (*LHSBits)[i].hasValue()
1407 ? ValueBit((*LHSBits)[i].getValue(),
1408 (*LHSBits)[i].getValueBitIndex(),
1409 ValueBit::VariableKnownToBeZero)
1410 : ValueBit(ValueBit::ConstZero);
1412 return std::make_pair(Interesting, &Bits);
1420 for (
unsigned i = 0; i < NumValidBits; ++i)
1421 Bits[i] = ValueBit(V, i);
1424 for (
unsigned i = NumValidBits; i < NumBits; ++i)
1425 Bits[i] = ValueBit(V, i, ValueBit::VariableKnownToBeZero);
1429 return std::make_pair(Interesting =
false, &Bits);
1434 for (
unsigned i = 0; i < NumBits; ++i)
1435 Bits[i] = ValueBit(V, i);
1437 return std::make_pair(Interesting =
false, &Bits);
1442 void computeRotationAmounts() {
1444 RLAmt.resize(
Bits.size());
1445 for (
unsigned i = 0; i <
Bits.size(); ++i)
1446 if (
Bits[i].hasValue()) {
1447 unsigned VBI =
Bits[i].getValueBitIndex();
1451 RLAmt[i] =
Bits.size() - (VBI - i);
1454 RLAmt[i] = UINT32_MAX;
1463 void collectBitGroups(
bool LateMask) {
1466 unsigned LastRLAmt = RLAmt[0];
1468 unsigned LastGroupStartIdx = 0;
1469 bool IsGroupOfZeros = !
Bits[LastGroupStartIdx].hasValue();
1470 for (
unsigned i = 1; i <
Bits.size(); ++i) {
1471 unsigned ThisRLAmt = RLAmt[i];
1473 if (LateMask && !ThisValue) {
1474 ThisValue = LastValue;
1475 ThisRLAmt = LastRLAmt;
1478 if (BitGroups.empty())
1479 LastGroupStartIdx = 0;
1491 if (ThisRLAmt == LastRLAmt && ThisValue == LastValue)
1494 if (!(IsGroupOfZeros && ThisValue && !
Bits[i].
isZero()))
1498 BitGroups.push_back(BitGroup(LastValue, LastRLAmt, LastGroupStartIdx,
1500 LastRLAmt = ThisRLAmt;
1501 LastValue = ThisValue;
1502 LastGroupStartIdx = i;
1503 IsGroupOfZeros = !
Bits[LastGroupStartIdx].hasValue();
1506 BitGroups.push_back(BitGroup(LastValue, LastRLAmt, LastGroupStartIdx,
1509 if (BitGroups.empty())
1513 if (BitGroups.size() > 1) {
1517 if (BitGroups[0].StartIdx == 0 &&
1518 BitGroups[BitGroups.size()-1].EndIdx ==
Bits.size()-1 &&
1519 BitGroups[0].V == BitGroups[BitGroups.size()-1].V &&
1520 BitGroups[0].RLAmt == BitGroups[BitGroups.size()-1].RLAmt) {
1521 LLVM_DEBUG(
dbgs() <<
"\tcombining final bit group with initial one\n");
1522 BitGroups[BitGroups.size()-1].EndIdx = BitGroups[0].EndIdx;
1523 BitGroups.erase(BitGroups.begin());
1533 void collectValueRotInfo() {
1536 for (
auto &BG : BitGroups) {
1537 unsigned RLAmtKey = BG.RLAmt + (BG.Repl32 ? 64 : 0);
1538 ValueRotInfo &VRI = ValueRots[std::make_pair(BG.V, RLAmtKey)];
1540 VRI.RLAmt = BG.RLAmt;
1541 VRI.Repl32 = BG.Repl32;
1543 VRI.FirstGroupStartIdx = std::min(VRI.FirstGroupStartIdx, BG.StartIdx);
1548 ValueRotsVec.clear();
1549 for (
auto &
I : ValueRots) {
1550 ValueRotsVec.push_back(
I.second);
1563 void assignRepl32BitGroups() {
1574 auto IsAllLow32 = [
this](BitGroup & BG) {
1575 if (BG.StartIdx <= BG.EndIdx) {
1576 for (
unsigned i = BG.StartIdx; i <= BG.EndIdx; ++i) {
1577 if (!
Bits[i].hasValue())
1579 if (
Bits[i].getValueBitIndex() >= 32)
1583 for (
unsigned i = BG.StartIdx; i <
Bits.size(); ++i) {
1584 if (!
Bits[i].hasValue())
1586 if (
Bits[i].getValueBitIndex() >= 32)
1589 for (
unsigned i = 0; i <= BG.EndIdx; ++i) {
1590 if (!
Bits[i].hasValue())
1592 if (
Bits[i].getValueBitIndex() >= 32)
1600 for (
auto &BG : BitGroups) {
1604 if (BG.RLAmt == 0) {
1605 auto PotentiallyMerged = [
this](BitGroup & BG) {
1606 for (
auto &BG2 : BitGroups)
1607 if (&BG != &BG2 && BG.V == BG2.V &&
1608 (BG2.RLAmt == 0 || BG2.RLAmt == 32))
1612 if (!PotentiallyMerged(BG))
1615 if (BG.StartIdx < 32 && BG.EndIdx < 32) {
1616 if (IsAllLow32(BG)) {
1617 if (BG.RLAmt >= 32) {
1625 << BG.V.getNode() <<
" RLAmt = " << BG.RLAmt <<
" [" 1626 << BG.StartIdx <<
", " << BG.EndIdx <<
"]\n");
1632 for (
auto I = BitGroups.begin();
I != BitGroups.end();) {
1635 auto IP = (
I == BitGroups.begin()) ?
1636 std::prev(BitGroups.end()) : std::prev(
I);
1637 if (
I->Repl32 && IP->Repl32 &&
I->V == IP->V &&
I->RLAmt == IP->RLAmt &&
1638 I->StartIdx == (IP->EndIdx + 1) % 64 &&
I != IP) {
1640 LLVM_DEBUG(
dbgs() <<
"\tcombining 32-bit replicated bit group for " 1641 <<
I->V.getNode() <<
" RLAmt = " <<
I->RLAmt <<
" [" 1642 <<
I->StartIdx <<
", " <<
I->EndIdx
1643 <<
"] with group with range [" << IP->StartIdx <<
", " 1644 << IP->EndIdx <<
"]\n");
1646 IP->EndIdx =
I->EndIdx;
1647 IP->Repl32CR = IP->Repl32CR ||
I->Repl32CR;
1648 IP->Repl32Coalesced =
true;
1649 I = BitGroups.erase(
I);
1658 if (
I->StartIdx == 32 &&
I->EndIdx == 63) {
1659 assert(std::next(
I) == BitGroups.end() &&
1660 "bit group ends at index 63 but there is another?");
1661 auto IN = BitGroups.begin();
1663 if (IP->Repl32 && IN->Repl32 &&
I->V == IP->V &&
I->V == IN->V &&
1664 (
I->RLAmt % 32) == IP->RLAmt && (
I->RLAmt % 32) == IN->RLAmt &&
1665 IP->EndIdx == 31 && IN->StartIdx == 0 &&
I != IP &&
1669 <<
" RLAmt = " <<
I->RLAmt <<
" [" <<
I->StartIdx
1670 <<
", " <<
I->EndIdx
1671 <<
"] with 32-bit replicated groups with ranges [" 1672 << IP->StartIdx <<
", " << IP->EndIdx <<
"] and [" 1673 << IN->StartIdx <<
", " << IN->EndIdx <<
"]\n");
1681 IP->Repl32CR = IP->Repl32CR ||
I->RLAmt >= 32;
1682 IP->Repl32Coalesced =
true;
1683 I = BitGroups.erase(
I);
1688 IP->EndIdx = IN->EndIdx;
1689 IP->Repl32CR = IP->Repl32CR || IN->Repl32CR ||
I->RLAmt >= 32;
1690 IP->Repl32Coalesced =
true;
1691 I = BitGroups.erase(
I);
1692 BitGroups.erase(BitGroups.begin());
1707 return CurDAG->getTargetConstant(Imm, dl,
MVT::i32);
1710 uint64_t getZerosMask() {
1712 for (
unsigned i = 0; i <
Bits.size(); ++i) {
1713 if (
Bits[i].hasValue())
1715 Mask |= (UINT64_C(1) << i);
1730 SDValue SubRegIdx = CurDAG->getTargetConstant(PPC::sub_32, dl,
MVT::i32);
1731 SDValue ImDef =
SDValue(CurDAG->getMachineNode(PPC::IMPLICIT_DEF, dl,
1733 SDValue ExtVal =
SDValue(CurDAG->getMachineNode(PPC::INSERT_SUBREG, dl,
1744 SDValue SubRegIdx = CurDAG->getTargetConstant(PPC::sub_32, dl,
MVT::i32);
1745 SDValue SubVal =
SDValue(CurDAG->getMachineNode(PPC::EXTRACT_SUBREG, dl,
1753 void SelectAndParts32(
const SDLoc &dl,
SDValue &Res,
unsigned *InstCnt) {
1757 for (ValueRotInfo &VRI : ValueRotsVec) {
1759 for (
unsigned i = 0; i <
Bits.size(); ++i) {
1760 if (!
Bits[i].hasValue() ||
Bits[i].getValue() != VRI.V)
1762 if (RLAmt[i] != VRI.RLAmt)
1768 unsigned ANDIMask = (Mask & UINT16_MAX), ANDISMask = Mask >> 16;
1769 assert((ANDIMask != 0 || ANDISMask != 0) &&
1770 "No set bits in mask for value bit groups");
1771 bool NeedsRotate = VRI.RLAmt != 0;
1787 unsigned NumAndInsts = (
unsigned) NeedsRotate +
1788 (
unsigned) (ANDIMask != 0) +
1789 (
unsigned) (ANDISMask != 0) +
1790 (
unsigned) (ANDIMask != 0 && ANDISMask != 0) +
1791 (
unsigned) (
bool) Res;
1793 LLVM_DEBUG(
dbgs() <<
"\t\trotation groups for " << VRI.V.getNode()
1794 <<
" RL: " << VRI.RLAmt <<
":" 1795 <<
"\n\t\t\tisel using masking: " << NumAndInsts
1796 <<
" using rotates: " << VRI.NumGroups <<
"\n");
1798 if (NumAndInsts >= VRI.NumGroups)
1803 if (InstCnt) *InstCnt += NumAndInsts;
1808 { TruncateToInt32(VRI.V, dl), getI32Imm(VRI.RLAmt, dl),
1809 getI32Imm(0, dl), getI32Imm(31, dl) };
1813 VRot = TruncateToInt32(VRI.V, dl);
1819 VRot, getI32Imm(ANDIMask, dl)),
1824 getI32Imm(ANDISMask, dl)),
1829 TotalVal = ANDISVal;
1834 ANDIVal, ANDISVal), 0);
1844 eraseMatchingBitGroups([VRI](
const BitGroup &BG) {
1845 return BG.V == VRI.V && BG.RLAmt == VRI.RLAmt;
1851 SDNode *Select32(
SDNode *N,
bool LateMask,
unsigned *InstCnt) {
1855 if (InstCnt) *InstCnt = 0;
1858 SelectAndParts32(dl, Res, InstCnt);
1863 if ((!NeedMask || LateMask) && !Res) {
1864 ValueRotInfo &VRI = ValueRotsVec[0];
1866 if (InstCnt) *InstCnt += 1;
1868 { TruncateToInt32(VRI.V, dl), getI32Imm(VRI.RLAmt, dl),
1869 getI32Imm(0, dl), getI32Imm(31, dl) };
1873 Res = TruncateToInt32(VRI.V, dl);
1877 eraseMatchingBitGroups([VRI](
const BitGroup &BG) {
1878 return BG.V == VRI.V && BG.RLAmt == VRI.RLAmt;
1882 if (InstCnt) *InstCnt += BitGroups.size();
1885 for (
auto &BG : BitGroups) {
1888 { TruncateToInt32(BG.V, dl), getI32Imm(BG.RLAmt, dl),
1889 getI32Imm(
Bits.size() - BG.EndIdx - 1, dl),
1890 getI32Imm(
Bits.size() - BG.StartIdx - 1, dl) };
1891 Res =
SDValue(CurDAG->getMachineNode(PPC::RLWINM, dl,
MVT::i32, Ops), 0);
1894 { Res, TruncateToInt32(BG.V, dl), getI32Imm(BG.RLAmt, dl),
1895 getI32Imm(
Bits.size() - BG.EndIdx - 1, dl),
1896 getI32Imm(
Bits.size() - BG.StartIdx - 1, dl) };
1897 Res =
SDValue(CurDAG->getMachineNode(PPC::RLWIMI, dl,
MVT::i32, Ops), 0);
1902 unsigned Mask = (
unsigned) getZerosMask();
1904 unsigned ANDIMask = (Mask & UINT16_MAX), ANDISMask = Mask >> 16;
1905 assert((ANDIMask != 0 || ANDISMask != 0) &&
1906 "No set bits in zeros mask?");
1908 if (InstCnt) *InstCnt += (
unsigned) (ANDIMask != 0) +
1910 (
unsigned) (ANDIMask != 0 && ANDISMask != 0);
1915 Res, getI32Imm(ANDIMask, dl)),
1920 getI32Imm(ANDISMask, dl)),
1929 ANDIVal, ANDISVal), 0);
1935 unsigned SelectRotMask64Count(
unsigned RLAmt,
bool Repl32,
1936 unsigned MaskStart,
unsigned MaskEnd,
1940 unsigned InstMaskStart = 64 - MaskEnd - 1,
1941 InstMaskEnd = 64 - MaskStart - 1;
1946 if ((!IsIns && (InstMaskEnd == 63 || InstMaskStart == 0)) ||
1947 InstMaskEnd == 63 - RLAmt)
1956 bool Repl32,
unsigned MaskStart,
unsigned MaskEnd,
1957 unsigned *InstCnt =
nullptr) {
1960 unsigned InstMaskStart = 64 - MaskEnd - 1,
1961 InstMaskEnd = 64 - MaskStart - 1;
1963 if (InstCnt) *InstCnt += 1;
1969 assert(InstMaskStart >= 32 &&
"Mask cannot start out of range");
1970 assert(InstMaskEnd >= 32 &&
"Mask cannot end out of range");
1972 { ExtendToInt64(V, dl), getI32Imm(RLAmt, dl),
1973 getI32Imm(InstMaskStart - 32, dl), getI32Imm(InstMaskEnd - 32, dl) };
1978 if (InstMaskEnd == 63) {
1980 { ExtendToInt64(V, dl), getI32Imm(RLAmt, dl),
1981 getI32Imm(InstMaskStart, dl) };
1982 return SDValue(CurDAG->getMachineNode(PPC::RLDICL, dl,
MVT::i64, Ops), 0);
1985 if (InstMaskStart == 0) {
1987 { ExtendToInt64(V, dl), getI32Imm(RLAmt, dl),
1988 getI32Imm(InstMaskEnd, dl) };
1989 return SDValue(CurDAG->getMachineNode(PPC::RLDICR, dl,
MVT::i64, Ops), 0);
1992 if (InstMaskEnd == 63 - RLAmt) {
1994 { ExtendToInt64(V, dl), getI32Imm(RLAmt, dl),
1995 getI32Imm(InstMaskStart, dl) };
1996 return SDValue(CurDAG->getMachineNode(PPC::RLDIC, dl,
MVT::i64, Ops), 0);
2005 if (InstCnt) *InstCnt += 1;
2008 unsigned RLAmt2 = MaskStart;
2011 unsigned RLAmt1 = (64 + RLAmt - RLAmt2) % 64;
2013 V = SelectRotMask64(V, dl, RLAmt1,
false, 0, 63);
2014 return SelectRotMask64(V, dl, RLAmt2,
false, MaskStart, MaskEnd);
2020 unsigned RLAmt,
bool Repl32,
unsigned MaskStart,
2021 unsigned MaskEnd,
unsigned *InstCnt =
nullptr) {
2024 unsigned InstMaskStart = 64 - MaskEnd - 1,
2025 InstMaskEnd = 64 - MaskStart - 1;
2027 if (InstCnt) *InstCnt += 1;
2033 assert(InstMaskStart >= 32 &&
"Mask cannot start out of range");
2034 assert(InstMaskEnd >= 32 &&
"Mask cannot end out of range");
2036 { ExtendToInt64(Base, dl), ExtendToInt64(V, dl), getI32Imm(RLAmt, dl),
2037 getI32Imm(InstMaskStart - 32, dl), getI32Imm(InstMaskEnd - 32, dl) };
2042 if (InstMaskEnd == 63 - RLAmt) {
2044 { ExtendToInt64(Base, dl), ExtendToInt64(V, dl), getI32Imm(RLAmt, dl),
2045 getI32Imm(InstMaskStart, dl) };
2046 return SDValue(CurDAG->getMachineNode(PPC::RLDIMI, dl,
MVT::i64, Ops), 0);
2055 if (InstCnt) *InstCnt += 1;
2058 unsigned RLAmt2 = MaskStart;
2061 unsigned RLAmt1 = (64 + RLAmt - RLAmt2) % 64;
2063 V = SelectRotMask64(V, dl, RLAmt1,
false, 0, 63);
2064 return SelectRotMaskIns64(Base, V, dl, RLAmt2,
false, MaskStart, MaskEnd);
2067 void SelectAndParts64(
const SDLoc &dl,
SDValue &Res,
unsigned *InstCnt) {
2080 for (ValueRotInfo &VRI : ValueRotsVec) {
2088 auto MatchingBG = [VRI](
const BitGroup &BG) {
2092 unsigned EffRLAmt = BG.RLAmt;
2093 if (!VRI.Repl32 && BG.Repl32) {
2094 if (BG.StartIdx < 32 && BG.EndIdx < 32 && BG.StartIdx <= BG.EndIdx &&
2095 !BG.Repl32Coalesced) {
2101 }
else if (VRI.Repl32 != BG.Repl32) {
2105 return VRI.RLAmt == EffRLAmt;
2108 for (
auto &BG : BitGroups) {
2109 if (!MatchingBG(BG))
2112 if (BG.StartIdx <= BG.EndIdx) {
2113 for (
unsigned i = BG.StartIdx; i <= BG.EndIdx; ++i)
2114 Mask |= (UINT64_C(1) << i);
2116 for (
unsigned i = BG.StartIdx; i <
Bits.size(); ++i)
2117 Mask |= (UINT64_C(1) << i);
2118 for (
unsigned i = 0; i <= BG.EndIdx; ++i)
2119 Mask |= (UINT64_C(1) << i);
2128 unsigned ANDIMask = (Mask & UINT16_MAX),
2129 ANDISMask = (Mask >> 16) & UINT16_MAX;
2131 bool NeedsRotate = VRI.RLAmt || (VRI.Repl32 && !
isUInt<32>(
Mask));
2133 unsigned NumAndInsts = (
unsigned) NeedsRotate +
2134 (
unsigned) (
bool) Res;
2137 (
unsigned) (ANDIMask != 0 && ANDISMask != 0);
2141 unsigned NumRLInsts = 0;
2142 bool FirstBG =
true;
2143 bool MoreBG =
false;
2144 for (
auto &BG : BitGroups) {
2145 if (!MatchingBG(BG)) {
2150 SelectRotMask64Count(BG.RLAmt, BG.Repl32, BG.StartIdx, BG.EndIdx,
2155 LLVM_DEBUG(
dbgs() <<
"\t\trotation groups for " << VRI.V.getNode()
2156 <<
" RL: " << VRI.RLAmt << (VRI.Repl32 ?
" (32):" :
":")
2157 <<
"\n\t\t\tisel using masking: " << NumAndInsts
2158 <<
" using rotates: " << NumRLInsts <<
"\n");
2164 if (NumAndInsts > NumRLInsts)
2169 if ((Use32BitInsts || MoreBG) && NumAndInsts == NumRLInsts)
2174 if (InstCnt) *InstCnt += NumAndInsts;
2181 if (VRI.RLAmt || (VRI.Repl32 && !
isUInt<32>(Mask)))
2182 VRot = SelectRotMask64(VRI.V, dl, VRI.RLAmt, VRI.Repl32,
2183 VRI.Repl32 ? 31 : 0, VRI.Repl32 ? 30 : 63);
2188 if (Use32BitInsts) {
2189 assert((ANDIMask != 0 || ANDISMask != 0) &&
2190 "No set bits in mask when using 32-bit ands for 64-bit value");
2194 ANDIVal =
SDValue(CurDAG->getMachineNode(PPC::ANDI8_rec, dl,
MVT::i64,
2195 ExtendToInt64(VRot, dl),
2196 getI32Imm(ANDIMask, dl)),
2201 ExtendToInt64(VRot, dl),
2202 getI32Imm(ANDISMask, dl)),
2206 TotalVal = ANDISVal;
2211 ExtendToInt64(ANDIVal, dl), ANDISVal), 0);
2216 ExtendToInt64(VRot, dl), TotalVal),
2224 ExtendToInt64(Res, dl), TotalVal),
2229 eraseMatchingBitGroups(MatchingBG);
2234 SDNode *Select64(
SDNode *N,
bool LateMask,
unsigned *InstCnt) {
2238 if (InstCnt) *InstCnt = 0;
2241 SelectAndParts64(dl, Res, InstCnt);
2246 if ((!NeedMask || LateMask) && !Res) {
2250 unsigned MaxGroupsIdx = 0;
2251 if (!ValueRotsVec[0].Repl32) {
2252 for (
unsigned i = 0, ie = ValueRotsVec.size(); i < ie; ++i)
2253 if (ValueRotsVec[i].Repl32) {
2254 if (ValueRotsVec[i].NumGroups > ValueRotsVec[0].NumGroups)
2260 ValueRotInfo &VRI = ValueRotsVec[MaxGroupsIdx];
2261 bool NeedsRotate =
false;
2264 }
else if (VRI.Repl32) {
2265 for (
auto &BG : BitGroups) {
2266 if (BG.V != VRI.V || BG.RLAmt != VRI.RLAmt ||
2267 BG.Repl32 != VRI.Repl32)
2272 if (BG.StartIdx < 32 && BG.EndIdx < 32 && BG.StartIdx < BG.EndIdx)
2281 Res = SelectRotMask64(VRI.V, dl, VRI.RLAmt, VRI.Repl32,
2282 VRI.Repl32 ? 31 : 0, VRI.Repl32 ? 30 : 63,
2289 eraseMatchingBitGroups([VRI](
const BitGroup &BG) {
2290 return BG.V == VRI.V && BG.RLAmt == VRI.RLAmt &&
2291 BG.Repl32 == VRI.Repl32;
2298 for (
auto I = BitGroups.begin(),
IE = BitGroups.end();
I !=
IE; ++
I) {
2299 if (SelectRotMask64Count(
I->RLAmt,
I->Repl32,
I->StartIdx,
I->EndIdx,
2301 SelectRotMask64Count(
I->RLAmt,
I->Repl32,
I->StartIdx,
I->EndIdx,
2303 if (
I != BitGroups.begin()) {
2306 BitGroups.insert(BitGroups.begin(), BG);
2314 for (
auto &BG : BitGroups) {
2316 Res = SelectRotMask64(BG.V, dl, BG.RLAmt, BG.Repl32, BG.StartIdx,
2317 BG.EndIdx, InstCnt);
2319 Res = SelectRotMaskIns64(Res, BG.V, dl, BG.RLAmt, BG.Repl32,
2320 BG.StartIdx, BG.EndIdx, InstCnt);
2324 uint64_t Mask = getZerosMask();
2331 unsigned ANDIMask = (Mask & UINT16_MAX),
2332 ANDISMask = (Mask >> 16) & UINT16_MAX;
2334 if (Use32BitInsts) {
2335 assert((ANDIMask != 0 || ANDISMask != 0) &&
2336 "No set bits in mask when using 32-bit ands for 64-bit value");
2338 if (InstCnt) *InstCnt += (
unsigned) (ANDIMask != 0) +
2340 (
unsigned) (ANDIMask != 0 && ANDISMask != 0);
2344 ANDIVal =
SDValue(CurDAG->getMachineNode(PPC::ANDI8_rec, dl,
MVT::i64,
2345 ExtendToInt64(Res, dl),
2346 getI32Imm(ANDIMask, dl)),
2351 ExtendToInt64(Res, dl),
2352 getI32Imm(ANDISMask, dl)),
2361 ExtendToInt64(ANDIVal, dl), ANDISVal), 0);
2368 ExtendToInt64(Res, dl), MaskVal), 0);
2377 collectBitGroups(LateMask);
2378 if (BitGroups.empty())
2382 if (
Bits.size() == 64)
2383 assignRepl32BitGroups();
2386 collectValueRotInfo();
2388 if (
Bits.size() == 32) {
2389 return Select32(N, LateMask, InstCnt);
2391 assert(
Bits.size() == 64 &&
"Not 64 bits here?");
2392 return Select64(N, LateMask, InstCnt);
2398 void eraseMatchingBitGroups(
function_ref<
bool(
const BitGroup &)>
F) {
2399 BitGroups.erase(
remove_if(BitGroups,
F), BitGroups.end());
2404 bool NeedMask =
false;
2427 Bits = std::move(*Result.second);
2429 LLVM_DEBUG(
dbgs() <<
"Considering bit-permutation-based instruction" 2430 " selection for: ");
2434 computeRotationAmounts();
2447 unsigned InstCnt = 0, InstCntLateMask = 0;
2450 LLVM_DEBUG(
dbgs() <<
"\t\tisel would use " << InstCnt <<
" instructions\n");
2455 <<
" instructions\n");
2457 if (InstCnt <= InstCntLateMask) {
2467 class IntegerCompareEliminator {
2472 enum ExtOrTruncConversion {
Ext, Trunc };
2480 enum SetccInGPROpts { ZExtOrig, ZExtInvert, SExtOrig, SExtInvert };
2490 enum ZeroCompare { GEZExt, GESExt, LEZExt, LESExt };
2497 SDValue addExtOrTrunc(
SDValue NatWidthRes, ExtOrTruncConversion Conv);
2501 int64_t RHSValue,
SDLoc dl);
2503 int64_t RHSValue,
SDLoc dl);
2505 int64_t RHSValue,
SDLoc dl);
2507 int64_t RHSValue,
SDLoc dl);
2512 PPCDAGToDAGISel *Sel) : CurDAG(DAG), S(Sel) {
2515 "Only expecting to use this on 64 bit targets.");
2531 return tryEXTEND(N);
2535 return tryLogicOpOfCompares(N);
2541 static bool isLogicOp(
unsigned Opc) {
2546 SDNode *IntegerCompareEliminator::tryEXTEND(
SDNode *N) {
2549 "Expecting a zero/sign extend node!");
2556 WideRes = computeLogicOpInGPR(N->
getOperand(0));
2563 SetccInGPROpts::SExtOrig : SetccInGPROpts::ZExtOrig);
2576 if (Input32Bit != Output32Bit)
2578 ExtOrTruncConversion::Trunc);
2586 SDNode *IntegerCompareEliminator::tryLogicOpOfCompares(
SDNode *N) {
2590 "Expected a logic operation on setcc results.");
2592 if (!LoweredLogical)
2597 unsigned SubRegToExtract = IsBitwiseNegate ? PPC::sub_eq : PPC::sub_gt;
2606 if (IsBitwiseNegate &&
2609 else if (IsBitwiseNegate)
2611 OpToConvToRecForm = LoweredLogical.
getOperand(0);
2615 OpToConvToRecForm = LoweredLogical;
2625 if (NewOpc != -1 && IsBitwiseNegate) {
2628 "Expected a PPC::XORI8 only for bitwise negation.");
2630 std::vector<SDValue> Ops;
2632 Ops.push_back(OpToConvToRecForm.
getOperand(i));
2635 SDValue(CurDAG->getMachineNode(NewOpc, dl,
2639 assert((NewOpc != -1 || !IsBitwiseNegate) &&
2640 "No record form available for AND8/OR8/XOR8?");
2642 SDValue(CurDAG->getMachineNode(NewOpc == -1 ? PPC::ANDI8_rec : NewOpc,
2652 CurDAG->getTargetConstant(SubRegToExtract, dl,
MVT::i32);
2654 SDValue(CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG, dl,
2668 SDValue IntegerCompareEliminator::computeLogicOpInGPR(
SDValue LogicOp) {
2670 "Can only handle logic operations here.");
2672 "Can only handle logic operations on i1 values here.");
2684 unsigned OperandOpcode = Operand.
getOpcode();
2686 return getSETCCInGPR(Operand, SetccInGPROpts::ZExtOrig);
2690 return SDValue(CurDAG->getMachineNode(InVT ==
MVT::i32 ? PPC::RLDICL_32 :
2691 PPC::RLDICL, dl, InVT, InputOp,
2692 S->getI64Imm(0, dl),
2693 S->getI64Imm(63, dl)), 0);
2694 }
else if (isLogicOp(OperandOpcode))
2695 return computeLogicOpInGPR(Operand);
2698 LHS = getLogicOperand(LogicOp.
getOperand(0));
2699 RHS = getLogicOperand(LogicOp.
getOperand(1));
2704 if (!LHS || (!RHS && !IsBitwiseNegation))
2707 NumLogicOpsOnComparison++;
2712 if (!IsBitwiseNegation && RHS.getValueType() ==
MVT::i32)
2718 case ISD::AND: NewOpc = PPC::AND8;
break;
2719 case ISD::OR: NewOpc = PPC::OR8;
break;
2720 case ISD::XOR: NewOpc = PPC::XOR8;
break;
2723 if (IsBitwiseNegation) {
2724 RHS = S->getI64Imm(1, dl);
2725 NewOpc = PPC::XORI8;
2728 return SDValue(CurDAG->getMachineNode(NewOpc, dl,
MVT::i64, LHS, RHS), 0);
2736 SDValue IntegerCompareEliminator::signExtendInputIfNeeded(
SDValue Input) {
2738 "Can only sign-extend 32-bit values here.");
2760 SignExtensionsAdded++;
2761 return SDValue(CurDAG->getMachineNode(PPC::EXTSW_32_64, dl,
2769 SDValue IntegerCompareEliminator::zeroExtendInputIfNeeded(
SDValue Input) {
2771 "Can only zero-extend 32-bit values here.");
2781 if (IsTruncateOfZExt)
2795 ZeroExtensionsAdded++;
2796 return SDValue(CurDAG->getMachineNode(PPC::RLDICL_32_64, dl,
MVT::i64, Input,
2797 S->getI64Imm(0, dl),
2798 S->getI64Imm(32, dl)), 0);
2805 SDValue IntegerCompareEliminator::addExtOrTrunc(
SDValue NatWidthRes,
2806 ExtOrTruncConversion Conv) {
2807 SDLoc dl(NatWidthRes);
2812 SDValue ImDef(CurDAG->getMachineNode(PPC::IMPLICIT_DEF, dl,
MVT::i64), 0);
2814 CurDAG->getTargetConstant(PPC::sub_32, dl,
MVT::i32);
2815 return SDValue(CurDAG->getMachineNode(PPC::INSERT_SUBREG, dl,
MVT::i64,
2816 ImDef, NatWidthRes, SubRegIdx), 0);
2819 assert(Conv == ExtOrTruncConversion::Trunc &&
2820 "Unknown convertion between 32 and 64 bit values.");
2824 CurDAG->getTargetConstant(PPC::sub_32, dl,
MVT::i32);
2825 return SDValue(CurDAG->getMachineNode(PPC::EXTRACT_SUBREG, dl,
MVT::i32,
2826 NatWidthRes, SubRegIdx), 0);
2832 IntegerCompareEliminator::getCompoundZeroComparisonInGPR(
SDValue LHS,
SDLoc dl,
2833 ZeroCompare CmpTy) {
2840 case ZeroCompare::GEZExt:
2841 case ZeroCompare::GESExt:
2842 ToExtend =
SDValue(CurDAG->getMachineNode(Is32Bit ? PPC::NOR : PPC::NOR8,
2843 dl, InVT, LHS, LHS), 0);
2845 case ZeroCompare::LEZExt:
2846 case ZeroCompare::LESExt: {
2849 LHS = signExtendInputIfNeeded(LHS);
2854 Neg, S->getI64Imm(1, dl),
2855 S->getI64Imm(63, dl)), 0);
2859 S->getI64Imm(~0ULL, dl)), 0);
2869 (CmpTy == ZeroCompare::GEZExt || CmpTy == ZeroCompare::LEZExt))
2871 ToExtend, S->getI64Imm(1, dl),
2872 S->getI64Imm(63, dl)), 0);
2874 (CmpTy == ZeroCompare::GESExt || CmpTy == ZeroCompare::LESExt))
2875 return SDValue(CurDAG->getMachineNode(PPC::SRADI, dl,
MVT::i64, ToExtend,
2876 S->getI64Imm(63, dl)), 0);
2878 assert(Is32Bit &&
"Should have handled the 32-bit sequences above.");
2881 case ZeroCompare::GEZExt: {
2882 SDValue ShiftOps[] = { ToExtend, S->getI32Imm(1, dl), S->getI32Imm(31, dl),
2883 S->getI32Imm(31, dl) };
2887 case ZeroCompare::GESExt:
2888 return SDValue(CurDAG->getMachineNode(PPC::SRAWI, dl,
MVT::i32, ToExtend,
2889 S->getI32Imm(31, dl)), 0);
2890 case ZeroCompare::LEZExt:
2891 return SDValue(CurDAG->getMachineNode(PPC::XORI8, dl,
MVT::i64, ToExtend,
2892 S->getI32Imm(1, dl)), 0);
2893 case ZeroCompare::LESExt:
2894 return SDValue(CurDAG->getMachineNode(PPC::ADDI8, dl,
MVT::i64, ToExtend,
2895 S->getI32Imm(-1, dl)), 0);
2906 IntegerCompareEliminator::get32BitZExtCompare(
SDValue LHS,
SDValue RHS,
2908 int64_t RHSValue,
SDLoc dl) {
2912 bool IsRHSZero = RHSValue == 0;
2913 bool IsRHSOne = RHSValue == 1;
2914 bool IsRHSNegOne = RHSValue == -1LL;
2920 SDValue Xor = IsRHSZero ? LHS :
2924 SDValue ShiftOps[] = { Clz, S->getI32Imm(27, dl), S->getI32Imm(5, dl),
2925 S->getI32Imm(31, dl) };
2932 SDValue Xor = IsRHSZero ? LHS :
2936 SDValue ShiftOps[] = { Clz, S->getI32Imm(27, dl), S->getI32Imm(5, dl),
2937 S->getI32Imm(31, dl) };
2939 SDValue(CurDAG->getMachineNode(PPC::RLWINM, dl,
MVT::i32, ShiftOps), 0);
2941 S->getI32Imm(1, dl)), 0);
2947 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::GEZExt);
2964 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::LEZExt);
2968 LHS = signExtendInputIfNeeded(LHS);
2969 RHS = signExtendInputIfNeeded(RHS);
2971 SDValue(CurDAG->getMachineNode(PPC::SUBF8, dl,
MVT::i64, LHS, RHS), 0);
2974 S->getI64Imm(1, dl), S->getI64Imm(63, dl)),
2977 SDValue(CurDAG->getMachineNode(PPC::XORI8, dl,
2978 MVT::i64, Shift, S->getI32Imm(1, dl)), 0);
2986 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::GEZExt);
2992 LHS = signExtendInputIfNeeded(LHS);
2993 RHS = signExtendInputIfNeeded(RHS);
2997 Neg, S->getI32Imm(1, dl), S->getI32Imm(63, dl)), 0);
3015 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::LEZExt);
3019 SDValue ShiftOps[] = { LHS, S->getI32Imm(1, dl), S->getI32Imm(31, dl),
3020 S->getI32Imm(31, dl) };
3028 LHS = signExtendInputIfNeeded(LHS);
3029 RHS = signExtendInputIfNeeded(RHS);
3031 SDValue(CurDAG->getMachineNode(PPC::SUBF8, dl,
MVT::i64, RHS, LHS), 0);
3033 SUBFNode, S->getI64Imm(1, dl),
3034 S->getI64Imm(63, dl)), 0);
3045 LHS = zeroExtendInputIfNeeded(LHS);
3046 RHS = zeroExtendInputIfNeeded(RHS);
3048 SDValue(CurDAG->getMachineNode(PPC::SUBF8, dl,
MVT::i64, LHS, RHS), 0);
3051 Subtract, S->getI64Imm(1, dl),
3052 S->getI64Imm(63, dl)), 0);
3053 return SDValue(CurDAG->getMachineNode(PPC::XORI8, dl,
MVT::i64, SrdiNode,
3054 S->getI32Imm(1, dl)), 0);
3065 LHS = zeroExtendInputIfNeeded(LHS);
3066 RHS = zeroExtendInputIfNeeded(RHS);
3068 SDValue(CurDAG->getMachineNode(PPC::SUBF8, dl,
MVT::i64, RHS, LHS), 0);
3070 Subtract, S->getI64Imm(1, dl),
3071 S->getI64Imm(63, dl)), 0);
3079 IntegerCompareEliminator::get32BitSExtCompare(
SDValue LHS,
SDValue RHS,
3081 int64_t RHSValue,
SDLoc dl) {
3085 bool IsRHSZero = RHSValue == 0;
3086 bool IsRHSOne = RHSValue == 1;
3087 bool IsRHSNegOne = RHSValue == -1LL;
3096 SDValue CountInput = IsRHSZero ? LHS :
3099 SDValue(CurDAG->getMachineNode(PPC::CNTLZW, dl,
MVT::i32, CountInput), 0);
3100 SDValue SHLOps[] = { Cntlzw, S->getI32Imm(27, dl),
3101 S->getI32Imm(5, dl), S->getI32Imm(31, dl) };
3103 SDValue(CurDAG->getMachineNode(PPC::RLWINM, dl,
MVT::i32, SHLOps), 0);
3114 SDValue Xor = IsRHSZero ? LHS :
3119 { Clz, S->getI32Imm(27, dl), S->getI32Imm(5, dl), S->getI32Imm(31, dl) };
3121 SDValue(CurDAG->getMachineNode(PPC::RLWINM, dl,
MVT::i32, ShiftOps), 0);
3124 S->getI32Imm(1, dl)), 0);
3131 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::GESExt);
3146 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::LESExt);
3149 LHS = signExtendInputIfNeeded(LHS);
3150 RHS = signExtendInputIfNeeded(RHS);
3156 SUBFNode, S->getI64Imm(1, dl),
3157 S->getI64Imm(63, dl)), 0);
3159 S->getI32Imm(-1, dl)), 0);
3166 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::GESExt);
3171 LHS = signExtendInputIfNeeded(LHS);
3172 RHS = signExtendInputIfNeeded(RHS);
3176 S->getI64Imm(63, dl)), 0);
3193 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::LESExt);
3197 S->getI32Imm(31, dl)), 0);
3202 LHS = signExtendInputIfNeeded(LHS);
3203 RHS = signExtendInputIfNeeded(RHS);
3205 SDValue(CurDAG->getMachineNode(PPC::SUBF8, dl,
MVT::i64, RHS, LHS), 0);
3207 SUBFNode, S->getI64Imm(63, dl)), 0);
3218 LHS = zeroExtendInputIfNeeded(LHS);
3219 RHS = zeroExtendInputIfNeeded(RHS);
3221 SDValue(CurDAG->getMachineNode(PPC::SUBF8, dl,
MVT::i64, LHS, RHS), 0);
3224 S->getI32Imm(1, dl), S->getI32Imm(63,dl)),
3226 return SDValue(CurDAG->getMachineNode(PPC::ADDI8, dl,
MVT::i64, Shift,
3227 S->getI32Imm(-1, dl)), 0);
3238 LHS = zeroExtendInputIfNeeded(LHS);
3239 RHS = zeroExtendInputIfNeeded(RHS);
3241 SDValue(CurDAG->getMachineNode(PPC::SUBF8, dl,
MVT::i64, RHS, LHS), 0);
3243 Subtract, S->getI64Imm(63, dl)), 0);
3251 IntegerCompareEliminator::get64BitZExtCompare(
SDValue LHS,
SDValue RHS,
3253 int64_t RHSValue,
SDLoc dl) {
3257 bool IsRHSZero = RHSValue == 0;
3258 bool IsRHSOne = RHSValue == 1;
3259 bool IsRHSNegOne = RHSValue == -1LL;
3265 SDValue Xor = IsRHSZero ? LHS :
3266 SDValue(CurDAG->getMachineNode(PPC::XOR8, dl,
MVT::i64, LHS, RHS), 0);
3270 S->getI64Imm(58, dl),
3271 S->getI64Imm(63, dl)), 0);
3278 SDValue Xor = IsRHSZero ? LHS :
3279 SDValue(CurDAG->getMachineNode(PPC::XOR8, dl,
MVT::i64, LHS, RHS), 0);
3282 Xor, S->getI32Imm(~0U, dl)), 0);
3292 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::GEZExt);
3304 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::LEZExt);
3307 S->getI64Imm(1, dl),
3308 S->getI64Imm(63, dl)), 0);
3311 S->getI64Imm(63, dl)), 0);
3316 ShiftR, ShiftL, SubtractCarry), 0);
3324 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::GEZExt);
3328 S->getI64Imm(~0ULL, dl)), 0);
3330 SDValue(CurDAG->getMachineNode(PPC::NOR8, dl,
MVT::i64, Addi, LHS), 0);
3332 S->getI64Imm(1, dl),
3333 S->getI64Imm(63, dl)), 0);
3347 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::LEZExt);
3350 S->getI64Imm(1, dl),
3351 S->getI64Imm(63, dl)), 0);
3354 LHS, S->getI64Imm(63, dl)), 0);
3357 RHS, S->getI64Imm(1, dl),
3358 S->getI64Imm(63, dl)), 0);
3364 SRDINode, SRADINode, SUBFC8Carry), 0);
3366 ADDE8Node, S->getI64Imm(1, dl)), 0);
3381 LHS, LHS, SUBFC8Carry), 0);
3383 SUBFE8Node, S->getI64Imm(1, dl)), 0);
3398 LHS, LHS, SubtractCarry), 0);
3408 IntegerCompareEliminator::get64BitSExtCompare(
SDValue LHS,
SDValue RHS,
3410 int64_t RHSValue,
SDLoc dl) {
3414 bool IsRHSZero = RHSValue == 0;
3415 bool IsRHSOne = RHSValue == 1;
3416 bool IsRHSNegOne = RHSValue == -1LL;
3424 SDValue AddInput = IsRHSZero ? LHS :
3425 SDValue(CurDAG->getMachineNode(PPC::XOR8, dl,
MVT::i64, LHS, RHS), 0);
3428 AddInput, S->getI32Imm(~0U, dl)), 0);
3429 return SDValue(CurDAG->getMachineNode(PPC::SUBFE8, dl,
MVT::i64, Addic,
3430 Addic, Addic.getValue(1)), 0);
3437 SDValue Xor = IsRHSZero ? LHS :
3438 SDValue(CurDAG->getMachineNode(PPC::XOR8, dl,
MVT::i64, LHS, RHS), 0);
3441 Xor, S->getI32Imm(0, dl)), 0);
3443 SC, SC.getValue(1)), 0);
3451 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::GESExt);
3463 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::LESExt);
3466 S->getI64Imm(63, dl)), 0);
3469 S->getI64Imm(1, dl),
3470 S->getI64Imm(63, dl)), 0);
3476 ShiftR, ShiftL, SubtractCarry), 0);
3477 return SDValue(CurDAG->getMachineNode(PPC::NEG8, dl,
MVT::i64, Adde), 0);
3485 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::GESExt);
3489 S->getI64Imm(-1, dl)), 0);
3491 SDValue(CurDAG->getMachineNode(PPC::NOR8, dl,
MVT::i64, Add, LHS), 0);
3493 S->getI64Imm(63, dl)), 0);
3507 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::LESExt);
3510 S->getI64Imm(63, dl)), 0);
3514 LHS, S->getI64Imm(63, dl)), 0);
3517 RHS, S->getI64Imm(1, dl),
3518 S->getI64Imm(63, dl)), 0);
3524 SRDINode, SRADINode, SUBFC8Carry), 0);
3527 ADDE8Node, S->getI64Imm(1, dl)), 0);
3544 LHS, SubtractCarry), 0);
3546 ExtSub, ExtSub), 0);
3560 LHS, LHS, SubCarry), 0);
3571 "An ISD::SETCC node required here.");
3583 !isLogicOp(CompareUse->getOpcode())) {
3584 OmittedForNonExtendUses++;
3594 SetccInGPROpts ConvOpts) {
3597 "An ISD::SETCC node required here.");
3610 cast<CondCodeSDNode>(Compare.
getOperand(CCOpNum))->
get();
3615 if (ConvOpts == SetccInGPROpts::ZExtInvert ||
3616 ConvOpts == SetccInGPROpts::SExtInvert)
3619 bool Inputs32Bit = InputVT ==
MVT::i32;
3624 bool IsSext = ConvOpts == SetccInGPROpts::SExtOrig ||
3625 ConvOpts == SetccInGPROpts::SExtInvert;
3627 if (IsSext && Inputs32Bit)
3628 return get32BitSExtCompare(LHS, RHS, CC, RHSValue, dl);
3629 else if (Inputs32Bit)
3630 return get32BitZExtCompare(LHS, RHS, CC, RHSValue, dl);
3632 return get64BitSExtCompare(LHS, RHS, CC, RHSValue, dl);
3633 return get64BitZExtCompare(LHS, RHS, CC, RHSValue, dl);
3638 bool PPCDAGToDAGISel::tryIntCompareInGPR(
SDNode *N) {
3656 IntegerCompareEliminator ICmpElim(CurDAG,
this);
3657 if (
SDNode *New = ICmpElim.Select(N)) {
3658 ReplaceNode(N, New);
3666 bool PPCDAGToDAGISel::tryBitPermutation(
SDNode *N) {
3681 BitPermutationSelector BPS(CurDAG);
3682 if (
SDNode *New = BPS.Select(N)) {
3683 ReplaceNode(N, New);
3707 getI32Imm(Imm & 0xFFFF, dl)),
3712 getI32Imm(Imm & 0xFFFF, dl)),
3725 getI32Imm(Imm >> 16, dl)), 0);
3727 getI32Imm(Imm & 0xFFFF, dl)), 0);
3733 getI32Imm(Imm & 0xFFFF, dl)), 0);
3739 getI32Imm((
int)SImm & 0xFFFF,
3751 getI32Imm(Imm & 0xFFFF, dl)),
3756 getI32Imm(Imm & 0xFFFF, dl)),
3770 getI64Imm(Imm >> 16, dl)), 0);
3772 getI64Imm(Imm & 0xFFFF, dl)),
3780 getI64Imm(Imm & 0xFFFF, dl)), 0);
3786 getI64Imm(SImm & 0xFFFF, dl)),
3791 if (PPCSubTarget->
hasSPE()) {
3796 Opc = PPC::EFSCMPEQ;
3804 Opc = PPC::EFSCMPLT;
3812 Opc = PPC::EFSCMPGT;
3818 if (PPCSubTarget->
hasSPE()) {
3823 Opc = PPC::EFDCMPEQ;
3831 Opc = PPC::EFDCMPLT;
3839 Opc = PPC::EFDCMPGT;
3843 Opc = PPCSubTarget->
hasVSX() ? PPC::XSCMPUDP : PPC::FCMPUD;
3846 assert(PPCSubTarget->
hasVSX() &&
"__float128 requires VSX");
3847 Opc = PPC::XSCMPUQP;
3849 return SDValue(CurDAG->getMachineNode(Opc, dl,
MVT::i32, LHS, RHS), 0);
3910 case ISD::SETO: Invert =
true;
return 3;
3926 bool HasVSX,
bool &Swap,
bool &Negate) {
3954 return HasVSX ? PPC::XVCMPEQSP : PPC::VCMPEQFP;
3956 return PPC::XVCMPEQDP;
3961 return HasVSX ? PPC::XVCMPGTSP : PPC::VCMPGTFP;
3963 return PPC::XVCMPGTDP;
3968 return HasVSX ? PPC::XVCMPGESP : PPC::VCMPGEFP;
3970 return PPC::XVCMPGEDP;
3998 return PPC::VCMPEQUB;
4000 return PPC::VCMPEQUH;
4002 return PPC::VCMPEQUW;
4004 return PPC::VCMPEQUD;
4008 return PPC::VCMPGTSB;
4010 return PPC::VCMPGTSH;
4012 return PPC::VCMPGTSW;
4014 return PPC::VCMPGTSD;
4018 return PPC::VCMPGTUB;
4020 return PPC::VCMPGTUH;
4022 return PPC::VCMPGTUW;
4024 return PPC::VCMPGTUD;
4033 bool PPCDAGToDAGISel::trySETCC(
SDNode *N) {
4038 CurDAG->getTargetLoweringInfo().getPointerTy(CurDAG->getDataLayout());
4039 bool isPPC64 = (PtrVT ==
MVT::i64);
4051 Op =
SDValue(CurDAG->getMachineNode(PPC::CNTLZW, dl,
MVT::i32, Op), 0);
4052 SDValue Ops[] = {
Op, getI32Imm(27, dl), getI32Imm(5, dl),
4053 getI32Imm(31, dl) };
4054 CurDAG->SelectNodeTo(N, PPC::RLWINM,
MVT::i32, Ops);
4061 Op, getI32Imm(~0U, dl)), 0);
4066 SDValue Ops[] = {
Op, getI32Imm(1, dl), getI32Imm(31, dl),
4067 getI32Imm(31, dl) };
4068 CurDAG->SelectNodeTo(N, PPC::RLWINM,
MVT::i32, Ops);
4074 T =
SDValue(CurDAG->getMachineNode(PPC::ANDC, dl,
MVT::i32, T, Op), 0);
4075 SDValue Ops[] = {
T, getI32Imm(1, dl), getI32Imm(31, dl),
4076 getI32Imm(31, dl) };
4077 CurDAG->SelectNodeTo(N, PPC::RLWINM,
MVT::i32, Ops);
4081 }
else if (Imm == ~0U) {
4088 Op, getI32Imm(1, dl)), 0);
4089 CurDAG->SelectNodeTo(N, PPC::ADDZE,
MVT::i32,
4090 SDValue(CurDAG->getMachineNode(PPC::LI, dl,
4097 Op =
SDValue(CurDAG->getMachineNode(PPC::NOR, dl,
MVT::i32, Op, Op), 0);
4099 Op, getI32Imm(~0U, dl));
4106 getI32Imm(1, dl)), 0);
4109 SDValue Ops[] = { AN, getI32Imm(1, dl), getI32Imm(31, dl),
4110 getI32Imm(31, dl) };
4111 CurDAG->SelectNodeTo(N, PPC::RLWINM,
MVT::i32, Ops);
4115 SDValue Ops[] = {
Op, getI32Imm(1, dl), getI32Imm(31, dl),
4116 getI32Imm(31, dl) };
4117 Op =
SDValue(CurDAG->getMachineNode(PPC::RLWINM, dl,
MVT::i32, Ops), 0);
4118 CurDAG->SelectNodeTo(N, PPC::XORI,
MVT::i32, Op, getI32Imm(1, dl));
4137 PPCSubTarget->
hasVSX(), Swap, Negate);
4143 SDValue VCmp(CurDAG->getMachineNode(VCmpInst, dl, ResVT, LHS, RHS), 0);
4144 CurDAG->SelectNodeTo(N, PPCSubTarget->
hasVSX() ? PPC::XXLNOR :
PPC::VNOR,
4149 CurDAG->SelectNodeTo(N, VCmpInst, ResVT, LHS, RHS);
4158 SDValue CCReg = SelectCC(LHS, RHS, CC, dl);
4171 CCReg = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, CR7Reg, CCReg,
4172 InFlag).getValue(1);
4177 SDValue Ops[] = { IntCR, getI32Imm((32 - (3 - Idx)) & 31, dl),
4178 getI32Imm(31, dl), getI32Imm(31, dl) };
4180 CurDAG->SelectNodeTo(N, PPC::RLWINM,
MVT::i32, Ops);
4187 CurDAG->SelectNodeTo(N, PPC::XORI,
MVT::i32, Tmp, getI32Imm(1, dl));
4193 bool PPCDAGToDAGISel::isOffsetMultipleOf(
SDNode *N,
unsigned Val)
const {
4206 AddrOp.getOpcode() ==
ISD::ADD ? AddrOp.getOperand(0) :
4213 if ((SlotAlign % Val) != 0)
4217 if (AddrOp.getOpcode() !=
ISD::ADD)
4221 if (AddrOp.getOpcode() ==
ISD::ADD)
4228 void PPCDAGToDAGISel::transferMemOperands(
SDNode *N,
SDNode *Result) {
4231 CurDAG->setNodeMemRefs(cast<MachineSDNode>(Result), {MemOp});
4235 bool &NeedSwapOps,
bool &IsUnCmp) {
4249 "Expecting either i64 or i32 here.");
4257 if ((TrueResVal < -1 || TrueResVal > 1) ||
4284 cast<CondCodeSDNode>(SetOrSelCC.
getOperand(InnerIsSel ? 4 : 2))->
get();
4292 if (!SelCCTrueConst || !SelCCFalseConst)
4295 int64_t SelCCFVal = SelCCFalseConst->getSExtValue();
4297 if (SelCCTVal == -1 && SelCCFVal == 1) {
4299 }
else if (SelCCTVal != 1 || SelCCFVal != -1)
4309 bool InnerSwapped =
false;
4310 if (LHS == InnerRHS && RHS == InnerLHS)
4311 InnerSwapped =
true;
4312 else if (LHS != InnerLHS || RHS != InnerRHS)
4323 NeedSwapOps = (InnerCC ==
ISD::SETGT) ? InnerSwapped : !InnerSwapped;
4340 NeedSwapOps = (TrueResVal == 1);
4359 NeedSwapOps = (TrueResVal == -1);
4368 LLVM_DEBUG(
dbgs() <<
"Found a node that can be lowered to a SETB: ");
4374 bool PPCDAGToDAGISel::tryAndWithMask(
SDNode *N) {
4380 unsigned Imm, Imm2, SH, MB, ME;
4388 SDValue Ops[] = { Val, getI32Imm(SH, dl), getI32Imm(MB, dl),
4389 getI32Imm(ME, dl) };
4390 CurDAG->SelectNodeTo(N, PPC::RLWINM,
MVT::i32, Ops);
4399 SDValue Ops[] = { Val, getI32Imm(0, dl), getI32Imm(MB, dl),
4400 getI32Imm(ME, dl) };
4401 CurDAG->SelectNodeTo(N, PPC::RLWINM,
MVT::i32, Ops);
4428 if (
isRunOfOnes(~(Imm^Imm2), MB, ME) && !(~Imm & Imm2)) {
4431 getI32Imm(0, dl), getI32Imm(MB, dl),
4432 getI32Imm(ME, dl) };
4433 ReplaceNode(N, CurDAG->getMachineNode(PPC::RLWIMI, dl,
MVT::i32, Ops));
4445 if ( Op0.getOpcode() ==
ISD::SRL &&
4449 auto ImDef = CurDAG->getMachineNode(PPC::IMPLICIT_DEF, dl,
4453 Val =
SDValue(CurDAG->getMachineNode(PPC::INSERT_SUBREG, dl,
4455 getI32Imm(1, dl)), 0);
4467 assert(Imm < 64 &&
"Illegal shift amount");
4472 SDValue Ops[] = { Val, getI32Imm(SH, dl), getI32Imm(MB, dl) };
4473 CurDAG->SelectNodeTo(N, PPC::RLDICL,
MVT::i64, Ops);
4481 SDValue Ops[] = { Val, getI32Imm(SH, dl), getI32Imm(MB, dl) };
4482 CurDAG->SelectNodeTo(N, PPC::RLDICR,
MVT::i64, Ops);
4489 if (MB >= 32 && MB <= ME) {
4498 SDValue Ops[] = { Val, getI64Imm(0, dl), getI64Imm(MB - 32, dl),
4499 getI64Imm(ME - 32, dl) };
4500 CurDAG->SelectNodeTo(N, PPC::RLWINM8,
MVT::i64, Ops);
4527 if (tryBitPermutation(N))
4531 if (tryIntCompareInGPR(N))
4553 if (PPCLowering->getPointerTy(CurDAG->getDataLayout()) !=
MVT::i32 ||
4562 if (PPCLowering->getPointerTy(CurDAG->getDataLayout()) !=
MVT::i32 ||
4581 ReplaceNode(N, getGlobalBaseReg());
4585 selectFrameIndex(N, N);
4603 CurDAG->getTargetConstant(*cast<ConstantSDNode>(N->
getOperand(1))->
4604 getConstantIntValue(), dl,
4615 "Expecting i64 or i32 in PPCISD::SRA_ADDZE");
4630 if (tryTLSXFormStore(ST))
4643 if (tryTLSXFormLoad(LD))
4656 assert((!isSExt || LoadedVT ==
MVT::i16) &&
"Invalid sext update load");
4657 switch (LoadedVT.getSimpleVT().SimpleTy) {
4659 case MVT::f64: Opcode = PPC::LFDU;
break;
4660 case MVT::f32: Opcode = PPC::LFSU;
break;
4661 case MVT::i32: Opcode = PPC::LWZU;
break;
4662 case MVT::i16: Opcode = isSExt ? PPC::LHAU : PPC::LHZU;
break;
4664 case MVT::i8: Opcode = PPC::LBZU;
break;
4668 assert((!isSExt || LoadedVT ==
MVT::i16) &&
"Invalid sext update load");
4669 switch (LoadedVT.getSimpleVT().SimpleTy) {
4671 case MVT::i64: Opcode = PPC::LDU;
break;
4672 case MVT::i32: Opcode = PPC::LWZU8;
break;
4673 case MVT::i16: Opcode = isSExt ? PPC::LHAU8 : PPC::LHZU8;
break;
4675 case MVT::i8: Opcode = PPC::LBZU8;
break;
4682 SDNode *MN = CurDAG->getMachineNode(
4684 PPCLowering->getPointerTy(CurDAG->getDataLayout()),
MVT::Other, Ops);
4685 transferMemOperands(N, MN);
4693 assert((!isSExt || LoadedVT ==
MVT::i16) &&
"Invalid sext update load");
4694 switch (LoadedVT.getSimpleVT().SimpleTy) {
4696 case MVT::v4f64: Opcode = PPC::QVLFDUX;
break;
4697 case MVT::v4f32: Opcode = PPC::QVLFSUX;
break;
4698 case MVT::f64: Opcode = PPC::LFDUX;
break;
4699 case MVT::f32: Opcode = PPC::LFSUX;
break;
4700 case MVT::i32: Opcode = PPC::LWZUX;
break;
4701 case MVT::i16: Opcode = isSExt ? PPC::LHAUX : PPC::LHZUX;
break;
4703 case MVT::i8: Opcode = PPC::LBZUX;
break;
4708 "Invalid sext update load");
4709 switch (LoadedVT.getSimpleVT().SimpleTy) {
4711 case MVT::i64: Opcode = PPC::LDUX;
break;
4712 case MVT::i32: Opcode = isSExt ? PPC::LWAUX : PPC::LWZUX8;
break;
4713 case MVT::i16: Opcode = isSExt ? PPC::LHAUX8 : PPC::LHZUX8;
break;
4715 case MVT::i8: Opcode = PPC::LBZUX8;
break;
4722 SDNode *MN = CurDAG->getMachineNode(
4724 PPCLowering->getPointerTy(CurDAG->getDataLayout()),
MVT::Other, Ops);
4725 transferMemOperands(N, MN);
4733 if (tryAndWithMask(N))
4740 if (tryBitfieldInsert(N))
4759 bool IsPPC64 = PPCSubTarget->
isPPC64();
4761 (Imm64 & ~0xFFFFFFFFuLL) == 0) {
4763 uint64_t ImmHi = Imm64 >> 16;
4764 uint64_t ImmLo = Imm64 & 0xFFFF;
4765 if (ImmHi != 0 && ImmLo != 0) {
4768 getI16Imm(ImmLo, dl));
4770 CurDAG->SelectNodeTo(N, PPC::ORIS8,
MVT::i64, Ops1);
4782 bool IsPPC64 = PPCSubTarget->
isPPC64();
4784 (Imm64 & ~0xFFFFFFFFuLL) == 0) {
4786 uint64_t ImmHi = Imm64 >> 16;
4787 uint64_t ImmLo = Imm64 & 0xFFFF;
4788 if (ImmHi != 0 && ImmLo != 0) {
4791 getI16Imm(ImmLo, dl));
4793 CurDAG->SelectNodeTo(N, PPC::XORIS8,
MVT::i64, Ops1);
4811 unsigned Imm, SH, MB, ME;
4813 isRotateAndMask(N, Imm,
true, SH, MB, ME)) {
4815 getI32Imm(SH, dl), getI32Imm(MB, dl),
4816 getI32Imm(ME, dl) };
4817 CurDAG->SelectNodeTo(N, PPC::RLWINM,
MVT::i32, Ops);
4825 unsigned Imm, SH, MB, ME;
4827 isRotateAndMask(N, Imm,
true, SH, MB, ME)) {
4829 getI32Imm(SH, dl), getI32Imm(MB, dl),
4830 getI32Imm(ME, dl) };
4831 CurDAG->SelectNodeTo(N, PPC::RLWINM,
MVT::i32, Ops);
4846 "Invalid input type for ANDI_rec_1_EQ_BIT");
4848 unsigned Opcode = (InVT ==
MVT::i64) ? PPC::ANDI8_rec : PPC::ANDI_rec;
4851 CurDAG->getTargetConstant(1, dl, InVT)),
4854 SDValue SRIdxVal = CurDAG->getTargetConstant(
4858 CurDAG->SelectNodeTo(N, TargetOpcode::EXTRACT_SUBREG,
MVT::i1, CR0Reg,
4865 CurDAG->getTargetLoweringInfo().getPointerTy(CurDAG->getDataLayout());
4866 bool isPPC64 = (PtrVT ==
MVT::i64);
4874 bool NeedSwapOps =
false;
4875 bool IsUnCmp =
false;
4876 if (
mayUseP9Setb(N, CC, CurDAG, NeedSwapOps, IsUnCmp)) {
4890 CurDAG->SelectNodeTo(
4903 if (N1C->isNullValue() && N3C->isNullValue() &&
4904 N2C->getZExtValue() == 1ULL && CC ==
ISD::SETNE &&
4925 case 0: SRI = PPC::sub_lt;
break;
4926 case 1: SRI = PPC::sub_gt;
break;
4927 case 2: SRI = PPC::sub_eq;
break;
4928 case 3: SRI = PPC::sub_un;
break;
4931 SDValue CCBit = CurDAG->getTargetExtractSubreg(SRI, dl,
MVT::i1, CCReg);
4935 SDValue C = Inv ? NotCCBit : CCBit,
4936 NotC = Inv ? CCBit : NotCCBit;
4943 CurDAG->SelectNodeTo(N, PPC::CROR,
MVT::i1, CAndT, NotCAndF);
4950 unsigned SelectCCOp;
4952 SelectCCOp = PPC::SELECT_CC_I4;
4954 SelectCCOp = PPC::SELECT_CC_I8;
4957 SelectCCOp = PPC::SELECT_CC_VSSRC;
4958 else if (PPCSubTarget->
hasSPE())
4959 SelectCCOp = PPC::SELECT_CC_SPE4;
4961 SelectCCOp = PPC::SELECT_CC_F4;
4963 if (PPCSubTarget->
hasVSX())
4964 SelectCCOp = PPC::SELECT_CC_VSFRC;
4965 else if (PPCSubTarget->
hasSPE())
4966 SelectCCOp = PPC::SELECT_CC_SPE;
4968 SelectCCOp = PPC::SELECT_CC_F8;
4970 SelectCCOp = PPC::SELECT_CC_F16;
4971 else if (PPCSubTarget->
hasSPE())
4972 SelectCCOp = PPC::SELECT_CC_SPE;
4974 SelectCCOp = PPC::SELECT_CC_QFRC;
4976 SelectCCOp = PPC::SELECT_CC_QSRC;
4978 SelectCCOp = PPC::SELECT_CC_QBRC;
4981 SelectCCOp = PPC::SELECT_CC_VSRC;
4983 SelectCCOp = PPC::SELECT_CC_VRRC;
4986 getI32Imm(BROpc, dl) };
4987 CurDAG->SelectNodeTo(N, SelectCCOp, N->
getValueType(0), Ops);
4999 for (
int i = 0; i < 2; ++i)
5005 if (Op1 == Op2 && DM[0] == 0 && DM[1] == 0 &&
5007 isa<LoadSDNode>(Op1.getOperand(0))) {
5008 LoadSDNode *LD = cast<LoadSDNode>(Op1.getOperand(0));
5018 SDNode *NewN = CurDAG->SelectNodeTo(N, PPC::LXVDSX,
5020 CurDAG->setNodeMemRefs(cast<MachineSDNode>(NewN), {MemOp});
5029 unsigned tmp = DM[0];
5034 SDValue DMV = CurDAG->getTargetConstant(DM[1] | (DM[0] << 1), dl,
5036 SDValue Ops[] = { Op1, Op2, DMV };
5044 bool IsPPC64 = PPCSubTarget->
isPPC64();
5048 : (IsPPC64 ? PPC::BDZ8 :
PPC::BDZ),
5059 unsigned PCC = cast<ConstantSDNode>(N->
getOperand(1))->getZExtValue();
5063 SDValue Pred = getI32Imm(PCC, dl);
5066 CurDAG->SelectNodeTo(N, PPC::BCC,
MVT::Other, Ops);
5079 case PPC::PRED_LT: Opc = PPC::CRANDC; Swap =
true;
break;
5080 case PPC::PRED_LE: Opc = PPC::CRORC; Swap =
true;
break;
5081 case PPC::PRED_EQ: Opc = PPC::CREQV; Swap =
false;
break;
5082 case PPC::PRED_GE: Opc = PPC::CRORC; Swap =
false;
break;
5083 case PPC::PRED_GT: Opc = PPC::CRANDC; Swap =
false;
break;
5084 case PPC::PRED_NE: Opc = PPC::CRXOR; Swap =
false;
break;
5110 CurDAG->SelectNodeTo(N, PPC::BCC,
MVT::Other, Ops);
5121 CurDAG->SelectNodeTo(N, Reg,
MVT::Other, Chain);
5125 const bool isPPC64 = PPCSubTarget->
isPPC64();
5126 const bool isELFABI = PPCSubTarget->
isSVR4ABI();
5127 const bool isAIXABI = PPCSubTarget->
isAIXABI();
5129 assert(!PPCSubTarget->
isDarwin() &&
"TOC is an ELF/XCOFF construct");
5134 "PowerPC doesn't support tiny or kernel code models.");
5147 auto replaceWithLWZtoc = [
this, &dl](
SDNode *TocEntry) {
5150 SDNode *MN = CurDAG->getMachineNode(PPC::LWZtoc, dl,
MVT::i32, GA,
5152 transferMemOperands(TocEntry, MN);
5153 ReplaceNode(TocEntry, MN);
5158 "32-bit ELF can only have TOC entries in position independent" 5161 replaceWithLWZtoc(N);
5166 replaceWithLWZtoc(N);
5173 assert((isPPC64 || (isAIXABI && !isPPC64)) &&
"We are dealing with 64-bit" 5174 " ELF/AIX or 32-bit AIX in the following.");
5191 SDNode *Tmp = CurDAG->getMachineNode(
5192 isPPC64 ? PPC::ADDIStocHA8 : PPC::ADDIStocHA, dl, VT, TOCbase, GA);
5194 if (PPCLowering->isAccessedAsGotIndirect(GA)) {
5197 SDNode *MN = CurDAG->getMachineNode(
5198 isPPC64 ? PPC::LDtocL : PPC::LWZtocL, dl, VT, GA,
SDValue(Tmp, 0));
5200 transferMemOperands(N, MN);
5206 ReplaceNode(N, CurDAG->getMachineNode(PPC::ADDItocL, dl,
MVT::i64,
5213 "PPCISD::PPC32_PICGOT is only supported for 32-bit SVR4");
5214 CurDAG->SelectNodeTo(N, PPC::PPC32PICGOT,
5215 PPCLowering->getPointerTy(CurDAG->getDataLayout()),
5224 "Invalid operand on VADD_SPLAT!");
5228 unsigned Opc1, Opc2, Opc3;
5232 Opc1 = PPC::VSPLTISB;
5233 Opc2 = PPC::VADDUBM;
5234 Opc3 = PPC::VSUBUBM;
5236 }
else if (EltSize == 2) {
5237 Opc1 = PPC::VSPLTISH;
5238 Opc2 = PPC::VADDUHM;
5239 Opc3 = PPC::VSUBUHM;
5242 assert(EltSize == 4 &&
"Invalid element size on VADD_SPLAT!");
5243 Opc1 = PPC::VSPLTISW;
5244 Opc2 = PPC::VADDUWM;
5245 Opc3 = PPC::VSUBUWM;
5249 if ((Elt & 1) == 0) {
5256 SDValue EltVal = getI32Imm(Elt >> 1, dl);
5257 SDNode *Tmp = CurDAG->getMachineNode(Opc1, dl, VT, EltVal);
5259 ReplaceNode(N, CurDAG->getMachineNode(Opc2, dl, VT, TmpVal, TmpVal));
5261 }
else if (Elt > 0) {
5268 SDValue EltVal = getI32Imm(Elt - 16, dl);
5269 SDNode *Tmp1 = CurDAG->getMachineNode(Opc1, dl, VT, EltVal);
5270 EltVal = getI32Imm(-16, dl);
5271 SDNode *Tmp2 = CurDAG->getMachineNode(Opc1, dl, VT, EltVal);
5272 ReplaceNode(N, CurDAG->getMachineNode(Opc3, dl, VT,
SDValue(Tmp1, 0),
5282 SDValue EltVal = getI32Imm(Elt + 16, dl);
5283 SDNode *Tmp1 = CurDAG->getMachineNode(Opc1, dl, VT, EltVal);
5284 EltVal = getI32Imm(-16, dl);
5285 SDNode *Tmp2 = CurDAG->getMachineNode(Opc1, dl, VT, EltVal);
5286 ReplaceNode(N, CurDAG->getMachineNode(Opc2, dl, VT,
SDValue(Tmp1, 0),
5306 "Only OR nodes are supported for CMPB");
5319 bool BytesFound[8] = {
false,
false,
false,
false,
false,
false,
false,
false};
5320 uint64_t Mask = 0, Alt = 0;
5322 auto IsByteSelectCC = [
this](
SDValue O,
unsigned &b,
5323 uint64_t &
Mask, uint64_t &Alt,
5335 for (b = 0; b < 8; ++b) {
5336 uint64_t Mask = UINT64_C(0xFF) << (8*b);
5337 if (PM && (PM & Mask) == PM && (PAlt &
Mask) == PAlt)
5381 if (ULim != (UINT64_C(1) << b*8))
5387 if (!CurDAG->MaskedValueIsZero(
5442 while (!Queue.
empty()) {
5447 uint64_t M = 0, A = 0;
5451 }
else if (IsByteSelectCC(O, b, M, A, OLHS, ORHS)) {
5455 BytesFound[b] =
true;
5458 }
else if ((LHS == ORHS && RHS == OLHS) ||
5459 (RHS == ORHS && LHS == OLHS)) {
5460 BytesFound[b] =
true;
5472 unsigned LastB = 0, BCnt = 0;
5473 for (
unsigned i = 0; i < 8; ++i)
5474 if (BytesFound[LastB]) {
5479 if (!LastB || BCnt < 2)
5484 if (LHS.getValueType() != VT) {
5485 LHS = CurDAG->getAnyExtOrTrunc(LHS, dl, VT);
5486 RHS = CurDAG->getAnyExtOrTrunc(RHS, dl, VT);
5491 bool NonTrivialMask = ((int64_t) Mask) != INT64_C(-1);
5492 if (NonTrivialMask && !Alt) {
5494 Res = CurDAG->getNode(
ISD::AND, dl, VT, Res,
5495 CurDAG->getConstant(Mask, dl, VT));
5503 Res = CurDAG->getNode(
ISD::AND, dl, VT, Res,
5504 CurDAG->getConstant(Mask ^ Alt, dl, VT));
5505 Res = CurDAG->getNode(
ISD::XOR, dl, VT, Res,
5506 CurDAG->getConstant(Alt, dl, VT));
5519 void PPCDAGToDAGISel::foldBoolExts(
SDValue &Res,
SDNode *&N) {
5539 SDValue ConstFalse = CurDAG->getConstant(0, dl, VT);
5546 auto TryFold = [
this,
N, User, dl](
SDValue Val) {
5551 return CurDAG->FoldConstantArithmetic(User->getOpcode(), dl,
5552 User->getValueType(0),
5558 SDValue TrueRes = TryFold(ConstTrue);
5559 if (!TrueRes || TrueRes.
isUndef())
5561 SDValue FalseRes = TryFold(ConstFalse);
5562 if (!FalseRes || FalseRes.
isUndef())
5567 uint64_t True = cast<ConstantSDNode>(TrueRes)->getZExtValue(),
5568 False = cast<ConstantSDNode>(FalseRes)->getZExtValue();
5574 Res = CurDAG->getSelect(dl, User->getValueType(0), Cond, TrueRes, FalseRes);
5576 ConstTrue = TrueRes;
5577 ConstFalse = FalseRes;
5581 void PPCDAGToDAGISel::PreprocessISelDAG() {
5584 bool MadeChange =
false;
5585 while (Position != CurDAG->allnodes_begin()) {
5594 Res = combineToCMPB(N);
5599 foldBoolExts(Res, N);
5608 CurDAG->ReplaceAllUsesOfValueWith(
SDValue(N, 0), Res);
5614 CurDAG->RemoveDeadNodes();
5619 void PPCDAGToDAGISel::PostprocessISelDAG() {
5626 PeepholePPC64ZExt();
5634 bool PPCDAGToDAGISel::AllUsersSelectZero(
SDNode *N) {
5663 void PPCDAGToDAGISel::SwapAllSelectUsers(
SDNode *N) {
5670 "Must have all select users");
5675 UE = ToReplace.
end(); UI != UE; ++UI) {
5689 ReplaceUses(User, ResNode);
5693 void PPCDAGToDAGISel::PeepholeCROps() {
5697 for (
SDNode &Node : CurDAG->allnodes()) {
5699 if (!MachineNode || MachineNode->
use_empty())
5701 SDNode *ResNode = MachineNode;
5703 bool Op1Set =
false, Op1Unset =
false,
5705 Op2Set =
false, Op2Unset =
false,
5733 case PPC::SELECT_I4:
5734 case PPC::SELECT_I8:
5735 case PPC::SELECT_F4:
5736 case PPC::SELECT_F8:
5737 case PPC::SELECT_QFRC:
5738 case PPC::SELECT_QSRC:
5739 case PPC::SELECT_QBRC:
5740 case PPC::SELECT_SPE:
5741 case PPC::SELECT_SPE4:
5742 case PPC::SELECT_VRRC:
5743 case PPC::SELECT_VSFRC:
5744 case PPC::SELECT_VSSRC:
5745 case PPC::SELECT_VSRC: {
5760 bool SelectSwap =
false;
5773 else if (Op1Unset || Op2Unset)
5775 ResNode = CurDAG->getMachineNode(PPC::CRUNSET,
SDLoc(MachineNode),
5779 ResNode = CurDAG->getMachineNode(PPC::CRANDC,
SDLoc(MachineNode),
5785 ResNode = CurDAG->getMachineNode(PPC::CRANDC,
SDLoc(MachineNode),
5789 else if (AllUsersSelectZero(MachineNode)) {
5790 ResNode = CurDAG->getMachineNode(PPC::CRNAND,
SDLoc(MachineNode),
5799 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
5804 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
5809 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
5812 else if (Op1Unset || Op2Unset)
5814 ResNode = CurDAG->getMachineNode(PPC::CRSET,
SDLoc(MachineNode),
5818 ResNode = CurDAG->getMachineNode(PPC::CRORC,
SDLoc(MachineNode),
5824 ResNode = CurDAG->getMachineNode(PPC::CRORC,
SDLoc(MachineNode),
5828 else if (AllUsersSelectZero(MachineNode)) {
5829 ResNode = CurDAG->getMachineNode(PPC::CRAND,
SDLoc(MachineNode),
5839 else if (Op1Set || Op2Set)
5841 ResNode = CurDAG->getMachineNode(PPC::CRSET,
SDLoc(MachineNode),
5851 ResNode = CurDAG->getMachineNode(PPC::CRORC,
SDLoc(MachineNode),
5857 ResNode = CurDAG->getMachineNode(PPC::CRORC,
SDLoc(MachineNode),
5861 else if (AllUsersSelectZero(MachineNode)) {
5862 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
5871 ResNode = CurDAG->getMachineNode(PPC::CRUNSET,
SDLoc(MachineNode),
5875 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
5880 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
5891 ResNode = CurDAG->getMachineNode(PPC::CREQV,
SDLoc(MachineNode),
5897 ResNode = CurDAG->getMachineNode(PPC::CREQV,
SDLoc(MachineNode),
5901 else if (AllUsersSelectZero(MachineNode)) {
5902 ResNode = CurDAG->getMachineNode(PPC::CREQV,
SDLoc(MachineNode),
5909 if (Op1Set || Op2Set)
5911 ResNode = CurDAG->getMachineNode(PPC::CRUNSET,
SDLoc(MachineNode),
5915 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
5920 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
5925 ResNode = CurDAG->getMachineNode(PPC::CRANDC,
SDLoc(MachineNode),
5931 ResNode = CurDAG->getMachineNode(PPC::CRANDC,
SDLoc(MachineNode),
5935 else if (AllUsersSelectZero(MachineNode)) {
5936 ResNode = CurDAG->getMachineNode(PPC::CROR,
SDLoc(MachineNode),
5945 ResNode = CurDAG->getMachineNode(PPC::CRSET,
SDLoc(MachineNode),
5955 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
5960 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
5965 ResNode = CurDAG->getMachineNode(PPC::CRXOR,
SDLoc(MachineNode),
5971 ResNode = CurDAG->getMachineNode(PPC::CRXOR,
SDLoc(MachineNode),
5975 else if (AllUsersSelectZero(MachineNode)) {
5976 ResNode = CurDAG->getMachineNode(PPC::CRXOR,
SDLoc(MachineNode),
5985 ResNode = CurDAG->getMachineNode(PPC::CRUNSET,
SDLoc(MachineNode),
5989 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
5992 else if (Op1Unset || Op2Set)
5994 ResNode = CurDAG->getMachineNode(PPC::CRUNSET,
SDLoc(MachineNode),
6001 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
6007 ResNode = CurDAG->getMachineNode(PPC::CRAND,
SDLoc(MachineNode),
6011 else if (AllUsersSelectZero(MachineNode)) {
6012 ResNode = CurDAG->getMachineNode(PPC::CRORC,
SDLoc(MachineNode),
6021 ResNode = CurDAG->getMachineNode(PPC::CRSET,
SDLoc(MachineNode),
6023 else if (Op1Set || Op2Unset)
6025 ResNode = CurDAG->getMachineNode(PPC::CRSET,
SDLoc(MachineNode),
6032 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
6037 ResNode = CurDAG->getMachineNode(PPC::CRNAND,
SDLoc(MachineNode),
6043 ResNode = CurDAG->getMachineNode(PPC::CROR,
SDLoc(MachineNode),
6047 else if (AllUsersSelectZero(MachineNode)) {
6048 ResNode = CurDAG->getMachineNode(PPC::CRANDC,
SDLoc(MachineNode),
6054 case PPC::SELECT_I4:
6055 case PPC::SELECT_I8:
6056 case PPC::SELECT_F4:
6057 case PPC::SELECT_F8:
6058 case PPC::SELECT_QFRC:
6059 case PPC::SELECT_QSRC:
6060 case PPC::SELECT_QBRC:
6061 case PPC::SELECT_SPE:
6062 case PPC::SELECT_SPE4:
6063 case PPC::SELECT_VRRC:
6064 case PPC::SELECT_VSFRC:
6065 case PPC::SELECT_VSSRC:
6066 case PPC::SELECT_VSRC:
6083 ResNode = CurDAG->getMachineNode(Opcode == PPC::BC ? PPC::BCn :
6098 SwapAllSelectUsers(MachineNode);
6100 if (ResNode != MachineNode) {
6107 ReplaceUses(MachineNode, ResNode);
6112 CurDAG->RemoveDeadNodes();
6113 }
while (IsModified);
6224 if (!Op0OK && !Op1OK)
6247 if (!Op0OK && !Op1OK)
6261 void PPCDAGToDAGISel::PeepholePPC64ZExt() {
6276 bool MadeChange =
false;
6277 while (Position != CurDAG->allnodes_begin()) {
6322 bool OutsideUse =
false;
6323 for (
SDNode *PN : ToPromote) {
6325 if (!ToPromote.count(UN) && UN != ISR.
getNode()) {
6343 for (
SDNode *PN : ToPromote) {
6345 switch (PN->getMachineOpcode()) {
6348 case PPC::RLWINM: NewOpcode = PPC::RLWINM8;
break;
6349 case PPC::RLWNM: NewOpcode = PPC::RLWNM8;
break;
6350 case PPC::SLW: NewOpcode = PPC::SLW8;
break;
6351 case PPC::SRW: NewOpcode = PPC::SRW8;
break;
6352 case PPC::LI: NewOpcode = PPC::LI8;
break;
6353 case PPC::LIS: NewOpcode = PPC::LIS8;
break;
6354 case PPC::LHBRX: NewOpcode = PPC::LHBRX8;
break;
6355 case PPC::LWBRX: NewOpcode = PPC::LWBRX8;
break;
6356 case PPC::CNTLZW: NewOpcode = PPC::CNTLZW8;
break;
6357 case PPC::CNTTZW: NewOpcode = PPC::CNTTZW8;
break;
6358 case PPC::RLWIMI: NewOpcode = PPC::RLWIMI8;
break;
6359 case PPC::OR: NewOpcode = PPC::OR8;
break;
6360 case PPC::SELECT_I4: NewOpcode = PPC::SELECT_I8;
break;
6361 case PPC::ORI: NewOpcode = PPC::ORI8;
break;
6362 case PPC::ORIS: NewOpcode = PPC::ORIS8;
break;
6363 case PPC::AND: NewOpcode = PPC::AND8;
break;
6365 NewOpcode = PPC::ANDI8_rec;
6367 case PPC::ANDIS_rec:
6368 NewOpcode = PPC::ANDIS8_rec;
6379 if (!ToPromote.count(V.getNode()) && V.getValueType() ==
MVT::i32 &&
6380 !isa<ConstantSDNode>(V)) {
6383 CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG,
SDLoc(V),
6397 for (
unsigned i = 0, ie = VTs.
NumVTs; i != ie; ++i)
6406 CurDAG->SelectNodeTo(PN, NewOpcode, CurDAG->getVTList(NewVTs), Ops);
6423 ReplaceUses(N, Op32.
getNode());
6427 CurDAG->RemoveDeadNodes();
6430 void PPCDAGToDAGISel::PeepholePPC64() {
6437 while (Position != CurDAG->allnodes_begin()) {
6445 bool RequiresMod4Offset =
false;
6447 switch (StorageOpcode) {
6452 case PPC::DFLOADf64:
6453 case PPC::DFLOADf32:
6454 RequiresMod4Offset =
true;
6470 case PPC::DFSTOREf64:
6471 case PPC::DFSTOREf32:
6472 RequiresMod4Offset =
true;
6490 if (!isa<ConstantSDNode>(N->
getOperand(FirstOp)))
6498 bool ReplaceFlags =
true;
6518 ReplaceFlags =
false;
6522 if (RequiresMod4Offset &&
6527 case PPC::ADDIdtprelL:
6530 case PPC::ADDItlsldL:
6544 int MaxDisplacement = 7;
6547 MaxDisplacement = std::min((
int) GV->
getAlignment() - 1, MaxDisplacement);
6550 bool UpdateHBase =
false;
6555 if (Offset < 0 || Offset > MaxDisplacement) {
6570 if (HImmOpnd != ImmOpnd)
6581 if (
auto *
C = dyn_cast<ConstantSDNode>(ImmOpnd)) {
6582 Offset +=
C->getSExtValue();
6584 if (RequiresMod4Offset && (Offset % 4) != 0)
6590 ImmOpnd = CurDAG->getTargetConstant(Offset,
SDLoc(ImmOpnd),
6592 }
else if (Offset != 0) {
6601 LLVM_DEBUG(
dbgs() <<
"Folding add-immediate into mem-op:\nBase: ");
6616 (RequiresMod4Offset || (Offset % 4) != 0)) {
6617 LLVM_DEBUG(
dbgs() <<
"Rejected this candidate for alignment.\n\n");
6620 ImmOpnd = CurDAG->getTargetGlobalAddress(GV, dl,
MVT::i64, Offset, Flags);
6622 dyn_cast<ConstantPoolSDNode>(ImmOpnd)) {
6624 ImmOpnd = CurDAG->getTargetConstantPool(C,
MVT::i64,
6631 (void)CurDAG->UpdateNodeOperands(N, N->
getOperand(0), ImmOpnd,
6634 (void)CurDAG->UpdateNodeOperands(N, ImmOpnd, Base.
getOperand(0),
6643 CurDAG->RemoveDeadNode(Base.
getNode());
6652 return new PPCDAGToDAGISel(TM, OptLevel);
G8RC = ADDI_TLSLD_L_ADDR G8RReg, Symbol, Symbol - Op that combines ADDI_TLSLD_L and GET_TLSLD_ADDR un...
constexpr bool isUInt< 32 >(uint64_t x)
EVT getValueType() const
Return the ValueType of the referenced return value.
const SDValue & getOffset() const
raw_ostream & errs()
This returns a reference to a raw_ostream for standard error.
T findLastSet(T Val, ZeroBehavior ZB=ZB_Max)
Get the index of the last set bit starting from the least significant bit.
uint64_t getZExtValue() const
Get zero extended value.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
static cl::opt< bool > UseBitPermRewriter("ppc-use-bit-perm-rewriter", cl::init(true), cl::desc("use aggressive ppc isel for bit permutations"), cl::Hidden)
CondCode getSetCCInverse(CondCode Operation, EVT Type)
Return the operation corresponding to !(X op Y), where 'op' is a valid SetCC operation.
LLVM_ATTRIBUTE_NORETURN void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
BR_CC - Conditional branch.
This class represents lattice values for constants.
GPRC = address of GLOBAL_OFFSET_TABLE.
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
A Module instance is used to store all the information related to an LLVM module. ...
bool isPPC64() const
isPPC64 - Return true if we are generating code for 64-bit pointer mode.
BasicBlock * getSuccessor(unsigned Idx) const
Return the specified successor. This instruction must be a terminator.
unsigned getSizeInBits(Register Reg, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI) const
Get the size in bits of Reg.
const SDValue & getBasePtr() const
void push_back(const T &Elt)
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
VRRC = VADD_SPLAT Elt, EltSize - Temporary node to be expanded during instruction selection to optimi...
static int getRecordFormOpcode(unsigned Opcode)
const SDValue & getValue() const
SDVTList getVTList() const
static unsigned selectI64ImmInstrCountDirect(int64_t Imm)
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
static cl::opt< ICmpInGPRType > CmpInGPR("ppc-gpr-icmps", cl::Hidden, cl::init(ICGPR_All), cl::desc("Specify the types of comparisons to emit GPR-only code for."), cl::values(clEnumValN(ICGPR_None, "none", "Do not modify integer comparisons."), clEnumValN(ICGPR_All, "all", "All possible int comparisons in GPRs."), clEnumValN(ICGPR_I32, "i32", "Only i32 comparisons in GPRs."), clEnumValN(ICGPR_I64, "i64", "Only i64 comparisons in GPRs."), clEnumValN(ICGPR_NonExtIn, "nonextin", "Only comparisons where inputs don't need [sz]ext."), clEnumValN(ICGPR_Zext, "zext", "Only comparisons with zext result."), clEnumValN(ICGPR_ZextI32, "zexti32", "Only i32 comparisons with zext result."), clEnumValN(ICGPR_ZextI64, "zexti64", "Only i64 comparisons with zext result."), clEnumValN(ICGPR_Sext, "sext", "Only comparisons with sext result."), clEnumValN(ICGPR_SextI32, "sexti32", "Only i32 comparisons with sext result."), clEnumValN(ICGPR_SextI64, "sexti64", "Only i64 comparisons with sext result.")))
An efficient, type-erasing, non-owning reference to a callable.
const SDValue & getChain() const
ISD::MemIndexedMode getAddressingMode() const
Return the addressing mode for this load or store: unindexed, pre-inc, pre-dec, post-inc, or post-dec.
static cl::opt< bool > BPermRewriterNoMasking("ppc-bit-perm-rewriter-stress-rotates", cl::desc("stress rotate selection in aggressive ppc isel for " "bit permutations"), cl::Hidden)
TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or anything else with this node...
constexpr bool isInt< 16 >(int64_t x)
static bool isInt32Immediate(SDNode *N, unsigned &Imm)
isInt32Immediate - This method tests to see if the node is a 32-bit constant operand.
STATISTIC(NumFunctions, "Total number of functions")
static RegisterPass< DebugifyModulePass > DM("debugify", "Attach debug info to everything")
unsigned const TargetRegisterInfo * TRI
MVT getSimpleValueType(unsigned ResNo) const
Return the type of a specified result as a simple type.
CALL - A direct function call.
static cl::opt< bool > EnableTLSOpt("ppc-tls-opt", cl::init(true), cl::desc("Enable tls optimization peephole"), cl::Hidden)
void setNodeId(int Id)
Set unique node id.
SDNode * getNode() const
get the SDNode which holds the desired result
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
const Instruction * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned &Imm)
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
bool hasOneUse() const
Return true if there is exactly one node using value ResNo of Node.
bool isUnsignedIntSetCC(CondCode Code)
Return true if this is a setcc instruction that performs an unsigned comparison when used with intege...
This SDNode is used to implement the code generator support for the llvm IR shufflevector instruction...
GlobalBaseReg - On Darwin, this node represents the result of the mflr at function entry...
A templated base class for SmallPtrSet which provides the typesafe interface that is common across al...
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
bool hasOneUse() const
Return true if there is exactly one use of this node.
A description of a memory reference used in the backend.
PPCFunctionInfo - This class is derived from MachineFunction private PowerPC target-specific informat...
const HexagonInstrInfo * TII
G8RC = ADDI_TLSGD_L_ADDR G8RReg, Symbol, Symbol - Op that combines ADDI_TLSGD_L and GET_TLS_ADDR unti...
Shift and rotation operations.
A Use represents the edge between a Value definition and its users.
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), MachineInstr opcode, and operands.
uint64_t getConstantOperandVal(unsigned i) const
ISD::LoadExtType getExtensionType() const
Return whether this is a plain node, or one of the varieties of value-extending loads.
bool isZEXTLoad(const SDNode *N)
Returns true if the specified node is a ZEXTLOAD.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
TypeSize getValueSizeInBits() const
Returns the size of the value in bits.
const DataLayout & getDataLayout() const
unsigned getID() const
Return the register class ID number.
Position
Position to insert a new instruction relative to an existing instruction.
This file implements a class to represent arbitrary precision integral constant values and operations...
This represents a list of ValueType's that has been intern'd by a SelectionDAG.
static bool isRunOfOnes64(uint64_t Val, unsigned &MB, unsigned &ME)
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
int64_t getSExtValue() const
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...
CHAIN = BDNZ CHAIN, DESTBB - These are used to create counter-based loops.
R32 = MFOCRF(CRREG, INFLAG) - Represents the MFOCRF instruction.
Simple integer binary arithmetic operators.
static PPC::Predicate getPredicateForSetCC(ISD::CondCode CC, const EVT &VT, const PPCSubtarget *Subtarget)
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out...
unsigned getOperandNo() const
Return the operand # of this use in its User.
TargetConstant* - Like Constant*, but the DAG does not do any folding, simplification, or lowering of the constant.
unsigned getAlignment() const
SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
ArrayRef< SDUse > ops() const
bool isSignedIntSetCC(CondCode Code)
Return true if this is a setcc instruction that performs a signed comparison when used with integer o...
unsigned getNumSuccessors() const
Return the number of successors that this instruction has.
This class is used to represent ISD::STORE nodes.
TargetInstrInfo - Interface to description of machine instruction set.
static APInt getHighBitsSet(unsigned numBits, unsigned hiBitsSet)
Get a value with high bits set.
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
unsigned getObjectAlignment(int ObjectIdx) const
Return the alignment of the specified stack object.
const SDValue & getBasePtr() const
initializer< Ty > init(const Ty &Val)
cl::opt< bool > ANDIGlueBug("expose-ppc-andi-glue-bug", cl::desc("expose the ANDI glue bug on PPC"), cl::Hidden)
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
use_iterator use_begin() const
Provide iteration support to walk over all uses of an SDNode.
LLVM Basic Block Representation.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
static SDNode * selectI64ImmDirect(SelectionDAG *CurDAG, const SDLoc &dl, int64_t Imm)
bool isMachineOpcode() const
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This is an important base class in LLVM.
ValuesClass values(OptsTy... Options)
Helper to build a ValuesClass by forwarding a variable number of arguments as an initializer list to ...
const SDValue & getOperand(unsigned Num) const
CHAIN,FLAG = MTCTR(VAL, CHAIN[, INFLAG]) - Directly corresponds to a MTCTR instruction.
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
const SDValue & getOffset() const
This class provides iterator support for SDUse operands that use a specific SDNode.
unsigned getMachineOpcode() const
const PPCTargetLowering * getTargetLowering() const override
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
static bool isInt64Immediate(SDNode *N, uint64_t &Imm)
isInt64Immediate - This method tests to see if the node is a 64-bit constant operand.
FunctionPass class - This class is used to implement most global optimizations.
AssertSext, AssertZext - These nodes record if a register contains a value that has already been zero...
Common code between 32-bit and 64-bit PowerPC targets.
auto remove_if(R &&Range, UnaryPredicate P) -> decltype(adl_begin(Range))
Provide wrappers to std::remove_if which take ranges instead of having to pass begin/end explicitly...
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...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
const MachineBasicBlock & front() const
TypeSize getSizeInBits() const
Return the size of the specified value type in bits.
bool isLittleEndian() const
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode...
unsigned getNumOperands() const
Return the number of values used by this operation.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
MachineBasicBlock * MBB
MBB - The current block.
bool isUnindexed() const
Return true if this is NOT a pre/post inc/dec load/store.
BranchProbability getEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors) const
Get an edge's probability, relative to other out-edges of the Src.
void sort(IteratorTy Start, IteratorTy End)
bool use_empty() const
Return true if there are no uses of this node.
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
void dump() const
Dump this node, for debugging.
const PPCRegisterInfo * getRegisterInfo() const override
static bool PeepholePPC64ZExtGather(SDValue Op32, SmallPtrSetImpl< SDNode *> &ToPromote)
const TargetLowering & getTargetLoweringInfo() const
Iterator for intrusive lists based on ilist_node.
SmallPtrSet - This class implements a set which is optimized for holding SmallSize or less elements...
GPRC = TOC_ENTRY GA, TOC Loads the entry for GA from the TOC, where the TOC base is given by the last...
constexpr bool isInt< 32 >(int64_t x)
Align max(MaybeAlign Lhs, Align Rhs)
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
const PPCInstrInfo * getInstrInfo() const override
static bool mayUseP9Setb(SDNode *N, const ISD::CondCode &CC, SelectionDAG *DAG, bool &NeedSwapOps, bool &IsUnCmp)
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
G8RC = ADD_TLS G8RReg, Symbol - Used by the initial-exec TLS model, produces an ADD instruction that ...
Module.h This file contains the declarations for the Module class.
bool is32BitELFABI() const
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
EVT changeVectorElementTypeToInteger() const
Return a vector with the same number of elements as this vector, but with the element type converted ...
An SDNode that represents everything that will be needed to construct a MachineInstr.
LLVM_NODISCARD T pop_back_val()
CHAIN = SC CHAIN, Imm128 - System call.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
Represents one node in the SelectionDAG.
SelectionDAGISel - This is the common base class used for SelectionDAG-based pattern-matching instruc...
These values identify relocations on immediates folded into memory operations.
bool isBitwiseNot(SDValue V, bool AllowUndefs=false)
Returns true if V is a bitwise not operation.
const Function & getFunction() const
Return the LLVM function that this machine code represents.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
The access may modify the value stored in memory.
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
EVT getMemoryVT() const
Return the type of the in-memory value.
Target - Wrapper for Target specific information.
CodeModel::Model getCodeModel() const
Returns the code model.
iterator_range< use_iterator > uses()
BranchProbabilityInfo * BPI
Select(COND, TRUEVAL, FALSEVAL).
static use_iterator use_end()
ZERO_EXTEND - Used for integer types, zeroing the new bits.
static cl::opt< unsigned > Threshold("loop-unswitch-threshold", cl::desc("Max loop size to unswitch"), cl::init(100), cl::Hidden)
ANY_EXTEND - Used for integer types. The high bits are undefined.
The combination of sra[wd]i and addze used to implemented signed integer division by a power of 2...
int getMaskElt(unsigned Idx) const
static SDNode * selectI64Imm(SelectionDAG *CurDAG, const SDLoc &dl, int64_t Imm)
#define clEnumValN(ENUMVAL, FLAGNAME, DESC)
static unsigned allUsesTruncate(SelectionDAG *CurDAG, SDNode *N)
static unsigned getBranchHint(unsigned PCC, const FunctionLoweringInfo &FuncInfo, const SDValue &DestMBB)
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
bool isVector() const
Return true if this is a vector value type.
Bitwise operators - logical and, logical or, logical xor.
FunctionPass * createPPCISelDag(PPCTargetMachine &TM, CodeGenOpt::Level OL)
createPPCISelDag - This pass converts a legalized DAG into a PowerPC-specific DAG, ready for instruction scheduling.
LLVM_NODISCARD bool empty() const
bool isPositionIndependent() const
static unsigned selectI64ImmInstrCount(int64_t Imm)
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
StringRef getName() const
Return a constant reference to the value's name.
FunctionLoweringInfo - This contains information that is global to a function that is used when lower...
The CMPB instruction (takes two operands of i32 or i64).
static cl::opt< bool > EnableBranchHint("ppc-use-branch-hint", cl::init(true), cl::desc("Enable static hinting of branches on ppc"), cl::Hidden)
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
bool useCRBits() const
useCRBits - Return true if we should store and manipulate i1 values in the individual condition regis...
unsigned getOpcode() const
SDValue getValue(unsigned R) const
constexpr bool isUInt< 16 >(uint64_t x)
bool isDarwin() const
isDarwin - True if this is any darwin platform.
constexpr int64_t SignExtend64(uint64_t x)
Sign-extend the number in the bottom B bits of X to a 64-bit integer.
CopyFromReg - This node indicates that the input value is a virtual or physical register that is defi...
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
i1 = ANDI_rec_1_[EQ|GT]_BIT(i32 or i64 x) - Represents the result of the eq or gt bit of CR0 after ex...
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...
bool operator<(int64_t V1, const APSInt &V2)
static uint64_t Rot64(uint64_t Imm, unsigned R)
Module * getParent()
Get the module that this global value is contained inside of...
uint64_t getConstantOperandVal(unsigned Num) const
Helper method returns the integer value of a ConstantSDNode operand.
unsigned getResNo() const
get the index which selects a specific result in the SDNode
CHAIN = COND_BRANCH CHAIN, CRRC, OPC, DESTBB [, INFLAG] - This corresponds to the COND_BRANCH pseudo ...
unsigned getMachineOpcode() const
This may only be called if isMachineOpcode returns true.
unsigned countTrailingOnes(T Value, ZeroBehavior ZB=ZB_Width)
Count the number of ones from the least significant bit to the first zero bit.
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
std::underlying_type< E >::type Mask()
Get a bitmask with 1s in all places up to the high-order bit of E's largest value.
static unsigned getCRIdxForSetCC(ISD::CondCode CC, bool &Invert)
getCRIdxForSetCC - Return the index of the condition register field associated with the SetCC conditi...
PICLevel::Level getPICLevel() const
Returns the PIC level (small or large model)
StringRef - Represent a constant reference to a string, i.e.
SetCC operator - This evaluates to a true value iff the condition is true.
unsigned getNumOperands() const
const SDValue & getOperand(unsigned i) const
TRUNCATE - Completely drop the high bits.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
On a symbol operand "FOO", this indicates that the reference is actually to "FOO@plt".
const MachineInstrBuilder & addReg(Register RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
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...
SCALAR_TO_VECTOR(VAL) - This represents the operation of loading a scalar value into element 0 of the...
Wrapper class representing virtual and physical registers.
XXPERMDI - The PPC XXPERMDI instruction.
virtual const TargetRegisterClass * getPointerRegClass(const MachineFunction &MF, unsigned Kind=0) const
Returns a TargetRegisterClass used for pointer values.
static unsigned int getVCmpInst(MVT VecVT, ISD::CondCode CC, bool HasVSX, bool &Swap, bool &Negate)
This class is used to represent ISD::LOAD nodes.