[PATCH] D78517: [PC Relative][Expolitation] Remove "unskipableSimplifyCode()" in PPCMIPeephole.cpp

Victor Huang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 20 14:06:21 PDT 2020


NeHuang created this revision.
NeHuang added reviewers: nemanjai, lei, stefanp, hfinkel, power-llvm-team.
NeHuang added a project: LLVM.
Herald added subscribers: llvm-commits, kbarton, hiraditya.

unskipableSimplifyCode() was added to handle unsafe BL8_NOTOC instruction when TOC was not completely removed. The function is not needed after confirming no TOC usage with PC Relative addressing.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D78517

Files:
  llvm/lib/Target/PowerPC/PPCMIPeephole.cpp


Index: llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
===================================================================
--- llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
+++ llvm/lib/Target/PowerPC/PPCMIPeephole.cpp
@@ -57,8 +57,6 @@
           "Number of pairs of rotate left, clear left/right collapsed");
 STATISTIC(NumEXTSWAndSLDICombined,
           "Number of pairs of EXTSW and SLDI combined as EXTSWSLI");
-STATISTIC(NumX2FoundForPCRel, "Number of times the X2 TOC pointer has been "
-                              "found when PC relative NOTOC is being used.");
 
 static cl::opt<bool>
 FixedPointRegToImm("ppc-reg-to-imm-fixed-point", cl::Hidden, cl::init(true),
@@ -101,11 +99,6 @@
   // Initialize class variables.
   void initialize(MachineFunction &MFParm);
 
-  // Perform peepholes that cannot be skipped.
-  // Some peephole simplifications are required for correctness and will not
-  // be skipped even if skipFunction(MF.getFunction()) returns true.
-  void unskipableSimplifyCode(void);
-
   // Perform peepholes.
   bool simplifyCode(void);
 
@@ -132,11 +125,12 @@
   // Main entry point for this pass.
   bool runOnMachineFunction(MachineFunction &MF) override {
     initialize(MF);
-    // FIXME: This introduces another complete traversal of the instructions
-    // in the function in the common case (function is not skipped). Although
-    // this is less than ideal for compile time, this code will go away once
-    // our PC-Rel implementation is complete.
-    unskipableSimplifyCode();
+    // At this point, R2 can be only used as the TOC pointer, which should not
+    // be found when using PC Relative.
+    assert((MF.getRegInfo().use_empty(PPC::X2)
+            || !MF.getSubtarget<PPCSubtarget>().isUsingPCRelativeCalls())
+           && "R2 found in PPCMIPeephole when using PC Relative");
+
     if (skipFunction(MF.getFunction()))
       return false;
     return simplifyCode();
@@ -272,41 +266,6 @@
   TOCSaves[MI] = Keep;
 }
 
-void PPCMIPeephole::unskipableSimplifyCode(void) {
-  // If this function has no uses of R2 there is nothing to do here.
-  if(MF->getRegInfo().use_empty(PPC::X2))
-    return;
-
-  // This is only for PCRelative calls.
-  if (!MF->getSubtarget<PPCSubtarget>().isUsingPCRelativeCalls()) {
-    return;
-  }
-
-  // This function has R2 so we need to mark an implicit def for it.
-  PPCFunctionInfo *FuncInfo = MF->getInfo<PPCFunctionInfo>();
-  FuncInfo->setUsesTOCBasePtr();
-  for (MachineBasicBlock &MBB : *MF) {
-    for (MachineInstr &MI : MBB) {
-      if (MI.getOpcode() == PPC::BL8_NOTOC) {
-        // At this point the BL8_NOTOC instruction is not really safe because it
-        // assumes that the caller does not need the TOC. It will be safe
-        // later once the full PC relative implementation is complete but it is
-        // not now.
-        // Here we are looking for X2. Since this is Pre-RA the only uses of X2
-        // would indicate the use of the TOC. We want to detect all uses of the
-        // TOC. Once the work is done we should not see any uses of the TOC.
-        // TODO: Once the implementation is complete this should be turned into
-        // an assert
-        Register Reg = MF->getSubtarget<PPCSubtarget>().getTOCPointerRegister();
-        MachineOperand MO = MachineOperand::CreateReg(Reg, false, true);
-        MI.addOperand(*MF, MO);
-        MI.setDesc(TII->get(PPC::BL8_NOP));
-        ++NumX2FoundForPCRel;
-      }
-    }
-  }
-}
-
 // Perform peephole optimizations.
 bool PPCMIPeephole::simplifyCode(void) {
   bool Simplified = false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D78517.258835.patch
Type: text/x-patch
Size: 3566 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200420/4e27a253/attachment.bin>


More information about the llvm-commits mailing list