From 6fa1a2c084ea877c782987169649cac111c3d463 Mon Sep 17 00:00:00 2001 From: Hans Wennborg Date: Thu, 15 Jun 2023 15:01:36 +0200 Subject: [PATCH] [X86] Fix callee side of receiving byval args on the stack 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 implemented byval lowering for Win64. 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. Differential revision: https://reviews.llvm.org/D153020 --- llvm/lib/Target/X86/X86ISelLowering.cpp | 4 +++- llvm/test/CodeGen/X86/win64-byval.ll | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp b/llvm/lib/Target/X86/X86ISelLowering.cpp index 7197fc3..14ca38d 100644 --- a/llvm/lib/Target/X86/X86ISelLowering.cpp +++ b/llvm/lib/Target/X86/X86ISelLowering.cpp @@ -4316,9 +4316,11 @@ SDValue X86TargetLowering::LowerFormalArguments( } // 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); } diff --git a/llvm/test/CodeGen/X86/win64-byval.ll b/llvm/test/CodeGen/X86/win64-byval.ll index bb6be14..676e811 100644 --- a/llvm/test/CodeGen/X86/win64-byval.ll +++ b/llvm/test/CodeGen/X86/win64-byval.ll @@ -87,3 +87,13 @@ define void @test() { 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 +} -- 2.7.4