Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

[PowerPC] Fix the calling convention for i1 arguments on PPC32 #127

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions lib/Target/PowerPC/PPCISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3510,9 +3510,14 @@ SDValue PPCTargetLowering::LowerFormalArguments_32SVR4(
// Argument stored in memory.
assert(VA.isMemLoc());

// Get the extended size of the argument type in stack
unsigned ArgSize = VA.getLocVT().getStoreSize();
int FI = MFI.CreateFixedObject(ArgSize, VA.getLocMemOffset(),
isImmutable);
// Get the actual size of the argument type
unsigned ObjSize = VA.getValVT().getStoreSize();
unsigned ArgOffset = VA.getLocMemOffset();
// Stack objects in PPC32 are right justified.
ArgOffset += ArgSize - ObjSize;
int FI = MFI.CreateFixedObject(ArgSize, ArgOffset, isImmutable);

// Create load nodes to retrieve arguments from the stack.
SDValue FIN = DAG.getFrameIndex(FI, PtrVT);
Expand Down Expand Up @@ -5467,10 +5472,15 @@ SDValue PPCTargetLowering::LowerCall_32SVR4(
Arg = PtrOff;
}

if (VA.isRegLoc()) {
if (Arg.getValueType() == MVT::i1)
Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, MVT::i32, Arg);
// When useCRBits() is true, there can be i1 arguments.
// It is because getRegisterType(MVT::i1) => MVT::i1,
// and for other integer types getRegisterType() => MVT::i32.
// Extend i1 and ensure callee will get i32.
if (Arg.getValueType() == MVT::i1)
Arg = DAG.getNode(Flags.isSExt() ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND,
dl, MVT::i32, Arg);

if (VA.isRegLoc()) {
seenFloatArg |= VA.getLocVT().isFloatingPoint();
// Put argument in a physical register.
RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
Expand Down
24 changes: 24 additions & 0 deletions test/CodeGen/PowerPC/ppc32-i1-stack-arguments-abi-bug.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
; RUN: llc -verify-machineinstrs < %s -mcpu=ppc32 -mattr=+crbits | FileCheck %s
target triple = "powerpc-unknown-linux-gnu"

define void @check_callee(
i32, i32, i32, i32,
i32, i32, i32, i32,
i1 zeroext %s1
) {
call void @check_caller(
i32 9, i32 9, i32 9, i32 9,
i32 9, i32 9, i32 9, i32 9,
i1 zeroext %s1)
ret void
}

; CHECK-LABEL: @check_callee
; CHECK: lbz {{[0-9]+}}, 27(1)
; CHECK: stw {{[0-9]+}}, 8(1)

declare void @check_caller(
i32, i32, i32, i32,
i32, i32, i32, i32,
i1 zeroext
)