From d35d48c9b0f605892a18055d5a5bf52d57d022b3 Mon Sep 17 00:00:00 2001 From: Tim Northover Date: Thu, 2 Mar 2017 15:34:18 +0000 Subject: [PATCH] GlobalISel: record correct stack usage for signext parameters. The CallingConv.td rules allocate 8 bytes for these kinds of arguments on AAPCS targets, but we were only recording the smaller amount. The difference is theoretical on AArch64 because we don't actually store more than the smaller amount, but it's still much better to have these two components in agreement. Based on Diana Picus's ARM equivalent patch (where it matters a lot more). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@296754 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/AArch64/AArch64CallLowering.cpp | 10 +++++++--- test/CodeGen/AArch64/GlobalISel/arm64-callingconv.ll | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/Target/AArch64/AArch64CallLowering.cpp b/lib/Target/AArch64/AArch64CallLowering.cpp index 6148359da81..b1b98708753 100644 --- a/lib/Target/AArch64/AArch64CallLowering.cpp +++ b/lib/Target/AArch64/AArch64CallLowering.cpp @@ -136,7 +136,6 @@ struct OutgoingArgHandler : public CallLowering::ValueHandler { MIRBuilder.buildGEP(AddrReg, SPReg, OffsetReg); MPO = MachinePointerInfo::getStack(MIRBuilder.getMF(), Offset); - StackSize = std::max(StackSize, Size + Offset); return AddrReg; } @@ -158,9 +157,14 @@ struct OutgoingArgHandler : public CallLowering::ValueHandler { CCValAssign::LocInfo LocInfo, const CallLowering::ArgInfo &Info, CCState &State) override { + bool Res; if (Info.IsFixed) - return AssignFn(ValNo, ValVT, LocVT, LocInfo, Info.Flags, State); - return AssignFnVarArg(ValNo, ValVT, LocVT, LocInfo, Info.Flags, State); + Res = AssignFn(ValNo, ValVT, LocVT, LocInfo, Info.Flags, State); + else + Res = AssignFnVarArg(ValNo, ValVT, LocVT, LocInfo, Info.Flags, State); + + StackSize = State.getNextStackOffset(); + return Res; } MachineInstrBuilder MIB; diff --git a/test/CodeGen/AArch64/GlobalISel/arm64-callingconv.ll b/test/CodeGen/AArch64/GlobalISel/arm64-callingconv.ll index 350ae0e4c08..59b9bb49f0e 100644 --- a/test/CodeGen/AArch64/GlobalISel/arm64-callingconv.ll +++ b/test/CodeGen/AArch64/GlobalISel/arm64-callingconv.ll @@ -80,3 +80,17 @@ define void @test_varargs() { call void(i32, double, i64, ...) @varargs(i32 42, double 1.0, i64 12, i8 3, i16 1, i32 4, float 1.0, double 2.0) ret void } + +; signext/zeroext parameters on the stack: not part of any real ABI as far as I +; know, but ELF currently allocates 8 bytes for a signext parameter on the +; stack. The ADJCALLSTACK ops should reflect this, even if the difference is +; theoretical. +declare void @stack_ext_needed([8 x i64], i8 signext %in) +; CHECK-LABEL: name: test_stack_ext_needed +; CHECK: ADJCALLSTACKDOWN 8 +; CHECK: BL @stack_ext_needed +; CHECK: ADJCALLSTACKUP 8 +define void @test_stack_ext_needed() { + call void @stack_ext_needed([8 x i64] undef, i8 signext 42) + ret void +} -- 2.11.0