Skip to content

Commit

Permalink
[RISCV] Use CCValAssign::getCustomReg for fixed vector arguments/retu…
Browse files Browse the repository at this point in the history
…rns with RVV. (llvm#108470)

We need to insert a insert_subvector or extract_subvector which feels
pretty custom.

This should make it easier to support fixed vector arguments for GISel.
  • Loading branch information
topperc authored Sep 13, 2024
1 parent a3ea018 commit ee4582f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
12 changes: 10 additions & 2 deletions llvm/lib/Target/RISCV/RISCVCallingConv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,8 +448,12 @@ bool llvm::CC_RISCV(unsigned ValNo, MVT ValVT, MVT LocVT,
if (Reg) {
// Fixed-length vectors are located in the corresponding scalable-vector
// container types.
if (ValVT.isFixedLengthVector())
if (ValVT.isFixedLengthVector()) {
LocVT = TLI.getContainerForFixedLengthVector(LocVT);
State.addLoc(
CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
return false;
}
} else {
// For return values, the vector must be passed fully via registers or
// via the stack.
Expand Down Expand Up @@ -583,8 +587,12 @@ bool llvm::CC_RISCV_FastCC(unsigned ValNo, MVT ValVT, MVT LocVT,
if (MCRegister Reg = allocateRVVReg(ValVT, ValNo, State, TLI)) {
// Fixed-length vectors are located in the corresponding scalable-vector
// container types.
if (LocVT.isFixedLengthVector())
if (LocVT.isFixedLengthVector()) {
LocVT = TLI.getContainerForFixedLengthVector(LocVT);
State.addLoc(
CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
return false;
}
State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
return false;
}
Expand Down
28 changes: 12 additions & 16 deletions llvm/lib/Target/RISCV/RISCVISelLowering.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19090,20 +19090,18 @@ static SDValue convertLocVTToValVT(SelectionDAG &DAG, SDValue Val,
if (VA.needsCustom()) {
if (VA.getLocVT().isInteger() &&
(VA.getValVT() == MVT::f16 || VA.getValVT() == MVT::bf16))
Val = DAG.getNode(RISCVISD::FMV_H_X, DL, VA.getValVT(), Val);
else if (VA.getLocVT() == MVT::i64 && VA.getValVT() == MVT::f32)
Val = DAG.getNode(RISCVISD::FMV_W_X_RV64, DL, MVT::f32, Val);
else
llvm_unreachable("Unexpected Custom handling.");
return Val;
return DAG.getNode(RISCVISD::FMV_H_X, DL, VA.getValVT(), Val);
if (VA.getLocVT() == MVT::i64 && VA.getValVT() == MVT::f32)
return DAG.getNode(RISCVISD::FMV_W_X_RV64, DL, MVT::f32, Val);
if (VA.getValVT().isFixedLengthVector() && VA.getLocVT().isScalableVector())
return convertFromScalableVector(VA.getValVT(), Val, DAG, Subtarget);
llvm_unreachable("Unexpected Custom handling.");
}

switch (VA.getLocInfo()) {
default:
llvm_unreachable("Unexpected CCValAssign::LocInfo");
case CCValAssign::Full:
if (VA.getValVT().isFixedLengthVector() && VA.getLocVT().isScalableVector())
Val = convertFromScalableVector(VA.getValVT(), Val, DAG, Subtarget);
break;
case CCValAssign::BCvt:
Val = DAG.getNode(ISD::BITCAST, DL, VA.getValVT(), Val);
Expand Down Expand Up @@ -19155,20 +19153,18 @@ static SDValue convertValVTToLocVT(SelectionDAG &DAG, SDValue Val,
if (VA.needsCustom()) {
if (LocVT.isInteger() &&
(VA.getValVT() == MVT::f16 || VA.getValVT() == MVT::bf16))
Val = DAG.getNode(RISCVISD::FMV_X_ANYEXTH, DL, LocVT, Val);
else if (LocVT == MVT::i64 && VA.getValVT() == MVT::f32)
Val = DAG.getNode(RISCVISD::FMV_X_ANYEXTW_RV64, DL, MVT::i64, Val);
else
llvm_unreachable("Unexpected Custom handling.");
return Val;
return DAG.getNode(RISCVISD::FMV_X_ANYEXTH, DL, LocVT, Val);
if (LocVT == MVT::i64 && VA.getValVT() == MVT::f32)
return DAG.getNode(RISCVISD::FMV_X_ANYEXTW_RV64, DL, MVT::i64, Val);
if (VA.getValVT().isFixedLengthVector() && LocVT.isScalableVector())
return convertToScalableVector(LocVT, Val, DAG, Subtarget);
llvm_unreachable("Unexpected Custom handling.");
}

switch (VA.getLocInfo()) {
default:
llvm_unreachable("Unexpected CCValAssign::LocInfo");
case CCValAssign::Full:
if (VA.getValVT().isFixedLengthVector() && LocVT.isScalableVector())
Val = convertToScalableVector(LocVT, Val, DAG, Subtarget);
break;
case CCValAssign::BCvt:
Val = DAG.getNode(ISD::BITCAST, DL, LocVT, Val);
Expand Down

0 comments on commit ee4582f

Please sign in to comment.