[PATCH] D67147: Remove the additional constant which requires an extra register for statepoint lowering.

zuojian lin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 4 00:47:43 PDT 2019


linzj created this revision.
linzj added a reviewer: sanjoy.
Herald added subscribers: llvm-commits, hiraditya.
Herald added a project: LLVM.

The newly-created constant zero will need an extra register to hold it
in the current statepoint lowering implementation. Remove it if there exists
one.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D67147

Files:
  llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp
  llvm/test/CodeGen/X86/statepoint-no-extra-const.ll


Index: llvm/test/CodeGen/X86/statepoint-no-extra-const.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/X86/statepoint-no-extra-const.ll
@@ -0,0 +1,21 @@
+define i8 addrspace(1)* @no_extra_const(i8 addrspace(1)* %obj) gc "statepoint-example" {
+; CHECK-LABEL:   no_extra_const:
+; CHECK:	       .cfi_startproc
+; CHECK-NEXT:    # %bb.0:                                # %entry
+; CHECK-NEXT:    pushq	%rax
+; CHECK-NEXT:    .cfi_def_cfa_offset 16
+; CHECK-NEXT:    movq	%rdi, (%rsp)
+; CHECK-NEXT:    nopl	8(%rax)
+; CHECK-NEXT:    .Ltmp0:
+; CHECK-NEXT:    movq	(%rsp), %rax
+; CHECK-NEXT:    popq	%rcx
+; CHECK-NEXT:    .cfi_def_cfa_offset 8
+; CHECK-NEXT:    retq
+entry:
+  %safepoint_token = call token (i64, i32, void ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_isVoidf(i64 0, i32 4, void ()* null, i32 0, i32 0, i32 0, i32 0, i8 addrspace(1)* %obj)
+  %obj.relocated = call coldcc i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token %safepoint_token, i32 7, i32 7) ; (%obj, %obj)
+  ret i8 addrspace(1)* %obj.relocated
+}
+
+declare token @llvm.experimental.gc.statepoint.p0f_isVoidf(i64, i32, void ()*, i32, i32, ...)
+declare i8 addrspace(1)* @llvm.experimental.gc.relocate.p1i8(token, i32, i32)
Index: llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp
===================================================================
--- llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp
+++ llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp
@@ -858,7 +858,17 @@
     const auto &DL = DAG.getDataLayout();
 
     unsigned AS = ISP.getCalledValue()->getType()->getPointerAddressSpace();
-    ActualCallee = DAG.getConstant(0, getCurSDLoc(), TLI.getPointerTy(DL, AS));
+    // Don't generate an extra constant if there is already one.
+    // Or it will ends up an extra MOV Constant to PhyReg instruction.
+    if (auto *ConstCallee =
+            dyn_cast<ConstantSDNode>(getValue(ISP.getCalledValue()))) {
+      ActualCallee =
+          DAG.getIntPtrConstant(ConstCallee->getZExtValue(), getCurSDLoc(),
+                                /*isTarget=*/true);
+    } else {
+      ActualCallee =
+          DAG.getConstant(0, getCurSDLoc(), TLI.getPointerTy(DL, AS));
+    }
   } else {
     ActualCallee = getValue(ISP.getCalledValue());
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D67147.218604.patch
Type: text/x-patch
Size: 2326 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190904/eaf82bea/attachment.bin>


More information about the llvm-commits mailing list