-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[LV] Check early for supported interleave factors with scalable types [nfc] #111592
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 |
---|---|---|
|
@@ -3406,6 +3406,7 @@ bool LoopVectorizationCostModel::interleavedAccessCanBeWidened( | |
"Decision should not be set yet."); | ||
auto *Group = getInterleavedAccessGroup(I); | ||
assert(Group && "Must have a group."); | ||
unsigned InterleaveFactor = Group->getFactor(); | ||
|
||
// If the instruction's allocated size doesn't equal it's type size, it | ||
// requires padding and will be scalarized. | ||
|
@@ -3414,9 +3415,14 @@ bool LoopVectorizationCostModel::interleavedAccessCanBeWidened( | |
if (hasIrregularType(ScalarTy, DL)) | ||
return false; | ||
|
||
// We currently only know how to emit interleave/deinterleave with | ||
// Factor=2 for scalable vectors. This is purely an implementation | ||
// limit. | ||
if (VF.isScalable() && InterleaveFactor != 2) | ||
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. How is this handled for AArch64 SVE? Does the change mean support for different factors must be added for all architectures with scalable vectors at the same time? 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. SVE also has a similar check in interleavedAccessCanBeWidened. 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 there's the same check just later in LV, could it be replaced by an assert? 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 can't find this check except in the AArch64 cost model (now removed). What are you referring to? 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.
This is an IR representation issue. We have no way to represent in IR a interleave load or store at anything other than Factor=2 today. When we change that, yes, we will have to audit the cost models for each of the targets which support the new intrinsic. That seems pretty standard. 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.
My mistake. I mentioned the wrong function earlier; it should be getInterleavedMemoryOpCost rather than interleavedAccessCanBeWidened. |
||
return false; | ||
|
||
// If the group involves a non-integral pointer, we may not be able to | ||
// losslessly cast all values to a common type. | ||
unsigned InterleaveFactor = Group->getFactor(); | ||
bool ScalarNI = DL.isNonIntegralPointerType(ScalarTy); | ||
for (unsigned Idx = 0; Idx < InterleaveFactor; Idx++) { | ||
Instruction *Member = Group->getMember(Idx); | ||
|
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.
should this assert that Factor == 2 for SVE to guard against accidentally returning an incorrect non-invalid cost? Same for RISCV
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.
From what I can tell, the existing costs should be valid for Factor > 2. We already use them for fixed vector interleaves and for VF=2 scalable, so the code should be plausible. Once we add an IR representation for these (which we don't currently have), the costs will need audited, but the current implementation seems sane.
You seem reasonable opposed to what I consider a simple cleanup. I'm not particularly motivated to keep pushing this, if you'd rather I just drop the patch, please say so.
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.
If I understand correctly, I think all @fhahn is worried about here is a situation where the vectoriser may support larger interleave factors for scalable vectors but relies on the cost model returning Invalid for factors they don't support. So having an assert that Factor == 2 with scalable vectors for both RISC and AArch64 seems reasonable I guess?
The intent of this patch seems reasonable to me - by bailing out early in interleavedAccessCanBeWidened we can avoid doing unnecessary work. It's perhaps worth pointing that there is currently a patch (#89018) to add support for factors > 2.
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'm with @preames, there's no legal LLVM IR that cannot be handled by the code generator when scalable vectors are available and thus there's no reason for the cost model to return an invalid cost. #89018 changes nothing because it doesn't introduce any new IR and thus at worst the cost might be wrong, but it'll still safely make it through code generation.
The cost model shouldn't have to worry about non-existent LLVM IR, whereas it seems prudent for LoopVectorize to first check that what it's trying to do is possible within the current limitations of LLVM IR.
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.
Thanks for checking & clarifying @preames, just wanted to make sure to fully understand what's going on and make sure the costs returned should be reasonable when dropping the early exit.