Skip to content

Commit 9bd90e7

Browse files
committed
using UNDEF SDNODE instead of Constant SDNODE for unused arg
1 parent 79e788d commit 9bd90e7

File tree

2 files changed

+158
-13
lines changed

2 files changed

+158
-13
lines changed

llvm/lib/Target/PowerPC/PPCISelLowering.cpp

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7706,20 +7706,22 @@ SDValue PPCTargetLowering::LowerCall_AIX(
77067706
CCValAssign &VA = ArgLocs[I++];
77077707
const MVT LocVT = VA.getLocVT();
77087708
const MVT ValVT = VA.getValVT();
7709-
7710-
switch (VA.getLocInfo()) {
7711-
default:
7712-
report_fatal_error("Unexpected argument extension type.");
7713-
case CCValAssign::Full:
7714-
break;
7715-
case CCValAssign::ZExt:
7716-
Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg);
7717-
break;
7718-
case CCValAssign::SExt:
7719-
Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg);
7720-
break;
7709+
if (Arg.getOpcode() == ISD::UNDEF)
7710+
Arg = DAG.getUNDEF(VA.getLocVT());
7711+
else {
7712+
switch (VA.getLocInfo()) {
7713+
default:
7714+
report_fatal_error("Unexpected argument extension type.");
7715+
case CCValAssign::Full:
7716+
break;
7717+
case CCValAssign::ZExt:
7718+
Arg = DAG.getNode(ISD::ZERO_EXTEND, dl, VA.getLocVT(), Arg);
7719+
break;
7720+
case CCValAssign::SExt:
7721+
Arg = DAG.getNode(ISD::SIGN_EXTEND, dl, VA.getLocVT(), Arg);
7722+
break;
7723+
}
77217724
}
7722-
77237725
if (VA.isRegLoc() && !VA.needsCustom()) {
77247726
RegsToPass.push_back(std::make_pair(VA.getLocReg(), Arg));
77257727
continue;
@@ -18829,6 +18831,12 @@ bool PPCTargetLowering::splitValueIntoRegisterParts(
1882918831
SelectionDAG &DAG, const SDLoc &DL, SDValue Val, SDValue *Parts,
1883018832
unsigned NumParts, MVT PartVT, std::optional<CallingConv::ID> CC) const {
1883118833
EVT ValVT = Val.getValueType();
18834+
if (Val.getOpcode() == ISD::UNDEF) {
18835+
for (unsigned i = 0; i <= NumParts; i++)
18836+
Parts[i] = DAG.getUNDEF(PartVT);
18837+
return true;
18838+
}
18839+
1883218840
// If we are splitting a scalar integer into f64 parts (i.e. so they
1883318841
// can be placed into VFRC registers), we need to zero extend and
1883418842
// bitcast the values. This will ensure the value is placed into a
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
;; Test the unused argument are converted to ISD::UNDEF SDNode.
2+
3+
; RUN: llc -verify-machineinstrs -mtriple powerpc-ibm-aix-xcoff -debug-only=isel \
4+
; RUN: %s -o - 2>&1 >/dev/null | FileCheck --check-prefix=CHECK32 %s
5+
6+
; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff -debug-only=isel \
7+
; RUN: %s -o - 2>&1 >/dev/null | FileCheck --check-prefix=CHECK64 %s
8+
9+
define void @bar32(i32 zeroext %var1, i32 noundef zeroext %var2) local_unnamed_addr {
10+
entry:
11+
tail call void @foo32(i32 noundef zeroext %var2)
12+
ret void
13+
}
14+
15+
declare void @foo32(i32 noundef zeroext) local_unnamed_addr
16+
17+
define void @test32() local_unnamed_addr {
18+
entry:
19+
tail call void @bar32(i32 zeroext poison, i32 noundef zeroext 255)
20+
ret void
21+
}
22+
23+
; CHECK32: Initial selection DAG: %bb.0 'test32:entry'
24+
; CHECK32-DAG: SelectionDAG has 18 nodes:
25+
; CHECK32-DAG: t1: i32 = GlobalAddress<ptr @bar32> 0
26+
; CHECK32-DAG: t7: i32 = Register $r1
27+
; CHECK32-DAG: t0: ch,glue = EntryToken
28+
; CHECK32-DAG: t6: ch,glue = callseq_start t0, TargetConstant:i32<56>, TargetConstant:i32<0>
29+
; CHECK32-DAG: t9: ch,glue = CopyToReg t6, Register:i32 $r3, undef:i32
30+
; CHECK32-DAG: t11: ch,glue = CopyToReg t9, Register:i32 $r4, Constant:i32<255>, t9:1
31+
; CHECK32-DAG: t15: ch,glue = PPCISD::CALL_NOP t11, MCSymbol:i32, Register:i32 $r3, Register:i32 $r4, Register:i32 $r2, RegisterMask:Untyped, t11:1
32+
; CHECK32-DAG: t16: ch,glue = callseq_end t15, TargetConstant:i32<56>, TargetConstant:i32<0>, t15:1
33+
; CHECK32-DAG: t17: ch = PPCISD::RET_GLUE t16
34+
35+
; CHECK64: Initial selection DAG: %bb.0 'test32:entry'
36+
; CHECK64-DAG: SelectionDAG has 20 nodes:
37+
; CHECK64-DAG: t1: i64 = GlobalAddress<ptr @bar32> 0
38+
; CHECK64-DAG: t2: i32 = undef
39+
; CHECK64-DAG: t3: i32 = Constant<255>
40+
; CHECK64-DAG: t7: i64 = Register $x1
41+
; CHECK64-DAG: t0: ch,glue = EntryToken
42+
; CHECK64-DAG: t6: ch,glue = callseq_start t0, TargetConstant:i64<112>, TargetConstant:i64<0>
43+
; CHECK64-DAG: t11: ch,glue = CopyToReg t6, Register:i64 $x3, undef:i64
44+
; CHECK64-DAG: t13: ch,glue = CopyToReg t11, Register:i64 $x4, Constant:i64<255>, t11:1
45+
; CHECK64-DAG: t17: ch,glue = PPCISD::CALL_NOP t13, MCSymbol:i64, Register:i64 $x3, Register:i64 $x4, Register:i64 $x2, RegisterMask:Untyped, t13:1
46+
; CHECK64-DAG: t18: ch,glue = callseq_end t17, TargetConstant:i64<112>, TargetConstant:i64<0>, t17:1
47+
; CHECK64-DAG: t19: ch = PPCISD::RET_GLUE t18
48+
49+
define void @bar8(i8 zeroext %var1, i8 noundef zeroext %var2) local_unnamed_addr {
50+
entry:
51+
tail call void @foo8(i8 noundef zeroext %var2)
52+
ret void
53+
}
54+
55+
declare void @foo8(i8 noundef zeroext) local_unnamed_addr
56+
57+
define void @test8() local_unnamed_addr {
58+
entry:
59+
tail call void @bar8(i8 zeroext poison, i8 noundef zeroext 255)
60+
ret void
61+
}
62+
63+
; CHECK32: Initial selection DAG: %bb.0 'test8:entry'
64+
; CHECK32-DAG: SelectionDAG has 20 nodes:
65+
; CHECK32-DAG: t1: i32 = GlobalAddress<ptr @bar8> 0
66+
; CHECK32-DAG: t2: i8 = undef
67+
; CHECK32-DAG: t3: i8 = Constant<-1>
68+
; CHECK32-DAG: t9: i32 = Register $r1
69+
; CHECK32-DAG: t0: ch,glue = EntryToken
70+
; CHECK32-DAG: t8: ch,glue = callseq_start t0, TargetConstant:i32<56>, TargetConstant:i32<0>
71+
; CHECK32-DAG: t11: ch,glue = CopyToReg t8, Register:i32 $r3, undef:i32
72+
; CHECK32-DAG: t13: ch,glue = CopyToReg t11, Register:i32 $r4, Constant:i32<255>, t11:1
73+
; CHECK32-DAG: t17: ch,glue = PPCISD::CALL_NOP t13, MCSymbol:i32, Register:i32 $r3, Register:i32 $r4, Register:i32 $r2, RegisterMask:Untyped, t13:1
74+
; CHECK32-DAG: t18: ch,glue = callseq_end t17, TargetConstant:i32<56>, TargetConstant:i32<0>, t17:1
75+
; CHECK32-DAG: t19: ch = PPCISD::RET_GLUE t18
76+
77+
78+
; CHECK64: Initial selection DAG: %bb.0 'test8:entry'
79+
; CHECK64-DAG: SelectionDAG has 22 nodes:
80+
; CHECK64-DAG: t1: i64 = GlobalAddress<ptr @bar8> 0
81+
; CHECK64-DAG: t2: i8 = undef
82+
; CHECK64-DAG: t3: i8 = Constant<-1>
83+
; CHECK64-DAG: t4: i32 = undef
84+
; CHECK64-DAG: t5: i32 = Constant<255>
85+
; CHECK64-DAG: t9: i64 = Register $x1
86+
; CHECK64-DAG: t0: ch,glue = EntryToken
87+
; CHECK64-DAG: t8: ch,glue = callseq_start t0, TargetConstant:i64<112>, TargetConstant:i64<0>
88+
; CHECK64-DAG: t13: ch,glue = CopyToReg t8, Register:i64 $x3, undef:i64
89+
; CHECK64-DAG: t15: ch,glue = CopyToReg t13, Register:i64 $x4, Constant:i64<255>, t13:1
90+
; CHECK64-DAG: t19: ch,glue = PPCISD::CALL_NOP t15, MCSymbol:i64, Register:i64 $x3, Register:i64 $x4, Register:i64 $x2, RegisterMask:Untyped, t15:1
91+
; CHECK64-DAG: t20: ch,glue = callseq_end t19, TargetConstant:i64<112>, TargetConstant:i64<0>, t19:1
92+
; CHECK64-DAG: t21: ch = PPCISD::RET_GLUE t20
93+
94+
95+
define void @bar64(i64 zeroext %var1, i64 noundef zeroext %var2) local_unnamed_addr {
96+
entry:
97+
tail call void @foo64(i64 noundef zeroext %var2)
98+
ret void
99+
}
100+
101+
declare void @foo64(i64 noundef zeroext) local_unnamed_addr
102+
103+
; Function Attrs: noinline nounwind
104+
define void @test64() local_unnamed_addr {
105+
entry:
106+
tail call void @bar64(i64 zeroext poison, i64 noundef zeroext 255)
107+
ret void
108+
}
109+
110+
; CHECK32: Initial selection DAG: %bb.0 'test64:entry'
111+
; CHECK32-DAG: SelectionDAG has 26 nodes:
112+
; CHECK32-DAG: t1: i32 = GlobalAddress<ptr @bar64> 0
113+
; CHECK32-DAG: t2: i64 = undef
114+
; CHECK32-DAG: t3: i64 = Constant<255>
115+
; CHECK32-DAG: t5: i32 = Constant<1>
116+
; CHECK32-DAG: t11: i32 = Register $r1
117+
; CHECK32-DAG: t0: ch,glue = EntryToken
118+
; CHECK32-DAG: t10: ch,glue = callseq_start t0, TargetConstant:i32<56>, TargetConstant:i32<0>
119+
; CHECK32-DAG: t13: ch,glue = CopyToReg t10, Register:i32 $r3, undef:i32
120+
; CHECK32-DAG: t15: ch,glue = CopyToReg t13, Register:i32 $r4, undef:i32, t13:1
121+
; CHECK32-DAG: t17: ch,glue = CopyToReg t15, Register:i32 $r5, Constant:i32<0>, t15:1
122+
; CHECK32-DAG: t19: ch,glue = CopyToReg t17, Register:i32 $r6, Constant:i32<255>, t17:1
123+
; CHECK32-DAG: t23: ch,glue = PPCISD::CALL_NOP t19, MCSymbol:i32, Register:i32 $r3, Register:i32 $r4, Register:i32 $r5, Register:i32 $r6, Register:i32 $r2, RegisterMask:Untyped, t19:1
124+
; CHECK32-DAG: t24: ch,glue = callseq_end t23, TargetConstant:i32<56>, TargetConstant:i32<0>, t23:1
125+
; CHECK32-DAG: t25: ch = PPCISD::RET_GLUE t24
126+
127+
; CHECK64: Initial selection DAG: %bb.0 'test64:entry'
128+
; CHECK64-DAG: SelectionDAG has 18 nodes:
129+
; CHECK64-DAG: t1: i64 = GlobalAddress<ptr @bar64> 0
130+
; CHECK64-DAG: t7: i64 = Register $x1
131+
; CHECK64-DAG: t0: ch,glue = EntryToken
132+
; CHECK64-DAG: t6: ch,glue = callseq_start t0, TargetConstant:i64<112>, TargetConstant:i64<0>
133+
; CHECK64-DAG: t9: ch,glue = CopyToReg t6, Register:i64 $x3, undef:i64
134+
; CHECK64-DAG: t11: ch,glue = CopyToReg t9, Register:i64 $x4, Constant:i64<255>, t9:1
135+
; CHECK64-DAG: t15: ch,glue = PPCISD::CALL_NOP t11, MCSymbol:i64, Register:i64 $x3, Register:i64 $x4, Register:i64 $x2, RegisterMask:Untyped, t11:1
136+
; CHECK64-DAG: t16: ch,glue = callseq_end t15, TargetConstant:i64<112>, TargetConstant:i64<0>, t15:1
137+
; CHECK64-DAG: t17: ch = PPCISD::RET_GLUE t16

0 commit comments

Comments
 (0)