Skip to content

Commit 7400865

Browse files
[PowerPC] Fix issue with lowering byval parameters.
Lowering of byval parameters with sizes that are not represented by a single store require multiple stores to properly address the correct size of the parameter. Sizes that cannot be done with a single store are 3 bytes, 5 bytes, 6 bytes, 7 bytes. It is not correct to simply perform an 8 byte store and for these elements because then the store would be larger than the element and alias analysis would assume that this is undefined behaivour and return NoAlias for them. This patch adds the correct stores so that the size of the store is not larger than the size of the element. Reviewed By: nemanjai, #powerpc Differential Revision: https://reviews.llvm.org/D108795
1 parent 4be7f48 commit 7400865

File tree

4 files changed

+189
-101
lines changed

4 files changed

+189
-101
lines changed

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4369,21 +4369,10 @@ SDValue PPCTargetLowering::LowerFormalArguments_64SVR4(
43694369
unsigned VReg = MF.addLiveIn(GPR[GPR_idx++], &PPC::G8RCRegClass);
43704370
FuncInfo->addLiveInAttr(VReg, Flags);
43714371
SDValue Val = DAG.getCopyFromReg(Chain, dl, VReg, PtrVT);
4372-
SDValue Store;
4373-
4374-
if (ObjSize==1 || ObjSize==2 || ObjSize==4) {
4375-
EVT ObjType = (ObjSize == 1 ? MVT::i8 :
4376-
(ObjSize == 2 ? MVT::i16 : MVT::i32));
4377-
Store = DAG.getTruncStore(Val.getValue(1), dl, Val, Arg,
4378-
MachinePointerInfo(&*FuncArg), ObjType);
4379-
} else {
4380-
// For sizes that don't fit a truncating store (3, 5, 6, 7),
4381-
// store the whole register as-is to the parameter save area
4382-
// slot.
4383-
Store = DAG.getStore(Val.getValue(1), dl, Val, FIN,
4384-
MachinePointerInfo(&*FuncArg));
4385-
}
4386-
4372+
EVT ObjType = EVT::getIntegerVT(*DAG.getContext(), ObjSize * 8);
4373+
SDValue Store =
4374+
DAG.getTruncStore(Val.getValue(1), dl, Val, Arg,
4375+
MachinePointerInfo(&*FuncArg), ObjType);
43874376
MemOps.push_back(Store);
43884377
}
43894378
// Whether we copied from a register or not, advance the offset

llvm/test/CodeGen/PowerPC/jaggedstructs.ll

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,21 @@ entry:
1818
ret void
1919
}
2020

21-
; CHECK-DAG: std 3, 160(1)
22-
; CHECK-DAG: std 6, 184(1)
23-
; CHECK-DAG: std 5, 176(1)
24-
; CHECK-DAG: std 4, 168(1)
21+
; CHECK-LABEL: test
22+
; CHECK: stb 6, 191(1)
23+
; CHECK: rldicl 7, 6, 56, 8
24+
; CHECK: sth 7, 189(1)
25+
; CHECK: rldicl 6, 6, 40, 24
26+
; CHECK: stw 6, 185(1)
27+
; CHECK: sth 5, 182(1)
28+
; CHECK: rldicl 5, 5, 48, 16
29+
; CHECK: stw 5, 178(1)
30+
; CHECK: stb 4, 175(1)
31+
; CHECK: rldicl 4, 4, 56, 8
32+
; CHECK: stw 4, 171(1)
33+
; CHECK: stb 3, 167(1)
34+
; CHECK: rldicl 3, 3, 56, 8
35+
; CHECK: sth 3, 165(1)
2536
; CHECK-DAG: lbz {{[0-9]+}}, 167(1)
2637
; CHECK-DAG: lhz {{[0-9]+}}, 165(1)
2738
; CHECK-DAG: stb {{[0-9]+}}, 55(1)

0 commit comments

Comments
 (0)