70 #define DEBUG_TYPE "ppc-codegen"
73 "Number of (sext(setcc)) nodes expanded into GPR sequence.");
75 "Number of (zext(setcc)) nodes expanded into GPR sequence.");
77 "Number of sign extensions for compare inputs added.");
79 "Number of zero extensions for compare inputs added.");
81 "Number of logical ops on i1 values calculated in GPR.");
83 "Number of compares not eliminated as they have non-extending uses.");
91 cl::desc(
"use aggressive ppc isel for bit permutations"),
94 "ppc-bit-perm-rewriter-stress-rotates",
95 cl::desc(
"stress rotate selection in aggressive ppc isel for "
100 "ppc-use-branch-hint",
cl::init(
true),
101 cl::desc(
"Enable static hinting of branches on ppc"),
127 if (!PPCSubTarget->isSVR4ABI())
128 InsertVRSaveCode(MF);
133 void PreprocessISelDAG()
override;
134 void PostprocessISelDAG()
override;
138 inline SDValue getI32Imm(
unsigned Imm,
const SDLoc &dl) {
139 return CurDAG->getTargetConstant(Imm, dl,
MVT::i32);
144 inline SDValue getI64Imm(uint64_t Imm,
const SDLoc &dl) {
145 return CurDAG->getTargetConstant(Imm, dl,
MVT::i64);
149 inline SDValue getSmallIPtrImm(
unsigned Imm,
const SDLoc &dl) {
150 return CurDAG->getTargetConstant(
151 Imm, dl, PPCLowering->getPointerTy(CurDAG->getDataLayout()));
156 static bool isRotateAndMask(
SDNode *
N,
unsigned Mask,
bool isShiftMask,
157 unsigned &SH,
unsigned &MB,
unsigned &ME);
161 SDNode *getGlobalBaseReg();
169 bool tryBitfieldInsert(
SDNode *
N);
170 bool tryBitPermutation(
SDNode *
N);
181 return PPCLowering->SelectAddressRegImm(N, Disp, Base, *CurDAG, 0);
201 return PPCLowering->SelectAddressRegReg(N, Base, Index, *CurDAG);
207 return PPCLowering->SelectAddressRegRegOnly(N, Base, Index, *CurDAG);
214 return PPCLowering->SelectAddressRegImm(N, Disp, Base, *CurDAG, 4);
218 return PPCLowering->SelectAddressRegImm(N, Disp, Base, *CurDAG, 16);
232 bool SelectInlineAsmMemoryOperand(
const SDValue &
Op,
233 unsigned ConstraintID,
234 std::vector<SDValue> &OutOps)
override {
235 switch(ConstraintID) {
237 errs() <<
"ConstraintID: " << ConstraintID <<
"\n";
253 SDValue(CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS,
257 OutOps.push_back(NewOp);
266 return "PowerPC DAG->DAG Pattern Instruction Selection";
270 #include "PPCGenDAGISel.inc"
275 enum ExtOrTruncConversion {
Ext, Trunc };
283 enum SetccInGPROpts { ZExtOrig, ZExtInvert, SExtOrig, SExtInvert };
286 bool tryEXTEND(
SDNode *N);
287 bool tryLogicOpOfCompares(
SDNode *N);
291 SDValue addExtOrTrunc(
SDValue NatWidthRes, ExtOrTruncConversion Conv);
293 int64_t RHSValue,
SDLoc dl);
295 int64_t RHSValue,
SDLoc dl);
297 int64_t RHSValue,
SDLoc dl);
299 int64_t RHSValue,
SDLoc dl);
302 void PeepholePPC64();
303 void PeepholePPC64ZExt();
304 void PeepholeCROps();
309 bool AllUsersSelectZero(
SDNode *N);
310 void SwapAllSelectUsers(
SDNode *N);
312 bool isOffsetMultipleOf(
SDNode *N,
unsigned Val)
const;
327 bool HasVectorVReg =
false;
328 for (
unsigned i = 0, e = RegInfo->getNumVirtRegs(); i != e; ++i) {
330 if (RegInfo->getRegClass(Reg) == &PPC::VRRCRegClass) {
331 HasVectorVReg =
true;
335 if (!HasVectorVReg)
return;
349 unsigned InVRSAVE = RegInfo->createVirtualRegister(&PPC::GPRCRegClass);
350 unsigned UpdatedVRSAVE = RegInfo->createVirtualRegister(&PPC::GPRCRegClass);
360 BuildMI(EntryBB, IP, dl, TII.
get(PPC::MFVRSAVE), InVRSAVE);
361 BuildMI(EntryBB, IP, dl, TII.
get(PPC::UPDATE_VRSAVE),
362 UpdatedVRSAVE).addReg(InVRSAVE);
363 BuildMI(EntryBB, IP, dl, TII.
get(PPC::MTVRSAVE)).addReg(UpdatedVRSAVE);
367 if (BB->isReturnBlock()) {
368 IP = BB->end(); --IP;
373 while (I2 != BB->begin() && (--I2)->isTerminator())
377 BuildMI(*BB, IP, dl, TII.
get(PPC::MTVRSAVE)).addReg(InVRSAVE);
385 SDNode *PPCDAGToDAGISel::getGlobalBaseReg() {
394 if (PPCLowering->getPointerTy(CurDAG->getDataLayout()) ==
MVT::i32) {
395 if (PPCSubTarget->isTargetELF()) {
398 BuildMI(FirstMBB, MBBI, dl, TII.
get(PPC::MoveGOTtoLR));
402 BuildMI(FirstMBB, MBBI, dl, TII.
get(PPC::MovePCtoLR));
404 unsigned TempReg = RegInfo->createVirtualRegister(&PPC::GPRCRegClass);
412 RegInfo->createVirtualRegister(&PPC::GPRC_and_GPRC_NOR0RegClass);
413 BuildMI(FirstMBB, MBBI, dl, TII.
get(PPC::MovePCtoLR));
417 GlobalBaseReg = RegInfo->createVirtualRegister(&PPC::G8RC_and_G8RC_NOX0RegClass);
418 BuildMI(FirstMBB, MBBI, dl, TII.
get(PPC::MovePCtoLR8));
423 PPCLowering->getPointerTy(CurDAG->getDataLayout()))
431 Imm = cast<ConstantSDNode>(
N)->getZExtValue();
441 Imm = cast<ConstantSDNode>(
N)->getZExtValue();
455 assert(isa<BasicBlockSDNode>(DestMBB));
490 <<
" -> " << TBB->
getName() <<
": " << TProb <<
"\n"
491 <<
" -> " << FBB->
getName() <<
": " << FProb <<
"\n");
497 if (BBDN->getBasicBlock()->getBasicBlock() != TBB)
513 int FI = cast<FrameIndexSDNode>(
N)->getIndex();
518 getSmallIPtrImm(Offset, dl));
520 ReplaceNode(SN, CurDAG->getMachineNode(Opc, dl, N->
getValueType(0), TFI,
521 getSmallIPtrImm(Offset, dl)));
524 bool PPCDAGToDAGISel::isRotateAndMask(
SDNode *N,
unsigned Mask,
525 bool isShiftMask,
unsigned &SH,
526 unsigned &MB,
unsigned &ME) {
533 unsigned Indeterminant = ~0;
541 if (isShiftMask) Mask = Mask << Shift;
543 Indeterminant = ~(0xFFFFFFFFu << Shift);
546 if (isShiftMask) Mask = Mask >> Shift;
548 Indeterminant = ~(0xFFFFFFFFu >> Shift);
558 if (Mask && !(Mask & Indeterminant)) {
568 bool PPCDAGToDAGISel::tryBitfieldInsert(
SDNode *N) {
574 CurDAG->computeKnownBits(Op0, LKnown);
575 CurDAG->computeKnownBits(Op1, RKnown);
580 if ((TargetMask | InsertMask) == 0xFFFFFFFF) {
583 unsigned Value, SH = 0;
584 TargetMask = ~TargetMask;
585 InsertMask = ~InsertMask;
615 SH = (Op1Opc ==
ISD::SHL) ? Value : 32 - Value;
622 CurDAG->computeKnownBits(Op1.
getOperand(1), MKnown);
631 SH = (SHOpc ==
ISD::SHL) ? Value : 32 - Value;
636 SDValue Ops[] = { Op0, Op1, getI32Imm(SH, dl), getI32Imm(MB, dl),
638 ReplaceNode(N, CurDAG->getMachineNode(PPC::RLWIMI, dl,
MVT::i32, Ops));
649 unsigned Remainder = 0;
655 Shift = countTrailingZeros<uint64_t>(Imm);
656 int64_t ImmSh =
static_cast<uint64_t
>(Imm) >> Shift;
674 unsigned Lo = Imm & 0xFFFF;
689 if (!Shift)
return Result;
693 if ((
unsigned)(Imm & 0xFFFFFFFF) == Remainder) {
703 if ((Remainder >> 16) & 0xFFFF)
705 if (Remainder & 0xFFFF)
711 static uint64_t
Rot64(uint64_t Imm,
unsigned R) {
712 return (Imm << R) | (Imm >> (64 - R));
723 for (
unsigned r = 1; r < 63; ++r) {
724 uint64_t RImm =
Rot64(Imm, r);
733 uint64_t OnesMask = -(int64_t) (UINT64_C(1) << (LS+1));
734 uint64_t RImmWithOnes = RImm | OnesMask;
748 unsigned Remainder = 0;
754 Shift = countTrailingZeros<uint64_t>(Imm);
755 int64_t ImmSh =
static_cast<uint64_t
>(Imm) >> Shift;
773 unsigned Lo = Imm & 0xFFFF;
774 unsigned Hi = (Imm >> 16) & 0xFFFF;
776 auto getI32Imm = [CurDAG, dl](
unsigned Imm) {
786 unsigned OpC = Hi ? PPC::LIS8 : PPC::LI8;
790 SDValue(Result, 0), getI32Imm(Lo));
797 if (!Shift)
return Result;
801 if ((
unsigned)(Imm & 0xFFFFFFFF) == Remainder) {
803 {
SDValue(Result, 0),
SDValue(Result, 0), getI32Imm(Shift), getI32Imm(0)};
812 getI32Imm(63 - Shift));
816 if ((Hi = (Remainder >> 16) & 0xFFFF)) {
818 SDValue(Result, 0), getI32Imm(Hi));
820 if ((Lo = Remainder & 0xFFFF)) {
822 SDValue(Result, 0), getI32Imm(Lo));
841 for (
unsigned r = 1; r < 63; ++r) {
842 uint64_t RImm =
Rot64(Imm, r);
844 if (RCount < Count) {
863 uint64_t OnesMask = -(int64_t) (UINT64_C(1) << (LS+1));
864 uint64_t RImmWithOnes = RImm | OnesMask;
867 if (RCount < Count) {
870 MatImm = RImmWithOnes;
878 auto getI32Imm = [CurDAG, dl](
unsigned Imm) {
884 getI32Imm(64 - RMin), getI32Imm(MaskEnd));
892 int64_t Imm = cast<ConstantSDNode>(
N)->getZExtValue();
898 class BitPermutationSelector {
912 : V(V), Idx(I), K(K) {}
913 ValueBit(
Kind K = Variable)
914 : V(
SDValue(nullptr, 0)), Idx(UINT32_MAX), K(K) {}
917 return K == ConstZero;
920 bool hasValue()
const {
921 return K == Variable;
925 assert(hasValue() &&
"Cannot get the value of a constant bit");
929 unsigned getValueBitIndex()
const {
930 assert(hasValue() &&
"Cannot get the value bit index of a constant bit");
939 unsigned StartIdx, EndIdx;
949 bool Repl32Coalesced;
951 BitGroup(
SDValue V,
unsigned R,
unsigned S,
unsigned E)
952 : V(V), RLAmt(R), StartIdx(S), EndIdx(E), Repl32(
false), Repl32CR(
false),
953 Repl32Coalesced(
false) {
955 " [" << S <<
", " << E <<
"]\n");
961 struct ValueRotInfo {
964 unsigned NumGroups = 0;
968 ValueRotInfo() =
default;
972 bool operator < (
const ValueRotInfo &Other)
const {
976 if (Repl32 < Other.Repl32)
978 else if (Repl32 > Other.Repl32)
980 else if (NumGroups > Other.NumGroups)
982 else if (NumGroups < Other.NumGroups)
984 else if (FirstGroupStartIdx < Other.FirstGroupStartIdx)
990 using ValueBitsMemoizedValue = std::pair<bool, SmallVector<ValueBit, 64>>;
991 using ValueBitsMemoizer =
993 ValueBitsMemoizer Memoizer;
999 std::pair<bool, SmallVector<ValueBit, 64> *> getValueBits(
SDValue V,
1001 auto &ValueEntry = Memoizer[V];
1003 return std::make_pair(ValueEntry->first, &ValueEntry->second);
1004 ValueEntry.reset(
new ValueBitsMemoizedValue());
1005 bool &Interesting = ValueEntry->first;
1017 for (
unsigned i = 0; i < NumBits; ++i)
1018 Bits[i] = LHSBits[i < RotAmt ? i + (NumBits - RotAmt) : i - RotAmt];
1020 return std::make_pair(Interesting =
true, &Bits);
1029 for (
unsigned i = ShiftAmt; i < NumBits; ++i)
1030 Bits[i] = LHSBits[i - ShiftAmt];
1032 for (
unsigned i = 0; i < ShiftAmt; ++i)
1033 Bits[i] = ValueBit(ValueBit::ConstZero);
1035 return std::make_pair(Interesting =
true, &Bits);
1044 for (
unsigned i = 0; i < NumBits - ShiftAmt; ++i)
1045 Bits[i] = LHSBits[i + ShiftAmt];
1047 for (
unsigned i = NumBits - ShiftAmt; i < NumBits; ++i)
1048 Bits[i] = ValueBit(ValueBit::ConstZero);
1050 return std::make_pair(Interesting =
true, &Bits);
1062 std::tie(Interesting, LHSBits) = getValueBits(V.
getOperand(0), NumBits);
1064 for (
unsigned i = 0; i < NumBits; ++i)
1065 if (((Mask >> i) & 1) == 1)
1066 Bits[i] = (*LHSBits)[i];
1068 Bits[i] = ValueBit(ValueBit::ConstZero);
1070 return std::make_pair(Interesting, &Bits);
1077 bool AllDisjoint =
true;
1078 for (
unsigned i = 0; i < NumBits; ++i)
1080 Bits[i] = RHSBits[i];
1081 else if (RHSBits[i].
isZero())
1082 Bits[i] = LHSBits[i];
1084 AllDisjoint =
false;
1091 return std::make_pair(Interesting =
true, &Bits);
1095 for (
unsigned i = 0; i < NumBits; ++i)
1096 Bits[i] = ValueBit(V, i);
1098 return std::make_pair(Interesting =
false, &Bits);
1103 void computeRotationAmounts() {
1105 RLAmt.resize(Bits.
size());
1106 for (
unsigned i = 0; i < Bits.
size(); ++i)
1107 if (Bits[i].hasValue()) {
1108 unsigned VBI = Bits[i].getValueBitIndex();
1112 RLAmt[i] = Bits.
size() - (VBI - i);
1113 }
else if (Bits[i].
isZero()) {
1115 RLAmt[i] = UINT32_MAX;
1124 void collectBitGroups(
bool LateMask) {
1127 unsigned LastRLAmt = RLAmt[0];
1128 SDValue LastValue = Bits[0].hasValue() ? Bits[0].getValue() :
SDValue();
1129 unsigned LastGroupStartIdx = 0;
1130 for (
unsigned i = 1; i < Bits.
size(); ++i) {
1131 unsigned ThisRLAmt = RLAmt[i];
1132 SDValue ThisValue = Bits[i].hasValue() ? Bits[i].getValue() :
SDValue();
1133 if (LateMask && !ThisValue) {
1134 ThisValue = LastValue;
1135 ThisRLAmt = LastRLAmt;
1138 if (BitGroups.empty())
1139 LastGroupStartIdx = 0;
1144 if (ThisRLAmt == LastRLAmt && ThisValue == LastValue)
1148 BitGroups.push_back(BitGroup(LastValue, LastRLAmt, LastGroupStartIdx,
1150 LastRLAmt = ThisRLAmt;
1151 LastValue = ThisValue;
1152 LastGroupStartIdx = i;
1155 BitGroups.push_back(BitGroup(LastValue, LastRLAmt, LastGroupStartIdx,
1158 if (BitGroups.empty())
1162 if (BitGroups.size() > 1) {
1166 if (BitGroups[0].StartIdx == 0 &&
1167 BitGroups[BitGroups.size()-1].EndIdx == Bits.
size()-1 &&
1168 BitGroups[0].V == BitGroups[BitGroups.size()-1].V &&
1169 BitGroups[0].RLAmt == BitGroups[BitGroups.size()-1].RLAmt) {
1170 DEBUG(
dbgs() <<
"\tcombining final bit group with initial one\n");
1171 BitGroups[BitGroups.size()-1].EndIdx = BitGroups[0].EndIdx;
1172 BitGroups.erase(BitGroups.begin());
1180 void collectValueRotInfo() {
1183 for (
auto &BG : BitGroups) {
1184 unsigned RLAmtKey = BG.RLAmt + (BG.Repl32 ? 64 : 0);
1185 ValueRotInfo &VRI = ValueRots[std::make_pair(BG.V, RLAmtKey)];
1187 VRI.RLAmt = BG.RLAmt;
1188 VRI.Repl32 = BG.Repl32;
1190 VRI.FirstGroupStartIdx =
std::min(VRI.FirstGroupStartIdx, BG.StartIdx);
1195 ValueRotsVec.clear();
1196 for (
auto &
I : ValueRots) {
1197 ValueRotsVec.push_back(
I.second);
1199 std::sort(ValueRotsVec.begin(), ValueRotsVec.end());
1210 void assignRepl32BitGroups() {
1221 auto IsAllLow32 = [
this](BitGroup & BG) {
1222 if (BG.StartIdx <= BG.EndIdx) {
1223 for (
unsigned i = BG.StartIdx; i <= BG.EndIdx; ++i) {
1224 if (!Bits[i].hasValue())
1226 if (Bits[i].getValueBitIndex() >= 32)
1230 for (
unsigned i = BG.StartIdx; i < Bits.
size(); ++i) {
1231 if (!Bits[i].hasValue())
1233 if (Bits[i].getValueBitIndex() >= 32)
1236 for (
unsigned i = 0; i <= BG.EndIdx; ++i) {
1237 if (!Bits[i].hasValue())
1239 if (Bits[i].getValueBitIndex() >= 32)
1247 for (
auto &BG : BitGroups) {
1248 if (BG.StartIdx < 32 && BG.EndIdx < 32) {
1249 if (IsAllLow32(BG)) {
1250 if (BG.RLAmt >= 32) {
1257 DEBUG(
dbgs() <<
"\t32-bit replicated bit group for " <<
1258 BG.V.getNode() <<
" RLAmt = " << BG.RLAmt <<
1259 " [" << BG.StartIdx <<
", " << BG.EndIdx <<
"]\n");
1265 for (
auto I = BitGroups.begin();
I != BitGroups.end();) {
1268 auto IP = (
I == BitGroups.begin()) ?
1269 std::prev(BitGroups.end()) : std::prev(
I);
1270 if (
I->Repl32 && IP->Repl32 &&
I->V == IP->V &&
I->RLAmt == IP->RLAmt &&
1271 I->StartIdx == (IP->EndIdx + 1) % 64 &&
I != IP) {
1273 DEBUG(
dbgs() <<
"\tcombining 32-bit replicated bit group for " <<
1274 I->V.getNode() <<
" RLAmt = " <<
I->RLAmt <<
1275 " [" <<
I->StartIdx <<
", " <<
I->EndIdx <<
1276 "] with group with range [" <<
1277 IP->StartIdx <<
", " << IP->EndIdx <<
"]\n");
1279 IP->EndIdx =
I->EndIdx;
1280 IP->Repl32CR = IP->Repl32CR ||
I->Repl32CR;
1281 IP->Repl32Coalesced =
true;
1282 I = BitGroups.erase(
I);
1291 if (
I->StartIdx == 32 &&
I->EndIdx == 63) {
1292 assert(std::next(
I) == BitGroups.end() &&
1293 "bit group ends at index 63 but there is another?");
1294 auto IN = BitGroups.begin();
1296 if (IP->Repl32 && IN->Repl32 &&
I->V == IP->V &&
I->V == IN->V &&
1297 (
I->RLAmt % 32) == IP->RLAmt && (
I->RLAmt % 32) == IN->RLAmt &&
1298 IP->EndIdx == 31 && IN->StartIdx == 0 &&
I != IP &&
1301 DEBUG(
dbgs() <<
"\tcombining bit group for " <<
1302 I->V.getNode() <<
" RLAmt = " <<
I->RLAmt <<
1303 " [" <<
I->StartIdx <<
", " <<
I->EndIdx <<
1304 "] with 32-bit replicated groups with ranges [" <<
1305 IP->StartIdx <<
", " << IP->EndIdx <<
"] and [" <<
1306 IN->StartIdx <<
", " << IN->EndIdx <<
"]\n");
1314 IP->Repl32CR = IP->Repl32CR ||
I->RLAmt >= 32;
1315 IP->Repl32Coalesced =
true;
1316 I = BitGroups.erase(
I);
1321 IP->EndIdx = IN->EndIdx;
1322 IP->Repl32CR = IP->Repl32CR || IN->Repl32CR ||
I->RLAmt >= 32;
1323 IP->Repl32Coalesced =
true;
1324 I = BitGroups.erase(
I);
1325 BitGroups.erase(BitGroups.begin());
1340 return CurDAG->getTargetConstant(Imm, dl,
MVT::i32);
1343 uint64_t getZerosMask() {
1345 for (
unsigned i = 0; i < Bits.
size(); ++i) {
1346 if (Bits[i].hasValue())
1348 Mask |= (UINT64_C(1) << i);
1357 void SelectAndParts32(
const SDLoc &dl,
SDValue &Res,
unsigned *InstCnt) {
1361 for (ValueRotInfo &VRI : ValueRotsVec) {
1363 for (
unsigned i = 0; i < Bits.
size(); ++i) {
1364 if (!Bits[i].hasValue() || Bits[i].getValue() != VRI.V)
1366 if (RLAmt[i] != VRI.RLAmt)
1372 unsigned ANDIMask = (Mask & UINT16_MAX), ANDISMask = Mask >> 16;
1373 assert((ANDIMask != 0 || ANDISMask != 0) &&
1374 "No set bits in mask for value bit groups");
1375 bool NeedsRotate = VRI.RLAmt != 0;
1391 unsigned NumAndInsts = (
unsigned) NeedsRotate +
1392 (
unsigned) (ANDIMask != 0) +
1393 (
unsigned) (ANDISMask != 0) +
1394 (
unsigned) (ANDIMask != 0 && ANDISMask != 0) +
1395 (
unsigned) (
bool) Res;
1397 DEBUG(
dbgs() <<
"\t\trotation groups for " << VRI.V.getNode() <<
1398 " RL: " << VRI.RLAmt <<
":" <<
1399 "\n\t\t\tisel using masking: " << NumAndInsts <<
1400 " using rotates: " << VRI.NumGroups <<
"\n");
1402 if (NumAndInsts >= VRI.NumGroups)
1405 DEBUG(
dbgs() <<
"\t\t\t\tusing masking\n");
1407 if (InstCnt) *InstCnt += NumAndInsts;
1412 { VRI.V, getI32Imm(VRI.RLAmt, dl), getI32Imm(0, dl),
1413 getI32Imm(31, dl) };
1423 VRot, getI32Imm(ANDIMask, dl)), 0);
1426 VRot, getI32Imm(ANDISMask, dl)), 0);
1430 TotalVal = ANDISVal;
1435 ANDIVal, ANDISVal), 0);
1445 eraseMatchingBitGroups([VRI](
const BitGroup &BG) {
1446 return BG.V == VRI.V && BG.RLAmt == VRI.RLAmt;
1452 SDNode *Select32(
SDNode *N,
bool LateMask,
unsigned *InstCnt) {
1456 if (InstCnt) *InstCnt = 0;
1459 SelectAndParts32(dl, Res, InstCnt);
1464 if ((!HasZeros || LateMask) && !Res) {
1465 ValueRotInfo &VRI = ValueRotsVec[0];
1467 if (InstCnt) *InstCnt += 1;
1469 { VRI.V, getI32Imm(VRI.RLAmt, dl), getI32Imm(0, dl),
1470 getI32Imm(31, dl) };
1478 eraseMatchingBitGroups([VRI](
const BitGroup &BG) {
1479 return BG.V == VRI.V && BG.RLAmt == VRI.RLAmt;
1483 if (InstCnt) *InstCnt += BitGroups.size();
1486 for (
auto &BG : BitGroups) {
1489 { BG.V, getI32Imm(BG.RLAmt, dl),
1490 getI32Imm(Bits.
size() - BG.EndIdx - 1, dl),
1491 getI32Imm(Bits.
size() - BG.StartIdx - 1, dl) };
1492 Res =
SDValue(CurDAG->getMachineNode(PPC::RLWINM, dl,
MVT::i32, Ops), 0);
1495 { Res, BG.V, getI32Imm(BG.RLAmt, dl),
1496 getI32Imm(Bits.
size() - BG.EndIdx - 1, dl),
1497 getI32Imm(Bits.
size() - BG.StartIdx - 1, dl) };
1498 Res =
SDValue(CurDAG->getMachineNode(PPC::RLWIMI, dl,
MVT::i32, Ops), 0);
1503 unsigned Mask = (
unsigned) getZerosMask();
1505 unsigned ANDIMask = (Mask & UINT16_MAX), ANDISMask = Mask >> 16;
1506 assert((ANDIMask != 0 || ANDISMask != 0) &&
1507 "No set bits in zeros mask?");
1509 if (InstCnt) *InstCnt += (
unsigned) (ANDIMask != 0) +
1511 (
unsigned) (ANDIMask != 0 && ANDISMask != 0);
1516 Res, getI32Imm(ANDIMask, dl)), 0);
1519 Res, getI32Imm(ANDISMask, dl)), 0);
1527 ANDIVal, ANDISVal), 0);
1533 unsigned SelectRotMask64Count(
unsigned RLAmt,
bool Repl32,
1534 unsigned MaskStart,
unsigned MaskEnd,
1538 unsigned InstMaskStart = 64 - MaskEnd - 1,
1539 InstMaskEnd = 64 - MaskStart - 1;
1544 if ((!IsIns && (InstMaskEnd == 63 || InstMaskStart == 0)) ||
1545 InstMaskEnd == 63 - RLAmt)
1554 bool Repl32,
unsigned MaskStart,
unsigned MaskEnd,
1555 unsigned *InstCnt =
nullptr) {
1558 unsigned InstMaskStart = 64 - MaskEnd - 1,
1559 InstMaskEnd = 64 - MaskStart - 1;
1561 if (InstCnt) *InstCnt += 1;
1567 assert(InstMaskStart >= 32 &&
"Mask cannot start out of range");
1568 assert(InstMaskEnd >= 32 &&
"Mask cannot end out of range");
1570 { V, getI32Imm(RLAmt, dl), getI32Imm(InstMaskStart - 32, dl),
1571 getI32Imm(InstMaskEnd - 32, dl) };
1576 if (InstMaskEnd == 63) {
1578 { V, getI32Imm(RLAmt, dl), getI32Imm(InstMaskStart, dl) };
1579 return SDValue(CurDAG->getMachineNode(PPC::RLDICL, dl,
MVT::i64, Ops), 0);
1582 if (InstMaskStart == 0) {
1584 { V, getI32Imm(RLAmt, dl), getI32Imm(InstMaskEnd, dl) };
1585 return SDValue(CurDAG->getMachineNode(PPC::RLDICR, dl,
MVT::i64, Ops), 0);
1588 if (InstMaskEnd == 63 - RLAmt) {
1590 { V, getI32Imm(RLAmt, dl), getI32Imm(InstMaskStart, dl) };
1591 return SDValue(CurDAG->getMachineNode(PPC::RLDIC, dl,
MVT::i64, Ops), 0);
1600 if (InstCnt) *InstCnt += 1;
1603 unsigned RLAmt2 = MaskStart;
1606 unsigned RLAmt1 = (64 + RLAmt - RLAmt2) % 64;
1608 V = SelectRotMask64(V, dl, RLAmt1,
false, 0, 63);
1609 return SelectRotMask64(V, dl, RLAmt2,
false, MaskStart, MaskEnd);
1615 unsigned RLAmt,
bool Repl32,
unsigned MaskStart,
1616 unsigned MaskEnd,
unsigned *InstCnt =
nullptr) {
1619 unsigned InstMaskStart = 64 - MaskEnd - 1,
1620 InstMaskEnd = 64 - MaskStart - 1;
1622 if (InstCnt) *InstCnt += 1;
1628 assert(InstMaskStart >= 32 &&
"Mask cannot start out of range");
1629 assert(InstMaskEnd >= 32 &&
"Mask cannot end out of range");
1631 { Base, V, getI32Imm(RLAmt, dl), getI32Imm(InstMaskStart - 32, dl),
1632 getI32Imm(InstMaskEnd - 32, dl) };
1637 if (InstMaskEnd == 63 - RLAmt) {
1639 { Base, V, getI32Imm(RLAmt, dl), getI32Imm(InstMaskStart, dl) };
1640 return SDValue(CurDAG->getMachineNode(PPC::RLDIMI, dl,
MVT::i64, Ops), 0);
1649 if (InstCnt) *InstCnt += 1;
1652 unsigned RLAmt2 = MaskStart;
1655 unsigned RLAmt1 = (64 + RLAmt - RLAmt2) % 64;
1657 V = SelectRotMask64(V, dl, RLAmt1,
false, 0, 63);
1658 return SelectRotMaskIns64(Base, V, dl, RLAmt2,
false, MaskStart, MaskEnd);
1661 void SelectAndParts64(
const SDLoc &dl,
SDValue &Res,
unsigned *InstCnt) {
1674 for (ValueRotInfo &VRI : ValueRotsVec) {
1682 auto MatchingBG = [VRI](
const BitGroup &BG) {
1686 unsigned EffRLAmt = BG.RLAmt;
1687 if (!VRI.Repl32 && BG.Repl32) {
1688 if (BG.StartIdx < 32 && BG.EndIdx < 32 && BG.StartIdx <= BG.EndIdx &&
1689 !BG.Repl32Coalesced) {
1695 }
else if (VRI.Repl32 != BG.Repl32) {
1699 return VRI.RLAmt == EffRLAmt;
1702 for (
auto &BG : BitGroups) {
1703 if (!MatchingBG(BG))
1706 if (BG.StartIdx <= BG.EndIdx) {
1707 for (
unsigned i = BG.StartIdx; i <= BG.EndIdx; ++i)
1708 Mask |= (UINT64_C(1) << i);
1710 for (
unsigned i = BG.StartIdx; i < Bits.
size(); ++i)
1711 Mask |= (UINT64_C(1) << i);
1712 for (
unsigned i = 0; i <= BG.EndIdx; ++i)
1713 Mask |= (UINT64_C(1) << i);
1722 unsigned ANDIMask = (Mask & UINT16_MAX),
1723 ANDISMask = (Mask >> 16) & UINT16_MAX;
1725 bool NeedsRotate = VRI.RLAmt || (VRI.Repl32 && !
isUInt<32>(
Mask));
1727 unsigned NumAndInsts = (
unsigned) NeedsRotate +
1728 (
unsigned) (
bool) Res;
1731 (
unsigned) (ANDIMask != 0 && ANDISMask != 0);
1735 unsigned NumRLInsts = 0;
1736 bool FirstBG =
true;
1737 bool MoreBG =
false;
1738 for (
auto &BG : BitGroups) {
1739 if (!MatchingBG(BG)) {
1744 SelectRotMask64Count(BG.RLAmt, BG.Repl32, BG.StartIdx, BG.EndIdx,
1749 DEBUG(
dbgs() <<
"\t\trotation groups for " << VRI.V.getNode() <<
1750 " RL: " << VRI.RLAmt << (VRI.Repl32 ?
" (32):" :
":") <<
1751 "\n\t\t\tisel using masking: " << NumAndInsts <<
1752 " using rotates: " << NumRLInsts <<
"\n");
1758 if (NumAndInsts > NumRLInsts)
1763 if ((Use32BitInsts || MoreBG) && NumAndInsts == NumRLInsts)
1766 DEBUG(
dbgs() <<
"\t\t\t\tusing masking\n");
1768 if (InstCnt) *InstCnt += NumAndInsts;
1775 if (VRI.RLAmt || (VRI.Repl32 && !
isUInt<32>(Mask)))
1776 VRot = SelectRotMask64(VRI.V, dl, VRI.RLAmt, VRI.Repl32,
1777 VRI.Repl32 ? 31 : 0, VRI.Repl32 ? 30 : 63);
1782 if (Use32BitInsts) {
1783 assert((ANDIMask != 0 || ANDISMask != 0) &&
1784 "No set bits in mask when using 32-bit ands for 64-bit value");
1789 VRot, getI32Imm(ANDIMask, dl)), 0);
1792 VRot, getI32Imm(ANDISMask, dl)), 0);
1795 TotalVal = ANDISVal;
1800 ANDIVal, ANDISVal), 0);
1805 VRot, TotalVal), 0);
1816 eraseMatchingBitGroups(MatchingBG);
1821 SDNode *Select64(
SDNode *N,
bool LateMask,
unsigned *InstCnt) {
1825 if (InstCnt) *InstCnt = 0;
1828 SelectAndParts64(dl, Res, InstCnt);
1833 if ((!HasZeros || LateMask) && !Res) {
1837 unsigned MaxGroupsIdx = 0;
1838 if (!ValueRotsVec[0].Repl32) {
1839 for (
unsigned i = 0, ie = ValueRotsVec.size(); i < ie; ++i)
1840 if (ValueRotsVec[i].Repl32) {
1841 if (ValueRotsVec[i].NumGroups > ValueRotsVec[0].NumGroups)
1847 ValueRotInfo &VRI = ValueRotsVec[MaxGroupsIdx];
1848 bool NeedsRotate =
false;
1851 }
else if (VRI.Repl32) {
1852 for (
auto &BG : BitGroups) {
1853 if (BG.V != VRI.V || BG.RLAmt != VRI.RLAmt ||
1854 BG.Repl32 != VRI.Repl32)
1859 if (BG.StartIdx < 32 && BG.EndIdx < 32 && BG.StartIdx < BG.EndIdx)
1868 Res = SelectRotMask64(VRI.V, dl, VRI.RLAmt, VRI.Repl32,
1869 VRI.Repl32 ? 31 : 0, VRI.Repl32 ? 30 : 63,
1876 eraseMatchingBitGroups([VRI](
const BitGroup &BG) {
1877 return BG.V == VRI.V && BG.RLAmt == VRI.RLAmt &&
1878 BG.Repl32 == VRI.Repl32;
1885 for (
auto I = BitGroups.begin(),
IE = BitGroups.end();
I !=
IE; ++
I) {
1886 if (SelectRotMask64Count(
I->RLAmt,
I->Repl32,
I->StartIdx,
I->EndIdx,
1888 SelectRotMask64Count(
I->RLAmt,
I->Repl32,
I->StartIdx,
I->EndIdx,
1890 if (
I != BitGroups.begin()) {
1893 BitGroups.insert(BitGroups.begin(), BG);
1901 for (
auto &BG : BitGroups) {
1903 Res = SelectRotMask64(BG.V, dl, BG.RLAmt, BG.Repl32, BG.StartIdx,
1904 BG.EndIdx, InstCnt);
1906 Res = SelectRotMaskIns64(Res, BG.V, dl, BG.RLAmt, BG.Repl32,
1907 BG.StartIdx, BG.EndIdx, InstCnt);
1911 uint64_t Mask = getZerosMask();
1918 unsigned ANDIMask = (Mask & UINT16_MAX),
1919 ANDISMask = (Mask >> 16) & UINT16_MAX;
1921 if (Use32BitInsts) {
1922 assert((ANDIMask != 0 || ANDISMask != 0) &&
1923 "No set bits in mask when using 32-bit ands for 64-bit value");
1925 if (InstCnt) *InstCnt += (
unsigned) (ANDIMask != 0) +
1927 (
unsigned) (ANDIMask != 0 && ANDISMask != 0);
1932 Res, getI32Imm(ANDIMask, dl)), 0);
1935 Res, getI32Imm(ANDISMask, dl)), 0);
1943 ANDIVal, ANDISVal), 0);
1959 collectBitGroups(LateMask);
1960 if (BitGroups.empty())
1964 if (Bits.
size() == 64)
1965 assignRepl32BitGroups();
1968 collectValueRotInfo();
1970 if (Bits.
size() == 32) {
1971 return Select32(N, LateMask, InstCnt);
1973 assert(Bits.
size() == 64 &&
"Not 64 bits here?");
1974 return Select64(N, LateMask, InstCnt);
1980 void eraseMatchingBitGroups(
function_ref<
bool(
const BitGroup &)>
F) {
1981 BitGroups.erase(
remove_if(BitGroups,
F), BitGroups.end());
2009 Bits = std::move(*Result.second);
2011 DEBUG(
dbgs() <<
"Considering bit-permutation-based instruction"
2012 " selection for: ");
2016 computeRotationAmounts();
2029 unsigned InstCnt, InstCntLateMask;
2032 DEBUG(
dbgs() <<
"\t\tisel would use " << InstCnt <<
" instructions\n");
2036 DEBUG(
dbgs() <<
"\t\tisel would use " << InstCntLateMask <<
2039 if (InstCnt <= InstCntLateMask) {
2040 DEBUG(
dbgs() <<
"\tUsing early-masking for isel\n");
2044 DEBUG(
dbgs() <<
"\tUsing late-masking for isel\n");
2051 bool PPCDAGToDAGISel::tryBitPermutation(
SDNode *N) {
2066 BitPermutationSelector BPS(CurDAG);
2067 if (
SDNode *New = BPS.Select(N)) {
2068 ReplaceNode(N, New);
2092 getI32Imm(Imm & 0xFFFF, dl)),
2097 getI32Imm(Imm & 0xFFFF, dl)),
2110 getI32Imm(Imm >> 16, dl)), 0);
2112 getI32Imm(Imm & 0xFFFF, dl)), 0);
2118 getI32Imm(Imm & 0xFFFF, dl)), 0);
2124 getI32Imm((
int)SImm & 0xFFFF,
2136 getI32Imm(Imm & 0xFFFF, dl)),
2141 getI32Imm(Imm & 0xFFFF, dl)),
2155 getI64Imm(Imm >> 16, dl)), 0);
2157 getI64Imm(Imm & 0xFFFF, dl)),
2165 getI64Imm(Imm & 0xFFFF, dl)), 0);
2171 getI64Imm(SImm & 0xFFFF, dl)),
2179 Opc = PPCSubTarget->hasVSX() ? PPC::XSCMPUDP : PPC::FCMPUD;
2232 case ISD::SETO: Invert =
true;
return 3;
2248 bool HasVSX,
bool &Swap,
bool &Negate) {
2276 return HasVSX ? PPC::XVCMPEQSP : PPC::VCMPEQFP;
2278 return PPC::XVCMPEQDP;
2283 return HasVSX ? PPC::XVCMPGTSP : PPC::VCMPGTFP;
2285 return PPC::XVCMPGTDP;
2290 return HasVSX ? PPC::XVCMPGESP : PPC::VCMPGEFP;
2292 return PPC::XVCMPGEDP;
2320 return PPC::VCMPEQUB;
2322 return PPC::VCMPEQUH;
2324 return PPC::VCMPEQUW;
2326 return PPC::VCMPEQUD;
2330 return PPC::VCMPGTSB;
2332 return PPC::VCMPGTSH;
2334 return PPC::VCMPGTSW;
2336 return PPC::VCMPGTSD;
2340 return PPC::VCMPGTUB;
2342 return PPC::VCMPGTUH;
2344 return PPC::VCMPGTUW;
2346 return PPC::VCMPGTUD;
2355 bool PPCDAGToDAGISel::trySETCC(
SDNode *N) {
2361 bool isPPC64 = (PtrVT ==
MVT::i64);
2363 if (!PPCSubTarget->useCRBits() &&
2374 SDValue Ops[] = {
Op, getI32Imm(27, dl), getI32Imm(5, dl),
2375 getI32Imm(31, dl) };
2383 Op, getI32Imm(~0U, dl)), 0);
2388 SDValue Ops[] = {
Op, getI32Imm(1, dl), getI32Imm(31, dl),
2389 getI32Imm(31, dl) };
2397 SDValue Ops[] = {
T, getI32Imm(1, dl), getI32Imm(31, dl),
2398 getI32Imm(31, dl) };
2403 }
else if (Imm == ~0U) {
2410 Op, getI32Imm(1, dl)), 0);
2421 Op, getI32Imm(~0U, dl));
2428 getI32Imm(1, dl)), 0);
2431 SDValue Ops[] = { AN, getI32Imm(1, dl), getI32Imm(31, dl),
2432 getI32Imm(31, dl) };
2437 SDValue Ops[] = {
Op, getI32Imm(1, dl), getI32Imm(31, dl),
2438 getI32Imm(31, dl) };
2453 if (PPCSubTarget->hasQPX())
2459 PPCSubTarget->hasVSX(), Swap, Negate);
2475 if (PPCSubTarget->useCRBits())
2480 SDValue CCReg = SelectCC(LHS, RHS, CC, dl);
2488 InFlag).getValue(1);
2493 SDValue Ops[] = { IntCR, getI32Imm((32 - (3 - Idx)) & 31, dl),
2494 getI32Imm(31, dl), getI32Imm(31, dl) };
2517 bool PPCDAGToDAGISel::tryEXTEND(
SDNode *N) {
2522 "Expecting a zero/sign extend node!");
2530 WideRes = computeLogicOpInGPR(N->
getOperand(0));
2537 SetccInGPROpts::SExtOrig : SetccInGPROpts::ZExtOrig);
2550 if (Inputs32Bit != Output32Bit)
2552 ExtOrTruncConversion::Trunc);
2553 ReplaceNode(N, ConvOp.
getNode());
2568 "Can only handle logic operations here.");
2570 "Can only handle logic operations on i1 values here.");
2582 unsigned OperandOpcode = Operand.
getOpcode();
2584 return getSETCCInGPR(Operand, SetccInGPROpts::ZExtOrig);
2590 PPC::RLDICL, dl, InVT, InputOp,
2591 getI64Imm(0, dl), getI64Imm(63, dl)), 0);
2593 return computeLogicOpInGPR(Operand);
2596 LHS = getLogicOperand(LogicOp.
getOperand(0));
2597 RHS = getLogicOperand(LogicOp.
getOperand(1));
2602 if (!LHS || (!RHS && !IsBitwiseNegation))
2605 NumLogicOpsOnComparison++;
2610 if (!IsBitwiseNegation && RHS.getValueType() ==
MVT::i32)
2616 case ISD::AND: NewOpc = PPC::AND8;
break;
2617 case ISD::OR: NewOpc = PPC::OR8;
break;
2618 case ISD::XOR: NewOpc = PPC::XOR8;
break;
2621 if (IsBitwiseNegation) {
2622 RHS = getI64Imm(1, dl);
2623 NewOpc = PPC::XORI8;
2635 bool PPCDAGToDAGISel::tryLogicOpOfCompares(
SDNode *N) {
2641 "Expected a logic operation on setcc results.");
2643 if (!LoweredLogical)
2648 unsigned SubRegToExtract = IsBitwiseNegate ? PPC::sub_eq : PPC::sub_gt;
2657 if (IsBitwiseNegate &&
2660 else if (IsBitwiseNegate)
2662 OpToConvToRecForm = LoweredLogical.
getOperand(0);
2666 OpToConvToRecForm = LoweredLogical;
2676 if (NewOpc != -1 && IsBitwiseNegate) {
2679 "Expected a PPC::XORI8 only for bitwise negation.");
2681 std::vector<SDValue> Ops;
2682 for (
int i = 0, e = OpToConvToRecForm.
getNumOperands(); i < e; i++)
2683 Ops.push_back(OpToConvToRecForm.
getOperand(i));
2690 assert((NewOpc != -1 || !IsBitwiseNegate) &&
2691 "No record form available for AND8/OR8/XOR8?");
2707 ReplaceNode(N, CRBit.
getNode());
2714 SDValue PPCDAGToDAGISel::signExtendInputIfNeeded(
SDValue Input) {
2716 "Can only sign-extend 32-bit values here.");
2738 SignExtensionsAdded++;
2745 SDValue PPCDAGToDAGISel::zeroExtendInputIfNeeded(
SDValue Input) {
2747 "Can only zero-extend 32-bit values here.");
2753 if (InputLoad && InputLoad->getExtensionType() !=
ISD::SEXTLOAD)
2757 bool InputZExtConst = InputConst && InputConst->
getSExtValue() >= 0;
2765 ZeroExtensionsAdded++;
2767 getI64Imm(0, dl), getI64Imm(32, dl)),
2776 ExtOrTruncConversion Conv) {
2777 SDLoc dl(NatWidthRes);
2786 ImDef, NatWidthRes, SubRegIdx), 0);
2789 assert(Conv == ExtOrTruncConversion::Trunc &&
2790 "Unknown convertion between 32 and 64 bit values.");
2796 NatWidthRes, SubRegIdx), 0);
2803 int64_t RHSValue,
SDLoc dl) {
2804 bool IsRHSZero = RHSValue == 0;
2810 SDValue Xor = IsRHSZero ? LHS :
2814 SDValue ShiftOps[] = { Clz, getI32Imm(27, dl), getI32Imm(5, dl),
2815 getI32Imm(31, dl) };
2822 SDValue Xor = IsRHSZero ? LHS :
2826 SDValue ShiftOps[] = { Clz, getI32Imm(27, dl), getI32Imm(5, dl),
2827 getI32Imm(31, dl) };
2831 getI32Imm(1, dl)), 0);
2840 int64_t RHSValue,
SDLoc dl) {
2841 bool IsRHSZero = RHSValue == 0;
2849 SDValue CountInput = IsRHSZero ? LHS :
2853 SDValue SHLOps[] = { Cntlzw, getI32Imm(58, dl), getI32Imm(0, dl) };
2857 getI32Imm(63, dl)), 0);
2867 SDValue Xor = IsRHSZero ? LHS :
2872 { Clz, getI32Imm(27, dl), getI32Imm(5, dl), getI32Imm(31, dl) };
2877 getI32Imm(1, dl)), 0);
2887 int64_t RHSValue,
SDLoc dl) {
2888 bool IsRHSZero = RHSValue == 0;
2894 SDValue Xor = IsRHSZero ? LHS :
2899 getI64Imm(58, dl), getI64Imm(63, dl)),
2909 int64_t RHSValue,
SDLoc dl) {
2910 bool IsRHSZero = RHSValue == 0;
2918 SDValue AddInput = IsRHSZero ? LHS :
2922 AddInput, getI32Imm(~0U, dl)), 0);
2924 Addic, Addic.getValue(1)), 0);
2935 "An ISD::SETCC node required here.");
2948 OmittedForNonExtendUses++;
2958 SetccInGPROpts ConvOpts) {
2961 "An ISD::SETCC node required here.");
2974 cast<CondCodeSDNode>(Compare.
getOperand(CCOpNum))->
get();
2979 if (ConvOpts == SetccInGPROpts::ZExtInvert ||
2980 ConvOpts == SetccInGPROpts::SExtInvert)
2983 bool Inputs32Bit = InputVT ==
MVT::i32;
2985 LHS = signExtendInputIfNeeded(LHS);
2986 RHS = signExtendInputIfNeeded(RHS);
2988 LHS = zeroExtendInputIfNeeded(LHS);
2989 RHS = zeroExtendInputIfNeeded(RHS);
2994 int64_t RHSValue = RHSConst ? RHSConst->
getSExtValue() : INT64_MAX;
2995 bool IsSext = ConvOpts == SetccInGPROpts::SExtOrig ||
2996 ConvOpts == SetccInGPROpts::SExtInvert;
2998 if (IsSext && Inputs32Bit)
2999 return get32BitSExtCompare(LHS, RHS, CC, RHSValue, dl);
3000 else if (Inputs32Bit)
3001 return get32BitZExtCompare(LHS, RHS, CC, RHSValue, dl);
3003 return get64BitSExtCompare(LHS, RHS, CC, RHSValue, dl);
3004 return get64BitZExtCompare(LHS, RHS, CC, RHSValue, dl);
3009 bool PPCDAGToDAGISel::isOffsetMultipleOf(
SDNode *N,
unsigned Val)
const {
3019 if (AddrOp.getOpcode() ==
ISD::ADD)
3026 void PPCDAGToDAGISel::transferMemOperands(
SDNode *N,
SDNode *Result) {
3029 MemOp[0] = cast<MemSDNode>(
N)->getMemOperand();
3030 cast<MachineSDNode>(Result)->setMemRefs(MemOp, MemOp + 1);
3050 if (tryBitPermutation(N))
3058 ReplaceNode(N,
getInt64(CurDAG, N));
3075 ReplaceNode(N, getGlobalBaseReg());
3079 selectFrameIndex(N, N);
3098 getConstantIntValue(), dl,
3109 "Expecting i64 or i32 in PPCISD::SRA_ADDZE");
3136 assert((!isSExt || LoadedVT ==
MVT::i16) &&
"Invalid sext update load");
3137 switch (LoadedVT.getSimpleVT().SimpleTy) {
3139 case MVT::f64: Opcode = PPC::LFDU;
break;
3140 case MVT::f32: Opcode = PPC::LFSU;
break;
3141 case MVT::i32: Opcode = PPC::LWZU;
break;
3142 case MVT::i16: Opcode = isSExt ? PPC::LHAU : PPC::LHZU;
break;
3144 case MVT::i8: Opcode = PPC::LBZU;
break;
3148 assert((!isSExt || LoadedVT ==
MVT::i16) &&
"Invalid sext update load");
3149 switch (LoadedVT.getSimpleVT().SimpleTy) {
3151 case MVT::i64: Opcode = PPC::LDU;
break;
3152 case MVT::i32: Opcode = PPC::LWZU8;
break;
3153 case MVT::i16: Opcode = isSExt ? PPC::LHAU8 : PPC::LHZU8;
break;
3155 case MVT::i8: Opcode = PPC::LBZU8;
break;
3165 transferMemOperands(N, MN);
3173 assert((!isSExt || LoadedVT ==
MVT::i16) &&
"Invalid sext update load");
3174 switch (LoadedVT.getSimpleVT().SimpleTy) {
3176 case MVT::v4f64: Opcode = PPC::QVLFDUX;
break;
3177 case MVT::v4f32: Opcode = PPC::QVLFSUX;
break;
3178 case MVT::f64: Opcode = PPC::LFDUX;
break;
3179 case MVT::f32: Opcode = PPC::LFSUX;
break;
3180 case MVT::i32: Opcode = PPC::LWZUX;
break;
3181 case MVT::i16: Opcode = isSExt ? PPC::LHAUX : PPC::LHZUX;
break;
3183 case MVT::i8: Opcode = PPC::LBZUX;
break;
3188 "Invalid sext update load");
3189 switch (LoadedVT.getSimpleVT().SimpleTy) {
3191 case MVT::i64: Opcode = PPC::LDUX;
break;
3192 case MVT::i32: Opcode = isSExt ? PPC::LWAUX : PPC::LWZUX8;
break;
3193 case MVT::i16: Opcode = isSExt ? PPC::LHAUX8 : PPC::LHZUX8;
break;
3195 case MVT::i8: Opcode = PPC::LBZUX8;
break;
3205 transferMemOperands(N, MN);
3212 if (tryLogicOpOfCompares(N))
3215 unsigned Imm, Imm2, SH, MB, ME;
3223 SDValue Ops[] = { Val, getI32Imm(SH, dl), getI32Imm(MB, dl),
3224 getI32Imm(ME, dl) };
3234 SDValue Ops[] = { Val, getI32Imm(0, dl), getI32Imm(MB, dl),
3235 getI32Imm(ME, dl) };
3258 getI32Imm(1, dl)), 0);
3270 assert(Imm < 64 &&
"Illegal shift amount");
3275 SDValue Ops[] = { Val, getI32Imm(SH, dl), getI32Imm(MB, dl) };
3287 SDValue Ops[] = { Val, getI32Imm(SH, dl), getI32Imm(MB, dl) };
3316 if (
isRunOfOnes(~(Imm^Imm2), MB, ME) && !(~Imm & Imm2)) {
3319 getI32Imm(0, dl), getI32Imm(MB, dl),
3320 getI32Imm(ME, dl) };
3331 if (tryBitfieldInsert(N))
3334 if (tryLogicOpOfCompares(N))
3355 if (tryLogicOpOfCompares(N))
3370 unsigned Imm, SH, MB, ME;
3372 isRotateAndMask(N, Imm,
true, SH, MB, ME)) {
3374 getI32Imm(SH, dl), getI32Imm(MB, dl),
3375 getI32Imm(ME, dl) };
3384 unsigned Imm, SH, MB, ME;
3386 isRotateAndMask(N, Imm,
true, SH, MB, ME)) {
3388 getI32Imm(SH, dl), getI32Imm(MB, dl),
3389 getI32Imm(ME, dl) };
3405 "Invalid input type for ANDIo_1_EQ_BIT");
3407 unsigned Opcode = (InVT ==
MVT::i64) ? PPC::ANDIo8 : PPC::ANDIo;
3415 PPC::sub_eq : PPC::sub_gt, dl,
MVT::i32);
3418 SRIdxVal,
SDValue(AndI.getNode(), 1) );
3425 bool isPPC64 = (PtrVT ==
MVT::i64);
3428 if (PPCSubTarget->useCRBits() &&
3437 if (N1C->isNullValue() && N3C->isNullValue() &&
3438 N2C->getZExtValue() == 1ULL && CC ==
ISD::SETNE &&
3459 case 0: SRI = PPC::sub_lt;
break;
3460 case 1: SRI = PPC::sub_gt;
break;
3461 case 2: SRI = PPC::sub_eq;
break;
3462 case 3: SRI = PPC::sub_un;
break;
3469 SDValue C = Inv ? NotCCBit : CCBit,
3470 NotC = Inv ? CCBit : NotCCBit;
3483 unsigned SelectCCOp;
3485 SelectCCOp = PPC::SELECT_CC_I4;
3487 SelectCCOp = PPC::SELECT_CC_I8;
3489 if (PPCSubTarget->hasP8Vector())
3490 SelectCCOp = PPC::SELECT_CC_VSSRC;
3492 SelectCCOp = PPC::SELECT_CC_F4;
3494 if (PPCSubTarget->hasVSX())
3495 SelectCCOp = PPC::SELECT_CC_VSFRC;
3497 SelectCCOp = PPC::SELECT_CC_F8;
3499 SelectCCOp = PPC::SELECT_CC_QFRC;
3501 SelectCCOp = PPC::SELECT_CC_QSRC;
3503 SelectCCOp = PPC::SELECT_CC_QBRC;
3506 SelectCCOp = PPC::SELECT_CC_VSRC;
3508 SelectCCOp = PPC::SELECT_CC_VRRC;
3511 getI32Imm(BROpc, dl) };
3516 if (PPCSubTarget->hasVSX()) {
3532 for (
int i = 0; i < 2; ++i)
3538 if (Op1 == Op2 && DM[0] == 0 && DM[1] == 0 &&
3540 isa<LoadSDNode>(Op1.getOperand(0))) {
3541 LoadSDNode *LD = cast<LoadSDNode>(Op1.getOperand(0));
3554 cast<MachineSDNode>(NewN)->setMemRefs(MemOp, MemOp + 1);
3561 if (PPCSubTarget->isLittleEndian()) {
3563 unsigned tmp = DM[0];
3570 SDValue Ops[] = { Op1, Op2, DMV };
3578 bool IsPPC64 = PPCSubTarget->isPPC64();
3582 : (IsPPC64 ? PPC::BDZ8 :
PPC::BDZ),
3593 unsigned PCC = cast<ConstantSDNode>(N->
getOperand(1))->getZExtValue();
3597 SDValue Pred = getI32Imm(PCC, dl);
3612 case PPC::PRED_LT: Opc = PPC::CRANDC; Swap =
true;
break;
3613 case PPC::PRED_LE: Opc = PPC::CRORC; Swap =
true;
break;
3614 case PPC::PRED_EQ: Opc = PPC::CREQV; Swap =
false;
break;
3615 case PPC::PRED_GE: Opc = PPC::CRORC; Swap =
false;
break;
3616 case PPC::PRED_GT: Opc = PPC::CRANDC; Swap =
false;
break;
3617 case PPC::PRED_NE: Opc = PPC::CRXOR; Swap =
false;
break;
3649 assert ((PPCSubTarget->isPPC64() || PPCSubTarget->isSVR4ABI()) &&
3650 "Only supported for 64-bit ABI and 32-bit SVR4");
3651 if (PPCSubTarget->isSVR4ABI() && !PPCSubTarget->isPPC64()) {
3655 transferMemOperands(N, MN);
3677 if (isa<JumpTableSDNode>(GA) || isa<BlockAddressSDNode>(GA) ||
3681 transferMemOperands(N, MN);
3688 unsigned char GVFlags = PPCSubTarget->classifyGlobalReference(GV);
3692 transferMemOperands(N, MN);
3704 assert(!PPCSubTarget->isPPC64() && PPCSubTarget->isSVR4ABI() &&
3705 "PPCISD::PPC32_PICGOT is only supported for 32-bit SVR4");
3716 "Invalid operand on VADD_SPLAT!");
3720 unsigned Opc1, Opc2, Opc3;
3724 Opc1 = PPC::VSPLTISB;
3725 Opc2 = PPC::VADDUBM;
3726 Opc3 = PPC::VSUBUBM;
3728 }
else if (EltSize == 2) {
3729 Opc1 = PPC::VSPLTISH;
3730 Opc2 = PPC::VADDUHM;
3731 Opc3 = PPC::VSUBUHM;
3734 assert(EltSize == 4 &&
"Invalid element size on VADD_SPLAT!");
3735 Opc1 = PPC::VSPLTISW;
3736 Opc2 = PPC::VADDUWM;
3737 Opc3 = PPC::VSUBUWM;
3741 if ((Elt & 1) == 0) {
3748 SDValue EltVal = getI32Imm(Elt >> 1, dl);
3751 ReplaceNode(N, CurDAG->
getMachineNode(Opc2, dl, VT, TmpVal, TmpVal));
3753 }
else if (Elt > 0) {
3760 SDValue EltVal = getI32Imm(Elt - 16, dl);
3762 EltVal = getI32Imm(-16, dl);
3774 SDValue EltVal = getI32Imm(Elt + 16, dl);
3776 EltVal = getI32Imm(-16, dl);
3798 "Only OR nodes are supported for CMPB");
3801 if (!PPCSubTarget->hasCMPB())
3811 bool BytesFound[8] = {
false,
false,
false,
false,
false,
false,
false,
false};
3812 uint64_t Mask = 0, Alt = 0;
3814 auto IsByteSelectCC = [
this](
SDValue O,
unsigned &b,
3815 uint64_t &
Mask, uint64_t &Alt,
3827 for (b = 0; b < 8; ++b) {
3828 uint64_t Mask = UINT64_C(0xFF) << (8*b);
3829 if (PM && (PM & Mask) == PM && (PAlt &
Mask) == PAlt)
3873 if (ULim != (UINT64_C(1) << b*8))
3934 while (!
Queue.empty()) {
3939 uint64_t M = 0,
A = 0;
3943 }
else if (IsByteSelectCC(O, b, M,
A, OLHS, ORHS)) {
3947 BytesFound[b] =
true;
3950 }
else if ((LHS == ORHS && RHS == OLHS) ||
3951 (RHS == ORHS && LHS == OLHS)) {
3952 BytesFound[b] =
true;
3964 unsigned LastB = 0, BCnt = 0;
3965 for (
unsigned i = 0; i < 8; ++i)
3966 if (BytesFound[LastB]) {
3971 if (!LastB || BCnt < 2)
3976 if (LHS.getValueType() != VT) {
3983 bool NonTrivialMask = ((int64_t) Mask) != INT64_C(-1);
3984 if (NonTrivialMask && !Alt) {
4011 void PPCDAGToDAGISel::foldBoolExts(
SDValue &Res,
SDNode *&N) {
4012 if (!PPCSubTarget->useCRBits())
4038 auto TryFold = [
this,
N, User, dl](
SDValue Val) {
4044 User->getValueType(0),
4050 SDValue TrueRes = TryFold(ConstTrue);
4051 if (!TrueRes || TrueRes.
isUndef())
4053 SDValue FalseRes = TryFold(ConstFalse);
4054 if (!FalseRes || FalseRes.
isUndef())
4059 uint64_t True = cast<ConstantSDNode>(TrueRes)->getZExtValue(),
4060 False = cast<ConstantSDNode>(FalseRes)->getZExtValue();
4066 Res = CurDAG->
getSelect(dl, User->getValueType(0), Cond, TrueRes, FalseRes);
4068 ConstTrue = TrueRes;
4069 ConstFalse = FalseRes;
4073 void PPCDAGToDAGISel::PreprocessISelDAG() {
4077 bool MadeChange =
false;
4079 SDNode *N = &*--Position;
4087 Res = combineToCMPB(N);
4092 foldBoolExts(Res, N);
4095 DEBUG(
dbgs() <<
"PPC DAG preprocessing replacing:\nOld: ");
4112 void PPCDAGToDAGISel::PostprocessISelDAG() {
4119 PeepholePPC64ZExt();
4127 bool PPCDAGToDAGISel::AllUsersSelectZero(
SDNode *N) {
4156 void PPCDAGToDAGISel::SwapAllSelectUsers(
SDNode *N) {
4163 "Must have all select users");
4168 UE = ToReplace.
end(); UI != UE; ++UI) {
4176 DEBUG(
dbgs() <<
"CR Peephole replacing:\nOld: ");
4182 ReplaceUses(User, ResNode);
4186 void PPCDAGToDAGISel::PeepholeCROps() {
4192 if (!MachineNode || MachineNode->
use_empty())
4194 SDNode *ResNode = MachineNode;
4196 bool Op1Set =
false, Op1Unset =
false,
4198 Op2Set =
false, Op2Unset =
false,
4226 case PPC::SELECT_I4:
4227 case PPC::SELECT_I8:
4228 case PPC::SELECT_F4:
4229 case PPC::SELECT_F8:
4230 case PPC::SELECT_QFRC:
4231 case PPC::SELECT_QSRC:
4232 case PPC::SELECT_QBRC:
4233 case PPC::SELECT_VRRC:
4234 case PPC::SELECT_VSFRC:
4235 case PPC::SELECT_VSSRC:
4236 case PPC::SELECT_VSRC: {
4251 bool SelectSwap =
false;
4264 else if (Op1Unset || Op2Unset)
4280 else if (AllUsersSelectZero(MachineNode)) {
4303 else if (Op1Unset || Op2Unset)
4319 else if (AllUsersSelectZero(MachineNode)) {
4330 else if (Op1Set || Op2Set)
4352 else if (AllUsersSelectZero(MachineNode)) {
4392 else if (AllUsersSelectZero(MachineNode)) {
4400 if (Op1Set || Op2Set)
4426 else if (AllUsersSelectZero(MachineNode)) {
4466 else if (AllUsersSelectZero(MachineNode)) {
4483 else if (Op1Unset || Op2Set)
4502 else if (AllUsersSelectZero(MachineNode)) {
4514 else if (Op1Set || Op2Unset)
4538 else if (AllUsersSelectZero(MachineNode)) {
4545 case PPC::SELECT_I4:
4546 case PPC::SELECT_I8:
4547 case PPC::SELECT_F4:
4548 case PPC::SELECT_F8:
4549 case PPC::SELECT_QFRC:
4550 case PPC::SELECT_QSRC:
4551 case PPC::SELECT_QBRC:
4552 case PPC::SELECT_VRRC:
4553 case PPC::SELECT_VSFRC:
4554 case PPC::SELECT_VSSRC:
4555 case PPC::SELECT_VSRC:
4587 SwapAllSelectUsers(MachineNode);
4589 if (ResNode != MachineNode) {
4590 DEBUG(
dbgs() <<
"CR Peephole replacing:\nOld: ");
4596 ReplaceUses(MachineNode, ResNode);
4602 }
while (IsModified);
4713 if (!Op0OK && !Op1OK)
4736 if (!Op0OK && !Op1OK)
4750 void PPCDAGToDAGISel::PeepholePPC64ZExt() {
4751 if (!PPCSubTarget->isPPC64())
4766 bool MadeChange =
false;
4768 SDNode *N = &*--Position;
4812 bool OutsideUse =
false;
4813 for (
SDNode *PN : ToPromote) {
4815 if (!ToPromote.count(UN) && UN != ISR.
getNode()) {
4833 for (
SDNode *PN : ToPromote) {
4835 switch (PN->getMachineOpcode()) {
4838 case PPC::RLWINM: NewOpcode = PPC::RLWINM8;
break;
4839 case PPC::RLWNM: NewOpcode = PPC::RLWNM8;
break;
4840 case PPC::SLW: NewOpcode = PPC::SLW8;
break;
4841 case PPC::SRW: NewOpcode = PPC::SRW8;
break;
4842 case PPC::LI: NewOpcode = PPC::LI8;
break;
4843 case PPC::LIS: NewOpcode = PPC::LIS8;
break;
4844 case PPC::LHBRX: NewOpcode = PPC::LHBRX8;
break;
4845 case PPC::LWBRX: NewOpcode = PPC::LWBRX8;
break;
4846 case PPC::CNTLZW: NewOpcode = PPC::CNTLZW8;
break;
4847 case PPC::CNTTZW: NewOpcode = PPC::CNTTZW8;
break;
4848 case PPC::RLWIMI: NewOpcode = PPC::RLWIMI8;
break;
4849 case PPC::OR: NewOpcode = PPC::OR8;
break;
4850 case PPC::SELECT_I4: NewOpcode = PPC::SELECT_I8;
break;
4851 case PPC::ORI: NewOpcode = PPC::ORI8;
break;
4852 case PPC::ORIS: NewOpcode = PPC::ORIS8;
break;
4853 case PPC::AND: NewOpcode = PPC::AND8;
break;
4854 case PPC::ANDIo: NewOpcode = PPC::ANDIo8;
break;
4855 case PPC::ANDISo: NewOpcode = PPC::ANDISo8;
break;
4866 !isa<ConstantSDNode>(V)) {
4883 for (
unsigned i = 0, ie = VTs.
NumVTs; i != ie; ++i)
4889 DEBUG(
dbgs() <<
"PPC64 ZExt Peephole morphing:\nOld: ");
4890 DEBUG(PN->dump(CurDAG));
4895 DEBUG(PN->dump(CurDAG));
4903 DEBUG(
dbgs() <<
"PPC64 ZExt Peephole replacing:\nOld: ");
4909 ReplaceUses(N, Op32.
getNode());
4916 void PPCDAGToDAGISel::PeepholePPC64() {
4918 if (PPCSubTarget->isDarwin() || !PPCSubTarget->isPPC64())
4925 SDNode *N = &*--Position;
4933 switch (StorageOpcode) {
4968 if (!isa<ConstantSDNode>(N->
getOperand(FirstOp)))
4976 bool ReplaceFlags =
true;
4996 ReplaceFlags =
false;
5000 if ((StorageOpcode == PPC::LWA ||
5002 StorageOpcode == PPC::STD) &&
5007 case PPC::ADDIdtprelL:
5010 case PPC::ADDItlsldL:
5024 int MaxDisplacement = 7;
5030 bool UpdateHBase =
false;
5035 if (Offset < 0 || Offset > MaxDisplacement) {
5050 if (HImmOpnd != ImmOpnd)
5061 if (
auto *C = dyn_cast<ConstantSDNode>(ImmOpnd)) {
5064 if ((StorageOpcode == PPC::LWA || StorageOpcode ==
PPC::LD ||
5065 StorageOpcode == PPC::STD) && (Offset % 4) != 0)
5073 }
else if (Offset != 0) {
5082 DEBUG(
dbgs() <<
"Folding add-immediate into mem-op:\nBase: ");
5097 (StorageOpcode ==
PPC::LD || StorageOpcode == PPC::STD ||
5098 StorageOpcode == PPC::LWA || (Offset % 4) != 0)) {
5099 DEBUG(
dbgs() <<
"Rejected this candidate for alignment.\n\n");
5104 dyn_cast<ConstantPoolSDNode>(ImmOpnd)) {
5134 return new PPCDAGToDAGISel(TM, OptLevel);
constexpr bool isUInt< 32 >(uint64_t x)
bool use_empty() const
Return true if there are no uses of this node.
void push_back(const T &Elt)
SDValue getValue(unsigned R) 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.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
uint64_t getZExtValue() const
Get zero extended value.
STATISTIC(NumFunctions,"Total number of functions")
static cl::opt< bool > UseBitPermRewriter("ppc-use-bit-perm-rewriter", cl::init(true), cl::desc("use aggressive ppc isel for bit permutations"), cl::Hidden)
BR_CC - Conditional branch.
GPRC = address of GLOBAL_OFFSET_TABLE.
bool hasOneUse() const
Return true if there is exactly one use of this node.
VECTOR_SHUFFLE(VEC1, VEC2) - Returns a vector, of the same type as VEC1/VEC2.
static unsigned index2VirtReg(unsigned Index)
Convert a 0-based index to a virtual register number.
A Module instance is used to store all the information related to an LLVM module. ...
bool hasOneUse() const
Return true if there is exactly one node using value ResNo of Node.
auto remove_if(R &&Range, UnaryPredicate P) -> decltype(std::begin(Range))
Provide wrappers to std::remove_if which take ranges instead of having to pass begin/end explicitly...
SDVTList getVTList() const
Maximum length of the test input libFuzzer tries to guess a good value based on the corpus and reports it always prefer smaller inputs during the corpus shuffle When libFuzzer itself reports a bug this exit code will be used If indicates the maximal total time in seconds to run the fuzzer minimizes the provided crash input Use with tries to cleanse the provided crash input to make it contain fewer original bytes Use with exact_artifact_path to specify the output Experimental Use value profile to guide fuzzing Number of jobs to run If min(jobs, NumberOfCpuCores()/2)\" is used.") FUZZER_FLAG_INT(reload
VRRC = VADD_SPLAT Elt, EltSize - Temporary node to be expanded during instruction selection to optimi...
static int getRecordFormOpcode(unsigned Opcode)
static bool allUsesExtend(SDValue Compare, SelectionDAG *CurDAG)
Does this SDValue have any uses for which keeping the value in a GPR is appropriate.
unsigned getOpcode() const
Return the SelectionDAG opcode value for this node.
An efficient, type-erasing, non-owning reference to a callable.
unsigned getID() const
Return the register class ID number.
TargetGlobalAddress - Like GlobalAddress, but the DAG does no folding or anything else with this node...
bool isUnindexed() const
Return true if this is NOT a pre/post inc/dec load/store.
bool isBitwiseNot(SDValue V)
Returns true if V is a bitwise not operation.
unsigned getNumOperands() const
Return the number of values used by this operation.
unsigned getNumOperands() const
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
unsigned getValueSizeInBits() const
Returns the size of the value in bits.
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.
const SDValue & getOperand(unsigned Num) const
const Function * getFunction() const
getFunction - Return the LLVM function that this machine code represents
SDValue getSelect(const SDLoc &DL, EVT VT, SDValue Cond, SDValue LHS, SDValue RHS)
Helper function to make it easier to build Select's if you just have operands and don't want to check...
void setNodeId(int Id)
Set unique node id.
SDValue getNode(unsigned Opcode, const SDLoc &DL, EVT VT, ArrayRef< SDUse > Ops)
Gets or creates the specified node.
static bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned &Imm)
const SDValue & getBasePtr() const
static bool isLogicOp(unsigned Opc)
Select with condition operator - This selects between a true value and a false value (ops #2 and #3) ...
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...
static SDNode * getInt64(SelectionDAG *CurDAG, const SDLoc &dl, int64_t Imm)
StringRef getName() const
Return a constant reference to the value's name.
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 isVector() const
Return true if this is a vector value type.
static bool PeepholePPC64ZExtGather(SDValue Op32, SmallPtrSetImpl< SDNode * > &ToPromote)
A description of a memory reference used in the backend.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
PPCFunctionInfo - This class is derived from MachineFunction private PowerPC target-specific informat...
const HexagonInstrInfo * TII
Shift and rotation operations.
std::size_t countTrailingOnes(T Value, ZeroBehavior ZB=ZB_Width)
Count the number of ones from the least significant bit to the first zero bit.
EVT getValueType(unsigned ResNo) const
Return the type of a specified result.
SDValue getTargetExtractSubreg(int SRIdx, const SDLoc &DL, EVT VT, SDValue Operand)
A convenience function for creating TargetInstrInfo::EXTRACT_SUBREG nodes.
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.
Reg
All possible values of the reg field in the ModR/M byte.
unsigned getMachineOpcode() const
int getMaskElt(unsigned Idx) const
SDVTList getVTList(EVT VT)
Return an SDVTList that represents the list of values specified.
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.
iterator_range< allnodes_iterator > allnodes()
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
const MachineBasicBlock & front() 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.
Select with a vector condition (op #0) and two vector operands (ops #1 and #2), returning a vector re...
R32 = MFOCRF(CRREG, INFLAG) - Represents the MFOCRF instruction.
Simple integer binary arithmetic operators.
CondCode
ISD::CondCode enum - These are ordered carefully to make the bitfields below work out...
TargetConstant* - Like Constant*, but the DAG does not do any folding, simplification, or lowering of the constant.
EVT getMemoryVT() const
Return the type of the in-memory value.
SDValue getTargetConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isOpaque=false)
bool isSignedIntSetCC(CondCode Code)
Return true if this is a setcc instruction that performs a signed comparison when used with integer o...
const DataLayout & getDataLayout() const
const BasicBlock * getBasicBlock() const
Return the LLVM basic block that this instance corresponded to originally.
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.
SDNode * getNode() const
get the SDNode which holds the desired result
Function Alias Analysis false
MachineInstrBuilder BuildMI(MachineFunction &MF, const DebugLoc &DL, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
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)
Subclasses of this class are all able to terminate a basic block.
LLVM Basic Block Representation.
const SDValue & getOperand(unsigned i) const
This is an important base class in LLVM.
MO_NLP_FLAG - If this bit is set, the symbol reference is actually to the non_lazy_ptr for the global...
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator begin()
static PPC::Predicate getPredicateForSetCC(ISD::CondCode CC)
CHAIN,FLAG = MTCTR(VAL, CHAIN[, INFLAG]) - Directly corresponds to a MTCTR instruction.
bool isFloatingPoint() const
Return true if this is a FP or a vector FP type.
static ManagedStatic< OptionRegistry > OR
std::pair< iterator, bool > insert(PtrType Ptr)
Inserts Ptr if and only if there is no element in the container equal to Ptr.
void RemoveDeadNodes()
This method deletes all unreachable nodes in the SelectionDAG.
This class provides iterator support for SDUse operands that use a specific SDNode.
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.
unsigned getOpcode() const
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...
void RemoveDeadNode(SDNode *N)
Remove the specified node from the system.
uint64_t getConstantOperandVal(unsigned Num) const
Helper method returns the integer value of a ConstantSDNode operand.
use_iterator use_begin() const
Provide iteration support to walk over all uses of an SDNode.
Common code between 32-bit and 64-bit PowerPC targets.
bool MaskedValueIsZero(SDValue Op, const APInt &Mask, unsigned Depth=0) const
Return true if 'Op & Mask' is known to be zero.
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
ISD::MemIndexedMode getAddressingMode() const
Return the addressing mode for this load or store: unindexed, pre-inc, pre-dec, post-inc, or post-dec.
const SDValue & getRoot() const
Return the root tag of the SelectionDAG.
const MCInstrDesc & get(unsigned Opcode) const
Return the machine instruction descriptor that corresponds to the specified instruction opcode...
MachineBasicBlock * MBB
MBB - The current block.
const SDValue & getOffset() const
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)
SDValue getTargetConstantPool(const Constant *C, EVT VT, unsigned Align=0, int Offset=0, unsigned char TargetFlags=0)
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...
PICLevel::Level getPICLevel() const
Returns the PIC level (small or large model)
void dump() const
Dump this node, for debugging.
constexpr bool isInt< 32 >(int64_t x)
allnodes_const_iterator allnodes_begin() const
void computeKnownBits(SDValue Op, KnownBits &Known, unsigned Depth=0) const
Determine which bits of Op are known to be either zero or one and return them in Known.
static SDNode * getInt64Direct(SelectionDAG *CurDAG, const SDLoc &dl, int64_t Imm)
SDNode * UpdateNodeOperands(SDNode *N, SDValue Op)
Mutate the specified node in-place to have the specified operands.
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
SDNode * SelectNodeTo(SDNode *N, unsigned TargetOpc, EVT VT)
These are used for target selectors to mutate the specified node to have the specified return type...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small...
Module.h This file contains the declarations for the Module class.
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
An SDNode that represents everything that will be needed to construct a MachineInstr.
const SDValue & getChain() const
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
Wrapper class for IR location info (IR ordering and DebugLoc) to be passed into SDNode creation funct...
bool isMachineOpcode() const
Represents one node in the SelectionDAG.
CondCode getSetCCInverse(CondCode Operation, bool isInteger)
Return the operation corresponding to !(X op Y), where 'op' is a valid SetCC operation.
SelectionDAGISel - This is the common base class used for SelectionDAG-based pattern-matching instruc...
These values identify relocations on immediates folded into memory operations.
SDValue getCopyToReg(SDValue Chain, const SDLoc &dl, unsigned Reg, SDValue N)
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
i1 = ANDIo_1_[EQ|GT]_BIT(i32 or i64 x) - Represents the result of the eq or gt bit of CR0 after execu...
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.
ISD::LoadExtType getExtensionType() const
Return whether this is a plain node, or one of the varieties of value-extending loads.
Target - Wrapper for Target specific information.
iterator_range< use_iterator > uses()
BranchProbabilityInfo * BPI
SDValue FoldConstantArithmetic(unsigned Opcode, const SDLoc &DL, EVT VT, SDNode *Cst1, SDNode *Cst2)
Select(COND, TRUEVAL, FALSEVAL).
int64_t getSExtValue() const
static use_iterator use_end()
ZERO_EXTEND - Used for integer types, zeroing the new bits.
ANY_EXTEND - Used for integer types. The high bits are undefined.
The combination of sra[wd]i and addze used to implemented signed integer division by a power of 2...
llvm_unreachable("Unknown RegBank!")
static std::vector< std::string > Flags
static bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
uint64_t getConstantOperandVal(unsigned i) const
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.
SIGN_EXTEND_INREG - This operator atomically performs a SHL/SRA pair to sign extend a small value in ...
LOAD and STORE have token chains as their first operand, then the same operands as an LLVM load/store...
unsigned getSizeInBits() const
Return the size of the specified value type in bits.
ArrayRef< SDUse > ops() const
LLVM_ATTRIBUTE_ALWAYS_INLINE size_type size() const
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)
LLVM_NODISCARD std::enable_if<!is_simple_type< Y >::value, typename cast_retty< X, const Y >::ret_type >::type dyn_cast(const Y &Val)
static unsigned getInt64Count(int64_t Imm)
constexpr bool isUInt< 16 >(uint64_t x)
CopyFromReg - This node indicates that the input value is a virtual or physical register that is defi...
EVT getValueType() const
Return the ValueType of the referenced return value.
SDValue getConstant(uint64_t Val, const SDLoc &DL, EVT VT, bool isTarget=false, bool isOpaque=false)
Create a ConstantSDNode wrapping a constant value.
static int const Threshold
TODO: Write a new FunctionPass AliasAnalysis so that it can keep a cache.
unsigned getAlignment() const
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
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)
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...
static unsigned getBranchHint(unsigned PCC, FunctionLoweringInfo *FuncInfo, const SDValue &DestMBB)
Module * getParent()
Get the module that this global value is contained inside of...
LLVM Value Representation.
SDValue getRegister(unsigned Reg, EVT VT)
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...
CHAIN = COND_BRANCH CHAIN, CRRC, OPC, DESTBB [, INFLAG] - This corresponds to the COND_BRANCH pseudo ...
#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...
const TargetLowering & getTargetLoweringInfo() const
BranchProbability getEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors) const
Get an edge's probability, relative to other out-edges of the Src.
void ReplaceAllUsesOfValueWith(SDValue From, SDValue To)
Replace any uses of From with To, leaving uses of other values produced by From.Val alone...
StringRef - Represent a constant reference to a string, i.e.
SetCC operator - This evaluates to a true value iff the condition is true.
void sort(Policy policy, RandomAccessIterator Start, RandomAccessIterator End, const Comparator &Comp=Comparator())
SDValue getEntryNode() const
Return the token chain corresponding to the entry of the function.
const TerminatorInst * getTerminator() const LLVM_READONLY
Returns the terminator instruction if the block is well formed or null if the block is not well forme...
TRUNCATE - Completely drop the high bits.
Unlike LLVM values, Selection DAG nodes may return multiple values as the result of a computation...
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
static unsigned getInt64CountDirect(int64_t Imm)
MachineInstr::mmo_iterator allocateMemRefsArray(unsigned long Num)
allocateMemRefsArray - Allocate an array to hold MachineMemOperand pointers.
virtual const TargetRegisterClass * getPointerRegClass(const MachineFunction &MF, unsigned Kind=0) const
Returns a TargetRegisterClass used for pointer values.
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...
EVT changeVectorElementTypeToInteger() const
Return a vector with the same number of elements as this vector, but with the element type converted ...
MVT getSimpleVT() const
Return the SimpleValueType held in the specified simple EVT.
XXPERMDI - The PPC XXPERMDI instruction.
bool isMachineOpcode() const
Test if this node has a post-isel opcode, directly corresponding to a MachineInstr opcode...
unsigned getMachineOpcode() const
This may only be called if isMachineOpcode returns true.
SDValue getTargetGlobalAddress(const GlobalValue *GV, const SDLoc &DL, EVT VT, int64_t offset=0, unsigned char TargetFlags=0)
static unsigned int getVCmpInst(MVT VecVT, ISD::CondCode CC, bool HasVSX, bool &Swap, bool &Negate)
This class is used to represent ISD::LOAD nodes.