[llvm] [RISCV] Use CCValAssign::getCustomReg for fixed vector arguments/returns with RVV. (PR #108470)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Thu Sep 12 16:39:27 PDT 2024
https://github.com/topperc updated https://github.com/llvm/llvm-project/pull/108470
>From 368aa5613936cdeeb69b0ad224472981e74884dc Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Thu, 12 Sep 2024 16:06:49 -0700
Subject: [PATCH 1/2] [RISCV] Use CCValAssign::getCustomReg for fixed vector
arguments/returns 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/lib/Target/RISCV/RISCVCallingConv.cpp | 10 ++++++--
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 28 +++++++++------------
2 files changed, 20 insertions(+), 18 deletions(-)
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);
>From 7bc4cb8d74c0df877a1e09663824c29205ef3fcd Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Thu, 12 Sep 2024 16:39:12 -0700
Subject: [PATCH 2/2] fixup! clang-format
---
llvm/lib/Target/RISCV/RISCVCallingConv.cpp | 6 ++++--
llvm/lib/Target/RISCV/RISCVISelLowering.cpp | 2 +-
2 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Target/RISCV/RISCVCallingConv.cpp b/llvm/lib/Target/RISCV/RISCVCallingConv.cpp
index 633f53e5cac98d..b7ed9de6ca84d1 100644
--- a/llvm/lib/Target/RISCV/RISCVCallingConv.cpp
+++ b/llvm/lib/Target/RISCV/RISCVCallingConv.cpp
@@ -450,7 +450,8 @@ bool llvm::CC_RISCV(unsigned ValNo, MVT ValVT, MVT LocVT,
// container types.
if (ValVT.isFixedLengthVector()) {
LocVT = TLI.getContainerForFixedLengthVector(LocVT);
- State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
+ State.addLoc(
+ CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
return false;
}
} else {
@@ -588,7 +589,8 @@ bool llvm::CC_RISCV_FastCC(unsigned ValNo, MVT ValVT, MVT LocVT,
// container types.
if (LocVT.isFixedLengthVector()) {
LocVT = TLI.getContainerForFixedLengthVector(LocVT);
- State.addLoc(CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
+ State.addLoc(
+ CCValAssign::getCustomReg(ValNo, ValVT, Reg, LocVT, LocInfo));
return false;
}
State.addLoc(CCValAssign::getReg(ValNo, ValVT, Reg, LocVT, LocInfo));
diff --git a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
index c24d26dbb7f6e0..be77fa3c4aa307 100644
--- a/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVISelLowering.cpp
@@ -19079,7 +19079,7 @@ static SDValue convertLocVTToValVT(SelectionDAG &DAG, SDValue Val,
if (VA.needsCustom()) {
if (VA.getLocVT().isInteger() &&
(VA.getValVT() == MVT::f16 || VA.getValVT() == MVT::bf16))
- return DAG.getNode(RISCVISD::FMV_H_X, DL, VA.getValVT(), 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())
More information about the llvm-commits
mailing list