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"),
106 cl::desc(
"Enable tls optimization peephole"),
115 cl::desc(
"Specify the types of comparisons to emit GPR-only code for."),
121 "Only comparisons where inputs don't need [sz]ext."),
124 "Only i32 comparisons with zext result."),
126 "Only i64 comparisons with zext result."),
129 "Only i32 comparisons with sext result."),
131 "Only i64 comparisons with sext result.")));
156 InsertVRSaveCode(MF);
161 void PreprocessISelDAG()
override;
162 void PostprocessISelDAG()
override;
166 inline SDValue getI16Imm(
unsigned Imm,
const SDLoc &dl) {
167 return CurDAG->getTargetConstant(Imm, dl,
MVT::i16);
172 inline SDValue getI32Imm(
unsigned Imm,
const SDLoc &dl) {
173 return CurDAG->getTargetConstant(Imm, dl,
MVT::i32);
178 inline SDValue getI64Imm(uint64_t Imm,
const SDLoc &dl) {
179 return CurDAG->getTargetConstant(Imm, dl,
MVT::i64);
183 inline SDValue getSmallIPtrImm(
unsigned Imm,
const SDLoc &dl) {
184 return CurDAG->getTargetConstant(
185 Imm, dl, PPCLowering->getPointerTy(CurDAG->getDataLayout()));
190 static bool isRotateAndMask(
SDNode *
N,
unsigned Mask,
bool isShiftMask,
191 unsigned &SH,
unsigned &MB,
unsigned &ME);
195 SDNode *getGlobalBaseReg();
203 bool tryBitfieldInsert(
SDNode *
N);
204 bool tryBitPermutation(
SDNode *
N);
205 bool tryIntCompareInGPR(
SDNode *
N);
224 return PPCLowering->SelectAddressRegImm(N, Disp, Base, *CurDAG, 0);
244 return PPCLowering->SelectAddressRegReg(N, Base, Index, *CurDAG);
250 return PPCLowering->SelectAddressRegRegOnly(N, Base, Index, *CurDAG);
257 return PPCLowering->SelectAddressRegImm(N, Disp, Base, *CurDAG, 4);
261 return PPCLowering->SelectAddressRegImm(N, Disp, Base, *CurDAG, 16);
275 bool SelectInlineAsmMemoryOperand(
const SDValue &
Op,
276 unsigned ConstraintID,
277 std::vector<SDValue> &OutOps)
override {
278 switch(ConstraintID) {
280 errs() <<
"ConstraintID: " << ConstraintID <<
"\n";
296 SDValue(CurDAG->getMachineNode(TargetOpcode::COPY_TO_REGCLASS,
300 OutOps.push_back(NewOp);
309 return "PowerPC DAG->DAG Pattern Instruction Selection";
313 #include "PPCGenDAGISel.inc" 318 void PeepholePPC64();
319 void PeepholePPC64ZExt();
320 void PeepholeCROps();
325 bool AllUsersSelectZero(
SDNode *N);
326 void SwapAllSelectUsers(
SDNode *N);
328 bool isOffsetMultipleOf(
SDNode *N,
unsigned Val)
const;
344 bool HasVectorVReg =
false;
345 for (
unsigned i = 0, e = RegInfo->getNumVirtRegs(); i != e; ++i) {
347 if (RegInfo->getRegClass(Reg) == &PPC::VRRCRegClass) {
348 HasVectorVReg =
true;
352 if (!HasVectorVReg)
return;
366 unsigned InVRSAVE = RegInfo->createVirtualRegister(&PPC::GPRCRegClass);
367 unsigned UpdatedVRSAVE = RegInfo->createVirtualRegister(&PPC::GPRCRegClass);
377 BuildMI(EntryBB, IP, dl, TII.
get(PPC::MFVRSAVE), InVRSAVE);
378 BuildMI(EntryBB, IP, dl, TII.
get(PPC::UPDATE_VRSAVE),
379 UpdatedVRSAVE).addReg(InVRSAVE);
380 BuildMI(EntryBB, IP, dl, TII.
get(PPC::MTVRSAVE)).addReg(UpdatedVRSAVE);
384 if (BB->isReturnBlock()) {
385 IP = BB->end(); --IP;
390 while (I2 != BB->begin() && (--I2)->isTerminator())
394 BuildMI(*BB, IP, dl, TII.
get(PPC::MTVRSAVE)).addReg(InVRSAVE);
402 SDNode *PPCDAGToDAGISel::getGlobalBaseReg() {
403 if (!GlobalBaseReg) {
411 if (PPCLowering->getPointerTy(CurDAG->getDataLayout()) ==
MVT::i32) {
413 GlobalBaseReg = PPC::R30;
415 BuildMI(FirstMBB, MBBI, dl, TII.
get(PPC::MoveGOTtoLR));
419 BuildMI(FirstMBB, MBBI, dl, TII.
get(PPC::MovePCtoLR));
421 unsigned TempReg = RegInfo->createVirtualRegister(&PPC::GPRCRegClass);
429 RegInfo->createVirtualRegister(&PPC::GPRC_and_GPRC_NOR0RegClass);
430 BuildMI(FirstMBB, MBBI, dl, TII.
get(PPC::MovePCtoLR));
444 GlobalBaseReg = RegInfo->createVirtualRegister(&PPC::G8RC_and_G8RC_NOX0RegClass);
445 BuildMI(FirstMBB, MBBI, dl, TII.
get(PPC::MovePCtoLR8));
449 return CurDAG->getRegister(GlobalBaseReg,
450 PPCLowering->getPointerTy(CurDAG->getDataLayout()))
458 Imm = cast<ConstantSDNode>(
N)->getZExtValue();
468 Imm = cast<ConstantSDNode>(
N)->getZExtValue();
488 assert(isa<BasicBlockSDNode>(DestMBB));
518 if (
std::max(TProb, FProb) / Threshold < std::min(TProb, FProb))
522 <<
"::" << BB->
getName() <<
"'\n" 523 <<
" -> " << TBB->
getName() <<
": " << TProb <<
"\n" 524 <<
" -> " << FBB->
getName() <<
": " << FProb <<
"\n");
530 if (BBDN->getBasicBlock()->getBasicBlock() != TBB)
546 int FI = cast<FrameIndexSDNode>(
N)->getIndex();
551 getSmallIPtrImm(Offset, dl));
553 ReplaceNode(SN, CurDAG->getMachineNode(Opc, dl, N->
getValueType(0), TFI,
554 getSmallIPtrImm(Offset, dl)));
557 bool PPCDAGToDAGISel::isRotateAndMask(
SDNode *N,
unsigned Mask,
558 bool isShiftMask,
unsigned &SH,
559 unsigned &MB,
unsigned &ME) {
566 unsigned Indeterminant = ~0;
574 if (isShiftMask) Mask = Mask << Shift;
576 Indeterminant = ~(0xFFFFFFFFu << Shift);
579 if (isShiftMask) Mask = Mask >> Shift;
581 Indeterminant = ~(0xFFFFFFFFu >> Shift);
591 if (Mask && !(Mask & Indeterminant)) {
616 Opcode = (RegVT ==
MVT::i32) ? PPC::STBXTLS_32 : PPC::STBXTLS;
620 Opcode = (RegVT ==
MVT::i32) ? PPC::STHXTLS_32 : PPC::STHXTLS;
624 Opcode = (RegVT ==
MVT::i32) ? PPC::STWXTLS_32 : PPC::STWXTLS;
628 Opcode = PPC::STDXTLS;
636 SDNode *MN = CurDAG->getMachineNode(Opcode, dl, VTs, Ops);
637 transferMemOperands(ST, MN);
658 Opcode = (RegVT ==
MVT::i32) ? PPC::LBZXTLS_32 : PPC::LBZXTLS;
662 Opcode = (RegVT ==
MVT::i32) ? PPC::LHZXTLS_32 : PPC::LHZXTLS;
666 Opcode = (RegVT ==
MVT::i32) ? PPC::LWZXTLS_32 : PPC::LWZXTLS;
670 Opcode = PPC::LDXTLS;
677 SDNode *MN = CurDAG->getMachineNode(Opcode, dl, VTs, Ops);
678 transferMemOperands(LD, MN);
685 bool PPCDAGToDAGISel::tryBitfieldInsert(
SDNode *N) {
691 CurDAG->computeKnownBits(Op0, LKnown);
692 CurDAG->computeKnownBits(Op1, RKnown);
697 if ((TargetMask | InsertMask) == 0xFFFFFFFF) {
700 unsigned Value, SH = 0;
701 TargetMask = ~TargetMask;
702 InsertMask = ~InsertMask;
730 SH = (Op1Opc ==
ISD::SHL) ? Value : 32 - Value;
737 CurDAG->computeKnownBits(Op1.
getOperand(1), MKnown);
746 SH = (SHOpc ==
ISD::SHL) ? Value : 32 - Value;
751 SDValue Ops[] = { Op0, Op1, getI32Imm(SH, dl), getI32Imm(MB, dl),
753 ReplaceNode(N, CurDAG->getMachineNode(PPC::RLWIMI, dl,
MVT::i32, Ops));
764 unsigned Remainder = 0;
770 Shift = countTrailingZeros<uint64_t>(Imm);
771 int64_t ImmSh =
static_cast<uint64_t
>(Imm) >> Shift;
789 unsigned Lo = Imm & 0xFFFF;
804 if (!Shift)
return Result;
808 if ((
unsigned)(Imm & 0xFFFFFFFF) == Remainder) {
818 if ((Remainder >> 16) & 0xFFFF)
820 if (Remainder & 0xFFFF)
826 static uint64_t
Rot64(uint64_t Imm,
unsigned R) {
827 return (Imm << R) | (Imm >> (64 - R));
838 for (
unsigned r = 1; r < 63; ++r) {
839 uint64_t RImm =
Rot64(Imm, r);
841 Count = std::min(Count, RCount);
848 uint64_t OnesMask = -(int64_t) (UINT64_C(1) << (LS+1));
849 uint64_t RImmWithOnes = RImm | OnesMask;
852 Count = std::min(Count, RCount);
863 unsigned Remainder = 0;
869 Shift = countTrailingZeros<uint64_t>(Imm);
870 int64_t ImmSh =
static_cast<uint64_t
>(Imm) >> Shift;
888 unsigned Lo = Imm & 0xFFFF;
889 unsigned Hi = (Imm >> 16) & 0xFFFF;
891 auto getI32Imm = [CurDAG, dl](
unsigned Imm) {
903 unsigned OpC = Hi ? PPC::LIS8 : PPC::LI8;
907 SDValue(Result, 0), getI32Imm(Lo));
914 if (!Shift)
return Result;
918 if ((
unsigned)(Imm & 0xFFFFFFFF) == Remainder) {
920 {
SDValue(Result, 0),
SDValue(Result, 0), getI32Imm(Shift), getI32Imm(0)};
929 getI32Imm(63 - Shift));
933 if ((Hi = (Remainder >> 16) & 0xFFFF)) {
935 SDValue(Result, 0), getI32Imm(Hi));
937 if ((Lo = Remainder & 0xFFFF)) {
939 SDValue(Result, 0), getI32Imm(Lo));
959 for (
unsigned r = 1; r < 63; ++r) {
960 uint64_t RImm =
Rot64(Imm, r);
962 if (RCount < Count) {
981 uint64_t OnesMask = -(int64_t) (UINT64_C(1) << (LS+1));
982 uint64_t RImmWithOnes = RImm | OnesMask;
985 if (RCount < Count) {
988 MatImm = RImmWithOnes;
996 auto getI32Imm = [CurDAG, dl](
unsigned Imm) {
1002 getI32Imm(64 - RMin), getI32Imm(MaskEnd));
1006 unsigned MaxTruncation = 0;
1013 Use->isMachineOpcode() ?
Use->getMachineOpcode() :
Use->getOpcode();
1017 if (
Use->isMachineOpcode())
1020 std::max(MaxTruncation,
Use->getValueType(0).getSizeInBits());
1023 if (
Use->isMachineOpcode())
1027 if (MemVTSize == 64 || Use.getOperandNo() != 0)
1029 MaxTruncation =
std::max(MaxTruncation, MemVTSize);
1038 MaxTruncation =
std::max(MaxTruncation, 32u);
1046 MaxTruncation =
std::max(MaxTruncation, 16u);
1054 MaxTruncation =
std::max(MaxTruncation, 8u);
1058 return MaxTruncation;
1066 int64_t Imm = cast<ConstantSDNode>(
N)->getZExtValue();
1078 class BitPermutationSelector {
1092 : V(V), Idx(I), K(K) {}
1093 ValueBit(
Kind K = Variable)
1094 : V(
SDValue(
nullptr, 0)), Idx(UINT32_MAX), K(K) {}
1097 return K == ConstZero;
1100 bool hasValue()
const {
1101 return K == Variable;
1105 assert(hasValue() &&
"Cannot get the value of a constant bit");
1109 unsigned getValueBitIndex()
const {
1110 assert(hasValue() &&
"Cannot get the value bit index of a constant bit");
1119 unsigned StartIdx, EndIdx;
1129 bool Repl32Coalesced;
1131 BitGroup(
SDValue V,
unsigned R,
unsigned S,
unsigned E)
1132 : V(V), RLAmt(R), StartIdx(S), EndIdx(E), Repl32(
false), Repl32CR(
false),
1133 Repl32Coalesced(
false) {
1135 <<
" [" << S <<
", " << E <<
"]\n");
1141 struct ValueRotInfo {
1144 unsigned NumGroups = 0;
1146 bool Repl32 =
false;
1148 ValueRotInfo() =
default;
1156 if (Repl32 < Other.Repl32)
1158 else if (Repl32 > Other.Repl32)
1160 else if (NumGroups > Other.NumGroups)
1162 else if (NumGroups < Other.NumGroups)
1164 else if (RLAmt == 0 && Other.RLAmt != 0)
1166 else if (RLAmt != 0 && Other.RLAmt == 0)
1168 else if (FirstGroupStartIdx < Other.FirstGroupStartIdx)
1174 using ValueBitsMemoizedValue = std::pair<bool, SmallVector<ValueBit, 64>>;
1175 using ValueBitsMemoizer =
1177 ValueBitsMemoizer Memoizer;
1183 std::pair<bool, SmallVector<ValueBit, 64> *> getValueBits(
SDValue V,
1185 auto &ValueEntry = Memoizer[V];
1187 return std::make_pair(ValueEntry->first, &ValueEntry->second);
1188 ValueEntry.reset(
new ValueBitsMemoizedValue());
1189 bool &Interesting = ValueEntry->first;
1201 for (
unsigned i = 0; i < NumBits; ++i)
1202 Bits[i] = LHSBits[i < RotAmt ? i + (NumBits - RotAmt) : i - RotAmt];
1204 return std::make_pair(Interesting =
true, &Bits);
1213 for (
unsigned i = ShiftAmt; i < NumBits; ++i)
1214 Bits[i] = LHSBits[i - ShiftAmt];
1216 for (
unsigned i = 0; i < ShiftAmt; ++i)
1217 Bits[i] = ValueBit(ValueBit::ConstZero);
1219 return std::make_pair(Interesting =
true, &Bits);
1228 for (
unsigned i = 0; i < NumBits - ShiftAmt; ++i)
1229 Bits[i] = LHSBits[i + ShiftAmt];
1231 for (
unsigned i = NumBits - ShiftAmt; i < NumBits; ++i)
1232 Bits[i] = ValueBit(ValueBit::ConstZero);
1234 return std::make_pair(Interesting =
true, &Bits);
1246 std::tie(Interesting, LHSBits) = getValueBits(V.
getOperand(0), NumBits);
1248 for (
unsigned i = 0; i < NumBits; ++i)
1249 if (((Mask >> i) & 1) == 1)
1250 Bits[i] = (*LHSBits)[i];
1252 Bits[i] = ValueBit(ValueBit::ConstZero);
1254 return std::make_pair(Interesting, &Bits);
1261 bool AllDisjoint =
true;
1262 for (
unsigned i = 0; i < NumBits; ++i)
1264 Bits[i] = RHSBits[i];
1265 else if (RHSBits[i].
isZero())
1266 Bits[i] = LHSBits[i];
1268 AllDisjoint =
false;
1275 return std::make_pair(Interesting =
true, &Bits);
1284 const unsigned NumOperandBits = 32;
1285 std::tie(Interesting, LHSBits) = getValueBits(V.
getOperand(0),
1288 for (
unsigned i = 0; i < NumOperandBits; ++i)
1289 Bits[i] = (*LHSBits)[i];
1291 for (
unsigned i = NumOperandBits; i < NumBits; ++i)
1292 Bits[i] = ValueBit(ValueBit::ConstZero);
1294 return std::make_pair(Interesting, &Bits);
1298 for (
unsigned i = 0; i < NumBits; ++i)
1299 Bits[i] = ValueBit(V, i);
1301 return std::make_pair(Interesting =
false, &Bits);
1306 void computeRotationAmounts() {
1308 RLAmt.resize(
Bits.size());
1309 for (
unsigned i = 0; i <
Bits.size(); ++i)
1310 if (
Bits[i].hasValue()) {
1311 unsigned VBI =
Bits[i].getValueBitIndex();
1315 RLAmt[i] =
Bits.size() - (VBI - i);
1318 RLAmt[i] = UINT32_MAX;
1327 void collectBitGroups(
bool LateMask) {
1330 unsigned LastRLAmt = RLAmt[0];
1332 unsigned LastGroupStartIdx = 0;
1333 for (
unsigned i = 1; i <
Bits.size(); ++i) {
1334 unsigned ThisRLAmt = RLAmt[i];
1336 if (LateMask && !ThisValue) {
1337 ThisValue = LastValue;
1338 ThisRLAmt = LastRLAmt;
1341 if (BitGroups.empty())
1342 LastGroupStartIdx = 0;
1347 if (ThisRLAmt == LastRLAmt && ThisValue == LastValue)
1351 BitGroups.push_back(BitGroup(LastValue, LastRLAmt, LastGroupStartIdx,
1353 LastRLAmt = ThisRLAmt;
1354 LastValue = ThisValue;
1355 LastGroupStartIdx = i;
1358 BitGroups.push_back(BitGroup(LastValue, LastRLAmt, LastGroupStartIdx,
1361 if (BitGroups.empty())
1365 if (BitGroups.size() > 1) {
1369 if (BitGroups[0].StartIdx == 0 &&
1370 BitGroups[BitGroups.size()-1].EndIdx ==
Bits.size()-1 &&
1371 BitGroups[0].V == BitGroups[BitGroups.size()-1].V &&
1372 BitGroups[0].RLAmt == BitGroups[BitGroups.size()-1].RLAmt) {
1373 LLVM_DEBUG(
dbgs() <<
"\tcombining final bit group with initial one\n");
1374 BitGroups[BitGroups.size()-1].EndIdx = BitGroups[0].EndIdx;
1375 BitGroups.erase(BitGroups.begin());
1385 void collectValueRotInfo() {
1388 for (
auto &BG : BitGroups) {
1389 unsigned RLAmtKey = BG.RLAmt + (BG.Repl32 ? 64 : 0);
1390 ValueRotInfo &VRI = ValueRots[std::make_pair(BG.V, RLAmtKey)];
1392 VRI.RLAmt = BG.RLAmt;
1393 VRI.Repl32 = BG.Repl32;
1395 VRI.FirstGroupStartIdx = std::min(VRI.FirstGroupStartIdx, BG.StartIdx);
1400 ValueRotsVec.clear();
1401 for (
auto &
I : ValueRots) {
1402 ValueRotsVec.push_back(
I.second);
1404 llvm::sort(ValueRotsVec.begin(), ValueRotsVec.end());
1415 void assignRepl32BitGroups() {
1426 auto IsAllLow32 = [
this](BitGroup & BG) {
1427 if (BG.StartIdx <= BG.EndIdx) {
1428 for (
unsigned i = BG.StartIdx; i <= BG.EndIdx; ++i) {
1429 if (!
Bits[i].hasValue())
1431 if (
Bits[i].getValueBitIndex() >= 32)
1435 for (
unsigned i = BG.StartIdx; i <
Bits.size(); ++i) {
1436 if (!
Bits[i].hasValue())
1438 if (
Bits[i].getValueBitIndex() >= 32)
1441 for (
unsigned i = 0; i <= BG.EndIdx; ++i) {
1442 if (!
Bits[i].hasValue())
1444 if (
Bits[i].getValueBitIndex() >= 32)
1452 for (
auto &BG : BitGroups) {
1456 if (BG.RLAmt == 0) {
1457 auto PotentiallyMerged = [
this](BitGroup & BG) {
1458 for (
auto &BG2 : BitGroups)
1459 if (&BG != &BG2 && BG.V == BG2.V &&
1460 (BG2.RLAmt == 0 || BG2.RLAmt == 32))
1464 if (!PotentiallyMerged(BG))
1467 if (BG.StartIdx < 32 && BG.EndIdx < 32) {
1468 if (IsAllLow32(BG)) {
1469 if (BG.RLAmt >= 32) {
1477 << BG.V.getNode() <<
" RLAmt = " << BG.RLAmt <<
" [" 1478 << BG.StartIdx <<
", " << BG.EndIdx <<
"]\n");
1484 for (
auto I = BitGroups.begin();
I != BitGroups.end();) {
1487 auto IP = (
I == BitGroups.begin()) ?
1488 std::prev(BitGroups.end()) : std::prev(
I);
1489 if (
I->Repl32 && IP->Repl32 &&
I->V == IP->V &&
I->RLAmt == IP->RLAmt &&
1490 I->StartIdx == (IP->EndIdx + 1) % 64 &&
I != IP) {
1492 LLVM_DEBUG(
dbgs() <<
"\tcombining 32-bit replicated bit group for " 1493 <<
I->V.getNode() <<
" RLAmt = " <<
I->RLAmt <<
" [" 1494 <<
I->StartIdx <<
", " <<
I->EndIdx
1495 <<
"] with group with range [" << IP->StartIdx <<
", " 1496 << IP->EndIdx <<
"]\n");
1498 IP->EndIdx =
I->EndIdx;
1499 IP->Repl32CR = IP->Repl32CR ||
I->Repl32CR;
1500 IP->Repl32Coalesced =
true;
1501 I = BitGroups.erase(
I);
1510 if (
I->StartIdx == 32 &&
I->EndIdx == 63) {
1511 assert(std::next(
I) == BitGroups.end() &&
1512 "bit group ends at index 63 but there is another?");
1513 auto IN = BitGroups.begin();
1515 if (IP->Repl32 && IN->Repl32 &&
I->V == IP->V &&
I->V == IN->V &&
1516 (
I->RLAmt % 32) == IP->RLAmt && (
I->RLAmt % 32) == IN->RLAmt &&
1517 IP->EndIdx == 31 && IN->StartIdx == 0 &&
I != IP &&
1521 <<
" RLAmt = " <<
I->RLAmt <<
" [" <<
I->StartIdx
1522 <<
", " <<
I->EndIdx
1523 <<
"] with 32-bit replicated groups with ranges [" 1524 << IP->StartIdx <<
", " << IP->EndIdx <<
"] and [" 1525 << IN->StartIdx <<
", " << IN->EndIdx <<
"]\n");
1533 IP->Repl32CR = IP->Repl32CR ||
I->RLAmt >= 32;
1534 IP->Repl32Coalesced =
true;
1535 I = BitGroups.erase(
I);
1540 IP->EndIdx = IN->EndIdx;
1541 IP->Repl32CR = IP->Repl32CR || IN->Repl32CR ||
I->RLAmt >= 32;
1542 IP->Repl32Coalesced =
true;
1543 I = BitGroups.erase(
I);
1544 BitGroups.erase(BitGroups.begin());
1559 return CurDAG->getTargetConstant(Imm, dl,
MVT::i32);
1562 uint64_t getZerosMask() {
1564 for (
unsigned i = 0; i <
Bits.size(); ++i) {
1565 if (
Bits[i].hasValue())
1567 Mask |= (UINT64_C(1) << i);
1582 SDValue SubRegIdx = CurDAG->getTargetConstant(PPC::sub_32, dl,
MVT::i32);
1583 SDValue ImDef =
SDValue(CurDAG->getMachineNode(PPC::IMPLICIT_DEF, dl,
1585 SDValue ExtVal =
SDValue(CurDAG->getMachineNode(PPC::INSERT_SUBREG, dl,
1594 void SelectAndParts32(
const SDLoc &dl,
SDValue &Res,
unsigned *InstCnt) {
1598 for (ValueRotInfo &VRI : ValueRotsVec) {
1600 for (
unsigned i = 0; i <
Bits.size(); ++i) {
1601 if (!
Bits[i].hasValue() ||
Bits[i].getValue() != VRI.V)
1603 if (RLAmt[i] != VRI.RLAmt)
1609 unsigned ANDIMask = (Mask & UINT16_MAX), ANDISMask = Mask >> 16;
1610 assert((ANDIMask != 0 || ANDISMask != 0) &&
1611 "No set bits in mask for value bit groups");
1612 bool NeedsRotate = VRI.RLAmt != 0;
1628 unsigned NumAndInsts = (
unsigned) NeedsRotate +
1629 (
unsigned) (ANDIMask != 0) +
1630 (
unsigned) (ANDISMask != 0) +
1631 (
unsigned) (ANDIMask != 0 && ANDISMask != 0) +
1632 (
unsigned) (
bool) Res;
1634 LLVM_DEBUG(
dbgs() <<
"\t\trotation groups for " << VRI.V.getNode()
1635 <<
" RL: " << VRI.RLAmt <<
":" 1636 <<
"\n\t\t\tisel using masking: " << NumAndInsts
1637 <<
" using rotates: " << VRI.NumGroups <<
"\n");
1639 if (NumAndInsts >= VRI.NumGroups)
1644 if (InstCnt) *InstCnt += NumAndInsts;
1649 { VRI.V, getI32Imm(VRI.RLAmt, dl), getI32Imm(0, dl),
1650 getI32Imm(31, dl) };
1660 VRot, getI32Imm(ANDIMask, dl)), 0);
1663 VRot, getI32Imm(ANDISMask, dl)), 0);
1667 TotalVal = ANDISVal;
1672 ANDIVal, ANDISVal), 0);
1682 eraseMatchingBitGroups([VRI](
const BitGroup &BG) {
1683 return BG.V == VRI.V && BG.RLAmt == VRI.RLAmt;
1689 SDNode *Select32(
SDNode *N,
bool LateMask,
unsigned *InstCnt) {
1693 if (InstCnt) *InstCnt = 0;
1696 SelectAndParts32(dl, Res, InstCnt);
1701 if ((!HasZeros || LateMask) && !Res) {
1702 ValueRotInfo &VRI = ValueRotsVec[0];
1704 if (InstCnt) *InstCnt += 1;
1706 { VRI.V, getI32Imm(VRI.RLAmt, dl), getI32Imm(0, dl),
1707 getI32Imm(31, dl) };
1715 eraseMatchingBitGroups([VRI](
const BitGroup &BG) {
1716 return BG.V == VRI.V && BG.RLAmt == VRI.RLAmt;
1720 if (InstCnt) *InstCnt += BitGroups.size();
1723 for (
auto &BG : BitGroups) {
1726 { BG.V, getI32Imm(BG.RLAmt, dl),
1727 getI32Imm(
Bits.size() - BG.EndIdx - 1, dl),
1728 getI32Imm(
Bits.size() - BG.StartIdx - 1, dl) };
1729 Res =
SDValue(CurDAG->getMachineNode(PPC::RLWINM, dl,
MVT::i32, Ops), 0);
1732 { Res, BG.V, getI32Imm(BG.RLAmt, dl),
1733 getI32Imm(
Bits.size() - BG.EndIdx - 1, dl),
1734 getI32Imm(
Bits.size() - BG.StartIdx - 1, dl) };
1735 Res =
SDValue(CurDAG->getMachineNode(PPC::RLWIMI, dl,
MVT::i32, Ops), 0);
1740 unsigned Mask = (
unsigned) getZerosMask();
1742 unsigned ANDIMask = (Mask & UINT16_MAX), ANDISMask = Mask >> 16;
1743 assert((ANDIMask != 0 || ANDISMask != 0) &&
1744 "No set bits in zeros mask?");
1746 if (InstCnt) *InstCnt += (
unsigned) (ANDIMask != 0) +
1748 (
unsigned) (ANDIMask != 0 && ANDISMask != 0);
1753 Res, getI32Imm(ANDIMask, dl)), 0);
1756 Res, getI32Imm(ANDISMask, dl)), 0);
1764 ANDIVal, ANDISVal), 0);
1770 unsigned SelectRotMask64Count(
unsigned RLAmt,
bool Repl32,
1771 unsigned MaskStart,
unsigned MaskEnd,
1775 unsigned InstMaskStart = 64 - MaskEnd - 1,
1776 InstMaskEnd = 64 - MaskStart - 1;
1781 if ((!IsIns && (InstMaskEnd == 63 || InstMaskStart == 0)) ||
1782 InstMaskEnd == 63 - RLAmt)
1791 bool Repl32,
unsigned MaskStart,
unsigned MaskEnd,
1792 unsigned *InstCnt =
nullptr) {
1795 unsigned InstMaskStart = 64 - MaskEnd - 1,
1796 InstMaskEnd = 64 - MaskStart - 1;
1798 if (InstCnt) *InstCnt += 1;
1804 assert(InstMaskStart >= 32 &&
"Mask cannot start out of range");
1805 assert(InstMaskEnd >= 32 &&
"Mask cannot end out of range");
1807 { ExtendToInt64(V, dl), getI32Imm(RLAmt, dl),
1808 getI32Imm(InstMaskStart - 32, dl), getI32Imm(InstMaskEnd - 32, dl) };
1813 if (InstMaskEnd == 63) {
1815 { ExtendToInt64(V, dl), getI32Imm(RLAmt, dl),
1816 getI32Imm(InstMaskStart, dl) };
1817 return SDValue(CurDAG->getMachineNode(PPC::RLDICL, dl,
MVT::i64, Ops), 0);
1820 if (InstMaskStart == 0) {
1822 { ExtendToInt64(V, dl), getI32Imm(RLAmt, dl),
1823 getI32Imm(InstMaskEnd, dl) };
1824 return SDValue(CurDAG->getMachineNode(PPC::RLDICR, dl,
MVT::i64, Ops), 0);
1827 if (InstMaskEnd == 63 - RLAmt) {
1829 { ExtendToInt64(V, dl), getI32Imm(RLAmt, dl),
1830 getI32Imm(InstMaskStart, dl) };
1831 return SDValue(CurDAG->getMachineNode(PPC::RLDIC, dl,
MVT::i64, Ops), 0);
1840 if (InstCnt) *InstCnt += 1;
1843 unsigned RLAmt2 = MaskStart;
1846 unsigned RLAmt1 = (64 + RLAmt - RLAmt2) % 64;
1848 V = SelectRotMask64(V, dl, RLAmt1,
false, 0, 63);
1849 return SelectRotMask64(V, dl, RLAmt2,
false, MaskStart, MaskEnd);
1855 unsigned RLAmt,
bool Repl32,
unsigned MaskStart,
1856 unsigned MaskEnd,
unsigned *InstCnt =
nullptr) {
1859 unsigned InstMaskStart = 64 - MaskEnd - 1,
1860 InstMaskEnd = 64 - MaskStart - 1;
1862 if (InstCnt) *InstCnt += 1;
1868 assert(InstMaskStart >= 32 &&
"Mask cannot start out of range");
1869 assert(InstMaskEnd >= 32 &&
"Mask cannot end out of range");
1871 { ExtendToInt64(Base, dl), ExtendToInt64(V, dl), getI32Imm(RLAmt, dl),
1872 getI32Imm(InstMaskStart - 32, dl), getI32Imm(InstMaskEnd - 32, dl) };
1877 if (InstMaskEnd == 63 - RLAmt) {
1879 { ExtendToInt64(Base, dl), ExtendToInt64(V, dl), getI32Imm(RLAmt, dl),
1880 getI32Imm(InstMaskStart, dl) };
1881 return SDValue(CurDAG->getMachineNode(PPC::RLDIMI, dl,
MVT::i64, Ops), 0);
1890 if (InstCnt) *InstCnt += 1;
1893 unsigned RLAmt2 = MaskStart;
1896 unsigned RLAmt1 = (64 + RLAmt - RLAmt2) % 64;
1898 V = SelectRotMask64(V, dl, RLAmt1,
false, 0, 63);
1899 return SelectRotMaskIns64(Base, V, dl, RLAmt2,
false, MaskStart, MaskEnd);
1902 void SelectAndParts64(
const SDLoc &dl,
SDValue &Res,
unsigned *InstCnt) {
1915 for (ValueRotInfo &VRI : ValueRotsVec) {
1923 auto MatchingBG = [VRI](
const BitGroup &BG) {
1927 unsigned EffRLAmt = BG.RLAmt;
1928 if (!VRI.Repl32 && BG.Repl32) {
1929 if (BG.StartIdx < 32 && BG.EndIdx < 32 && BG.StartIdx <= BG.EndIdx &&
1930 !BG.Repl32Coalesced) {
1936 }
else if (VRI.Repl32 != BG.Repl32) {
1940 return VRI.RLAmt == EffRLAmt;
1943 for (
auto &BG : BitGroups) {
1944 if (!MatchingBG(BG))
1947 if (BG.StartIdx <= BG.EndIdx) {
1948 for (
unsigned i = BG.StartIdx; i <= BG.EndIdx; ++i)
1949 Mask |= (UINT64_C(1) << i);
1951 for (
unsigned i = BG.StartIdx; i <
Bits.size(); ++i)
1952 Mask |= (UINT64_C(1) << i);
1953 for (
unsigned i = 0; i <= BG.EndIdx; ++i)
1954 Mask |= (UINT64_C(1) << i);
1963 unsigned ANDIMask = (Mask & UINT16_MAX),
1964 ANDISMask = (Mask >> 16) & UINT16_MAX;
1966 bool NeedsRotate = VRI.RLAmt || (VRI.Repl32 && !
isUInt<32>(
Mask));
1968 unsigned NumAndInsts = (
unsigned) NeedsRotate +
1969 (
unsigned) (
bool) Res;
1972 (
unsigned) (ANDIMask != 0 && ANDISMask != 0);
1976 unsigned NumRLInsts = 0;
1977 bool FirstBG =
true;
1978 bool MoreBG =
false;
1979 for (
auto &BG : BitGroups) {
1980 if (!MatchingBG(BG)) {
1985 SelectRotMask64Count(BG.RLAmt, BG.Repl32, BG.StartIdx, BG.EndIdx,
1990 LLVM_DEBUG(
dbgs() <<
"\t\trotation groups for " << VRI.V.getNode()
1991 <<
" RL: " << VRI.RLAmt << (VRI.Repl32 ?
" (32):" :
":")
1992 <<
"\n\t\t\tisel using masking: " << NumAndInsts
1993 <<
" using rotates: " << NumRLInsts <<
"\n");
1999 if (NumAndInsts > NumRLInsts)
2004 if ((Use32BitInsts || MoreBG) && NumAndInsts == NumRLInsts)
2009 if (InstCnt) *InstCnt += NumAndInsts;
2016 if (VRI.RLAmt || (VRI.Repl32 && !
isUInt<32>(Mask)))
2017 VRot = SelectRotMask64(VRI.V, dl, VRI.RLAmt, VRI.Repl32,
2018 VRI.Repl32 ? 31 : 0, VRI.Repl32 ? 30 : 63);
2023 if (Use32BitInsts) {
2024 assert((ANDIMask != 0 || ANDISMask != 0) &&
2025 "No set bits in mask when using 32-bit ands for 64-bit value");
2030 ExtendToInt64(VRot, dl),
2031 getI32Imm(ANDIMask, dl)),
2035 ExtendToInt64(VRot, dl),
2036 getI32Imm(ANDISMask, dl)),
2040 TotalVal = ANDISVal;
2045 ExtendToInt64(ANDIVal, dl), ANDISVal), 0);
2050 ExtendToInt64(VRot, dl), TotalVal),
2058 ExtendToInt64(Res, dl), TotalVal),
2063 eraseMatchingBitGroups(MatchingBG);
2068 SDNode *Select64(
SDNode *N,
bool LateMask,
unsigned *InstCnt) {
2072 if (InstCnt) *InstCnt = 0;
2075 SelectAndParts64(dl, Res, InstCnt);
2080 if ((!HasZeros || LateMask) && !Res) {
2084 unsigned MaxGroupsIdx = 0;
2085 if (!ValueRotsVec[0].Repl32) {
2086 for (
unsigned i = 0, ie = ValueRotsVec.size(); i < ie; ++i)
2087 if (ValueRotsVec[i].Repl32) {
2088 if (ValueRotsVec[i].NumGroups > ValueRotsVec[0].NumGroups)
2094 ValueRotInfo &VRI = ValueRotsVec[MaxGroupsIdx];
2095 bool NeedsRotate =
false;
2098 }
else if (VRI.Repl32) {
2099 for (
auto &BG : BitGroups) {
2100 if (BG.V != VRI.V || BG.RLAmt != VRI.RLAmt ||
2101 BG.Repl32 != VRI.Repl32)
2106 if (BG.StartIdx < 32 && BG.EndIdx < 32 && BG.StartIdx < BG.EndIdx)
2115 Res = SelectRotMask64(VRI.V, dl, VRI.RLAmt, VRI.Repl32,
2116 VRI.Repl32 ? 31 : 0, VRI.Repl32 ? 30 : 63,
2123 eraseMatchingBitGroups([VRI](
const BitGroup &BG) {
2124 return BG.V == VRI.V && BG.RLAmt == VRI.RLAmt &&
2125 BG.Repl32 == VRI.Repl32;
2132 for (
auto I = BitGroups.begin(),
IE = BitGroups.end();
I !=
IE; ++
I) {
2133 if (SelectRotMask64Count(
I->RLAmt,
I->Repl32,
I->StartIdx,
I->EndIdx,
2135 SelectRotMask64Count(
I->RLAmt,
I->Repl32,
I->StartIdx,
I->EndIdx,
2137 if (
I != BitGroups.begin()) {
2140 BitGroups.insert(BitGroups.begin(), BG);
2148 for (
auto &BG : BitGroups) {
2150 Res = SelectRotMask64(BG.V, dl, BG.RLAmt, BG.Repl32, BG.StartIdx,
2151 BG.EndIdx, InstCnt);
2153 Res = SelectRotMaskIns64(Res, BG.V, dl, BG.RLAmt, BG.Repl32,
2154 BG.StartIdx, BG.EndIdx, InstCnt);
2158 uint64_t Mask = getZerosMask();
2165 unsigned ANDIMask = (Mask & UINT16_MAX),
2166 ANDISMask = (Mask >> 16) & UINT16_MAX;
2168 if (Use32BitInsts) {
2169 assert((ANDIMask != 0 || ANDISMask != 0) &&
2170 "No set bits in mask when using 32-bit ands for 64-bit value");
2172 if (InstCnt) *InstCnt += (
unsigned) (ANDIMask != 0) +
2174 (
unsigned) (ANDIMask != 0 && ANDISMask != 0);
2179 ExtendToInt64(Res, dl), getI32Imm(ANDIMask, dl)), 0);
2182 ExtendToInt64(Res, dl), getI32Imm(ANDISMask, dl)), 0);
2190 ExtendToInt64(ANDIVal, dl), ANDISVal), 0);
2197 ExtendToInt64(Res, dl), MaskVal), 0);
2206 collectBitGroups(LateMask);
2207 if (BitGroups.empty())
2211 if (
Bits.size() == 64)
2212 assignRepl32BitGroups();
2215 collectValueRotInfo();
2217 if (
Bits.size() == 32) {
2218 return Select32(N, LateMask, InstCnt);
2220 assert(
Bits.size() == 64 &&
"Not 64 bits here?");
2221 return Select64(N, LateMask, InstCnt);
2227 void eraseMatchingBitGroups(
function_ref<
bool(
const BitGroup &)>
F) {
2228 BitGroups.erase(
remove_if(BitGroups,
F), BitGroups.end());
2256 Bits = std::move(*
Result.second);
2258 LLVM_DEBUG(
dbgs() <<
"Considering bit-permutation-based instruction" 2259 " selection for: ");
2263 computeRotationAmounts();
2276 unsigned InstCnt = 0, InstCntLateMask = 0;
2279 LLVM_DEBUG(
dbgs() <<
"\t\tisel would use " << InstCnt <<
" instructions\n");
2284 <<
" instructions\n");
2286 if (InstCnt <= InstCntLateMask) {
2296 class IntegerCompareEliminator {
2301 enum ExtOrTruncConversion {
Ext, Trunc };
2309 enum SetccInGPROpts { ZExtOrig, ZExtInvert, SExtOrig, SExtInvert };
2319 enum ZeroCompare { GEZExt, GESExt, LEZExt, LESExt };
2326 SDValue addExtOrTrunc(
SDValue NatWidthRes, ExtOrTruncConversion Conv);
2330 int64_t RHSValue,
SDLoc dl);
2332 int64_t RHSValue,
SDLoc dl);
2334 int64_t RHSValue,
SDLoc dl);
2336 int64_t RHSValue,
SDLoc dl);
2341 PPCDAGToDAGISel *Sel) : CurDAG(DAG), S(Sel) {
2344 "Only expecting to use this on 64 bit targets.");
2360 return tryEXTEND(N);
2364 return tryLogicOpOfCompares(N);
2370 static bool isLogicOp(
unsigned Opc) {
2375 SDNode *IntegerCompareEliminator::tryEXTEND(
SDNode *N) {
2378 "Expecting a zero/sign extend node!");
2385 WideRes = computeLogicOpInGPR(N->
getOperand(0));
2392 SetccInGPROpts::SExtOrig : SetccInGPROpts::ZExtOrig);
2405 if (Input32Bit != Output32Bit)
2407 ExtOrTruncConversion::Trunc);
2415 SDNode *IntegerCompareEliminator::tryLogicOpOfCompares(
SDNode *N) {
2419 "Expected a logic operation on setcc results.");
2421 if (!LoweredLogical)
2426 unsigned SubRegToExtract = IsBitwiseNegate ? PPC::sub_eq : PPC::sub_gt;
2435 if (IsBitwiseNegate &&
2438 else if (IsBitwiseNegate)
2440 OpToConvToRecForm = LoweredLogical.
getOperand(0);
2444 OpToConvToRecForm = LoweredLogical;
2454 if (NewOpc != -1 && IsBitwiseNegate) {
2457 "Expected a PPC::XORI8 only for bitwise negation.");
2459 std::vector<SDValue> Ops;
2460 for (
int i = 0, e = OpToConvToRecForm.
getNumOperands(); i < e; i++)
2461 Ops.push_back(OpToConvToRecForm.
getOperand(i));
2464 SDValue(CurDAG->getMachineNode(NewOpc, dl,
2468 assert((NewOpc != -1 || !IsBitwiseNegate) &&
2469 "No record form available for AND8/OR8/XOR8?");
2471 SDValue(CurDAG->getMachineNode(NewOpc == -1 ? PPC::ANDIo8 : NewOpc, dl,
2480 CurDAG->getTargetConstant(SubRegToExtract, dl,
MVT::i32);
2482 SDValue(CurDAG->getMachineNode(TargetOpcode::EXTRACT_SUBREG, dl,
2496 SDValue IntegerCompareEliminator::computeLogicOpInGPR(
SDValue LogicOp) {
2498 "Can only handle logic operations here.");
2500 "Can only handle logic operations on i1 values here.");
2512 unsigned OperandOpcode = Operand.
getOpcode();
2514 return getSETCCInGPR(Operand, SetccInGPROpts::ZExtOrig);
2518 return SDValue(CurDAG->getMachineNode(InVT ==
MVT::i32 ? PPC::RLDICL_32 :
2519 PPC::RLDICL, dl, InVT, InputOp,
2520 S->getI64Imm(0, dl),
2521 S->getI64Imm(63, dl)), 0);
2522 }
else if (isLogicOp(OperandOpcode))
2523 return computeLogicOpInGPR(Operand);
2526 LHS = getLogicOperand(LogicOp.
getOperand(0));
2527 RHS = getLogicOperand(LogicOp.
getOperand(1));
2532 if (!LHS || (!RHS && !IsBitwiseNegation))
2535 NumLogicOpsOnComparison++;
2540 if (!IsBitwiseNegation && RHS.getValueType() ==
MVT::i32)
2546 case ISD::AND: NewOpc = PPC::AND8;
break;
2547 case ISD::OR: NewOpc = PPC::OR8;
break;
2548 case ISD::XOR: NewOpc = PPC::XOR8;
break;
2551 if (IsBitwiseNegation) {
2552 RHS = S->getI64Imm(1, dl);
2553 NewOpc = PPC::XORI8;
2556 return SDValue(CurDAG->getMachineNode(NewOpc, dl,
MVT::i64, LHS, RHS), 0);
2564 SDValue IntegerCompareEliminator::signExtendInputIfNeeded(
SDValue Input) {
2566 "Can only sign-extend 32-bit values here.");
2588 SignExtensionsAdded++;
2589 return SDValue(CurDAG->getMachineNode(PPC::EXTSW_32_64, dl,
2597 SDValue IntegerCompareEliminator::zeroExtendInputIfNeeded(
SDValue Input) {
2599 "Can only zero-extend 32-bit values here.");
2609 if (IsTruncateOfZExt)
2623 ZeroExtensionsAdded++;
2624 return SDValue(CurDAG->getMachineNode(PPC::RLDICL_32_64, dl,
MVT::i64, Input,
2625 S->getI64Imm(0, dl),
2626 S->getI64Imm(32, dl)), 0);
2633 SDValue IntegerCompareEliminator::addExtOrTrunc(
SDValue NatWidthRes,
2634 ExtOrTruncConversion Conv) {
2635 SDLoc dl(NatWidthRes);
2640 SDValue ImDef(CurDAG->getMachineNode(PPC::IMPLICIT_DEF, dl,
MVT::i64), 0);
2642 CurDAG->getTargetConstant(PPC::sub_32, dl,
MVT::i32);
2643 return SDValue(CurDAG->getMachineNode(PPC::INSERT_SUBREG, dl,
MVT::i64,
2644 ImDef, NatWidthRes, SubRegIdx), 0);
2647 assert(Conv == ExtOrTruncConversion::Trunc &&
2648 "Unknown convertion between 32 and 64 bit values.");
2652 CurDAG->getTargetConstant(PPC::sub_32, dl,
MVT::i32);
2653 return SDValue(CurDAG->getMachineNode(PPC::EXTRACT_SUBREG, dl,
MVT::i32,
2654 NatWidthRes, SubRegIdx), 0);
2660 IntegerCompareEliminator::getCompoundZeroComparisonInGPR(
SDValue LHS,
SDLoc dl,
2661 ZeroCompare CmpTy) {
2668 case ZeroCompare::GEZExt:
2669 case ZeroCompare::GESExt:
2670 ToExtend =
SDValue(CurDAG->getMachineNode(Is32Bit ? PPC::NOR : PPC::NOR8,
2671 dl, InVT, LHS, LHS), 0);
2673 case ZeroCompare::LEZExt:
2674 case ZeroCompare::LESExt: {
2677 LHS = signExtendInputIfNeeded(LHS);
2682 Neg, S->getI64Imm(1, dl),
2683 S->getI64Imm(63, dl)), 0);
2687 S->getI64Imm(~0ULL, dl)), 0);
2697 (CmpTy == ZeroCompare::GEZExt || CmpTy == ZeroCompare::LEZExt))
2699 ToExtend, S->getI64Imm(1, dl),
2700 S->getI64Imm(63, dl)), 0);
2702 (CmpTy == ZeroCompare::GESExt || CmpTy == ZeroCompare::LESExt))
2703 return SDValue(CurDAG->getMachineNode(PPC::SRADI, dl,
MVT::i64, ToExtend,
2704 S->getI64Imm(63, dl)), 0);
2706 assert(Is32Bit &&
"Should have handled the 32-bit sequences above.");
2709 case ZeroCompare::GEZExt: {
2710 SDValue ShiftOps[] = { ToExtend, S->getI32Imm(1, dl), S->getI32Imm(31, dl),
2711 S->getI32Imm(31, dl) };
2715 case ZeroCompare::GESExt:
2716 return SDValue(CurDAG->getMachineNode(PPC::SRAWI, dl,
MVT::i32, ToExtend,
2717 S->getI32Imm(31, dl)), 0);
2718 case ZeroCompare::LEZExt:
2719 return SDValue(CurDAG->getMachineNode(PPC::XORI8, dl,
MVT::i64, ToExtend,
2720 S->getI32Imm(1, dl)), 0);
2721 case ZeroCompare::LESExt:
2722 return SDValue(CurDAG->getMachineNode(PPC::ADDI8, dl,
MVT::i64, ToExtend,
2723 S->getI32Imm(-1, dl)), 0);
2734 IntegerCompareEliminator::get32BitZExtCompare(
SDValue LHS,
SDValue RHS,
2736 int64_t RHSValue,
SDLoc dl) {
2740 bool IsRHSZero = RHSValue == 0;
2741 bool IsRHSOne = RHSValue == 1;
2742 bool IsRHSNegOne = RHSValue == -1LL;
2748 SDValue Xor = IsRHSZero ? LHS :
2752 SDValue ShiftOps[] = { Clz, S->getI32Imm(27, dl), S->getI32Imm(5, dl),
2753 S->getI32Imm(31, dl) };
2760 SDValue Xor = IsRHSZero ? LHS :
2764 SDValue ShiftOps[] = { Clz, S->getI32Imm(27, dl), S->getI32Imm(5, dl),
2765 S->getI32Imm(31, dl) };
2767 SDValue(CurDAG->getMachineNode(PPC::RLWINM, dl,
MVT::i32, ShiftOps), 0);
2769 S->getI32Imm(1, dl)), 0);
2775 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::GEZExt);
2792 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::LEZExt);
2796 LHS = signExtendInputIfNeeded(LHS);
2797 RHS = signExtendInputIfNeeded(RHS);
2799 SDValue(CurDAG->getMachineNode(PPC::SUBF8, dl,
MVT::i64, LHS, RHS), 0);
2802 S->getI64Imm(1, dl), S->getI64Imm(63, dl)),
2805 SDValue(CurDAG->getMachineNode(PPC::XORI8, dl,
2806 MVT::i64, Shift, S->getI32Imm(1, dl)), 0);
2814 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::GEZExt);
2820 LHS = signExtendInputIfNeeded(LHS);
2821 RHS = signExtendInputIfNeeded(RHS);
2825 Neg, S->getI32Imm(1, dl), S->getI32Imm(63, dl)), 0);
2843 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::LEZExt);
2847 SDValue ShiftOps[] = { LHS, S->getI32Imm(1, dl), S->getI32Imm(31, dl),
2848 S->getI32Imm(31, dl) };
2856 LHS = signExtendInputIfNeeded(LHS);
2857 RHS = signExtendInputIfNeeded(RHS);
2859 SDValue(CurDAG->getMachineNode(PPC::SUBF8, dl,
MVT::i64, RHS, LHS), 0);
2861 SUBFNode, S->getI64Imm(1, dl),
2862 S->getI64Imm(63, dl)), 0);
2873 LHS = zeroExtendInputIfNeeded(LHS);
2874 RHS = zeroExtendInputIfNeeded(RHS);
2876 SDValue(CurDAG->getMachineNode(PPC::SUBF8, dl,
MVT::i64, LHS, RHS), 0);
2879 Subtract, S->getI64Imm(1, dl),
2880 S->getI64Imm(63, dl)), 0);
2881 return SDValue(CurDAG->getMachineNode(PPC::XORI8, dl,
MVT::i64, SrdiNode,
2882 S->getI32Imm(1, dl)), 0);
2893 LHS = zeroExtendInputIfNeeded(LHS);
2894 RHS = zeroExtendInputIfNeeded(RHS);
2896 SDValue(CurDAG->getMachineNode(PPC::SUBF8, dl,
MVT::i64, RHS, LHS), 0);
2898 Subtract, S->getI64Imm(1, dl),
2899 S->getI64Imm(63, dl)), 0);
2907 IntegerCompareEliminator::get32BitSExtCompare(
SDValue LHS,
SDValue RHS,
2909 int64_t RHSValue,
SDLoc dl) {
2913 bool IsRHSZero = RHSValue == 0;
2914 bool IsRHSOne = RHSValue == 1;
2915 bool IsRHSNegOne = RHSValue == -1LL;
2924 SDValue CountInput = IsRHSZero ? LHS :
2927 SDValue(CurDAG->getMachineNode(PPC::CNTLZW, dl,
MVT::i32, CountInput), 0);
2928 SDValue SHLOps[] = { Cntlzw, S->getI32Imm(27, dl),
2929 S->getI32Imm(5, dl), S->getI32Imm(31, dl) };
2931 SDValue(CurDAG->getMachineNode(PPC::RLWINM, dl,
MVT::i32, SHLOps), 0);
2942 SDValue Xor = IsRHSZero ? LHS :
2947 { Clz, S->getI32Imm(27, dl), S->getI32Imm(5, dl), S->getI32Imm(31, dl) };
2949 SDValue(CurDAG->getMachineNode(PPC::RLWINM, dl,
MVT::i32, ShiftOps), 0);
2952 S->getI32Imm(1, dl)), 0);
2959 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::GESExt);
2974 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::LESExt);
2977 LHS = signExtendInputIfNeeded(LHS);
2978 RHS = signExtendInputIfNeeded(RHS);
2984 SUBFNode, S->getI64Imm(1, dl),
2985 S->getI64Imm(63, dl)), 0);
2987 S->getI32Imm(-1, dl)), 0);
2994 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::GESExt);
2999 LHS = signExtendInputIfNeeded(LHS);
3000 RHS = signExtendInputIfNeeded(RHS);
3004 S->getI64Imm(63, dl)), 0);
3021 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::LESExt);
3025 S->getI32Imm(31, dl)), 0);
3030 LHS = signExtendInputIfNeeded(LHS);
3031 RHS = signExtendInputIfNeeded(RHS);
3033 SDValue(CurDAG->getMachineNode(PPC::SUBF8, dl,
MVT::i64, RHS, LHS), 0);
3035 SUBFNode, S->getI64Imm(63, dl)), 0);
3046 LHS = zeroExtendInputIfNeeded(LHS);
3047 RHS = zeroExtendInputIfNeeded(RHS);
3049 SDValue(CurDAG->getMachineNode(PPC::SUBF8, dl,
MVT::i64, LHS, RHS), 0);
3052 S->getI32Imm(1, dl), S->getI32Imm(63,dl)),
3054 return SDValue(CurDAG->getMachineNode(PPC::ADDI8, dl,
MVT::i64, Shift,
3055 S->getI32Imm(-1, dl)), 0);
3066 LHS = zeroExtendInputIfNeeded(LHS);
3067 RHS = zeroExtendInputIfNeeded(RHS);
3069 SDValue(CurDAG->getMachineNode(PPC::SUBF8, dl,
MVT::i64, RHS, LHS), 0);
3071 Subtract, S->getI64Imm(63, dl)), 0);
3079 IntegerCompareEliminator::get64BitZExtCompare(
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;
3093 SDValue Xor = IsRHSZero ? LHS :
3094 SDValue(CurDAG->getMachineNode(PPC::XOR8, dl,
MVT::i64, LHS, RHS), 0);
3098 S->getI64Imm(58, dl),
3099 S->getI64Imm(63, dl)), 0);
3106 SDValue Xor = IsRHSZero ? LHS :
3107 SDValue(CurDAG->getMachineNode(PPC::XOR8, dl,
MVT::i64, LHS, RHS), 0);
3110 Xor, S->getI32Imm(~0U, dl)), 0);
3120 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::GEZExt);
3132 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::LEZExt);
3135 S->getI64Imm(1, dl),
3136 S->getI64Imm(63, dl)), 0);
3139 S->getI64Imm(63, dl)), 0);
3144 ShiftR, ShiftL, SubtractCarry), 0);
3152 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::GEZExt);
3156 S->getI64Imm(~0ULL, dl)), 0);
3158 SDValue(CurDAG->getMachineNode(PPC::NOR8, dl,
MVT::i64, Addi, LHS), 0);
3160 S->getI64Imm(1, dl),
3161 S->getI64Imm(63, dl)), 0);
3175 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::LEZExt);
3178 S->getI64Imm(1, dl),
3179 S->getI64Imm(63, dl)), 0);
3182 LHS, S->getI64Imm(63, dl)), 0);
3185 RHS, S->getI64Imm(1, dl),
3186 S->getI64Imm(63, dl)), 0);
3192 SRDINode, SRADINode, SUBFC8Carry), 0);
3194 ADDE8Node, S->getI64Imm(1, dl)), 0);
3209 LHS, LHS, SUBFC8Carry), 0);
3211 SUBFE8Node, S->getI64Imm(1, dl)), 0);
3226 LHS, LHS, SubtractCarry), 0);
3236 IntegerCompareEliminator::get64BitSExtCompare(
SDValue LHS,
SDValue RHS,
3238 int64_t RHSValue,
SDLoc dl) {
3242 bool IsRHSZero = RHSValue == 0;
3243 bool IsRHSOne = RHSValue == 1;
3244 bool IsRHSNegOne = RHSValue == -1LL;
3252 SDValue AddInput = IsRHSZero ? LHS :
3253 SDValue(CurDAG->getMachineNode(PPC::XOR8, dl,
MVT::i64, LHS, RHS), 0);
3256 AddInput, S->getI32Imm(~0U, dl)), 0);
3257 return SDValue(CurDAG->getMachineNode(PPC::SUBFE8, dl,
MVT::i64, Addic,
3258 Addic, Addic.getValue(1)), 0);
3265 SDValue Xor = IsRHSZero ? LHS :
3266 SDValue(CurDAG->getMachineNode(PPC::XOR8, dl,
MVT::i64, LHS, RHS), 0);
3269 Xor, S->getI32Imm(0, dl)), 0);
3271 SC, SC.getValue(1)), 0);
3279 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::GESExt);
3291 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::LESExt);
3294 S->getI64Imm(63, dl)), 0);
3297 S->getI64Imm(1, dl),
3298 S->getI64Imm(63, dl)), 0);
3304 ShiftR, ShiftL, SubtractCarry), 0);
3305 return SDValue(CurDAG->getMachineNode(PPC::NEG8, dl,
MVT::i64, Adde), 0);
3313 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::GESExt);
3317 S->getI64Imm(-1, dl)), 0);
3319 SDValue(CurDAG->getMachineNode(PPC::NOR8, dl,
MVT::i64, Add, LHS), 0);
3321 S->getI64Imm(63, dl)), 0);
3335 return getCompoundZeroComparisonInGPR(LHS, dl, ZeroCompare::LESExt);
3338 S->getI64Imm(63, dl)), 0);
3342 LHS, S->getI64Imm(63, dl)), 0);
3345 RHS, S->getI64Imm(1, dl),
3346 S->getI64Imm(63, dl)), 0);
3352 SRDINode, SRADINode, SUBFC8Carry), 0);
3355 ADDE8Node, S->getI64Imm(1, dl)), 0);
3372 LHS, SubtractCarry), 0);
3374 ExtSub, ExtSub), 0);
3388 LHS, LHS, SubCarry), 0);
3399 "An ISD::SETCC node required here.");
3411 !isLogicOp(CompareUse->getOpcode())) {
3412 OmittedForNonExtendUses++;
3422 SetccInGPROpts ConvOpts) {
3425 "An ISD::SETCC node required here.");
3438 cast<CondCodeSDNode>(Compare.
getOperand(CCOpNum))->
get();
3443 if (ConvOpts == SetccInGPROpts::ZExtInvert ||
3444 ConvOpts == SetccInGPROpts::SExtInvert)
3447 bool Inputs32Bit = InputVT ==
MVT::i32;
3452 bool IsSext = ConvOpts == SetccInGPROpts::SExtOrig ||
3453 ConvOpts == SetccInGPROpts::SExtInvert;
3455 if (IsSext && Inputs32Bit)
3456 return get32BitSExtCompare(LHS, RHS, CC, RHSValue, dl);
3457 else if (Inputs32Bit)
3458 return get32BitZExtCompare(LHS, RHS, CC, RHSValue, dl);
3460 return get64BitSExtCompare(LHS, RHS, CC, RHSValue, dl);
3461 return get64BitZExtCompare(LHS, RHS, CC, RHSValue, dl);
3466 bool PPCDAGToDAGISel::tryIntCompareInGPR(
SDNode *N) {
3484 IntegerCompareEliminator ICmpElim(CurDAG,
this);
3485 if (
SDNode *New = ICmpElim.Select(N)) {
3486 ReplaceNode(N, New);
3494 bool PPCDAGToDAGISel::tryBitPermutation(
SDNode *N) {
3509 BitPermutationSelector BPS(CurDAG);
3510 if (
SDNode *New = BPS.Select(N)) {
3511 ReplaceNode(N, New);
3535 getI32Imm(Imm & 0xFFFF, dl)),
3540 getI32Imm(Imm & 0xFFFF, dl)),
3553 getI32Imm(Imm >> 16, dl)), 0);
3555 getI32Imm(Imm & 0xFFFF, dl)), 0);
3561 getI32Imm(Imm & 0xFFFF, dl)), 0);
3567 getI32Imm((
int)SImm & 0xFFFF,
3579 getI32Imm(Imm & 0xFFFF, dl)),
3584 getI32Imm(Imm & 0xFFFF, dl)),
3598 getI64Imm(Imm >> 16, dl)), 0);
3600 getI64Imm(Imm & 0xFFFF, dl)),
3608 getI64Imm(Imm & 0xFFFF, dl)), 0);
3614 getI64Imm(SImm & 0xFFFF, dl)),
3619 if (PPCSubTarget->
hasSPE()) {
3624 Opc = PPC::EFSCMPEQ;
3632 Opc = PPC::EFSCMPLT;
3640 Opc = PPC::EFSCMPGT;
3646 if (PPCSubTarget->
hasSPE()) {
3651 Opc = PPC::EFDCMPEQ;
3659 Opc = PPC::EFDCMPLT;
3667 Opc = PPC::EFDCMPGT;
3671 Opc = PPCSubTarget->
hasVSX() ? PPC::XSCMPUDP : PPC::FCMPUD;
3674 assert(PPCSubTarget->
hasVSX() &&
"__float128 requires VSX");
3675 Opc = PPC::XSCMPUQP;
3677 return SDValue(CurDAG->getMachineNode(Opc, dl,
MVT::i32, LHS, RHS), 0);
3728 case ISD::SETO: Invert =
true;
return 3;
3744 bool HasVSX,
bool &Swap,
bool &Negate) {
3772 return HasVSX ? PPC::XVCMPEQSP : PPC::VCMPEQFP;
3774 return PPC::XVCMPEQDP;
3779 return HasVSX ? PPC::XVCMPGTSP : PPC::VCMPGTFP;
3781 return PPC::XVCMPGTDP;
3786 return HasVSX ? PPC::XVCMPGESP : PPC::VCMPGEFP;
3788 return PPC::XVCMPGEDP;
3816 return PPC::VCMPEQUB;
3818 return PPC::VCMPEQUH;
3820 return PPC::VCMPEQUW;
3822 return PPC::VCMPEQUD;
3826 return PPC::VCMPGTSB;
3828 return PPC::VCMPGTSH;
3830 return PPC::VCMPGTSW;
3832 return PPC::VCMPGTSD;
3836 return PPC::VCMPGTUB;
3838 return PPC::VCMPGTUH;
3840 return PPC::VCMPGTUW;
3842 return PPC::VCMPGTUD;
3851 bool PPCDAGToDAGISel::trySETCC(
SDNode *N) {
3856 CurDAG->getTargetLoweringInfo().getPointerTy(CurDAG->getDataLayout());
3857 bool isPPC64 = (PtrVT ==
MVT::i64);
3869 Op =
SDValue(CurDAG->getMachineNode(PPC::CNTLZW, dl,
MVT::i32, Op), 0);
3870 SDValue Ops[] = {
Op, getI32Imm(27, dl), getI32Imm(5, dl),
3871 getI32Imm(31, dl) };
3872 CurDAG->SelectNodeTo(N, PPC::RLWINM,
MVT::i32, Ops);
3879 Op, getI32Imm(~0U, dl)), 0);
3884 SDValue Ops[] = {
Op, getI32Imm(1, dl), getI32Imm(31, dl),
3885 getI32Imm(31, dl) };
3886 CurDAG->SelectNodeTo(N, PPC::RLWINM,
MVT::i32, Ops);
3892 T =
SDValue(CurDAG->getMachineNode(PPC::ANDC, dl,
MVT::i32, T, Op), 0);
3893 SDValue Ops[] = {
T, getI32Imm(1, dl), getI32Imm(31, dl),
3894 getI32Imm(31, dl) };
3895 CurDAG->SelectNodeTo(N, PPC::RLWINM,
MVT::i32, Ops);
3899 }
else if (Imm == ~0U) {
3906 Op, getI32Imm(1, dl)), 0);
3907 CurDAG->SelectNodeTo(N, PPC::ADDZE,
MVT::i32,
3908 SDValue(CurDAG->getMachineNode(PPC::LI, dl,
3915 Op =
SDValue(CurDAG->getMachineNode(PPC::NOR, dl,
MVT::i32, Op, Op), 0);
3917 Op, getI32Imm(~0U, dl));
3924 getI32Imm(1, dl)), 0);
3927 SDValue Ops[] = { AN, getI32Imm(1, dl), getI32Imm(31, dl),
3928 getI32Imm(31, dl) };
3929 CurDAG->SelectNodeTo(N, PPC::RLWINM,
MVT::i32, Ops);
3933 SDValue Ops[] = {
Op, getI32Imm(1, dl), getI32Imm(31, dl),
3934 getI32Imm(31, dl) };
3935 Op =
SDValue(CurDAG->getMachineNode(PPC::RLWINM, dl,
MVT::i32, Ops), 0);
3936 CurDAG->SelectNodeTo(N, PPC::XORI,
MVT::i32, Op, getI32Imm(1, dl));
3955 PPCSubTarget->
hasVSX(), Swap, Negate);
3961 SDValue VCmp(CurDAG->getMachineNode(VCmpInst, dl, ResVT, LHS, RHS), 0);
3962 CurDAG->SelectNodeTo(N, PPCSubTarget->
hasVSX() ? PPC::XXLNOR :
PPC::VNOR,
3967 CurDAG->SelectNodeTo(N, VCmpInst, ResVT, LHS, RHS);
3976 SDValue CCReg = SelectCC(LHS, RHS, CC, dl);
3989 CCReg = CurDAG->getCopyToReg(CurDAG->getEntryNode(), dl, CR7Reg, CCReg,
3990 InFlag).getValue(1);
3995 SDValue Ops[] = { IntCR, getI32Imm((32 - (3 - Idx)) & 31, dl),
3996 getI32Imm(31, dl), getI32Imm(31, dl) };
3998 CurDAG->SelectNodeTo(N, PPC::RLWINM,
MVT::i32, Ops);
4005 CurDAG->SelectNodeTo(N, PPC::XORI,
MVT::i32, Tmp, getI32Imm(1, dl));
4011 bool PPCDAGToDAGISel::isOffsetMultipleOf(
SDNode *N,
unsigned Val)
const {
4024 AddrOp.getOpcode() ==
ISD::ADD ? AddrOp.getOperand(0) :
4031 if ((SlotAlign % Val) != 0)
4035 if (AddrOp.getOpcode() !=
ISD::ADD)
4039 if (AddrOp.getOpcode() ==
ISD::ADD)
4049 MemOp[0] = cast<MemSDNode>(
N)->getMemOperand();
4050 cast<MachineSDNode>(Result)->setMemRefs(MemOp, MemOp + 1);
4058 PPCDAGToDAGISel::flipSignBit(
const SDValue &N,
SDNode **SignBitVec) {
4064 *SignBitVec = CurDAG->getMachineNode(PPC::XVNEGSP, dl, VecVT,
4067 return CurDAG->getMachineNode(PPC::XVNEGSP, dl, VecVT, N);
4071 getI32Imm(0x8000, dl));
4074 getI32Imm(0x8000, dl));
4075 SDNode *VecImm = CurDAG->getMachineNode(PPC::MTVSRWS, dl, VecVT,
4083 if (SignBitVec) *SignBitVec = VecImm;
4084 return CurDAG->getMachineNode(PPC::VADDUHM, dl, VecVT, N,
4088 SDNode *VecImm = CurDAG->getMachineNode(PPC::XXSPLTIB, dl,
MVT::i32,
4089 getI32Imm(0x80, dl));
4090 if (SignBitVec) *SignBitVec = VecImm;
4091 return CurDAG->getMachineNode(PPC::VADDUBM, dl, VecVT, N,
4115 if (tryBitPermutation(N))
4119 if (tryIntCompareInGPR(N))
4140 if (PPCLowering->getPointerTy(CurDAG->getDataLayout()) !=
MVT::i32 ||
4159 ReplaceNode(N, getGlobalBaseReg());
4163 selectFrameIndex(N, N);
4181 CurDAG->getTargetConstant(*cast<ConstantSDNode>(N->
getOperand(1))->
4182 getConstantIntValue(), dl,
4193 "Expecting i64 or i32 in PPCISD::SRA_ADDZE");
4208 if (tryTLSXFormStore(ST))
4221 if (tryTLSXFormLoad(LD))
4234 assert((!isSExt || LoadedVT ==
MVT::i16) &&
"Invalid sext update load");
4235 switch (LoadedVT.getSimpleVT().SimpleTy) {
4237 case MVT::f64: Opcode = PPC::LFDU;
break;
4238 case MVT::f32: Opcode = PPC::LFSU;
break;
4239 case MVT::i32: Opcode = PPC::LWZU;
break;
4240 case MVT::i16: Opcode = isSExt ? PPC::LHAU : PPC::LHZU;
break;
4242 case MVT::i8: Opcode = PPC::LBZU;
break;
4246 assert((!isSExt || LoadedVT ==
MVT::i16) &&
"Invalid sext update load");
4247 switch (LoadedVT.getSimpleVT().SimpleTy) {
4249 case MVT::i64: Opcode = PPC::LDU;
break;
4250 case MVT::i32: Opcode = PPC::LWZU8;
break;
4251 case MVT::i16: Opcode = isSExt ? PPC::LHAU8 : PPC::LHZU8;
break;
4253 case MVT::i8: Opcode = PPC::LBZU8;
break;
4260 SDNode *MN = CurDAG->getMachineNode(
4262 PPCLowering->getPointerTy(CurDAG->getDataLayout()),
MVT::Other, Ops);
4263 transferMemOperands(N, MN);
4271 assert((!isSExt || LoadedVT ==
MVT::i16) &&
"Invalid sext update load");
4272 switch (LoadedVT.getSimpleVT().SimpleTy) {
4274 case MVT::v4f64: Opcode = PPC::QVLFDUX;
break;
4275 case MVT::v4f32: Opcode = PPC::QVLFSUX;
break;
4276 case MVT::f64: Opcode = PPC::LFDUX;
break;
4277 case MVT::f32: Opcode = PPC::LFSUX;
break;
4278 case MVT::i32: Opcode = PPC::LWZUX;
break;
4279 case MVT::i16: Opcode = isSExt ? PPC::LHAUX : PPC::LHZUX;
break;
4281 case MVT::i8: Opcode = PPC::LBZUX;
break;
4286 "Invalid sext update load");
4287 switch (LoadedVT.getSimpleVT().SimpleTy) {
4289 case MVT::i64: Opcode = PPC::LDUX;
break;
4290 case MVT::i32: Opcode = isSExt ? PPC::LWAUX : PPC::LWZUX8;
break;
4291 case MVT::i16: Opcode = isSExt ? PPC::LHAUX8 : PPC::LHZUX8;
break;
4293 case MVT::i8: Opcode = PPC::LBZUX8;
break;
4300 SDNode *MN = CurDAG->getMachineNode(
4302 PPCLowering->getPointerTy(CurDAG->getDataLayout()),
MVT::Other, Ops);
4303 transferMemOperands(N, MN);
4310 unsigned Imm, Imm2, SH, MB, ME;
4318 SDValue Ops[] = { Val, getI32Imm(SH, dl), getI32Imm(MB, dl),
4319 getI32Imm(ME, dl) };
4320 CurDAG->SelectNodeTo(N, PPC::RLWINM,
MVT::i32, Ops);
4329 SDValue Ops[] = { Val, getI32Imm(0, dl), getI32Imm(MB, dl),
4330 getI32Imm(ME, dl) };
4331 CurDAG->SelectNodeTo(N, PPC::RLWINM,
MVT::i32, Ops);
4343 if ( Op0.getOpcode() ==
ISD::SRL &&
4347 auto ImDef = CurDAG->getMachineNode(PPC::IMPLICIT_DEF, dl,
4351 Val =
SDValue(CurDAG->getMachineNode(PPC::INSERT_SUBREG, dl,
4353 getI32Imm(1, dl)), 0);
4365 assert(Imm < 64 &&
"Illegal shift amount");
4370 SDValue Ops[] = { Val, getI32Imm(SH, dl), getI32Imm(MB, dl) };
4371 CurDAG->SelectNodeTo(N, PPC::RLDICL,
MVT::i64, Ops);
4382 SDValue Ops[] = { Val, getI32Imm(SH, dl), getI32Imm(MB, dl) };
4383 CurDAG->SelectNodeTo(N, PPC::RLDICR,
MVT::i64, Ops);
4411 if (
isRunOfOnes(~(Imm^Imm2), MB, ME) && !(~Imm & Imm2)) {
4414 getI32Imm(0, dl), getI32Imm(MB, dl),
4415 getI32Imm(ME, dl) };
4416 ReplaceNode(N, CurDAG->getMachineNode(PPC::RLWIMI, dl,
MVT::i32, Ops));
4426 if (tryBitfieldInsert(N))
4433 CurDAG->computeKnownBits(N->
getOperand(0), LHSKnown);
4446 bool IsPPC64 = PPCSubTarget->
isPPC64();
4448 (Imm64 & ~0xFFFFFFFFuLL) == 0) {
4450 uint64_t ImmHi = Imm64 >> 16;
4451 uint64_t ImmLo = Imm64 & 0xFFFF;
4452 if (ImmHi != 0 && ImmLo != 0) {
4455 getI16Imm(ImmLo, dl));
4457 CurDAG->SelectNodeTo(N, PPC::ORIS8,
MVT::i64, Ops1);
4469 bool IsPPC64 = PPCSubTarget->
isPPC64();
4471 (Imm64 & ~0xFFFFFFFFuLL) == 0) {
4473 uint64_t ImmHi = Imm64 >> 16;
4474 uint64_t ImmLo = Imm64 & 0xFFFF;
4475 if (ImmHi != 0 && ImmLo != 0) {
4478 getI16Imm(ImmLo, dl));
4480 CurDAG->SelectNodeTo(N, PPC::XORIS8,
MVT::i64, Ops1);
4498 unsigned Imm, SH, MB, ME;
4500 isRotateAndMask(N, Imm,
true, SH, MB, ME)) {
4502 getI32Imm(SH, dl), getI32Imm(MB, dl),
4503 getI32Imm(ME, dl) };
4504 CurDAG->SelectNodeTo(N, PPC::RLWINM,
MVT::i32, Ops);
4512 unsigned Imm, SH, MB, ME;
4514 isRotateAndMask(N, Imm,
true, SH, MB, ME)) {
4516 getI32Imm(SH, dl), getI32Imm(MB, dl),
4517 getI32Imm(ME, dl) };
4518 CurDAG->SelectNodeTo(N, PPC::RLWINM,
MVT::i32, Ops);
4533 "Invalid input type for ANDIo_1_EQ_BIT");
4535 unsigned Opcode = (InVT ==
MVT::i64) ? PPC::ANDIo8 : PPC::ANDIo;
4538 CurDAG->getTargetConstant(1, dl, InVT)),
4543 PPC::sub_eq : PPC::sub_gt, dl,
MVT::i32);
4545 CurDAG->SelectNodeTo(N, TargetOpcode::EXTRACT_SUBREG,
MVT::i1, CR0Reg,
4552 CurDAG->getTargetLoweringInfo().getPointerTy(CurDAG->getDataLayout());
4553 bool isPPC64 = (PtrVT ==
MVT::i64);
4565 if (N1C->isNullValue() && N3C->isNullValue() &&
4566 N2C->getZExtValue() == 1ULL && CC ==
ISD::SETNE &&
4587 case 0: SRI = PPC::sub_lt;
break;
4588 case 1: SRI = PPC::sub_gt;
break;
4589 case 2: SRI = PPC::sub_eq;
break;
4590 case 3: SRI = PPC::sub_un;
break;
4593 SDValue CCBit = CurDAG->getTargetExtractSubreg(SRI, dl,
MVT::i1, CCReg);
4597 SDValue C = Inv ? NotCCBit : CCBit,
4598 NotC = Inv ? CCBit : NotCCBit;
4605 CurDAG->SelectNodeTo(N, PPC::CROR,
MVT::i1, CAndT, NotCAndF);
4611 unsigned SelectCCOp;
4613 SelectCCOp = PPC::SELECT_CC_I4;
4615 SelectCCOp = PPC::SELECT_CC_I8;
4618 SelectCCOp = PPC::SELECT_CC_VSSRC;
4619 else if (PPCSubTarget->
hasSPE())
4620 SelectCCOp = PPC::SELECT_CC_SPE4;
4622 SelectCCOp = PPC::SELECT_CC_F4;
4624 if (PPCSubTarget->
hasVSX())
4625 SelectCCOp = PPC::SELECT_CC_VSFRC;
4626 else if (PPCSubTarget->
hasSPE())
4627 SelectCCOp = PPC::SELECT_CC_SPE;
4629 SelectCCOp = PPC::SELECT_CC_F8;
4631 SelectCCOp = PPC::SELECT_CC_F16;
4632 else if (PPCSubTarget->
hasSPE())
4633 SelectCCOp = PPC::SELECT_CC_SPE;
4635 SelectCCOp = PPC::SELECT_CC_QFRC;
4637 SelectCCOp = PPC::SELECT_CC_QSRC;
4639 SelectCCOp = PPC::SELECT_CC_QBRC;
4642 SelectCCOp = PPC::SELECT_CC_VSRC;
4644 SelectCCOp = PPC::SELECT_CC_VRRC;
4647 getI32Imm(BROpc, dl) };
4648 CurDAG->SelectNodeTo(N, SelectCCOp, N->
getValueType(0), Ops);
4652 if (PPCSubTarget->
hasVSX()) {
4654 CurDAG->SelectNodeTo(N, PPC::XXSEL, N->
getValueType(0), Ops);
4668 for (
int i = 0; i < 2; ++i)
4674 if (Op1 == Op2 && DM[0] == 0 && DM[1] == 0 &&
4676 isa<LoadSDNode>(Op1.getOperand(0))) {
4677 LoadSDNode *LD = cast<LoadSDNode>(Op1.getOperand(0));
4688 SDNode *NewN = CurDAG->SelectNodeTo(N, PPC::LXVDSX,
4690 cast<MachineSDNode>(NewN)->setMemRefs(MemOp, MemOp + 1);
4699 unsigned tmp = DM[0];
4704 SDValue DMV = CurDAG->getTargetConstant(DM[1] | (DM[0] << 1), dl,
4706 SDValue Ops[] = { Op1, Op2, DMV };
4714 bool IsPPC64 = PPCSubTarget->
isPPC64();
4718 : (IsPPC64 ? PPC::BDZ8 :
PPC::BDZ),
4729 unsigned PCC = cast<ConstantSDNode>(N->
getOperand(1))->getZExtValue();
4733 SDValue Pred = getI32Imm(PCC, dl);
4736 CurDAG->SelectNodeTo(N, PPC::BCC,
MVT::Other, Ops);
4748 case PPC::PRED_LT: Opc = PPC::CRANDC; Swap =
true;
break;
4749 case PPC::PRED_LE: Opc = PPC::CRORC; Swap =
true;
break;
4750 case PPC::PRED_EQ: Opc = PPC::CREQV; Swap =
false;
break;
4751 case PPC::PRED_GE: Opc = PPC::CRORC; Swap =
false;
break;
4752 case PPC::PRED_GT: Opc = PPC::CRANDC; Swap =
false;
break;
4753 case PPC::PRED_NE: Opc = PPC::CRXOR; Swap =
false;
break;
4770 CurDAG->SelectNodeTo(N, PPC::BCC,
MVT::Other, Ops);
4781 CurDAG->SelectNodeTo(N, Reg,
MVT::Other, Chain);
4786 "Only supported for 64-bit ABI and 32-bit SVR4");
4789 SDNode *MN = CurDAG->getMachineNode(PPC::LWZtoc, dl,
MVT::i32, GA,
4791 transferMemOperands(N, MN);
4810 SDNode *Tmp = CurDAG->getMachineNode(PPC::ADDIStocHA, dl,
MVT::i64,
4813 if (isa<JumpTableSDNode>(GA) || isa<BlockAddressSDNode>(GA) ||
4815 SDNode *MN = CurDAG->getMachineNode(PPC::LDtocL, dl,
MVT::i64, GA,
4817 transferMemOperands(N, MN);
4826 SDNode *MN = CurDAG->getMachineNode(PPC::LDtocL, dl,
MVT::i64, GA,
4828 transferMemOperands(N, MN);
4834 ReplaceNode(N, CurDAG->getMachineNode(PPC::ADDItocL, dl,
MVT::i64,
4841 "PPCISD::PPC32_PICGOT is only supported for 32-bit SVR4");
4842 CurDAG->SelectNodeTo(N, PPC::PPC32PICGOT,
4843 PPCLowering->getPointerTy(CurDAG->getDataLayout()),
4852 "Invalid operand on VADD_SPLAT!");
4856 unsigned Opc1, Opc2, Opc3;
4860 Opc1 = PPC::VSPLTISB;
4861 Opc2 = PPC::VADDUBM;
4862 Opc3 = PPC::VSUBUBM;
4864 }
else if (EltSize == 2) {
4865 Opc1 = PPC::VSPLTISH;
4866 Opc2 = PPC::VADDUHM;
4867 Opc3 = PPC::VSUBUHM;
4870 assert(EltSize == 4 &&
"Invalid element size on VADD_SPLAT!");
4871 Opc1 = PPC::VSPLTISW;
4872 Opc2 = PPC::VADDUWM;
4873 Opc3 = PPC::VSUBUWM;
4877 if ((Elt & 1) == 0) {
4884 SDValue EltVal = getI32Imm(Elt >> 1, dl);
4885 SDNode *Tmp = CurDAG->getMachineNode(Opc1, dl, VT, EltVal);
4887 ReplaceNode(N, CurDAG->getMachineNode(Opc2, dl, VT, TmpVal, TmpVal));
4889 }
else if (Elt > 0) {
4896 SDValue EltVal = getI32Imm(Elt - 16, dl);
4897 SDNode *Tmp1 = CurDAG->getMachineNode(Opc1, dl, VT, EltVal);
4898 EltVal = getI32Imm(-16, dl);
4899 SDNode *Tmp2 = CurDAG->getMachineNode(Opc1, dl, VT, EltVal);
4900 ReplaceNode(N, CurDAG->getMachineNode(Opc3, dl, VT,
SDValue(Tmp1, 0),
4910 SDValue EltVal = getI32Imm(Elt + 16, dl);
4911 SDNode *Tmp1 = CurDAG->getMachineNode(Opc1, dl, VT, EltVal);
4912 EltVal = getI32Imm(-16, dl);
4913 SDNode *Tmp2 = CurDAG->getMachineNode(Opc1, dl, VT, EltVal);
4914 ReplaceNode(N, CurDAG->getMachineNode(Opc2, dl, VT,
SDValue(Tmp1, 0),
4933 AbsOpcode = PPC::VABSDUW;
4935 AbsOpcode = PPC::VABSDUH;
4937 AbsOpcode = PPC::VABSDUB;
4946 AbsOp = CurDAG->getMachineNode(AbsOpcode, dl, VecVT,
4949 ReplaceNode(N, AbsOp);
4956 AbsOp = CurDAG->getMachineNode(AbsOpcode, dl, VecVT,
4962 AbsOp = CurDAG->getMachineNode(AbsOpcode, dl, VecVT,
SDValue(Op0, 0),
4965 ReplaceNode(N, AbsOp);
4983 "Only OR nodes are supported for CMPB");
4996 bool BytesFound[8] = {
false,
false,
false,
false,
false,
false,
false,
false};
4997 uint64_t Mask = 0, Alt = 0;
4999 auto IsByteSelectCC = [
this](
SDValue O,
unsigned &b,
5000 uint64_t &
Mask, uint64_t &Alt,
5012 for (b = 0; b < 8; ++b) {
5013 uint64_t Mask = UINT64_C(0xFF) << (8*b);
5014 if (PM && (PM & Mask) == PM && (PAlt &
Mask) == PAlt)
5058 if (ULim != (UINT64_C(1) << b*8))
5064 if (!CurDAG->MaskedValueIsZero(
5119 while (!Queue.
empty()) {
5124 uint64_t M = 0, A = 0;
5128 }
else if (IsByteSelectCC(O, b, M, A, OLHS, ORHS)) {
5132 BytesFound[b] =
true;
5135 }
else if ((LHS == ORHS && RHS == OLHS) ||
5136 (RHS == ORHS && LHS == OLHS)) {
5137 BytesFound[b] =
true;
5149 unsigned LastB = 0, BCnt = 0;
5150 for (
unsigned i = 0; i < 8; ++i)
5151 if (BytesFound[LastB]) {
5156 if (!LastB || BCnt < 2)
5161 if (LHS.getValueType() != VT) {
5162 LHS = CurDAG->getAnyExtOrTrunc(LHS, dl, VT);
5163 RHS = CurDAG->getAnyExtOrTrunc(RHS, dl, VT);
5168 bool NonTrivialMask = ((int64_t) Mask) != INT64_C(-1);
5169 if (NonTrivialMask && !Alt) {
5171 Res = CurDAG->getNode(
ISD::AND, dl, VT, Res,
5172 CurDAG->getConstant(Mask, dl, VT));
5180 Res = CurDAG->getNode(
ISD::AND, dl, VT, Res,
5181 CurDAG->getConstant(Mask ^ Alt, dl, VT));
5182 Res = CurDAG->getNode(
ISD::XOR, dl, VT, Res,
5183 CurDAG->getConstant(Alt, dl, VT));
5196 void PPCDAGToDAGISel::foldBoolExts(
SDValue &Res,
SDNode *&N) {
5216 SDValue ConstFalse = CurDAG->getConstant(0, dl, VT);
5223 auto TryFold = [
this,
N, User, dl](
SDValue Val) {
5228 return CurDAG->FoldConstantArithmetic(User->getOpcode(), dl,
5229 User->getValueType(0),
5235 SDValue TrueRes = TryFold(ConstTrue);
5236 if (!TrueRes || TrueRes.
isUndef())
5238 SDValue FalseRes = TryFold(ConstFalse);
5239 if (!FalseRes || FalseRes.
isUndef())
5244 uint64_t True = cast<ConstantSDNode>(TrueRes)->getZExtValue(),
5245 False = cast<ConstantSDNode>(FalseRes)->getZExtValue();
5251 Res = CurDAG->getSelect(dl, User->getValueType(0), Cond, TrueRes, FalseRes);
5253 ConstTrue = TrueRes;
5254 ConstFalse = FalseRes;
5258 void PPCDAGToDAGISel::PreprocessISelDAG() {
5261 bool MadeChange =
false;
5262 while (Position != CurDAG->allnodes_begin()) {
5271 Res = combineToCMPB(N);
5276 foldBoolExts(Res, N);
5285 CurDAG->ReplaceAllUsesOfValueWith(
SDValue(N, 0), Res);
5291 CurDAG->RemoveDeadNodes();
5296 void PPCDAGToDAGISel::PostprocessISelDAG() {
5303 PeepholePPC64ZExt();
5311 bool PPCDAGToDAGISel::AllUsersSelectZero(
SDNode *N) {
5340 void PPCDAGToDAGISel::SwapAllSelectUsers(
SDNode *N) {
5347 "Must have all select users");
5352 UE = ToReplace.
end(); UI != UE; ++UI) {
5366 ReplaceUses(User, ResNode);
5370 void PPCDAGToDAGISel::PeepholeCROps() {
5374 for (
SDNode &Node : CurDAG->allnodes()) {
5376 if (!MachineNode || MachineNode->
use_empty())
5378 SDNode *ResNode = MachineNode;
5380 bool Op1Set =
false, Op1Unset =
false,
5382 Op2Set =
false, Op2Unset =
false,
5410 case PPC::SELECT_I4:
5411 case PPC::SELECT_I8:
5412 case PPC::SELECT_F4:
5413 case PPC::SELECT_F8:
5414 case PPC::SELECT_QFRC:
5415 case PPC::SELECT_QSRC:
5416 case PPC::SELECT_QBRC:
5417 case PPC::SELECT_SPE:
5418 case PPC::SELECT_SPE4:
5419 case PPC::SELECT_VRRC:
5420 case PPC::SELECT_VSFRC:
5421 case PPC::SELECT_VSSRC:
5422 case PPC::SELECT_VSRC: {
5437 bool SelectSwap =
false;
5450 else if (Op1Unset || Op2Unset)
5452 ResNode = CurDAG->getMachineNode(PPC::CRUNSET,
SDLoc(MachineNode),
5456 ResNode = CurDAG->getMachineNode(PPC::CRANDC,
SDLoc(MachineNode),
5462 ResNode = CurDAG->getMachineNode(PPC::CRANDC,
SDLoc(MachineNode),
5466 else if (AllUsersSelectZero(MachineNode)) {
5467 ResNode = CurDAG->getMachineNode(PPC::CRNAND,
SDLoc(MachineNode),
5476 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
5481 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
5486 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
5489 else if (Op1Unset || Op2Unset)
5491 ResNode = CurDAG->getMachineNode(PPC::CRSET,
SDLoc(MachineNode),
5495 ResNode = CurDAG->getMachineNode(PPC::CRORC,
SDLoc(MachineNode),
5501 ResNode = CurDAG->getMachineNode(PPC::CRORC,
SDLoc(MachineNode),
5505 else if (AllUsersSelectZero(MachineNode)) {
5506 ResNode = CurDAG->getMachineNode(PPC::CRAND,
SDLoc(MachineNode),
5516 else if (Op1Set || Op2Set)
5518 ResNode = CurDAG->getMachineNode(PPC::CRSET,
SDLoc(MachineNode),
5528 ResNode = CurDAG->getMachineNode(PPC::CRORC,
SDLoc(MachineNode),
5534 ResNode = CurDAG->getMachineNode(PPC::CRORC,
SDLoc(MachineNode),
5538 else if (AllUsersSelectZero(MachineNode)) {
5539 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
5548 ResNode = CurDAG->getMachineNode(PPC::CRUNSET,
SDLoc(MachineNode),
5552 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
5557 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
5568 ResNode = CurDAG->getMachineNode(PPC::CREQV,
SDLoc(MachineNode),
5574 ResNode = CurDAG->getMachineNode(PPC::CREQV,
SDLoc(MachineNode),
5578 else if (AllUsersSelectZero(MachineNode)) {
5579 ResNode = CurDAG->getMachineNode(PPC::CREQV,
SDLoc(MachineNode),
5586 if (Op1Set || Op2Set)
5588 ResNode = CurDAG->getMachineNode(PPC::CRUNSET,
SDLoc(MachineNode),
5592 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
5597 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
5602 ResNode = CurDAG->getMachineNode(PPC::CRANDC,
SDLoc(MachineNode),
5608 ResNode = CurDAG->getMachineNode(PPC::CRANDC,
SDLoc(MachineNode),
5612 else if (AllUsersSelectZero(MachineNode)) {
5613 ResNode = CurDAG->getMachineNode(PPC::CROR,
SDLoc(MachineNode),
5622 ResNode = CurDAG->getMachineNode(PPC::CRSET,
SDLoc(MachineNode),
5632 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
5637 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
5642 ResNode = CurDAG->getMachineNode(PPC::CRXOR,
SDLoc(MachineNode),
5648 ResNode = CurDAG->getMachineNode(PPC::CRXOR,
SDLoc(MachineNode),
5652 else if (AllUsersSelectZero(MachineNode)) {
5653 ResNode = CurDAG->getMachineNode(PPC::CRXOR,
SDLoc(MachineNode),
5662 ResNode = CurDAG->getMachineNode(PPC::CRUNSET,
SDLoc(MachineNode),
5666 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
5669 else if (Op1Unset || Op2Set)
5671 ResNode = CurDAG->getMachineNode(PPC::CRUNSET,
SDLoc(MachineNode),
5678 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
5684 ResNode = CurDAG->getMachineNode(PPC::CRAND,
SDLoc(MachineNode),
5688 else if (AllUsersSelectZero(MachineNode)) {
5689 ResNode = CurDAG->getMachineNode(PPC::CRORC,
SDLoc(MachineNode),
5698 ResNode = CurDAG->getMachineNode(PPC::CRSET,
SDLoc(MachineNode),
5700 else if (Op1Set || Op2Unset)
5702 ResNode = CurDAG->getMachineNode(PPC::CRSET,
SDLoc(MachineNode),
5709 ResNode = CurDAG->getMachineNode(PPC::CRNOR,
SDLoc(MachineNode),
5714 ResNode = CurDAG->getMachineNode(PPC::CRNAND,
SDLoc(MachineNode),
5720 ResNode = CurDAG->getMachineNode(PPC::CROR,
SDLoc(MachineNode),
5724 else if (AllUsersSelectZero(MachineNode)) {
5725 ResNode = CurDAG->getMachineNode(PPC::CRANDC,
SDLoc(MachineNode),
5731 case PPC::SELECT_I4:
5732 case PPC::SELECT_I8:
5733 case PPC::SELECT_F4:
5734 case PPC::SELECT_F8:
5735 case PPC::SELECT_QFRC:
5736 case PPC::SELECT_QSRC:
5737 case PPC::SELECT_QBRC:
5738 case PPC::SELECT_SPE:
5739 case PPC::SELECT_SPE4:
5740 case PPC::SELECT_VRRC:
5741 case PPC::SELECT_VSFRC:
5742 case PPC::SELECT_VSSRC:
5743 case PPC::SELECT_VSRC:
5760 ResNode = CurDAG->getMachineNode(Opcode == PPC::BC ? PPC::BCn :
5775 SwapAllSelectUsers(MachineNode);
5777 if (ResNode != MachineNode) {
5784 ReplaceUses(MachineNode, ResNode);
5789 CurDAG->RemoveDeadNodes();
5790 }
while (IsModified);
5901 if (!Op0OK && !Op1OK)
5924 if (!Op0OK && !Op1OK)
5938 void PPCDAGToDAGISel::PeepholePPC64ZExt() {
5953 bool MadeChange =
false;
5954 while (Position != CurDAG->allnodes_begin()) {
5999 bool OutsideUse =
false;
6000 for (
SDNode *PN : ToPromote) {
6002 if (!ToPromote.count(UN) && UN != ISR.
getNode()) {
6020 for (
SDNode *PN : ToPromote) {
6022 switch (PN->getMachineOpcode()) {
6025 case PPC::RLWINM: NewOpcode = PPC::RLWINM8;
break;
6026 case PPC::RLWNM: NewOpcode = PPC::RLWNM8;
break;
6027 case PPC::SLW: NewOpcode = PPC::SLW8;
break;
6028 case PPC::SRW: NewOpcode = PPC::SRW8;
break;
6029 case PPC::LI: NewOpcode = PPC::LI8;
break;
6030 case PPC::LIS: NewOpcode = PPC::LIS8;
break;
6031 case PPC::LHBRX: NewOpcode = PPC::LHBRX8;
break;
6032 case PPC::LWBRX: NewOpcode = PPC::LWBRX8;
break;
6033 case PPC::CNTLZW: NewOpcode = PPC::CNTLZW8;
break;
6034 case PPC::CNTTZW: NewOpcode = PPC::CNTTZW8;
break;
6035 case PPC::RLWIMI: NewOpcode = PPC::RLWIMI8;
break;
6036 case PPC::OR: NewOpcode = PPC::OR8;
break;
6037 case PPC::SELECT_I4: NewOpcode = PPC::SELECT_I8;
break;
6038 case PPC::ORI: NewOpcode = PPC::ORI8;
break;
6039 case PPC::ORIS: NewOpcode = PPC::ORIS8;
break;
6040 case PPC::AND: NewOpcode = PPC::AND8;
break;
6041 case PPC::ANDIo: NewOpcode = PPC::ANDIo8;
break;
6042 case PPC::ANDISo: NewOpcode = PPC::ANDISo8;
break;
6052 if (!ToPromote.count(V.getNode()) && V.getValueType() ==
MVT::i32 &&
6053 !isa<ConstantSDNode>(V)) {
6056 CurDAG->getMachineNode(TargetOpcode::INSERT_SUBREG,
SDLoc(V),
6070 for (
unsigned i = 0, ie = VTs.
NumVTs; i != ie; ++i)
6079 CurDAG->SelectNodeTo(PN, NewOpcode, CurDAG->getVTList(NewVTs), Ops);
6096 ReplaceUses(N, Op32.
getNode());
6100 CurDAG->RemoveDeadNodes();
6103 void PPCDAGToDAGISel::PeepholePPC64() {
6110 while (Position != CurDAG->allnodes_begin()) {
6118 bool RequiresMod4Offset =
false;
6120 switch (StorageOpcode) {
6125 case PPC::DFLOADf64:
6126 case PPC::DFLOADf32:
6127 RequiresMod4Offset =
true;
6143 case PPC::DFSTOREf64:
6144 case PPC::DFSTOREf32:
6145 RequiresMod4Offset =
true;
6163 if (!isa<ConstantSDNode>(N->
getOperand(FirstOp)))
6171 bool ReplaceFlags =
true;
6191 ReplaceFlags =
false;
6195 if (RequiresMod4Offset &&
6200 case PPC::ADDIdtprelL:
6203 case PPC::ADDItlsldL:
6217 int MaxDisplacement = 7;
6220 MaxDisplacement = std::min((
int) GV->
getAlignment() - 1, MaxDisplacement);
6223 bool UpdateHBase =
false;
6228 if (Offset < 0 || Offset > MaxDisplacement) {
6243 if (HImmOpnd != ImmOpnd)
6254 if (
auto *
C = dyn_cast<ConstantSDNode>(ImmOpnd)) {
6255 Offset +=
C->getSExtValue();
6257 if (RequiresMod4Offset && (Offset % 4) != 0)
6263 ImmOpnd = CurDAG->getTargetConstant(Offset,
SDLoc(ImmOpnd),
6265 }
else if (Offset != 0) {
6274 LLVM_DEBUG(
dbgs() <<
"Folding add-immediate into mem-op:\nBase: ");
6289 (RequiresMod4Offset || (Offset % 4) != 0)) {
6290 LLVM_DEBUG(
dbgs() <<
"Rejected this candidate for alignment.\n\n");
6293 ImmOpnd = CurDAG->getTargetGlobalAddress(GV, dl,
MVT::i64, Offset, Flags);
6295 dyn_cast<ConstantPoolSDNode>(ImmOpnd)) {
6297 ImmOpnd = CurDAG->getTargetConstantPool(C,
MVT::i64,
6304 (void)CurDAG->UpdateNodeOperands(N, N->
getOperand(0), ImmOpnd,
6307 (void)CurDAG->UpdateNodeOperands(N, ImmOpnd, Base.
getOperand(0),
6316 CurDAG->RemoveDeadNode(Base.
getNode());
6325 return new PPCDAGToDAGISel(TM, OptLevel);
constexpr bool isUInt< 32 >(uint64_t x)
void push_back(const T &Elt)
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.
GCNRegPressure max(const GCNRegPressure &P1, const GCNRegPressure &P2)
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)
BR_CC - Conditional branch.
Compute iterated dominance frontiers using a linear time algorithm.
GPRC = address of GLOBAL_OFFSET_TABLE.
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 isPPC64() const
isPPC64 - Return true if we are generating code for 64-bit pointer mode.
BasicBlock * getSuccessor(unsigned idx) const
Return the specified successor.
const SDValue & getBasePtr() const
unsigned char classifyGlobalReference(const GlobalValue *GV) const
classifyGlobalReference - Classify a global variable reference for the current subtarget accourding t...
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...
bool isBitwiseNot(SDValue V)
Returns true if V is a bitwise not operation.
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")
unsigned const TargetRegisterInfo * TRI
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 bool isOpcWithIntImmediate(SDNode *N, unsigned Opc, unsigned &Imm)
MachineMemOperand * getMemOperand() const
Return a MachineMemOperand object describing the memory reference performed by operation.
unsigned getValueSizeInBits() const
Returns the size of the value in bits.
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
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.
ABS - Determine the unsigned absolute value of a signed integer value of the same bitwidth...
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.
The MachineFrameInfo class represents an abstract stack frame until prolog/epilog code is inserted...
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.
bool runOnMachineFunction(MachineFunction &MF) override
runOnMachineFunction - This method must be overloaded to perform the desired machine code transformat...
int64_t getSExtValue() const
unsigned getSizeInBits() const
Return the size of the specified value type in bits.
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...
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
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")
Subclasses of this class are all able to terminate a basic block.
CodeGenOpt::Level getOptLevel() const
Returns the optimization level: None, Less, Default, or Aggressive.
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...
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 ...
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()
const SDValue & getOperand(unsigned Num) const
static PPC::Predicate getPredicateForSetCC(ISD::CondCode CC)
CHAIN,FLAG = MTCTR(VAL, CHAIN[, INFLAG]) - Directly corresponds to a MTCTR instruction.
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.
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...
TargetRegisterInfo base class - We assume that the target defines a static array of TargetRegisterDes...
const MachineBasicBlock & front() const
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)
This is used to represent a portion of an LLVM function in a low-level Data Dependence DAG representa...
const PPCInstrInfo * getInstrInfo() const override
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.
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.
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.
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.
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.
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.
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 bool isZero(Value *V, const DataLayout &DL, DominatorTree *DT, AssumptionCache *AC)
LLVM_ATTRIBUTE_ALWAYS_INLINE iterator end()
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
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...
const MachineInstrBuilder & addReg(unsigned RegNo, unsigned flags=0, unsigned SubReg=0) const
Add a new virtual register operand.
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...
static int const Threshold
TODO: Write a new FunctionPass AliasAnalysis so that it can keep a cache.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
unsigned getNumSuccessors() const
Return the number of successors that this terminator has.
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)
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.
uint64_t getConstantOperandVal(unsigned Num) const
Helper method returns the integer value of a ConstantSDNode operand.
unsigned getSizeInBits(unsigned Reg, const MachineRegisterInfo &MRI, const TargetRegisterInfo &TRI) const
Get the size in bits of Reg.
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.
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)
#define LLVM_FALLTHROUGH
LLVM_FALLTHROUGH - Mark fallthrough cases in switch statements.
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
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...
On a symbol operand "FOO", this indicates that the reference is actually to "FOO@plt".
MachineInstr::mmo_iterator allocateMemRefsArray(unsigned long Num)
allocateMemRefsArray - Allocate an array to hold MachineMemOperand pointers.
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...
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.