-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[RISCV] Add codegen support for Zvfbfmin #87911
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1084,6 +1084,23 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM, | |
} | ||
} | ||
|
||
// TODO: Could we merge some code with zvfhmin? | ||
if (Subtarget.hasVInstructionsBF16()) { | ||
for (MVT VT : BF16VecVTs) { | ||
if (!isTypeLegal(VT)) | ||
continue; | ||
setOperationAction({ISD::FP_ROUND, ISD::FP_EXTEND}, VT, Custom); | ||
setOperationAction({ISD::VP_FP_ROUND, ISD::VP_FP_EXTEND}, VT, Custom); | ||
setOperationAction({ISD::STRICT_FP_ROUND, ISD::STRICT_FP_EXTEND}, VT, | ||
Custom); | ||
setOperationAction({ISD::CONCAT_VECTORS, ISD::INSERT_SUBVECTOR, | ||
ISD::EXTRACT_SUBVECTOR}, | ||
VT, Custom); | ||
setOperationAction({ISD::LOAD, ISD::STORE}, VT, Custom); | ||
// TODO: Promote to fp32. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like F16Minimal has support for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Zvfbfmin does not have any integer conversion instructions so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm curious what SPLAT_VECTOR for F16Minimal does since the scalar FP16 type isn't guaranteed legal with F16Minimal. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I create a pr #88275 to add the constraint for There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Based on the comments in this thread, we have been able to trim down the original list. We are left with consideration of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Added |
||
} | ||
} | ||
|
||
if (Subtarget.hasVInstructionsF32()) { | ||
for (MVT VT : F32VecVTs) { | ||
if (!isTypeLegal(VT)) | ||
|
@@ -1299,6 +1316,19 @@ RISCVTargetLowering::RISCVTargetLowering(const TargetMachine &TM, | |
continue; | ||
} | ||
|
||
if (VT.getVectorElementType() == MVT::bf16) { | ||
setOperationAction({ISD::FP_ROUND, ISD::FP_EXTEND}, VT, Custom); | ||
setOperationAction({ISD::VP_FP_ROUND, ISD::VP_FP_EXTEND}, VT, Custom); | ||
setOperationAction({ISD::STRICT_FP_ROUND, ISD::STRICT_FP_EXTEND}, VT, | ||
Custom); | ||
setOperationAction({ISD::CONCAT_VECTORS, ISD::INSERT_SUBVECTOR, | ||
ISD::EXTRACT_SUBVECTOR}, | ||
VT, Custom); | ||
setOperationAction({ISD::LOAD, ISD::STORE}, VT, Custom); | ||
// TODO: Promote to fp32. | ||
continue; | ||
} | ||
|
||
// We use EXTRACT_SUBVECTOR as a "cast" from scalable to fixed. | ||
setOperationAction({ISD::INSERT_SUBVECTOR, ISD::EXTRACT_SUBVECTOR}, VT, | ||
Custom); | ||
|
@@ -2558,6 +2588,10 @@ static bool useRVVForFixedLengthVectorVT(MVT VT, | |
if (!Subtarget.hasVInstructionsF16Minimal()) | ||
return false; | ||
break; | ||
case MVT::bf16: | ||
if (!Subtarget.hasVInstructionsBF16()) | ||
return false; | ||
break; | ||
case MVT::f32: | ||
if (!Subtarget.hasVInstructionsF32()) | ||
return false; | ||
|
@@ -2609,6 +2643,7 @@ static MVT getContainerForFixedLengthVector(const TargetLowering &TLI, MVT VT, | |
case MVT::i16: | ||
case MVT::i32: | ||
case MVT::i64: | ||
case MVT::bf16: | ||
case MVT::f16: | ||
case MVT::f32: | ||
case MVT::f64: { | ||
|
@@ -8057,8 +8092,10 @@ RISCVTargetLowering::lowerStrictFPExtendOrRoundLike(SDValue Op, | |
|
||
// RVV can only widen/truncate fp to types double/half the size as the source. | ||
if ((VT.getVectorElementType() == MVT::f64 && | ||
SrcVT.getVectorElementType() == MVT::f16) || | ||
(VT.getVectorElementType() == MVT::f16 && | ||
(SrcVT.getVectorElementType() == MVT::f16 || | ||
SrcVT.getVectorElementType() == MVT::bf16)) || | ||
((VT.getVectorElementType() == MVT::f16 || | ||
VT.getVectorElementType() == MVT::bf16) && | ||
SrcVT.getVectorElementType() == MVT::f64)) { | ||
// For double rounding, the intermediate rounding should be round-to-odd. | ||
unsigned InterConvOpc = Op.getOpcode() == ISD::STRICT_FP_EXTEND | ||
|
@@ -8102,9 +8139,12 @@ RISCVTargetLowering::lowerVectorFPExtendOrRoundLike(SDValue Op, | |
SDValue Src = Op.getOperand(0); | ||
MVT SrcVT = Src.getSimpleValueType(); | ||
|
||
bool IsDirectExtend = IsExtend && (VT.getVectorElementType() != MVT::f64 || | ||
SrcVT.getVectorElementType() != MVT::f16); | ||
bool IsDirectTrunc = !IsExtend && (VT.getVectorElementType() != MVT::f16 || | ||
bool IsDirectExtend = | ||
IsExtend && (VT.getVectorElementType() != MVT::f64 || | ||
(SrcVT.getVectorElementType() != MVT::f16 && | ||
SrcVT.getVectorElementType() != MVT::bf16)); | ||
bool IsDirectTrunc = !IsExtend && ((VT.getVectorElementType() != MVT::f16 && | ||
VT.getVectorElementType() != MVT::bf16) || | ||
SrcVT.getVectorElementType() != MVT::f64); | ||
|
||
bool IsDirectConv = IsDirectExtend || IsDirectTrunc; | ||
|
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.
Are concat, insert, extract, and scalar_to_vector tested? It's not immediately obvious from the test names
Uh oh!
There was an error while loading. Please reload this page.
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.
I added test cases for insert_vectors and extract_vectors, and removed scalar_to_vector now since it should need bf16 scalar extension. For concat_vectors, I didn't find the direct case of it.