[llvm] r262762 - [X86] Fix the lowering of setjmp intrinsic on i386.

Quentin Colombet via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 4 16:31:04 PST 2016


Author: qcolombet
Date: Fri Mar  4 18:31:04 2016
New Revision: 262762

URL: http://llvm.org/viewvc/llvm-project?rev=262762&view=rev
Log:
[X86] Fix the lowering of setjmp intrinsic on i386.
When the lowering of the setjmp intrinsic requires
a global base pointer to be set, make sure such pointer
gets defined by the CGBR pass.

This fixes PR26742.

Added:
    llvm/trunk/test/CodeGen/X86/i386-setjmp-pic.ll
Modified:
    llvm/trunk/lib/Target/X86/X86ISelLowering.cpp

Modified: llvm/trunk/lib/Target/X86/X86ISelLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86ISelLowering.cpp?rev=262762&r1=262761&r2=262762&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86ISelLowering.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86ISelLowering.cpp Fri Mar  4 18:31:04 2016
@@ -18322,6 +18322,16 @@ SDValue X86TargetLowering::LowerEH_RETUR
 SDValue X86TargetLowering::lowerEH_SJLJ_SETJMP(SDValue Op,
                                                SelectionDAG &DAG) const {
   SDLoc DL(Op);
+  // If the subtarget is not 64bit, we may need the global base reg
+  // after isel expand pseudo, i.e., after CGBR pass ran.
+  // Therefore, ask for the GlobalBaseReg now, so that the pass
+  // inserts the code for us in case we need it.
+  // Otherwise, we will end up in a situation where we will
+  // reference a virtual register that is not defined!
+  if (!Subtarget.is64Bit()) {
+    const X86InstrInfo *TII = Subtarget.getInstrInfo();
+    (void)TII->getGlobalBaseReg(&DAG.getMachineFunction());
+  }
   return DAG.getNode(X86ISD::EH_SJLJ_SETJMP, DL,
                      DAG.getVTList(MVT::i32, MVT::Other),
                      Op.getOperand(0), Op.getOperand(1));

Added: llvm/trunk/test/CodeGen/X86/i386-setjmp-pic.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/i386-setjmp-pic.ll?rev=262762&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/i386-setjmp-pic.ll (added)
+++ llvm/trunk/test/CodeGen/X86/i386-setjmp-pic.ll Fri Mar  4 18:31:04 2016
@@ -0,0 +1,23 @@
+; RUN: llc  -verify-machineinstrs -relocation-model=pic %s -o - | FileCheck %s
+target datalayout = "e-m:o-p:32:32-f64:32:64-f80:128-n8:16:32-S128"
+target triple = "i386-apple-macosx"
+
+; Check that the register used as base pointer for setjmp
+; is properly initialized.
+; The test used to fail with the machine verifier complaining
+; that the global base pointer is not initialized.
+; PR26742.
+;
+; CHECK: test:
+; CHECK: calll [[BP_SETUP_LABEL:L[$0-9a-zA-Z_-]+]]
+; CHECK: [[BP_SETUP_LABEL]]:
+; CHECK-NEXT: popl [[BP:%[a-z]+]]
+;
+; CHECK: leal [[BLOCK_ADDR:LBB[$0-9a-zA-Z_-]+]]-[[BP_SETUP_LABEL]]([[BP]]),
+define i32 @test(i8* %tmp) {
+entry:
+  %tmp9 = call i32 @llvm.eh.sjlj.setjmp(i8* %tmp)
+  ret i32 %tmp9
+}
+
+declare i32 @llvm.eh.sjlj.setjmp(i8*)




More information about the llvm-commits mailing list