Skip to content

Commit

Permalink
[PowerPC] Fix lowering of byval parameters for sizes greater than 8 b…
Browse files Browse the repository at this point in the history
…ytes.

To store a byval parameter the existing code would store as many 8 byte elements
as was required to store the full size of the byval parameter.
For example, a paramter of size 16 would store two element of 8 bytes.
A paramter of size 12 would also store two elements of 8 bytes.
This would sometimes store too many bytes as the size of the paramter is not
always a factor of 8.

This patch fixes that issue and now byval paramters are stored with the correct
number of bytes.

Reviewed By: nemanjai, #powerpc, quinnp, amyk

Differential Revision: https://reviews.llvm.org/D121430
  • Loading branch information
stefanp-ibm committed Mar 31, 2022
1 parent 33e1971 commit 585c85a
Show file tree
Hide file tree
Showing 3 changed files with 283 additions and 85 deletions.
14 changes: 10 additions & 4 deletions llvm/lib/Target/PowerPC/PPCISelLowering.cpp
Expand Up @@ -4431,8 +4431,11 @@ SDValue PPCTargetLowering::LowerFormalArguments_64SVR4(
SDValue Off = DAG.getConstant(j, dl, PtrVT);
Addr = DAG.getNode(ISD::ADD, dl, Off.getValueType(), Addr, Off);
}
SDValue Store = DAG.getStore(Val.getValue(1), dl, Val, Addr,
MachinePointerInfo(&*FuncArg, j));
unsigned StoreSizeInBits = std::min(PtrByteSize, (ObjSize - j)) * 8;
EVT ObjType = EVT::getIntegerVT(*DAG.getContext(), StoreSizeInBits);
SDValue Store =
DAG.getTruncStore(Val.getValue(1), dl, Val, Addr,
MachinePointerInfo(&*FuncArg, j), ObjType);
MemOps.push_back(Store);
++GPR_idx;
}
Expand Down Expand Up @@ -6269,8 +6272,11 @@ SDValue PPCTargetLowering::LowerCall_64SVR4(
SDValue Const = DAG.getConstant(j, dl, PtrOff.getValueType());
SDValue AddArg = DAG.getNode(ISD::ADD, dl, PtrVT, Arg, Const);
if (GPR_idx != NumGPRs) {
SDValue Load =
DAG.getLoad(PtrVT, dl, Chain, AddArg, MachinePointerInfo());
unsigned LoadSizeInBits = std::min(PtrByteSize, (Size - j)) * 8;
EVT ObjType = EVT::getIntegerVT(*DAG.getContext(), LoadSizeInBits);
SDValue Load = DAG.getExtLoad(ISD::EXTLOAD, dl, PtrVT, Chain, AddArg,
MachinePointerInfo(), ObjType);

MemOpChains.push_back(Load.getValue(1));
RegsToPass.push_back(std::make_pair(GPR[GPR_idx++], Load));
ArgOffset += PtrByteSize;
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/CodeGen/PowerPC/byval.ll
Expand Up @@ -22,7 +22,7 @@ define dso_local i32 @bar() {
; CHECK-NEXT: addi 3, 1, 40
; CHECK-NEXT: bl foo
; CHECK-NEXT: nop
; CHECK-NEXT: ld 7, 72(1)
; CHECK-NEXT: lwz 7, 72(1)
; CHECK-NEXT: ld 6, 64(1)
; CHECK-NEXT: ld 5, 56(1)
; CHECK-NEXT: ld 4, 48(1)
Expand Down

0 comments on commit 585c85a

Please sign in to comment.