Skip to content

Commit 0e1f468

Browse files
committed
[Mips] Fix compiler crash when returning fp128 after calling a function returning { i8, i128 }
Issue description: When process CanLowerReturn in function LowerCallTo, Mips implements this hook using CheckReturn with CCAssignFn RetCC_Mips. In CheckReturn, Mips would check whether lowered value was originated from f128, this step would check whether MF function return type was f128. In this issue, function return type was just fp128. In CCAssignFn RetCC_Mips, CCIfType i64 would be CCAssignToReg V0_64, A0_64 for soft-float. Then Mips process LowerCallResult which use CCAssignFn RetCC_Mips. It would also check whether lowered value was originated from f128. In this issue, call function return type was structure type and not {f128}, so in CCAssignFn RetCC_Mips, CCIfType i64 would be CCAssignToReg V0_64, V1_64. And in this issue, structure type return value was three i64, so when check the third i64, would report error "Call result #2 has unhandled type i64" due to there are no register available for it. Issue reason: Function CanLowerReturn is used both for function returns and call return values, and we analyze the wrong one. This needs to be fixed by analyzing the correct type. So we add a new parameter(return type) in function CanLowerReturn.
1 parent ce66b56 commit 0e1f468

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+146
-49
lines changed

llvm/include/llvm/CodeGen/TargetLowering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4778,7 +4778,7 @@ class TargetLowering : public TargetLoweringBase {
47784778
virtual bool CanLowerReturn(CallingConv::ID /*CallConv*/,
47794779
MachineFunction &/*MF*/, bool /*isVarArg*/,
47804780
const SmallVectorImpl<ISD::OutputArg> &/*Outs*/,
4781-
LLVMContext &/*Context*/) const
4781+
LLVMContext &/*Context*/, const Type *RetTy) const
47824782
{
47834783
// Return true by default to get preexisting behavior.
47844784
return true;

llvm/lib/CodeGen/SelectionDAG/FastISel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ bool FastISel::lowerCallTo(CallLoweringInfo &CLI) {
10011001
GetReturnInfo(CLI.CallConv, CLI.RetTy, getReturnAttrs(CLI), Outs, TLI, DL);
10021002

10031003
bool CanLowerReturn = TLI.CanLowerReturn(
1004-
CLI.CallConv, *FuncInfo.MF, CLI.IsVarArg, Outs, CLI.RetTy->getContext());
1004+
CLI.CallConv, *FuncInfo.MF, CLI.IsVarArg, Outs, CLI.RetTy->getContext(), CLI.RetTy);
10051005

10061006
// FIXME: sret demotion isn't supported yet - bail out.
10071007
if (!CanLowerReturn)

llvm/lib/CodeGen/SelectionDAG/FunctionLoweringInfo.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ void FunctionLoweringInfo::set(const Function &fn, MachineFunction &mf,
9999
GetReturnInfo(CC, Fn->getReturnType(), Fn->getAttributes(), Outs, *TLI,
100100
mf.getDataLayout());
101101
CanLowerReturn =
102-
TLI->CanLowerReturn(CC, *MF, Fn->isVarArg(), Outs, Fn->getContext());
102+
TLI->CanLowerReturn(CC, *MF, Fn->isVarArg(), Outs, Fn->getContext(), Fn->getReturnType());
103103

104104
// If this personality uses funclets, we need to do a bit more work.
105105
DenseMap<const AllocaInst *, TinyPtrVector<int *>> CatchObjects;

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11000,7 +11000,7 @@ TargetLowering::LowerCallTo(TargetLowering::CallLoweringInfo &CLI) const {
1100011000

1100111001
bool CanLowerReturn =
1100211002
this->CanLowerReturn(CLI.CallConv, CLI.DAG.getMachineFunction(),
11003-
CLI.IsVarArg, Outs, CLI.RetTy->getContext());
11003+
CLI.IsVarArg, Outs, CLI.RetTy->getContext(), CLI.RetTy);
1100411004

1100511005
SDValue DemoteStackSlot;
1100611006
int DemoteStackIdx = -100;

llvm/lib/Target/AArch64/AArch64ISelLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9417,7 +9417,8 @@ AArch64TargetLowering::LowerCall(CallLoweringInfo &CLI,
94179417

94189418
bool AArch64TargetLowering::CanLowerReturn(
94199419
CallingConv::ID CallConv, MachineFunction &MF, bool isVarArg,
9420-
const SmallVectorImpl<ISD::OutputArg> &Outs, LLVMContext &Context) const {
9420+
const SmallVectorImpl<ISD::OutputArg> &Outs, LLVMContext &Context,
9421+
const Type *RetTy) const {
94219422
CCAssignFn *RetCC = CCAssignFnForReturn(CallConv);
94229423
SmallVector<CCValAssign, 16> RVLocs;
94239424
CCState CCInfo(CallConv, isVarArg, MF, RVLocs, Context);

llvm/lib/Target/AArch64/AArch64ISelLowering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ class AArch64TargetLowering : public TargetLowering {
10901090
bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
10911091
bool isVarArg,
10921092
const SmallVectorImpl<ISD::OutputArg> &Outs,
1093-
LLVMContext &Context) const override;
1093+
LLVMContext &Context, const Type *RetTy) const override;
10941094

10951095
SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool isVarArg,
10961096
const SmallVectorImpl<ISD::OutputArg> &Outs,

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3112,7 +3112,8 @@ SDValue SITargetLowering::LowerFormalArguments(
31123112
// possible in registers before passing on stack.
31133113
bool SITargetLowering::CanLowerReturn(
31143114
CallingConv::ID CallConv, MachineFunction &MF, bool IsVarArg,
3115-
const SmallVectorImpl<ISD::OutputArg> &Outs, LLVMContext &Context) const {
3115+
const SmallVectorImpl<ISD::OutputArg> &Outs, LLVMContext &Context,
3116+
const Type *RetTy) const {
31163117
// Replacing returns with sret/stack usage doesn't make sense for shaders.
31173118
// FIXME: Also sort of a workaround for custom vector splitting in LowerReturn
31183119
// for shaders. Vector types should be explicitly handled by CC.

llvm/lib/Target/AMDGPU/SIISelLowering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ class SITargetLowering final : public AMDGPUTargetLowering {
387387
bool CanLowerReturn(CallingConv::ID CallConv,
388388
MachineFunction &MF, bool isVarArg,
389389
const SmallVectorImpl<ISD::OutputArg> &Outs,
390-
LLVMContext &Context) const override;
390+
LLVMContext &Context, const Type *RetTy) const override;
391391

392392
SDValue LowerReturn(SDValue Chain, CallingConv::ID CallConv, bool IsVarArg,
393393
const SmallVectorImpl<ISD::OutputArg> &Outs,

llvm/lib/Target/ARC/ARCISelLowering.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,8 @@ SDValue ARCTargetLowering::LowerCallArguments(
630630

631631
bool ARCTargetLowering::CanLowerReturn(
632632
CallingConv::ID CallConv, MachineFunction &MF, bool IsVarArg,
633-
const SmallVectorImpl<ISD::OutputArg> &Outs, LLVMContext &Context) const {
633+
const SmallVectorImpl<ISD::OutputArg> &Outs, LLVMContext &Context,
634+
const Type *RetTy) const {
634635
SmallVector<CCValAssign, 16> RVLocs;
635636
CCState CCInfo(CallConv, IsVarArg, MF, RVLocs, Context);
636637
if (!CCInfo.CheckReturn(Outs, RetCC_ARC))

llvm/lib/Target/ARC/ARCISelLowering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ class ARCTargetLowering : public TargetLowering {
112112
bool CanLowerReturn(CallingConv::ID CallConv, MachineFunction &MF,
113113
bool isVarArg,
114114
const SmallVectorImpl<ISD::OutputArg> &ArgsFlags,
115-
LLVMContext &Context) const override;
115+
LLVMContext &Context, const Type *RetTy) const override;
116116

117117
bool mayBeEmittedAsTailCall(const CallInst *CI) const override;
118118
};

0 commit comments

Comments
 (0)