[PATCH] Statepoint: Fix handling of Far Immediate calls
Swaroop Sridhar
Swaroop.Sridhar at microsoft.com
Wed Jun 3 18:39:44 PDT 2015
Hi sanjoy, reames, pgavlin,
gc.statepoint intrinsics with a far immediate target was lowered incorrectly as a pc-rel32 call.
For example, for
%safepoint_token = call i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* inttoptr (i64 140727162896504 to void ()*), i32 0, i32 0, i32 0, i32 0)
the CALL instruction generated was:
callq 140727162896504
This change fixes the problem, so that an indirect call via a scratch register is correctly generated:
movabsq $140727162896504, %rax
callq *%rax
In lowerCallFromStatepoint(), the callee-target was modified and represented as a "TargetConstant" node, rather than a "Constant" node.
Undoing this modification enabled LowerCall() to generate the correct CALL instruction.
http://reviews.llvm.org/D10232
Files:
lib/CodeGen/SelectionDAG/StatepointLowering.cpp
test/CodeGen/X86/statepoint-far-call.ll
Index: lib/CodeGen/SelectionDAG/StatepointLowering.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/StatepointLowering.cpp
+++ lib/CodeGen/SelectionDAG/StatepointLowering.cpp
@@ -238,17 +238,6 @@
SDValue ActualCallee = Builder.getValue(ISP.getActualCallee());
- // Handle immediate and symbolic callees.
- if (auto *ConstCallee = dyn_cast<ConstantSDNode>(ActualCallee.getNode()))
- ActualCallee = Builder.DAG.getIntPtrConstant(ConstCallee->getZExtValue(),
- Builder.getCurSDLoc(),
- /*isTarget=*/true);
- else if (auto *SymbolicCallee =
- dyn_cast<GlobalAddressSDNode>(ActualCallee.getNode()))
- ActualCallee = Builder.DAG.getTargetGlobalAddress(
- SymbolicCallee->getGlobal(), SDLoc(SymbolicCallee),
- SymbolicCallee->getValueType(0));
-
assert(CS.getCallingConv() != CallingConv::AnyReg &&
"anyregcc is not supported on statepoints!");
Index: test/CodeGen/X86/statepoint-far-call.ll
===================================================================
--- /dev/null
+++ test/CodeGen/X86/statepoint-far-call.ll
@@ -0,0 +1,22 @@
+; RUN: llc < %s | FileCheck %s
+; Test to check that Statepoints with X64 far-immediate targets
+; are lowered correctly to an indirect call via a scratch register.
+
+target datalayout = "e-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-win64"
+
+define void @test_far_call() gc "statepoint-example" {
+; CHECK-LABEL: test_far_call
+; CHECK: pushq %rax
+; CHECK: movabsq $140727162896504, %rax
+; CHECK: callq *%rax
+; CHECK: popq %rax
+; CHECK: retq
+
+entry:
+ %safepoint_token = call i32 (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 0, void ()* inttoptr (i64 140727162896504 to void ()*), i32 0, i32 0, i32 0, i32 0)
+ ret void
+}
+
+declare i32 @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
+
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D10232.27080.patch
Type: text/x-patch
Size: 2033 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150604/b0a3b820/attachment.bin>
More information about the llvm-commits
mailing list