-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[RISCV][CostModel] Updates reduction and shuffle cost #77342
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 |
---|---|---|
|
@@ -468,9 +468,8 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind, | |
// vmv.v.x v8, a0 | ||
// vmsne.vi v0, v8, 0 | ||
return LT.first * | ||
(TLI->getLMULCost(LT.second) + // FIXME: should be 1 for andi | ||
getRISCVInstructionCost({RISCV::VMV_V_X, RISCV::VMSNE_VI}, | ||
LT.second, CostKind)); | ||
(1 + getRISCVInstructionCost({RISCV::VMV_V_X, RISCV::VMSNE_VI}, | ||
LT.second, CostKind)); | ||
} | ||
// Example sequence: | ||
// vsetivli zero, 2, e8, mf8, ta, mu (ignored) | ||
|
@@ -482,11 +481,10 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind, | |
// vmsne.vi v0, v8, 0 | ||
|
||
return LT.first * | ||
(TLI->getLMULCost(LT.second) + // FIXME: this should be 1 for andi | ||
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. If the index is non-zero, then there's a vslide needed in the current sequence which does scale with LMUL. So, this change is wrong for non-zero index. 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. For SK_Broadcast, my understanding is that the index should always be the first element of the source vector.
Could we clarify this?" 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 you're correct here. There are other cases which create SK_Broadcast, but from what I can tell, all are consistent with the splat index always being zero. 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. To chime in here, it's defined in TargetTransformInfo.h as being a broadcast of element zero: enum ShuffleKind {
SK_Broadcast, ///< Broadcast element 0 to all other elements. |
||
getRISCVInstructionCost({RISCV::VMV_V_I, RISCV::VMERGE_VIM, | ||
RISCV::VMV_X_S, RISCV::VMV_V_X, | ||
RISCV::VMSNE_VI}, | ||
LT.second, CostKind)); | ||
(1 + getRISCVInstructionCost({RISCV::VMV_V_I, RISCV::VMERGE_VIM, | ||
RISCV::VMV_X_S, RISCV::VMV_V_X, | ||
RISCV::VMSNE_VI}, | ||
LT.second, CostKind)); | ||
} | ||
|
||
if (HasScalar) { | ||
|
@@ -531,9 +529,12 @@ InstructionCost RISCVTTIImpl::getShuffleCost(TTI::ShuffleKind Kind, | |
if (LT.second.isFixedLengthVector()) | ||
// vrsub.vi has a 5 bit immediate field, otherwise an li suffices | ||
LenCost = isInt<5>(LT.second.getVectorNumElements() - 1) ? 0 : 1; | ||
// FIXME: replace the constant `2` below with cost of {VID_V,VRSUB_VX} | ||
unsigned Opcodes[] = {RISCV::VID_V, RISCV::VRSUB_VX, RISCV::VRGATHER_VV}; | ||
if (LT.second.isFixedLengthVector() && | ||
isInt<5>(LT.second.getVectorNumElements() - 1)) | ||
Opcodes[1] = RISCV::VRSUB_VI; | ||
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. Just to double check, we don't cost 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. Yes, the cost for both is the same. |
||
InstructionCost GatherCost = | ||
2 + getRISCVInstructionCost(RISCV::VRGATHER_VV, LT.second, CostKind); | ||
getRISCVInstructionCost(Opcodes, LT.second, CostKind); | ||
// Mask operation additionally required extend and truncate | ||
InstructionCost ExtendCost = Tp->getElementType()->isIntegerTy(1) ? 3 : 0; | ||
return LT.first * (LenCost + GatherCost + ExtendCost); | ||
|
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.
Unrelated codegen opportunity
vmv.x.s a0, v8
andi a0, a0, 1
vmv.v.x v8, a0
Could be a vrgather.vi