[llvm] r350165 - [PowerPC] Fix machine verify pass error for PATCHPOINT pseudo instruction that bad machine code

Kang Zhang via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 30 07:13:52 PST 2018


Author: zhangkang
Date: Sun Dec 30 07:13:51 2018
New Revision: 350165

URL: http://llvm.org/viewvc/llvm-project?rev=350165&view=rev
Log:
[PowerPC] Fix machine verify pass error for PATCHPOINT pseudo instruction that bad machine code

Summary:
For SDAG, we pretend patchpoints aren't special at all until we emit the code for the pseudo.
Then the verifier runs and it seems like we have a use of an undefined register (the register will 
be reserved later, but the verifier doesn't know that).

So this patch call setUsesTOCBasePtr before emit the code for the pseudo, so verifier can know 
X2 is a reserved register.

Reviewed By: nemanjai

Differential Revision: https://reviews.llvm.org/D56148

Modified:
    llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp
    llvm/trunk/test/CodeGen/PowerPC/ppc64-anyregcc-crash.ll
    llvm/trunk/test/CodeGen/PowerPC/ppc64-anyregcc.ll
    llvm/trunk/test/CodeGen/PowerPC/ppc64-patchpoint.ll
    llvm/trunk/test/CodeGen/PowerPC/ppc64-stackmap.ll

Modified: llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp?rev=350165&r1=350164&r2=350165&view=diff
==============================================================================
--- llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/PowerPC/PPCISelLowering.cpp Sun Dec 30 07:13:51 2018
@@ -5097,9 +5097,15 @@ PrepareCall(SelectionDAG &DAG, SDValue &
 
   // All calls, in both the ELF V1 and V2 ABIs, need the TOC register live
   // into the call.
-  if (isSVR4ABI && isPPC64 && !isPatchPoint) {
+  // We do need to reserve X2 to appease the verifier for the PATCHPOINT.
+  if (isSVR4ABI && isPPC64) {
     setUsesTOCBasePtr(DAG);
-    Ops.push_back(DAG.getRegister(PPC::X2, PtrVT));
+
+    // We cannot add X2 as an operand here for PATCHPOINT, because there is no
+    // way to mark dependencies as implicit here. We will add the X2 dependency
+    // in EmitInstrWithCustomInserter.
+    if (!isPatchPoint) 
+      Ops.push_back(DAG.getRegister(PPC::X2, PtrVT));
   }
 
   return CallOpc;
@@ -10346,7 +10352,6 @@ PPCTargetLowering::EmitInstrWithCustomIn
       // way to mark the dependence as implicit there, and so the stackmap code
       // will confuse it with a regular operand. Instead, add the dependence
       // here.
-      setUsesTOCBasePtr(*BB->getParent());
       MI.addOperand(MachineOperand::CreateReg(PPC::X2, false, true));
     }
 

Modified: llvm/trunk/test/CodeGen/PowerPC/ppc64-anyregcc-crash.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/PowerPC/ppc64-anyregcc-crash.ll?rev=350165&r1=350164&r2=350165&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/PowerPC/ppc64-anyregcc-crash.ll (original)
+++ llvm/trunk/test/CodeGen/PowerPC/ppc64-anyregcc-crash.ll Sun Dec 30 07:13:51 2018
@@ -1,4 +1,4 @@
-; RUN: not llc < %s -mtriple=powerpc64-unknown-linux-gnu 2>&1 | FileCheck %s
+; RUN: not llc -verify-machineinstrs < %s -mtriple=powerpc64-unknown-linux-gnu 2>&1 | FileCheck %s
 ;
 ; Check that misuse of anyregcc results in a compile time error.
 

Modified: llvm/trunk/test/CodeGen/PowerPC/ppc64-anyregcc.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/PowerPC/ppc64-anyregcc.ll?rev=350165&r1=350164&r2=350165&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/PowerPC/ppc64-anyregcc.ll (original)
+++ llvm/trunk/test/CodeGen/PowerPC/ppc64-anyregcc.ll Sun Dec 30 07:13:51 2018
@@ -1,4 +1,4 @@
-; RUN: llc < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs < %s | FileCheck %s
 target datalayout = "E-m:e-i64:64-n32:64"
 target triple = "powerpc64-unknown-linux-gnu"
 

Modified: llvm/trunk/test/CodeGen/PowerPC/ppc64-patchpoint.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/PowerPC/ppc64-patchpoint.ll?rev=350165&r1=350164&r2=350165&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/PowerPC/ppc64-patchpoint.ll (original)
+++ llvm/trunk/test/CodeGen/PowerPC/ppc64-patchpoint.ll Sun Dec 30 07:13:51 2018
@@ -1,7 +1,7 @@
-; RUN: llc                             < %s | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-BE
-; RUN: llc -fast-isel -fast-isel-abort=1 < %s | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-BE
-; RUN: llc -mtriple=powerpc64le-unknown-linux-gnu                             < %s | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-LE
-; RUN: llc -mtriple=powerpc64le-unknown-linux-gnu -fast-isel -fast-isel-abort=1 < %s | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-LE
+; RUN: llc -verify-machineinstrs < %s | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-BE
+; RUN: llc -fast-isel -fast-isel-abort=1 -verify-machineinstrs < %s | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-BE
+; RUN: llc -mtriple=powerpc64le-unknown-linux-gnu -verify-machineinstrs < %s | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-LE
+; RUN: llc -mtriple=powerpc64le-unknown-linux-gnu -fast-isel -fast-isel-abort=1 -verify-machineinstrs < %s | FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-LE
 
 target triple = "powerpc64-unknown-linux-gnu"
 

Modified: llvm/trunk/test/CodeGen/PowerPC/ppc64-stackmap.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/PowerPC/ppc64-stackmap.ll?rev=350165&r1=350164&r2=350165&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/PowerPC/ppc64-stackmap.ll (original)
+++ llvm/trunk/test/CodeGen/PowerPC/ppc64-stackmap.ll Sun Dec 30 07:13:51 2018
@@ -1,4 +1,4 @@
-; RUN: llc                             < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs < %s | FileCheck %s
 ;
 ; Note: Print verbose stackmaps using -debug-only=stackmaps.
 




More information about the llvm-commits mailing list