52#define DEBUG_TYPE "ppc-mi-peepholes"
54STATISTIC(RemoveTOCSave,
"Number of TOC saves removed");
56 "Number of functions with multiple TOC saves that must be kept");
57STATISTIC(NumTOCSavesInPrologue,
"Number of TOC saves placed in the prologue");
58STATISTIC(NumEliminatedSExt,
"Number of eliminated sign-extensions");
59STATISTIC(NumEliminatedZExt,
"Number of eliminated zero-extensions");
60STATISTIC(NumOptADDLIs,
"Number of optimized ADD instruction fed by LI");
62 "Number of instructions converted to their immediate form");
64 "Number of functions entered in PPC MI Peepholes");
66 "Number of fixed-point iterations converting reg-reg instructions "
69 "Number of pairs of rotate left, clear left/right collapsed");
71 "Number of pairs of EXTSW and SLDI combined as EXTSWSLI");
73 "Number of LI(8) reg, 0 that are folded to r0 and removed");
77 cl::desc(
"Iterate to a fixed point when attempting to "
78 "convert reg-reg instructions to reg-imm"));
82 cl::desc(
"Convert eligible reg+reg instructions to reg+imm"));
86 cl::desc(
"enable elimination of sign-extensions"),
91 cl::desc(
"enable elimination of zero-extensions"),
96 cl::desc(
"enable optimization of conditional traps"),
100 PeepholeXToICounter,
"ppc-xtoi-peephole",
101 "Controls whether PPC reg+reg to reg+imm peephole is performed on a MI");
104 "Controls whether PPC per opcode peephole is performed on a MI");
118 MachineDominatorTree *MDT;
119 MachinePostDominatorTree *MPDT;
120 MachineBlockFrequencyInfo *MBFI;
121 BlockFrequency EntryFreq;
122 SmallSet<Register, 16> RegsToUpdate;
131 bool eliminateRedundantCompare();
132 bool eliminateRedundantTOCSaves(std::map<MachineInstr *, bool> &TOCSaves);
133 bool combineSEXTAndSHL(MachineInstr &
MI, MachineInstr *&ToErase);
134 bool emitRLDICWhenLoweringJumpTables(MachineInstr &
MI,
135 MachineInstr *&ToErase);
136 void UpdateTOCSaves(std::map<MachineInstr *, bool> &TOCSaves,
144 void addDummyDef(MachineBasicBlock &
MBB, MachineInstr *At,
Register Reg) {
147 void addRegToUpdateWithLine(
Register Reg,
int Line);
148 void convertUnprimedAccPHIs(
const PPCInstrInfo *TII, MachineRegisterInfo *MRI,
149 SmallVectorImpl<MachineInstr *> &PHIs,
153 void getAnalysisUsage(AnalysisUsage &AU)
const override {
155 AU.
addRequired<MachinePostDominatorTreeWrapperPass>();
156 AU.
addRequired<MachineBlockFrequencyInfoWrapperPass>();
159 AU.
addPreserved<MachineBlockFrequencyInfoWrapperPass>();
169 assert((MF.getRegInfo().use_empty(PPC::X2) ||
170 !MF.getSubtarget<PPCSubtarget>().isUsingPCRelativeCalls()) &&
171 "TOC pointer used in a function using PC-Relative addressing!");
172 if (skipFunction(MF.getFunction()))
174 return simplifyCode();
178#define addRegToUpdate(R) addRegToUpdateWithLine(R, __LINE__)
179void PPCMIPeephole::addRegToUpdateWithLine(
Register Reg,
int Line) {
180 if (!
Reg.isVirtual())
184 << Line <<
" for re-computation of kill flags\n");
191 MDT = &getAnalysis<MachineDominatorTreeWrapperPass>().getDomTree();
192 MPDT = &getAnalysis<MachinePostDominatorTreeWrapperPass>().getPostDomTree();
193 MBFI = &getAnalysis<MachineBlockFrequencyInfoWrapperPass>().getMBFI();
196 RegsToUpdate.
clear();
201static MachineInstr *getVRegDefOrNull(MachineOperand *
Op,
202 MachineRegisterInfo *
MRI) {
216static unsigned getKnownLeadingZeroCount(
const unsigned Reg,
217 const PPCInstrInfo *
TII,
218 const MachineRegisterInfo *
MRI) {
220 unsigned Opcode =
MI->getOpcode();
221 if (Opcode == PPC::RLDICL || Opcode == PPC::RLDICL_rec ||
222 Opcode == PPC::RLDCL || Opcode == PPC::RLDCL_rec)
223 return MI->getOperand(3).getImm();
225 if ((Opcode == PPC::RLDIC || Opcode == PPC::RLDIC_rec) &&
226 MI->getOperand(3).getImm() <= 63 -
MI->getOperand(2).getImm())
227 return MI->getOperand(3).getImm();
229 if ((Opcode == PPC::RLWINM || Opcode == PPC::RLWINM_rec ||
230 Opcode == PPC::RLWNM || Opcode == PPC::RLWNM_rec ||
231 Opcode == PPC::RLWINM8 || Opcode == PPC::RLWNM8) &&
232 MI->getOperand(3).getImm() <=
MI->getOperand(4).getImm())
233 return 32 +
MI->getOperand(3).getImm();
235 if (Opcode == PPC::ANDI_rec) {
236 uint16_t
Imm =
MI->getOperand(2).getImm();
240 if (Opcode == PPC::CNTLZW || Opcode == PPC::CNTLZW_rec ||
241 Opcode == PPC::CNTTZW || Opcode == PPC::CNTTZW_rec ||
242 Opcode == PPC::CNTLZW8 || Opcode == PPC::CNTTZW8)
246 if (Opcode == PPC::CNTLZD || Opcode == PPC::CNTLZD_rec ||
247 Opcode == PPC::CNTTZD || Opcode == PPC::CNTTZD_rec)
251 if (Opcode == PPC::LHZ || Opcode == PPC::LHZX ||
252 Opcode == PPC::LHZ8 || Opcode == PPC::LHZX8 ||
253 Opcode == PPC::LHZU || Opcode == PPC::LHZUX ||
254 Opcode == PPC::LHZU8 || Opcode == PPC::LHZUX8)
257 if (Opcode == PPC::LBZ || Opcode == PPC::LBZX ||
258 Opcode == PPC::LBZ8 || Opcode == PPC::LBZX8 ||
259 Opcode == PPC::LBZU || Opcode == PPC::LBZUX ||
260 Opcode == PPC::LBZU8 || Opcode == PPC::LBZUX8)
263 if (Opcode == PPC::AND || Opcode == PPC::AND8 || Opcode == PPC::AND_rec ||
264 Opcode == PPC::AND8_rec)
266 getKnownLeadingZeroCount(
MI->getOperand(1).getReg(),
TII,
MRI),
267 getKnownLeadingZeroCount(
MI->getOperand(2).getReg(),
TII,
MRI));
269 if (Opcode == PPC::OR || Opcode == PPC::OR8 || Opcode == PPC::XOR ||
270 Opcode == PPC::XOR8 || Opcode == PPC::OR_rec ||
271 Opcode == PPC::OR8_rec || Opcode == PPC::XOR_rec ||
272 Opcode == PPC::XOR8_rec)
274 getKnownLeadingZeroCount(
MI->getOperand(1).getReg(),
TII,
MRI),
275 getKnownLeadingZeroCount(
MI->getOperand(2).getReg(),
TII,
MRI));
289void PPCMIPeephole::UpdateTOCSaves(
290 std::map<MachineInstr *, bool> &TOCSaves, MachineInstr *
MI) {
291 assert(
TII->isTOCSaveMI(*
MI) &&
"Expecting a TOC save instruction here");
295 PPCFunctionInfo *FI = MF->
getInfo<PPCFunctionInfo>();
298 BlockFrequency CurrBlockFreq = MBFI->
getBlockFreq(
MI->getParent());
304 if (CurrBlockFreq > EntryFreq || MPDT->
dominates(
MI->getParent(), Entry))
310 for (
auto &TOCSave : TOCSaves)
311 TOCSave.second =
false;
313 TOCSaves[
MI] =
false;
319 for (
auto &
I : TOCSaves) {
320 MachineInstr *CurrInst =
I.first;
341static bool collectUnprimedAccPHIs(MachineRegisterInfo *
MRI,
342 MachineInstr *RootPHI,
343 SmallVectorImpl<MachineInstr *> &PHIs) {
345 unsigned VisitedIndex = 0;
346 while (VisitedIndex < PHIs.
size()) {
347 MachineInstr *VisitedPHI = PHIs[VisitedIndex];
349 PHIOp !=
NumOps; PHIOp += 2) {
356 unsigned Opcode =
Instr->getOpcode();
357 if (Opcode == PPC::COPY) {
361 }
else if (Opcode != PPC::IMPLICIT_DEF && Opcode != PPC::PHI)
367 if (Opcode != PPC::PHI)
382void PPCMIPeephole::convertUnprimedAccPHIs(
383 const PPCInstrInfo *
TII, MachineRegisterInfo *
MRI,
384 SmallVectorImpl<MachineInstr *> &PHIs,
Register Dst) {
385 DenseMap<MachineInstr *, MachineInstr *> ChangedPHIMap;
392 for (
unsigned PHIOp = 1,
NumOps =
PHI->getNumOperands(); PHIOp !=
NumOps;
397 assert((Opcode == PPC::COPY || Opcode == PPC::IMPLICIT_DEF ||
398 Opcode == PPC::PHI) &&
399 "Unexpected instruction");
400 if (Opcode == PPC::COPY) {
402 &PPC::ACCRCRegClass &&
403 "Unexpected register class");
405 }
else if (Opcode == PPC::IMPLICIT_DEF) {
408 TII->get(PPC::IMPLICIT_DEF), AccReg);
410 PHI->getOperand(PHIOp + 1)});
411 }
else if (Opcode == PPC::PHI) {
416 "This PHI node should have already been changed.");
417 MachineInstr *PrimedAccPHI = ChangedPHIMap.
lookup(PHIInput);
420 PHI->getOperand(PHIOp + 1)});
431 MachineInstrBuilder NewPHI =
BuildMI(
432 *
PHI->getParent(),
PHI,
PHI->getDebugLoc(),
TII->get(PPC::PHI), AccReg);
433 for (
auto RegMBB : PHIOps) {
434 NewPHI.
add(RegMBB.first).
add(RegMBB.second);
450bool PPCMIPeephole::simplifyCode() {
452 bool TrapOpt =
false;
453 MachineInstr* ToErase =
nullptr;
454 std::map<MachineInstr *, bool> TOCSaves;
456 NumFunctionsEnteredInMIPeephole++;
461 bool SomethingChanged =
false;
463 NumFixedPointIterations++;
464 SomethingChanged =
false;
465 for (MachineBasicBlock &
MBB : *MF) {
466 for (MachineInstr &
MI :
MBB) {
467 if (
MI.isDebugInstr())
473 SmallSet<Register, 4> RRToRIRegsToUpdate;
474 if (!
TII->convertToImmediateForm(
MI, RRToRIRegsToUpdate))
476 for (
Register R : RRToRIRegsToUpdate)
480 for (
const MachineOperand &MO :
MI.operands())
487 NumConvertedToImmediateForm++;
488 SomethingChanged =
true;
499 auto clearKillsForDyingInstr = [&]() {
500 if (RegsToUpdate.
empty())
502 for (MachineOperand &MO : ToErase->
operands()) {
503 if (!MO.isReg() || !MO.isDef() || !RegsToUpdate.
count(MO.getReg()))
506 RegsToUpdate.
erase(RegToUpdate);
511 MO.setReg(PPC::NoRegister);
513 Def.setIsDead(
false);
517 for (MachineBasicBlock &
MBB : *MF) {
518 for (MachineInstr &
MI :
MBB) {
525 clearKillsForDyingInstr();
538 if (
MI.isDebugInstr())
545 switch (
MI.getOpcode()) {
552 if (!Src.isVirtual() || !Dst.isVirtual())
571 SmallVector<MachineInstr *, 4> PHIs;
572 if (!collectUnprimedAccPHIs(
MRI, RootPHI, PHIs))
575 convertUnprimedAccPHIs(
TII,
MRI, PHIs, Dst);
585 if (!
MI.getOperand(1).isImm() ||
MI.getOperand(1).getImm() != 0)
587 Register MIDestReg =
MI.getOperand(0).getReg();
592 ++NumLoadImmZeroFoldedAndRemoved;
602 MachineFrameInfo &MFI = MF->getFrameInfo();
604 (!MF->getSubtarget<PPCSubtarget>().isELFv2ABI() &&
605 !MF->getSubtarget<PPCSubtarget>().isAIXABI()))
610 if (
TII->isTOCSaveMI(
MI))
611 UpdateTOCSaves(TOCSaves, &
MI);
614 case PPC::XXPERMDI: {
618 int Immed =
MI.getOperand(3).getImm();
630 TRI->lookThruCopyLike(
MI.getOperand(1).getReg(),
MRI);
632 TRI->lookThruCopyLike(
MI.getOperand(2).getReg(),
MRI);
634 if (!(TrueReg1 == TrueReg2 && TrueReg1.
isVirtual()))
648 auto isConversionOfLoadAndSplat = [=]() ->
bool {
649 if (DefOpc != PPC::XVCVDPSXDS && DefOpc != PPC::XVCVDPUXDS)
655 if (LoadMI && LoadMI->
getOpcode() == PPC::LXVDSX)
660 if ((Immed == 0 || Immed == 3) &&
661 (DefOpc == PPC::LXVDSX || isConversionOfLoadAndSplat())) {
663 "to load-and-splat/copy: ");
666 MI.getOperand(0).getReg())
667 .
add(
MI.getOperand(1));
675 if (DefOpc == PPC::XXPERMDI) {
683 if (DefReg1 != DefReg2) {
687 if (!(FeedReg1 == FeedReg2 && FeedReg1.
isVirtual()))
691 if (DefImmed == 0 || DefImmed == 3) {
696 MI.getOperand(0).getReg())
697 .
add(
MI.getOperand(1));
706 else if ((Immed == 0 || Immed == 3) && DefImmed == 2) {
711 MI.getOperand(1).setReg(DefReg1);
712 MI.getOperand(2).setReg(DefReg2);
713 MI.getOperand(3).setImm(3 - Immed);
721 else if (Immed == 2 && DefImmed == 2) {
727 MI.getOperand(0).getReg())
734 }
else if ((Immed == 0 || Immed == 3 || Immed == 2) &&
735 DefOpc == PPC::XXPERMDIs &&
747 MI.getOperand(0).getReg())
748 .
add(
MI.getOperand(1));
759 }
else if (Immed == 2 &&
760 (DefOpc == PPC::VSPLTB || DefOpc == PPC::VSPLTH ||
761 DefOpc == PPC::VSPLTW || DefOpc == PPC::XXSPLTW ||
762 DefOpc == PPC::VSPLTISB || DefOpc == PPC::VSPLTISH ||
763 DefOpc == PPC::VSPLTISW)) {
767 LLVM_DEBUG(
dbgs() <<
"Optimizing swap(vsplt(is)?[b|h|w]|xxspltw) => "
768 "copy(vsplt(is)?[b|h|w]|xxspltw): ");
771 MI.getOperand(0).getReg())
772 .
add(
MI.getOperand(1));
774 }
else if ((Immed == 0 || Immed == 3 || Immed == 2) &&
775 TII->isLoadFromConstantPool(
DefMI)) {
777 if (
C &&
C->getType()->isVectorTy() &&
C->getSplatValue()) {
781 <<
"Optimizing swap(splat pattern from constant-pool) "
782 "=> copy(splat pattern from constant-pool): ");
785 MI.getOperand(0).getReg())
786 .
add(
MI.getOperand(1));
795 unsigned MyOpcode =
MI.getOpcode();
797 unsigned OpNo = MyOpcode == PPC::XXSPLTW ? 1 : 2;
799 TRI->lookThruCopyLike(
MI.getOperand(OpNo).getReg(),
MRI);
806 auto isConvertOfSplat = [=]() ->
bool {
807 if (DefOpcode != PPC::XVCVSPSXWS && DefOpcode != PPC::XVCVSPUXWS)
813 return Splt && (Splt->
getOpcode() == PPC::LXVWSX ||
816 bool AlreadySplat = (MyOpcode == DefOpcode) ||
817 (MyOpcode == PPC::VSPLTB && DefOpcode == PPC::VSPLTBs) ||
818 (MyOpcode == PPC::VSPLTH && DefOpcode == PPC::VSPLTHs) ||
819 (MyOpcode == PPC::XXSPLTW && DefOpcode == PPC::XXSPLTWs) ||
820 (MyOpcode == PPC::XXSPLTW && DefOpcode == PPC::LXVWSX) ||
821 (MyOpcode == PPC::XXSPLTW && DefOpcode == PPC::MTVSRWS)||
822 (MyOpcode == PPC::XXSPLTW && isConvertOfSplat());
830 MI.getOperand(0).getReg())
831 .
add(
MI.getOperand(OpNo));
839 if (DefOpcode == PPC::XXSLDWI) {
861 unsigned SplatImmNo = MyOpcode == PPC::XXSPLTW ? 2 : 1;
862 unsigned SplatImm =
MI.getOperand(SplatImmNo).getImm();
868 auto CalculateNewElementIdx = [&](
unsigned Opcode) {
869 if (Opcode == PPC::VSPLTB)
870 return (SplatImm + ShiftImm * 4) & 0xF;
871 else if (Opcode == PPC::VSPLTH)
872 return (SplatImm + ShiftImm * 2) & 0x7;
874 return (SplatImm + ShiftImm) & 0x3;
877 unsigned NewElem = CalculateNewElementIdx(MyOpcode);
880 <<
" to " << NewElem <<
" in instruction: ");
886 MI.getOperand(OpNo).setReg(ShiftOp1);
887 MI.getOperand(SplatImmNo).setImm(NewElem);
892 case PPC::XVCVDPSP: {
895 TRI->lookThruCopyLike(
MI.getOperand(1).getReg(),
MRI);
918 auto removeFRSPIfPossible = [&](MachineInstr *RoundInstr) {
919 unsigned Opc = RoundInstr->getOpcode();
920 if ((
Opc == PPC::FRSP ||
Opc == PPC::XSRSP) &&
923 Register ConvReg1 = RoundInstr->getOperand(1).getReg();
924 Register FRSPDefines = RoundInstr->getOperand(0).getReg();
926 for (
int i = 0, e =
Use.getNumOperands(); i < e; ++i)
927 if (
Use.getOperand(i).isReg() &&
928 Use.getOperand(i).getReg() == FRSPDefines)
929 Use.getOperand(i).setReg(ConvReg1);
938 ToErase = RoundInstr;
946 removeFRSPIfPossible(P1);
947 removeFRSPIfPossible(P2);
950 removeFRSPIfPossible(P1);
956 case PPC::EXTSH8_32_64: {
958 Register NarrowReg =
MI.getOperand(1).getReg();
966 if (SrcOpcode == PPC::LHZ || SrcOpcode == PPC::LHZX) {
973 unsigned Opc = PPC::LHA;
974 bool SourceIsXForm = SrcOpcode == PPC::LHZX;
975 bool MIIs64Bit =
MI.getOpcode() == PPC::EXTSH8 ||
976 MI.getOpcode() == PPC::EXTSH8_32_64;
978 if (SourceIsXForm && MIIs64Bit)
980 else if (SourceIsXForm && !MIIs64Bit)
991 addDummyDef(
MBB, &
MI, NarrowReg);
1001 NumEliminatedSExt++;
1007 case PPC::EXTSW_32_64: {
1009 Register NarrowReg =
MI.getOperand(1).getReg();
1014 unsigned SrcOpcode = SrcMI->
getOpcode();
1019 bool SrcIsGPRCWordZextLoad =
1020 SrcOpcode == PPC::LWZ || SrcOpcode == PPC::LWZX;
1021 bool SrcIsG8RCWordZextLoad =
1022 SrcOpcode == PPC::LWZ8 || SrcOpcode == PPC::LWZX8;
1023 unsigned NarrowSubReg =
MI.getOperand(1).getSubReg();
1025 if ((!NarrowSubReg && SrcIsGPRCWordZextLoad) ||
1026 (NarrowSubReg == PPC::sub_32 && SrcIsG8RCWordZextLoad)) {
1034 bool IsWordAligned =
false;
1036 const GlobalVariable *GV =
1040 IsWordAligned =
true;
1044 IsWordAligned =
true;
1051 unsigned Opc = PPC::LWA_32;
1052 bool SourceIsXForm =
1053 SrcOpcode == PPC::LWZX || SrcOpcode == PPC::LWZX8;
1054 bool MIIs64Bit =
MI.getOpcode() == PPC::EXTSW ||
1055 MI.getOpcode() == PPC::EXTSW_32_64;
1057 if (SourceIsXForm && MIIs64Bit)
1059 else if (SourceIsXForm && !MIIs64Bit)
1064 if (!IsWordAligned && (
Opc == PPC::LWA ||
Opc == PPC::LWA_32))
1073 addDummyDef(
MBB, &
MI, NarrowReg);
1083 NumEliminatedSExt++;
1084 }
else if (
MI.getOpcode() == PPC::EXTSW_32_64 &&
1085 TII->isSignExtended(NarrowReg,
MRI)) {
1095 TII->promoteInstr32To64ForElimEXTSW(NarrowReg,
MRI, 0);
1099 unsigned NarrowSubReg =
MI.getOperand(1).getSubReg();
1103 assert(NarrowSubReg == PPC::sub_32 &&
1104 "EXTSW_32_64 input must read the sub_32 subregister");
1106 MI.getOperand(0).getReg())
1110 MF->getRegInfo().createVirtualRegister(&PPC::G8RCRegClass);
1114 MI.getOperand(0).getReg())
1122 NumEliminatedSExt++;
1135 if (
MI.getOperand(2).getImm() != 0)
1143 if (!(SrcMI && SrcMI->
getOpcode() == PPC::INSERT_SUBREG &&
1147 MachineInstr *ImpDefMI, *SubRegMI;
1150 if (ImpDefMI->
getOpcode() != PPC::IMPLICIT_DEF)
break;
1153 if (SubRegMI->
getOpcode() == PPC::COPY) {
1161 unsigned KnownZeroCount =
1163 if (
MI.getOperand(3).getImm() <= KnownZeroCount) {
1166 MI.getOperand(0).getReg())
1171 NumEliminatedZExt++;
1182 auto isSingleUsePHI = [&](MachineOperand *PhiOp) {
1183 assert(PhiOp &&
"Invalid Operand!");
1184 MachineInstr *DefPhiMI = getVRegDefOrNull(PhiOp,
MRI);
1186 return DefPhiMI && (DefPhiMI->
getOpcode() == PPC::PHI) &&
1190 auto dominatesAllSingleUseLIs = [&](MachineOperand *DominatorOp,
1191 MachineOperand *PhiOp) {
1192 assert(PhiOp &&
"Invalid Operand!");
1193 assert(DominatorOp &&
"Invalid Operand!");
1194 MachineInstr *DefPhiMI = getVRegDefOrNull(PhiOp,
MRI);
1195 MachineInstr *DefDomMI = getVRegDefOrNull(DominatorOp,
MRI);
1200 MachineInstr *LiMI =
1212 MachineOperand Op1 =
MI.getOperand(1);
1213 MachineOperand Op2 =
MI.getOperand(2);
1214 if (isSingleUsePHI(&Op2) && dominatesAllSingleUseLIs(&Op1, &Op2))
1216 else if (!isSingleUsePHI(&Op1) || !dominatesAllSingleUseLIs(&Op2, &Op1))
1223 ? &PPC::G8RC_and_G8RC_NOX0RegClass
1224 : &PPC::GPRC_and_GPRC_NOR0RegClass;
1228 MachineInstr *DefPhiMI = getVRegDefOrNull(&Op1,
MRI);
1230 MachineInstr *LiMI = getVRegDefOrNull(&DefPhiMI->
getOperand(i),
MRI);
1248 .addReg(DominatorReg)
1257 MI.getOperand(0).getReg())
1267 Simplified |= emitRLDICWhenLoweringJumpTables(
MI, ToErase) ||
1268 combineSEXTAndSHL(
MI, ToErase);
1272 case PPC::ANDI8_rec:
1273 case PPC::ANDIS_rec:
1274 case PPC::ANDIS8_rec: {
1276 TRI->lookThruCopyLike(
MI.getOperand(1).getReg(),
MRI);
1284 unsigned SrcOpCode = SrcMI->
getOpcode();
1285 if (SrcOpCode != PPC::RLDICL && SrcOpCode != PPC::RLDICR)
1290 DstReg =
MI.getOperand(1).getReg();
1297 if (
MI.getOpcode() == PPC::ANDIS_rec ||
1298 MI.getOpcode() == PPC::ANDIS8_rec)
1306 bool PatternResultZero =
1307 (SrcOpCode == PPC::RLDICL && (RZeroAndImm + ImmSrc > 63)) ||
1308 (SrcOpCode == PPC::RLDICR && LZeroAndImm > ImmSrc);
1312 bool PatternRemoveRotate =
1314 ((SrcOpCode == PPC::RLDICL && LZeroAndImm >= ImmSrc) ||
1315 (SrcOpCode == PPC::RLDICR && (RZeroAndImm + ImmSrc > 63)));
1317 if (!PatternResultZero && !PatternRemoveRotate)
1323 if (PatternResultZero)
1324 MI.getOperand(2).setImm(0);
1334 case PPC::RLWINM_rec:
1336 case PPC::RLWINM8_rec: {
1339 Register OrigOp1Reg =
MI.getOperand(1).isReg()
1340 ?
MI.getOperand(1).getReg()
1345 if (
MI.getOperand(1).isReg())
1351 ++NumRotatesCollapsed;
1362 MachineInstr *LiMI1 = getVRegDefOrNull(&
MI.getOperand(1),
MRI);
1363 MachineInstr *LiMI2 = getVRegDefOrNull(&
MI.getOperand(2),
MRI);
1364 bool IsOperand2Immediate =
MI.getOperand(2).isImm();
1367 if (!(LiMI1 && (LiMI1->
getOpcode() == PPC::LI ||
1370 if (!IsOperand2Immediate &&
1371 !(LiMI2 && (LiMI2->
getOpcode() == PPC::LI ||
1375 auto ImmOperand0 =
MI.getOperand(0).getImm();
1377 auto ImmOperand2 = IsOperand2Immediate ?
MI.getOperand(2).getImm()
1382 if ((ImmOperand0 == 31) ||
1383 ((ImmOperand0 & 0x10) &&
1384 ((int64_t)ImmOperand1 < (int64_t)ImmOperand2)) ||
1385 ((ImmOperand0 & 0x8) &&
1386 ((int64_t)ImmOperand1 > (int64_t)ImmOperand2)) ||
1387 ((ImmOperand0 & 0x2) &&
1389 ((ImmOperand0 & 0x1) &&
1391 ((ImmOperand0 & 0x4) && (ImmOperand1 == ImmOperand2))) {
1406 clearKillsForDyingInstr();
1416 Simplified |= eliminateRedundantTOCSaves(TOCSaves);
1417 PPCFunctionInfo *FI = MF->getInfo<PPCFunctionInfo>();
1419 NumTOCSavesInPrologue++;
1433 Def.setIsDead(
false);
1439static bool isEqOrNe(MachineInstr *BI) {
1445static bool isSupportedCmpOp(
unsigned opCode) {
1446 return (opCode == PPC::CMPLD || opCode == PPC::CMPD ||
1447 opCode == PPC::CMPLW || opCode == PPC::CMPW ||
1448 opCode == PPC::CMPLDI || opCode == PPC::CMPDI ||
1449 opCode == PPC::CMPLWI || opCode == PPC::CMPWI);
1452static bool is64bitCmpOp(
unsigned opCode) {
1453 return (opCode == PPC::CMPLD || opCode == PPC::CMPD ||
1454 opCode == PPC::CMPLDI || opCode == PPC::CMPDI);
1457static bool isSignedCmpOp(
unsigned opCode) {
1458 return (opCode == PPC::CMPD || opCode == PPC::CMPW ||
1459 opCode == PPC::CMPDI || opCode == PPC::CMPWI);
1462static unsigned getSignedCmpOpCode(
unsigned opCode) {
1463 if (opCode == PPC::CMPLD)
return PPC::CMPD;
1464 if (opCode == PPC::CMPLW)
return PPC::CMPW;
1465 if (opCode == PPC::CMPLDI)
return PPC::CMPDI;
1466 if (opCode == PPC::CMPLWI)
return PPC::CMPWI;
1472static unsigned getPredicateToDecImm(MachineInstr *BI, MachineInstr *CMPI) {
1474 bool SignedCmp = isSignedCmpOp(CMPI->
getOpcode());
1475 if ((!SignedCmp &&
Imm == 0) || (SignedCmp &&
Imm == 0x8000))
1491static unsigned getPredicateToIncImm(MachineInstr *BI, MachineInstr *CMPI) {
1493 bool SignedCmp = isSignedCmpOp(CMPI->
getOpcode());
1494 if ((!SignedCmp &&
Imm == 0xFFFF) || (SignedCmp &&
Imm == 0x7FFF))
1509static unsigned getIncomingRegForBlock(MachineInstr *Phi,
1510 MachineBasicBlock *
MBB) {
1511 for (
unsigned I = 2,
E =
Phi->getNumOperands() + 1;
I !=
E;
I += 2) {
1512 MachineOperand &MO =
Phi->getOperand(
I);
1514 return Phi->getOperand(
I-1).getReg();
1523static unsigned getSrcVReg(
unsigned Reg, MachineBasicBlock *BB1,
1524 MachineBasicBlock *BB2, MachineRegisterInfo *
MRI) {
1525 unsigned SrcReg =
Reg;
1527 unsigned NextReg = SrcReg;
1530 NextReg = getIncomingRegForBlock(Inst, BB1);
1536 if (NextReg == SrcReg || !Register::isVirtualRegister(NextReg))
1543static bool eligibleForCompareElimination(MachineBasicBlock &
MBB,
1544 MachineBasicBlock *&PredMBB,
1545 MachineBasicBlock *&MBBtoMoveCmp,
1546 MachineRegisterInfo *
MRI) {
1548 auto isEligibleBB = [&](MachineBasicBlock &BB) {
1549 auto BII = BB.getFirstInstrTerminator();
1553 if (BB.succ_size() == 2 &&
1554 BII != BB.instr_end() &&
1555 (*BII).getOpcode() == PPC::BCC &&
1556 (*BII).getOperand(1).isReg()) {
1558 Register CndReg = (*BII).getOperand(1).getReg();
1568 for (MachineOperand &MO : CMPI->
operands())
1581 auto isEligibleForMoveCmp = [](MachineBasicBlock &BB) {
1582 return BB.succ_size() == 1;
1585 if (!isEligibleBB(
MBB))
1589 if (NumPredBBs == 1) {
1591 if (isEligibleBB(*TmpMBB)) {
1593 MBBtoMoveCmp =
nullptr;
1597 else if (NumPredBBs == 2) {
1602 MachineBasicBlock *Pred1MBB = *PI;
1603 MachineBasicBlock *Pred2MBB = *(PI+1);
1605 if (isEligibleBB(*Pred1MBB) && isEligibleForMoveCmp(*Pred2MBB)) {
1610 else if (isEligibleBB(*Pred2MBB) && isEligibleForMoveCmp(*Pred1MBB)) {
1616 if (Pred1MBB == &
MBB)
1624 for (
int I = 1;
I <= 2;
I++)
1632 MBBtoMoveCmp = Pred2MBB;
1643bool PPCMIPeephole::eliminateRedundantTOCSaves(
1644 std::map<MachineInstr *, bool> &TOCSaves) {
1647 for (
auto TOCSave : TOCSaves) {
1648 if (!TOCSave.second) {
1649 TOCSave.first->eraseFromParent();
1685bool PPCMIPeephole::eliminateRedundantCompare() {
1688 for (MachineBasicBlock &MBB2 : *MF) {
1689 MachineBasicBlock *MBB1 =
nullptr, *MBBtoMoveCmp =
nullptr;
1718 if (!eligibleForCompareElimination(MBB2, MBB1, MBBtoMoveCmp,
MRI))
1724 MachineInstr *BI2 = &*MBB2.getFirstInstrTerminator();
1726 bool IsPartiallyRedundant = (MBBtoMoveCmp !=
nullptr);
1730 if (!isSupportedCmpOp(CMPI1->
getOpcode()) ||
1731 !isSupportedCmpOp(CMPI2->
getOpcode()) ||
1735 unsigned NewOpCode = 0;
1736 unsigned NewPredicate1 = 0, NewPredicate2 = 0;
1738 bool SwapOperands =
false;
1749 auto CmpAgainstImmWithSignBit = [](MachineInstr *
I) {
1750 if (!
I->getOperand(2).isImm())
1752 int16_t
Imm = (int16_t)
I->getOperand(2).getImm();
1756 if (isEqOrNe(BI2) && !CmpAgainstImmWithSignBit(CMPI2) &&
1759 else if (isEqOrNe(BI1) && !CmpAgainstImmWithSignBit(CMPI1) &&
1769 nullptr,
nullptr,
MRI);
1771 nullptr,
nullptr,
MRI);
1777 if (Cmp1Operand1 == Cmp2Operand1 && Cmp1Operand2 == Cmp2Operand2) {
1780 else if (Cmp1Operand1 == Cmp2Operand2 && Cmp1Operand2 == Cmp2Operand1) {
1787 SwapOperands =
true;
1795 nullptr,
nullptr,
MRI);
1798 if (Cmp1Operand1 != Cmp2Operand1)
1806 if (Imm1 != Imm2 && (!isEqOrNe(BI2) || !isEqOrNe(BI1))) {
1807 int Diff = Imm1 - Imm2;
1808 if (Diff < -2 || Diff > 2)
1811 unsigned PredToInc1 = getPredicateToIncImm(BI1, CMPI1);
1812 unsigned PredToDec1 = getPredicateToDecImm(BI1, CMPI1);
1813 unsigned PredToInc2 = getPredicateToIncImm(BI2, CMPI2);
1814 unsigned PredToDec2 = getPredicateToDecImm(BI2, CMPI2);
1816 if (PredToInc2 && PredToDec1) {
1817 NewPredicate2 = PredToInc2;
1818 NewPredicate1 = PredToDec1;
1823 else if (Diff == 1) {
1826 NewPredicate2 = PredToInc2;
1828 else if (PredToDec1) {
1830 NewPredicate1 = PredToDec1;
1833 else if (Diff == -1) {
1836 NewPredicate2 = PredToDec2;
1838 else if (PredToInc1) {
1840 NewPredicate1 = PredToInc1;
1843 else if (Diff == -2) {
1844 if (PredToDec2 && PredToInc1) {
1845 NewPredicate2 = PredToDec2;
1846 NewPredicate1 = PredToInc1;
1858 LLVM_DEBUG(
dbgs() <<
"Optimize two pairs of compare and branch:\n");
1863 for (
const MachineOperand &MO : CMPI1->
operands())
1866 for (
const MachineOperand &MO : CMPI2->
operands())
1871 if (NewOpCode != 0 && NewOpCode != CMPI1->
getOpcode()) {
1874 if (NewPredicate1) {
1877 if (NewPredicate2) {
1884 if (IsPartiallyRedundant) {
1896 for (
int I = 1;
I <= 2;
I++) {
1903 "We cannot support if an operand comes from this BB.");
1904 unsigned SrcReg = getIncomingRegForBlock(Inst, MBBtoMoveCmp);
1915 TII->get(PPC::PHI), NewVReg)
1938 if (IsPartiallyRedundant) {
1941 <<
" to handle partial redundancy.\n");
1953bool PPCMIPeephole::emitRLDICWhenLoweringJumpTables(MachineInstr &
MI,
1954 MachineInstr *&ToErase) {
1955 if (
MI.getOpcode() != PPC::RLDICR)
1966 MachineOperand MOpSHSrc = SrcMI->
getOperand(2);
1967 MachineOperand MOpMBSrc = SrcMI->
getOperand(3);
1968 MachineOperand MOpSHMI =
MI.getOperand(2);
1969 MachineOperand MOpMEMI =
MI.getOperand(3);
1980 if (NewMB > 63 || NewSH > 63)
1989 if ((63 - NewSH) != MEMI)
1996 MI.setDesc(
TII->get(PPC::RLDIC));
1998 MI.getOperand(2).setImm(NewSH);
1999 MI.getOperand(3).setImm(NewMB);
2005 NumRotatesCollapsed++;
2009 "Not expecting an implicit def with this instr.");
2026bool PPCMIPeephole::combineSEXTAndSHL(MachineInstr &
MI,
2027 MachineInstr *&ToErase) {
2028 if (
MI.getOpcode() != PPC::RLDICR)
2031 if (!MF->getSubtarget<PPCSubtarget>().isISA3_0())
2034 assert(
MI.getNumOperands() == 4 &&
"RLDICR should have 4 operands");
2036 MachineOperand MOpSHMI =
MI.getOperand(2);
2037 MachineOperand MOpMEMI =
MI.getOperand(3);
2043 if (SHMI + MEMI != 63)
2062 "EXTSW's second operand should be a register");
2070 MachineInstr *NewInstr =
2072 SrcMI->
getOpcode() == PPC::EXTSW ?
TII->get(PPC::EXTSWSLI)
2073 :
TII->get(PPC::EXTSWSLI_32_64),
2074 MI.getOperand(0).getReg())
2081 ++NumEXTSWAndSLDICombined;
2094 "PowerPC MI Peephole Optimization",
false,
false)
2101char PPCMIPeephole::ID = 0;
MachineInstrBuilder & UseMI
MachineInstrBuilder MachineInstrBuilder & DefMI
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
const AArch64InstrInfo & TII
MachineBasicBlock MachineBasicBlock::iterator DebugLoc DL
static GCRegistry::Add< ShadowStackGC > C("shadow-stack", "Very portable GC for uncooperative code generators")
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
This file provides an implementation of debug counters.
#define DEBUG_COUNTER(VARNAME, COUNTERNAME, DESC)
static Register UseReg(const MachineOperand &MO)
const size_t AbstractManglingParser< Derived, Alloc >::NumOps
Register const TargetRegisterInfo * TRI
Promote Memory to Register
#define addRegToUpdate(R)
static cl::opt< bool > EnableZExtElimination("ppc-eliminate-zeroext", cl::desc("enable elimination of zero-extensions"), cl::init(true), cl::Hidden)
static cl::opt< bool > FixedPointRegToImm("ppc-reg-to-imm-fixed-point", cl::Hidden, cl::init(true), cl::desc("Iterate to a fixed point when attempting to " "convert reg-reg instructions to reg-imm"))
static cl::opt< bool > EnableTrapOptimization("ppc-opt-conditional-trap", cl::desc("enable optimization of conditional traps"), cl::init(false), cl::Hidden)
static cl::opt< bool > ConvertRegReg("ppc-convert-rr-to-ri", cl::Hidden, cl::init(true), cl::desc("Convert eligible reg+reg instructions to reg+imm"))
static cl::opt< bool > EnableSExtElimination("ppc-eliminate-signext", cl::desc("enable elimination of sign-extensions"), cl::init(true), cl::Hidden)
#define INITIALIZE_PASS_DEPENDENCY(depName)
#define INITIALIZE_PASS_END(passName, arg, name, cfg, analysis)
#define INITIALIZE_PASS_BEGIN(passName, arg, name, cfg, analysis)
MachineBasicBlock * Folded
MachineRegisterInfo & MRI
This file defines the 'Statistic' class, which is designed to be an easy way to expose various metric...
#define STATISTIC(VARNAME, DESC)
static void initialize(TargetLibraryInfoImpl &TLI, const Triple &T, const llvm::StringTable &StandardNames, VectorLibrary VecLib)
Initialize the set of available library functions based on the specified target triple.
const AArch64RegisterInfo & getRegisterInfo() const
getRegisterInfo - TargetInstrInfo is a superset of MRegister info.
AnalysisUsage & addRequired()
AnalysisUsage & addPreserved()
Add the specified Pass class to the set of analyses preserved by this pass.
static bool shouldExecute(CounterInfo &Counter)
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
ValueT lookup(const_arg_type_t< KeyT > Val) const
Return the entry for the specified key, or a default constructed value if no such entry exists.
bool dominates(const DomTreeNodeBase< NodeT > *A, const DomTreeNodeBase< NodeT > *B) const
dominates - Returns true iff A dominates B.
FunctionPass class - This class is used to implement most global optimizations.
MaybeAlign getAlign() const
Returns the alignment of the given variable.
static MDTuple * get(LLVMContext &Context, ArrayRef< Metadata * > MDs)
unsigned pred_size() const
LLVM_ABI iterator getFirstTerminator()
Returns an iterator to the first terminator instruction of this basic block.
SmallVectorImpl< MachineBasicBlock * >::iterator pred_iterator
pred_iterator pred_begin()
const MachineFunction * getParent() const
Return the MachineFunction containing this basic block.
LLVM_ABI instr_iterator getFirstInstrTerminator()
Same getFirstTerminator but it ignores bundles and return an instr_iterator instead.
void splice(iterator Where, MachineBasicBlock *Other, iterator From)
Take an instruction from MBB 'Other' at the position From, and insert it into this MBB right before '...
MachineInstrBundleIterator< MachineInstr > iterator
LLVM_ABI BlockFrequency getBlockFreq(const MachineBasicBlock *MBB) const
getblockFreq - Return block frequency.
LLVM_ABI BlockFrequency getEntryFreq() const
Divide a block's BlockFrequency::getFrequency() value by this value to obtain the entry block - relat...
Analysis pass which computes a MachineDominatorTree.
bool dominates(const MachineInstr *A, const MachineInstr *B) const
bool hasVarSizedObjects() const
This method may be called any time after instruction selection is complete to determine if the stack ...
MachineFunctionPass - This class adapts the FunctionPass interface to allow convenient creation of pa...
void getAnalysisUsage(AnalysisUsage &AU) const override
getAnalysisUsage - Subclasses that override getAnalysisUsage must call this.
const TargetSubtargetInfo & getSubtarget() const
getSubtarget - Return the subtarget for which this machine code is being compiled.
void dump() const
dump - Print the current MachineFunction to cerr, useful for debugger use.
MachineRegisterInfo & getRegInfo()
getRegInfo - Return information about the registers currently in use.
Ty * getInfo()
getInfo - Keep track of various per-function pieces of information for backends that would like to do...
const MachineBasicBlock & front() const
const MachineInstrBuilder & addReg(Register RegNo, RegState Flags={}, unsigned SubReg=0) const
Add a new virtual register operand.
const MachineInstrBuilder & addImm(int64_t Val) const
Add a new immediate operand.
const MachineInstrBuilder & add(const MachineOperand &MO) const
const MachineInstrBuilder & addMBB(MachineBasicBlock *MBB, unsigned TargetFlags=0) const
MachineInstr * getInstr() const
If conversion operators fail, use this method to get the MachineInstr explicitly.
unsigned getOpcode() const
Returns the opcode of this MachineInstr.
const MachineBasicBlock * getParent() const
unsigned getNumOperands() const
Retuns the total number of operands.
bool hasImplicitDef() const
Returns true if the instruction has implicit definition.
mop_range explicit_uses()
LLVM_ABI void setDesc(const MCInstrDesc &TID)
Replace the instruction descriptor (thus opcode) of the current instruction with a new one.
const DebugLoc & getDebugLoc() const
Returns the debug location id of this MachineInstr.
LLVM_ABI void removeOperand(unsigned OpNo)
Erase an operand from an instruction, leaving it with one fewer operand than it started with.
LLVM_ABI void dump() const
const MachineOperand & getOperand(unsigned i) const
LLVM_ABI MachineInstrBundleIterator< MachineInstr > eraseFromParent()
Unlink 'this' from the containing basic block and delete it.
const GlobalValue * getGlobal() const
void setImm(int64_t immVal)
bool isReg() const
isReg - Tests if this is a MO_Register operand.
MachineBasicBlock * getMBB() const
LLVM_ABI void setReg(Register Reg)
Change the register this operand corresponds to.
bool isImm() const
isImm - Tests if this is a MO_Immediate operand.
bool isGlobal() const
isGlobal - Tests if this is a MO_GlobalAddress operand.
Register getReg() const
getReg - Returns the register number.
static MachineOperand CreateReg(Register Reg, bool isDef, bool isImp=false, bool isKill=false, bool isDead=false, bool isUndef=false, bool isEarlyClobber=false, unsigned SubReg=0, bool isDebug=false, bool isInternalRead=false, bool isRenamable=false)
int64_t getOffset() const
Return the offset from the symbol in this operand.
MachineRegisterInfo - Keep track of information for virtual and physical registers,...
LLVM_ABI bool hasOneNonDBGUse(Register RegNo) const
hasOneNonDBGUse - Return true if there is exactly one non-Debug use of the specified register.
const TargetRegisterClass * getRegClass(Register Reg) const
Return the register class of the specified virtual register.
LLVM_ABI LLVM_READONLY MachineInstr * getVRegDef(Register Reg) const
getVRegDef - Return the machine instr that defines the specified virtual register or null if none is ...
bool use_nodbg_empty(Register RegNo) const
use_nodbg_empty - Return true if there are no non-Debug instructions using the specified register.
LLVM_ABI Register createVirtualRegister(const TargetRegisterClass *RegClass, StringRef Name="")
createVirtualRegister - Create and return a new virtual register in the function with the specified r...
use_instr_nodbg_iterator use_instr_nodbg_begin(Register RegNo) const
LLVM_ABI bool hasOneNonDBGUser(Register RegNo) const
hasOneNonDBGUse - Return true if there is exactly one non-Debug instruction using the specified regis...
iterator_range< def_iterator > def_operands(Register Reg) const
LLVM_ABI void setRegClass(Register Reg, const TargetRegisterClass *RC)
setRegClass - Set the register class of the specified virtual register.
const TargetRegisterClass * getRegClassOrNull(Register Reg) const
Return the register class of Reg, or null if Reg has not been assigned a register class yet.
iterator_range< use_instr_iterator > use_instructions(Register Reg) const
LLVM_ABI const TargetRegisterClass * constrainRegClass(Register Reg, const TargetRegisterClass *RC, unsigned MinNumRegs=0)
constrainRegClass - Constrain the register class of the specified virtual register to be a common sub...
bool reg_empty(Register RegNo) const
reg_empty - Return true if there are no instructions using or defining the specified register (it may...
LLVM_ABI LLVM_READONLY MachineInstr * getUniqueVRegDef(Register Reg) const
getUniqueVRegDef - Return the unique machine instr that defines the specified virtual register or nul...
void setMustSaveTOC(bool U)
Wrapper class representing virtual and physical registers.
constexpr bool isVirtual() const
Return true if the specified register number is in the virtual register namespace.
size_type count(const T &V) const
count - Return 1 if the element is in the set, 0 otherwise.
std::pair< const_iterator, bool > insert(const T &V)
insert - Insert an element into the set if it isn't already there.
void push_back(const T &Elt)
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
Predicate getSwappedPredicate(Predicate Opcode)
Assume the condition register is set by MI(a,b), return the predicate if we modify the instructions s...
Predicate
Predicate - These are "(BI << 5) | BO" for various predicates.
unsigned getPredicateCondition(Predicate Opcode)
Return the condition without hint bits.
Predicate getPredicate(unsigned Condition, unsigned Hint)
Return predicate consisting of specified condition and hint bits.
unsigned getPredicateHint(Predicate Opcode)
Return the hint bits of the predicate.
initializer< Ty > init(const Ty &Val)
NodeAddr< DefNode * > Def
NodeAddr< InstrNode * > Instr
NodeAddr< PhiNode * > Phi
NodeAddr< UseNode * > Use
This is an optimization pass for GlobalISel generic memory operations.
MachineInstrBuilder BuildMI(MachineFunction &MF, const MIMetadata &MIMD, const MCInstrDesc &MCID)
Builder interface. Specify how to create the initial instruction itself.
decltype(auto) dyn_cast(const From &Val)
dyn_cast<X> - Return the argument parameter cast to the specified type.
RelativeUniformCounterPtr ValuesPtrExpr VTableAddr Value
int countr_zero(T Val)
Count number of 0's from the least significant bit to the most stopping at the first 1.
int countl_zero(T Val)
Count number of 0's from the most significant bit to the least stopping at the first 1.
auto reverse(ContainerTy &&C)
LLVM_ABI raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
class LLVM_GSL_OWNER SmallVector
Forward declaration of SmallVector so that calculateSmallVectorDefaultInlinedElements can reference s...
DWARFExpression::Operation Op
bool is_contained(R &&Range, const E &Element)
Returns true if Element is found in Range.
LLVM_ABI Printable printReg(Register Reg, const TargetRegisterInfo *TRI=nullptr, unsigned SubIdx=0, const MachineRegisterInfo *MRI=nullptr)
Prints virtual and physical registers with or without a TRI instance.
@ Keep
No function return thunk.
LLVM_ABI Printable printMBBReference(const MachineBasicBlock &MBB)
Prints a machine basic block reference.
FunctionPass * createPPCMIPeepholePass()
MCRegisterClass TargetRegisterClass
void swap(llvm::BitVector &LHS, llvm::BitVector &RHS)
Implement std::swap in terms of BitVector swap.