-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[RISCV][CostModel] Estimate cost of llvm.vector.reduce.fmaximum/fminimum #80697
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
Merged
Merged
Changes from 2 commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1001,6 +1001,51 @@ RISCVTTIImpl::getMinMaxReductionCost(Intrinsic::ID IID, VectorType *Ty, | |
return getArithmeticReductionCost(Instruction::And, Ty, FMF, CostKind); | ||
} | ||
|
||
if (IID == Intrinsic::maximum || IID == Intrinsic::minimum) { | ||
SmallVector<unsigned, 3> Opcodes; | ||
InstructionCost ExtraCost = 0; | ||
switch (IID) { | ||
case Intrinsic::maximum: | ||
if (FMF.noNaNs()) { | ||
Opcodes = {RISCV::VFREDMAX_VS, RISCV::VFMV_F_S}; | ||
} else { | ||
Opcodes = {RISCV::VMFNE_VV, RISCV::VCPOP_M, RISCV::VFREDMAX_VS, | ||
RISCV::VFMV_F_S}; | ||
// Cost of Canonical Nan + branch | ||
// lui a0, 523264 | ||
// fmv.w.x fa0, a0 | ||
Type *DstTy = Ty->getScalarType(); | ||
const unsigned EltTyBits = DL.getTypeSizeInBits(DstTy); | ||
Type *SrcTy = IntegerType::getIntNTy(DstTy->getContext(), EltTyBits); | ||
ExtraCost = 1 + | ||
getCastInstrCost(Instruction::UIToFP, DstTy, SrcTy, | ||
TTI::CastContextHint::None, CostKind) + | ||
getCFInstrCost(Instruction::Br, CostKind); | ||
} | ||
break; | ||
|
||
case Intrinsic::minimum: | ||
if (FMF.noNaNs()) { | ||
Opcodes = {RISCV::VFREDMIN_VS, RISCV::VFMV_F_S}; | ||
} else { | ||
Opcodes = {RISCV::VMFNE_VV, RISCV::VCPOP_M, RISCV::VFREDMIN_VS, | ||
RISCV::VFMV_F_S}; | ||
// Cost of Canonical Nan + branch | ||
// lui a0, 523264 | ||
// fmv.w.x fa0, a0 | ||
Type *DstTy = Ty->getScalarType(); | ||
const unsigned EltTyBits = DL.getTypeSizeInBits(DstTy); | ||
Comment on lines
+1036
to
+1037
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. Nit, I think |
||
Type *SrcTy = IntegerType::getIntNTy(DstTy->getContext(), EltTyBits); | ||
ExtraCost = 1 + | ||
getCastInstrCost(Instruction::UIToFP, DstTy, SrcTy, | ||
TTI::CastContextHint::None, CostKind) + | ||
getCFInstrCost(Instruction::Br, CostKind); | ||
} | ||
break; | ||
} | ||
return ExtraCost + getRISCVInstructionCost(Opcodes, LT.second, CostKind); | ||
} | ||
|
||
// IR Reduction is composed by two vmv and one rvv reduction instruction. | ||
InstructionCost BaseCost = 2; | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
You're missing the cost of the scalar select here.
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.
Fixed with getCFInstrCost.
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.
Worth noting that we assume branches are predicted so
getCFInstrCost(Instruction::Br, CostKind)
will return 0 for throughput