[PATCH] D34347: [PowerPC] fix potential verification error on __tls_get_addr

Hiroshi Inoue via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 19 05:21:54 PDT 2017


inouehrs created this revision.

This patch fixes a verification error with -verify-machineinstrs while expanding __tls_get_addr by not creating ADJCALLSTACKUP and ADJCALLSTACKDOWN if there is another ADJCALLSTACKUP in this basic block since nesting ADJCALLSTACKUP/ADJCALLSTACKDOWN is not allowed.

Here, ADJCALLSTACKUP and ADJCALLSTACKDOWN are created as a fence for instruction scheduling to avoid  _tls_get_addr is scheduled before mflr in the prologue (https://bugs.llvm.org//show_bug.cgi?id=25839). So if another ADJCALLSTACKUP exists before _tls_get_addr, we do not need to create a new ADJCALLSTACKUP.

With this patch and two previous patches (https://reviews.llvm.org/D34208 and https://reviews.llvm.org/D34209), I successfully compiled LLVM+CLANG with -verify-machineinstrs on ppc64le Linux.


https://reviews.llvm.org/D34347

Files:
  lib/Target/PowerPC/PPCTLSDynamicCall.cpp


Index: lib/Target/PowerPC/PPCTLSDynamicCall.cpp
===================================================================
--- lib/Target/PowerPC/PPCTLSDynamicCall.cpp
+++ lib/Target/PowerPC/PPCTLSDynamicCall.cpp
@@ -52,11 +52,17 @@
 protected:
     bool processBlock(MachineBasicBlock &MBB) {
       bool Changed = false;
+      bool NeedFence = true;
       bool Is64Bit = MBB.getParent()->getSubtarget<PPCSubtarget>().isPPC64();
 
       for (MachineBasicBlock::iterator I = MBB.begin(), IE = MBB.end();
            I != IE;) {
         MachineInstr &MI = *I;
+        if (MI.getOpcode() == PPC::ADJCALLSTACKDOWN) {
+          NeedFence = false;
+          ++I;
+          continue;
+        }
 
         if (MI.getOpcode() != PPC::ADDItlsgdLADDR &&
             MI.getOpcode() != PPC::ADDItlsldLADDR &&
@@ -99,8 +105,9 @@
         // Don't really need to save data to the stack - the clobbered
         // registers are already saved when the SDNode (e.g. PPCaddiTlsgdLAddr)
         // gets translated to the pseudo instruction (e.g. ADDItlsgdLADDR).
-        BuildMI(MBB, I, DL, TII->get(PPC::ADJCALLSTACKDOWN)).addImm(0)
-                                                            .addImm(0);
+        if (NeedFence)
+          BuildMI(MBB, I, DL, TII->get(PPC::ADJCALLSTACKDOWN)).addImm(0)
+                                                              .addImm(0);
 
         // Expand into two ops built prior to the existing instruction.
         MachineInstr *Addi = BuildMI(MBB, I, DL, TII->get(Opc1), GPR3)
@@ -116,7 +123,8 @@
                               .addReg(GPR3));
         Call->addOperand(MI.getOperand(3));
 
-        BuildMI(MBB, I, DL, TII->get(PPC::ADJCALLSTACKUP)).addImm(0).addImm(0);
+        if (NeedFence)
+          BuildMI(MBB, I, DL, TII->get(PPC::ADJCALLSTACKUP)).addImm(0).addImm(0);
 
         BuildMI(MBB, I, DL, TII->get(TargetOpcode::COPY), OutReg)
           .addReg(GPR3);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34347.103019.patch
Type: text/x-patch
Size: 1911 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170619/e73c5739/attachment.bin>


More information about the llvm-commits mailing list