[PATCH] D53889: [CodeGen] Prefer static frame index for STATEPOINT liveness args

Cherry Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 30 13:33:21 PDT 2018


cherry created this revision.
cherry added reviewers: thanm, niravd.
Herald added subscribers: llvm-commits, arphaman.

If a given liveness arg of STATEPOINT is at a fixed frame index
(e.g. a function argument passed on stack), prefer to use this
fixed location even the address is also in a register. If we use
the register it will generate a spill, which is not necessary
since the fixed frame index can be directly recorded in the stack
map.


Repository:
  rL LLVM

https://reviews.llvm.org/D53889

Files:
  lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
  lib/CodeGen/SelectionDAG/StatepointLowering.cpp
  test/CodeGen/X86/statepoint-stack-usage.ll


Index: test/CodeGen/X86/statepoint-stack-usage.ll
===================================================================
--- test/CodeGen/X86/statepoint-stack-usage.ll
+++ test/CodeGen/X86/statepoint-stack-usage.ll
@@ -133,4 +133,27 @@
 
 declare i32 @"personality_function"()
 
+; Test that function arguments at fixed stack offset
+; can be directly encoded in the stack map, without
+; spilling.
+%struct = type { i64, i64, i64 }
+
+declare void @use(%struct*)
+
+define void @test_fixed_arg(%struct* byval %x) gc "statepoint-example" {
+; CHECK-LABEL: test_fixed_arg
+; CHECK: leaq 16(%rsp), %rdi
+; Should not spill fixed stack address.
+; CHECK-NOT: movq %rdi, (%rsp)
+; CHECK: callq
+entry:
+  br label %bb
+
+bb:                                               ; preds = %entry
+  %statepoint_token = call token (i64, i32, void (%struct*)*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidp0s_structsf(i64 0, i32 0, void (%struct*)* @use, i32 1, i32 0, %struct* %x, i32 0, i32 1, %struct* %x)
+  ret void
+}
+
+declare token @llvm.experimental.gc.statepoint.p0f_isVoidp0s_structsf(i64, i32, void (%struct*)*, i32, i32, ...)
+
 attributes #1 = { uwtable }
Index: lib/CodeGen/SelectionDAG/StatepointLowering.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/StatepointLowering.cpp
+++ lib/CodeGen/SelectionDAG/StatepointLowering.cpp
@@ -522,7 +522,14 @@
   // The vm state arguments are lowered in an opaque manner.  We do not know
   // what type of values are contained within.
   for (const Value *V : SI.DeoptState) {
-    SDValue Incoming = Builder.getValue(V);
+    SDValue Incoming;
+    // If the argument is a static frame index, use it without spilling.
+    if (isa<AllocaInst>(V) ||
+        (isa<Argument>(V) &&
+         Builder.FuncInfo.getArgumentFrameIndex(cast<Argument>(V)) != INT_MAX))
+      Incoming = Builder.getNonRegisterValue(V);
+    else
+      Incoming = Builder.getValue(V);
     const bool LiveInValue = LiveInDeopt && !isGCValue(V);
     lowerIncomingStatepointValue(Incoming, LiveInValue, Ops, Builder);
   }
Index: lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
+++ lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
@@ -1376,6 +1376,14 @@
                                TLI.getFrameIndexTy(DAG.getDataLayout()));
   }
 
+  // If this is a function argument at a static frame index, generate it as
+  // the frame index.
+  if (const Argument *Arg = dyn_cast<Argument>(V)) {
+    int FI = FuncInfo.getArgumentFrameIndex(Arg);
+    if (FI != INT_MAX)
+      return DAG.getFrameIndex(FI, TLI.getFrameIndexTy(DAG.getDataLayout()));
+  }
+
   // If this is an instruction which fast-isel has deferred, select it now.
   if (const Instruction *Inst = dyn_cast<Instruction>(V)) {
     unsigned InReg = FuncInfo.InitializeRegForValue(Inst);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53889.171776.patch
Type: text/x-patch
Size: 2952 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181030/4ee05f75/attachment.bin>


More information about the llvm-commits mailing list