-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[RISCV] Use CCValAssign::getCustomReg for fixed vector arguments/returns with RVV. #108470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…rns with RVV. 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.
|
@llvm/pr-subscribers-backend-risc-v Author: Craig Topper (topperc) ChangesWe 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. Full diff: https://github.com/llvm/llvm-project/pull/108470.diff 2 Files Affected:
diff --git a/llvm/lib/Target/RISCV/RISCVCallingConv.cpp b/llvm/lib/Target/RISCV/RISCVCallingConv.cpp
index fc276d1063281c..633f53e5cac98d 100644
--- a/llvm/lib/Target/RISCV/RISCVCallingConv.cpp
+++ b/llvm/lib/Target/RISCV/RISCVCallingConv.cpp
@@ -448,8 +448,11 @@ 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.
@@ -583,8 +586,11 @@ 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;
}
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index ccc74ca9965899..c24d26dbb7f6e0 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -19079,20 +19079,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);
@@ -19144,20 +19142,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);
|
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
4vtomat
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds reasonable to me~
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.