[llvm] f533e8c - Recommit "[RISCV][GISel] Disable call lowering for integers larger than 2*XLen. (#69144)"
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 20 11:55:43 PDT 2023
Author: Craig Topper
Date: 2023-10-20T11:51:47-07:00
New Revision: f533e8ca9f0b37ccf6c3a78ee46aa0682c09da02
URL: https://github.com/llvm/llvm-project/commit/f533e8ca9f0b37ccf6c3a78ee46aa0682c09da02
DIFF: https://github.com/llvm/llvm-project/commit/f533e8ca9f0b37ccf6c3a78ee46aa0682c09da02.diff
LOG: 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.
Added:
Modified:
llvm/lib/Target/RISCV/GISel/RISCVCallLowering.cpp
llvm/test/CodeGen/RISCV/GlobalISel/irtranslator/calling-conv-lp64-lp64f-lp64d-common.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/RISCV/GISel/RISCVCallLowering.cpp b/llvm/lib/Target/RISCV/GISel/RISCVCallLowering.cpp
index 215aa938e5dc484..01b8e77252840f5 100644
--- a/llvm/lib/Target/RISCV/GISel/RISCVCallLowering.cpp
+++ b/llvm/lib/Target/RISCV/GISel/RISCVCallLowering.cpp
@@ -193,6 +193,40 @@ struct RISCVCallReturnHandler : public RISCVIncomingValueHandler {
RISCVCallLowering::RISCVCallLowering(const RISCVTargetLowering &TLI)
: CallLowering(&TLI) {}
+// TODO: Support all argument types.
+static bool isSupportedArgumentType(Type *T, const RISCVSubtarget &Subtarget) {
+ // TODO: Integers larger than 2*XLen are passed indirectly which is not
+ // supported yet.
+ if (T->isIntegerTy())
+ return T->getIntegerBitWidth() <= Subtarget.getXLen() * 2;
+ if (T->isPointerTy())
+ return true;
+ return false;
+}
+
+// TODO: Only integer, pointer and aggregate types are supported now.
+static bool isSupportedReturnType(Type *T, const RISCVSubtarget &Subtarget) {
+ // TODO: Integers larger than 2*XLen are passed indirectly which is not
+ // supported yet.
+ if (T->isIntegerTy())
+ return T->getIntegerBitWidth() <= Subtarget.getXLen() * 2;
+ if (T->isPointerTy())
+ return true;
+
+ if (T->isArrayTy())
+ return isSupportedReturnType(T->getArrayElementType(), Subtarget);
+
+ if (T->isStructTy()) {
+ auto StructT = cast<StructType>(T);
+ for (unsigned i = 0, e = StructT->getNumElements(); i != e; ++i)
+ if (!isSupportedReturnType(StructT->getElementType(i), Subtarget))
+ return false;
+ return true;
+ }
+
+ return false;
+}
+
bool RISCVCallLowering::lowerReturnVal(MachineIRBuilder &MIRBuilder,
const Value *Val,
ArrayRef<Register> VRegs,
@@ -200,8 +234,9 @@ bool RISCVCallLowering::lowerReturnVal(MachineIRBuilder &MIRBuilder,
if (!Val)
return true;
- // TODO: Only integer, pointer and aggregate types are supported now.
- if (!Val->getType()->isIntOrPtrTy() && !Val->getType()->isAggregateType())
+ const RISCVSubtarget &Subtarget =
+ MIRBuilder.getMF().getSubtarget<RISCVSubtarget>();
+ if (!isSupportedReturnType(Val->getType(), Subtarget))
return false;
MachineFunction &MF = MIRBuilder.getMF();
@@ -248,13 +283,11 @@ bool RISCVCallLowering::lowerFormalArguments(MachineIRBuilder &MIRBuilder,
if (F.isVarArg())
return false;
- // TODO: Support all argument types.
+ const RISCVSubtarget &Subtarget =
+ MIRBuilder.getMF().getSubtarget<RISCVSubtarget>();
for (auto &Arg : F.args()) {
- if (Arg.getType()->isIntegerTy())
- continue;
- if (Arg.getType()->isPointerTy())
- continue;
- return false;
+ if (!isSupportedArgumentType(Arg.getType(), Subtarget))
+ return false;
}
MachineFunction &MF = MIRBuilder.getMF();
@@ -292,15 +325,11 @@ bool RISCVCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
const Function &F = MF.getFunction();
CallingConv::ID CC = F.getCallingConv();
- // TODO: Support all argument types.
+ const RISCVSubtarget &Subtarget =
+ MIRBuilder.getMF().getSubtarget<RISCVSubtarget>();
for (auto &AInfo : Info.OrigArgs) {
- if (AInfo.Ty->isIntegerTy())
- continue;
- if (AInfo.Ty->isPointerTy())
- continue;
- if (AInfo.Ty->isFloatingPointTy())
- continue;
- return false;
+ if (!isSupportedArgumentType(AInfo.Ty, Subtarget))
+ return false;
}
SmallVector<ArgInfo, 32> SplitArgInfos;
@@ -337,8 +366,7 @@ bool RISCVCallLowering::lowerCall(MachineIRBuilder &MIRBuilder,
if (Info.OrigRet.Ty->isVoidTy())
return true;
- // TODO: Only integer, pointer and aggregate types are supported now.
- if (!Info.OrigRet.Ty->isIntOrPtrTy() && !Info.OrigRet.Ty->isAggregateType())
+ if (!isSupportedReturnType(Info.OrigRet.Ty, Subtarget))
return false;
SmallVector<ArgInfo, 4> SplitRetInfos;
diff --git a/llvm/test/CodeGen/RISCV/GlobalISel/irtranslator/calling-conv-lp64-lp64f-lp64d-common.ll b/llvm/test/CodeGen/RISCV/GlobalISel/irtranslator/calling-conv-lp64-lp64f-lp64d-common.ll
index 1b8ce7514bb09c8..8533ed77b557029 100644
--- a/llvm/test/CodeGen/RISCV/GlobalISel/irtranslator/calling-conv-lp64-lp64f-lp64d-common.ll
+++ b/llvm/test/CodeGen/RISCV/GlobalISel/irtranslator/calling-conv-lp64-lp64f-lp64d-common.ll
@@ -212,35 +212,6 @@ define i64 @caller_small_struct_ret() nounwind {
ret i64 %5
}
-; Check return of >2x xlen scalars
-
-define i256 @callee_large_scalar_ret() nounwind {
- ; RV64I-LABEL: name: callee_large_scalar_ret
- ; RV64I: bb.1 (%ir-block.0):
- ; RV64I-NEXT: [[C:%[0-9]+]]:_(s256) = G_CONSTANT i256 -123456789
- ; RV64I-NEXT: [[UV:%[0-9]+]]:_(s64), [[UV1:%[0-9]+]]:_(s64), [[UV2:%[0-9]+]]:_(s64), [[UV3:%[0-9]+]]:_(s64) = G_UNMERGE_VALUES [[C]](s256)
- ; RV64I-NEXT: $x10 = COPY [[UV]](s64)
- ; RV64I-NEXT: $x10 = COPY [[UV1]](s64)
- ; RV64I-NEXT: $x10 = COPY [[UV2]](s64)
- ; RV64I-NEXT: $x10 = COPY [[UV3]](s64)
- ; RV64I-NEXT: PseudoRET implicit $x10, implicit $x10, implicit $x10, implicit $x10
- ret i256 -123456789
-}
-
-define void @caller_large_scalar_ret() nounwind {
- ; RV64I-LABEL: name: caller_large_scalar_ret
- ; RV64I: bb.1 (%ir-block.0):
- ; 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
- ; RV64I-NEXT: [[COPY:%[0-9]+]]:_(s64) = COPY $x10
- ; RV64I-NEXT: [[COPY1:%[0-9]+]]:_(s64) = COPY $x10
- ; RV64I-NEXT: [[COPY2:%[0-9]+]]:_(s64) = COPY $x10
- ; RV64I-NEXT: [[COPY3:%[0-9]+]]:_(s64) = COPY $x10
- ; RV64I-NEXT: [[MV:%[0-9]+]]:_(s256) = G_MERGE_VALUES [[COPY]](s64), [[COPY1]](s64), [[COPY2]](s64), [[COPY3]](s64)
- ; RV64I-NEXT: PseudoRET
- %1 = call i256 @callee_large_scalar_ret()
- ret void
-}
-
; Check return of >2x xlen structs
%struct.large = type { i64, i64, i64, i64 }
More information about the llvm-commits
mailing list