Skip to content

Commit f533e8c

Browse files
committed
Recommit "[RISCV][GISel] Disable call lowering for integers larger than 2*XLen. (#69144)"
Remove bad test for >2x XLen scalar. Don't restrict struct returns if they aren't homogenous. Original commit message: Types larger than 2*XLen are passed indirectly which is not supported yet. Currently, we will incorrectly pass X10 multiple times.
1 parent b4729f7 commit f533e8c

File tree

2 files changed

+46
-47
lines changed

2 files changed

+46
-47
lines changed

llvm/lib/Target/RISCV/GISel/RISCVCallLowering.cpp

Lines changed: 46 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,50 @@ struct RISCVCallReturnHandler : public RISCVIncomingValueHandler {
193193
RISCVCallLowering::RISCVCallLowering(const RISCVTargetLowering &TLI)
194194
: CallLowering(&TLI) {}
195195

196+
// TODO: Support all argument types.
197+
static bool isSupportedArgumentType(Type *T, const RISCVSubtarget &Subtarget) {
198+
// TODO: Integers larger than 2*XLen are passed indirectly which is not
199+
// supported yet.
200+
if (T->isIntegerTy())
201+
return T->getIntegerBitWidth() <= Subtarget.getXLen() * 2;
202+
if (T->isPointerTy())
203+
return true;
204+
return false;
205+
}
206+
207+
// TODO: Only integer, pointer and aggregate types are supported now.
208+
static bool isSupportedReturnType(Type *T, const RISCVSubtarget &Subtarget) {
209+
// TODO: Integers larger than 2*XLen are passed indirectly which is not
210+
// supported yet.
211+
if (T->isIntegerTy())
212+
return T->getIntegerBitWidth() <= Subtarget.getXLen() * 2;
213+
if (T->isPointerTy())
214+
return true;
215+
216+
if (T->isArrayTy())
217+
return isSupportedReturnType(T->getArrayElementType(), Subtarget);
218+
219+
if (T->isStructTy()) {
220+
auto StructT = cast<StructType>(T);
221+
for (unsigned i = 0, e = StructT->getNumElements(); i != e; ++i)
222+
if (!isSupportedReturnType(StructT->getElementType(i), Subtarget))
223+
return false;
224+
return true;
225+
}
226+
227+
return false;
228+
}
229+
196230
bool RISCVCallLowering::lowerReturnVal(MachineIRBuilder &MIRBuilder,
197231
const Value *Val,
198232
ArrayRef<Register> VRegs,
199233
MachineInstrBuilder &Ret) const {
200234
if (!Val)
201235
return true;
202236

203-
// TODO: Only integer, pointer and aggregate types are supported now.
204-
if (!Val->getType()->isIntOrPtrTy() && !Val->getType()->isAggregateType())
237+
const RISCVSubtarget &Subtarget =
238+
MIRBuilder.getMF().getSubtarget<RISCVSubtarget>();
239+
if (!isSupportedReturnType(Val->getType(), Subtarget))
205240
return false;
206241

207242
MachineFunction &MF = MIRBuilder.getMF();
@@ -248,13 +283,11 @@ bool RISCVCallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
248283
if (F.isVarArg())
249284
return false;
250285

251-
// TODO: Support all argument types.
286+
const RISCVSubtarget &Subtarget =
287+
MIRBuilder.getMF().getSubtarget<RISCVSubtarget>();
252288
for (auto &Arg : F.args()) {
253-
if (Arg.getType()->isIntegerTy())
254-
continue;
255-
if (Arg.getType()->isPointerTy())
256-
continue;
257-
return false;
289+
if (!isSupportedArgumentType(Arg.getType(), Subtarget))
290+
return false;
258291
}
259292

260293
MachineFunction &MF = MIRBuilder.getMF();
@@ -292,15 +325,11 @@ bool RISCVCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
292325
const Function &F = MF.getFunction();
293326
CallingConv::ID CC = F.getCallingConv();
294327

295-
// TODO: Support all argument types.
328+
const RISCVSubtarget &Subtarget =
329+
MIRBuilder.getMF().getSubtarget<RISCVSubtarget>();
296330
for (auto &AInfo : Info.OrigArgs) {
297-
if (AInfo.Ty->isIntegerTy())
298-
continue;
299-
if (AInfo.Ty->isPointerTy())
300-
continue;
301-
if (AInfo.Ty->isFloatingPointTy())
302-
continue;
303-
return false;
331+
if (!isSupportedArgumentType(AInfo.Ty, Subtarget))
332+
return false;
304333
}
305334

306335
SmallVector<ArgInfo, 32> SplitArgInfos;
@@ -337,8 +366,7 @@ bool RISCVCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
337366
if (Info.OrigRet.Ty->isVoidTy())
338367
return true;
339368

340-
// TODO: Only integer, pointer and aggregate types are supported now.
341-
if (!Info.OrigRet.Ty->isIntOrPtrTy() && !Info.OrigRet.Ty->isAggregateType())
369+
if (!isSupportedReturnType(Info.OrigRet.Ty, Subtarget))
342370
return false;
343371

344372
SmallVector<ArgInfo, 4> SplitRetInfos;

llvm/test/CodeGen/RISCV/GlobalISel/irtranslator/calling-conv-lp64-lp64f-lp64d-common.ll

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -212,35 +212,6 @@ define i64 @caller_small_struct_ret() nounwind {
212212
ret i64 %5
213213
}
214214

215-
; Check return of >2x xlen scalars
216-
217-
define i256 @callee_large_scalar_ret() nounwind {
218-
; RV64I-LABEL: name: callee_large_scalar_ret
219-
; RV64I: bb.1 (%ir-block.0):
220-
; RV64I-NEXT: [[C:%[0-9]+]]:_(s256) = G_CONSTANT i256 -123456789
221-
; RV64I-NEXT: [[UV:%[0-9]+]]:_(s64), [[UV1:%[0-9]+]]:_(s64), [[UV2:%[0-9]+]]:_(s64), [[UV3:%[0-9]+]]:_(s64) = G_UNMERGE_VALUES [[C]](s256)
222-
; RV64I-NEXT: $x10 = COPY [[UV]](s64)
223-
; RV64I-NEXT: $x10 = COPY [[UV1]](s64)
224-
; RV64I-NEXT: $x10 = COPY [[UV2]](s64)
225-
; RV64I-NEXT: $x10 = COPY [[UV3]](s64)
226-
; RV64I-NEXT: PseudoRET implicit $x10, implicit $x10, implicit $x10, implicit $x10
227-
ret i256 -123456789
228-
}
229-
230-
define void @caller_large_scalar_ret() nounwind {
231-
; RV64I-LABEL: name: caller_large_scalar_ret
232-
; RV64I: bb.1 (%ir-block.0):
233-
; RV64I-NEXT: PseudoCALL target-flags(riscv-call) @callee_large_scalar_ret, implicit-def $x1, implicit-def $x10, implicit-def $x10, implicit-def $x10, implicit-def $x10
234-
; RV64I-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x10
235-
; RV64I-NEXT: [[COPY1:%[0-9]+]]:_(s64) = COPY $x10
236-
; RV64I-NEXT: [[COPY2:%[0-9]+]]:_(s64) = COPY $x10
237-
; RV64I-NEXT: [[COPY3:%[0-9]+]]:_(s64) = COPY $x10
238-
; RV64I-NEXT: [[MV:%[0-9]+]]:_(s256) = G_MERGE_VALUES [[COPY]](s64), [[COPY1]](s64), [[COPY2]](s64), [[COPY3]](s64)
239-
; RV64I-NEXT: PseudoRET
240-
%1 = call i256 @callee_large_scalar_ret()
241-
ret void
242-
}
243-
244215
; Check return of >2x xlen structs
245216

246217
%struct.large = type { i64, i64, i64, i64 }

0 commit comments

Comments
 (0)