Skip to content

Commit 4be1099

Browse files
authored
[RISCV] Improve fixed vector handling in isCtpopFast. (#158380)
Previously we considered fixed vectors fast if Zvbb or Zbb is enabled. Zbb only helps if the vector type will end up being scalarized.
1 parent 0cf6688 commit 4be1099

File tree

4 files changed

+240
-420
lines changed

4 files changed

+240
-420
lines changed

llvm/lib/Target/RISCV/RISCVISelLowering.cpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2752,7 +2752,7 @@ bool RISCVTargetLowering::isLegalElementTypeForRVV(EVT ScalarTy) const {
27522752
case MVT::i8:
27532753
case MVT::i16:
27542754
case MVT::i32:
2755-
return true;
2755+
return Subtarget.hasVInstructions();
27562756
case MVT::i64:
27572757
return Subtarget.hasVInstructionsI64();
27582758
case MVT::f16:
@@ -24820,12 +24820,16 @@ bool RISCVTargetLowering::areTwoSDNodeTargetMMOFlagsMergeable(
2482024820
}
2482124821

2482224822
bool RISCVTargetLowering::isCtpopFast(EVT VT) const {
24823-
if (VT.isScalableVector())
24824-
return isTypeLegal(VT) && Subtarget.hasStdExtZvbb();
24825-
if (VT.isFixedLengthVector() && Subtarget.hasStdExtZvbb())
24826-
return true;
24827-
return Subtarget.hasCPOPLike() &&
24828-
(VT == MVT::i32 || VT == MVT::i64 || VT.isFixedLengthVector());
24823+
if (VT.isVector()) {
24824+
EVT SVT = VT.getVectorElementType();
24825+
// If the element type is legal we can use cpop.v if it is enabled.
24826+
if (isLegalElementTypeForRVV(SVT))
24827+
return Subtarget.hasStdExtZvbb();
24828+
// Don't consider it fast if the type needs to be legalized or scalarized.
24829+
return false;
24830+
}
24831+
24832+
return Subtarget.hasCPOPLike() && (VT == MVT::i32 || VT == MVT::i64);
2482924833
}
2483024834

2483124835
unsigned RISCVTargetLowering::getCustomCtpopCost(EVT VT,

0 commit comments

Comments
 (0)