[PATCH] D153020: [X86] Fix callee side of receiving byval args on the stack

Hans Wennborg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 15 06:57:17 PDT 2023


hans created this revision.
hans added reviewers: rnk, loladiro, LiuChen3, craig.topper.
Herald added subscribers: pengfei, hiraditya.
Herald added a project: All.
hans requested review of this revision.
Herald added a project: LLVM.

See the discussion in https://discourse.llvm.org/t/generic-llvm-ir-windows-x64-argument-passing-issue-in-llvm-11-0-0-and-later/71350

D51842 <https://reviews.llvm.org/D51842> implemented byval lowering for Win64. D83175 <https://reviews.llvm.org/D83175> made the call lowering honor the "from now on treat this as a regular pointer" comment also when the argument gets passed on the stack. However, it didn't update the callee side.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153020

Files:
  llvm/lib/Target/X86/X86ISelLowering.cpp
  llvm/test/CodeGen/X86/win64-byval.ll


Index: llvm/test/CodeGen/X86/win64-byval.ll
===================================================================
--- llvm/test/CodeGen/X86/win64-byval.ll
+++ llvm/test/CodeGen/X86/win64-byval.ll
@@ -87,3 +87,13 @@
   call void @foo2(ptr byval({ float, double }) @G, ptr byval({ float, double }) @G, ptr byval({ float, double }) @G, ptr byval({ float, double }) @G, ptr byval({ float, double }) @G, i64 10)
   ret void
 }
+
+define i64 @receive_byval_arg_via_stack_arg(i64* byval(i64), i64* byval(i64), i64* byval(i64), i64* byval(i64), i64* byval(i64) %x) {
+; CHECK-LABEL: receive_byval_arg_via_stack_arg:
+; CHECK:       # %bb.0:
+; CHECK-NEXT:    movq {{[0-9]+}}(%rsp), %rax
+; CHECK-NEXT:    movq (%rax), %rax
+; CHECK-NEXT:    retq
+  %r = load i64, i64* %x
+  ret i64 %r
+}
Index: llvm/lib/Target/X86/X86ISelLowering.cpp
===================================================================
--- llvm/lib/Target/X86/X86ISelLowering.cpp
+++ llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -4316,9 +4316,11 @@
     }
 
     // If value is passed via pointer - do a load.
-    if (VA.getLocInfo() == CCValAssign::Indirect && !Ins[I].Flags.isByVal())
+    if (VA.getLocInfo() == CCValAssign::Indirect &&
+        !(Ins[I].Flags.isByVal() && VA.isRegLoc())) {
       ArgValue =
           DAG.getLoad(VA.getValVT(), dl, Chain, ArgValue, MachinePointerInfo());
+    }
 
     InVals.push_back(ArgValue);
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153020.531732.patch
Type: text/x-patch
Size: 1399 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230615/945dc702/attachment.bin>


More information about the llvm-commits mailing list