This is an archive of the discontinued LLVM Phabricator instance.

[VPlan] Add VPInterleaveRecipe::NeedsMaskForGaps field (NFCI).
ClosedPublic

Authored by fhahn on Apr 3 2023, 1:37 PM.

Details

Summary

This patch adds a NeedsMaskForGaps field to VPInterleaveRecipe to record
whether a mask for gaps is needed. This removes a dependence on the cost
model in VPlan code-generation.

Diff Detail

Event Timeline

fhahn created this revision.Apr 3 2023, 1:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 3 2023, 1:37 PM
fhahn requested review of this revision.Apr 3 2023, 1:37 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 3 2023, 1:37 PM
Ayal accepted this revision.Apr 5 2023, 4:11 AM

Whether masking of suffix gaps in interleaved loads can be optimized away or not should indeed be recorded during planning rather than IR generation.
Adding a couple of nits.

llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
2670–2671

nit (Independent of this patch): MaskForGaps is set here for loads and later reset for stores. Better to either set it here for both or place this setting inside the handling of loads.

9041

nit: may be clearer to first set bool NeedsMaskForGaps = IG->requiresScalarEpilogue() && !CM.isScalarEpilogueAllowed(); and then use it, instead of setting it inline.

llvm/lib/Transforms/Vectorize/VPlan.h
1398

nit: would be good to document and clarify or rename the two masks: HasMask indicates if the interleave group is inside a conditional basic block, i.e., HasBlockMask or HasMaskForBlock. NeedsMaskForGaps indicates if the interleave group of loads is allowed to speculatively load absent unused members or must avoid doing so by using a mask, i.e., !CanSpeculativelyLoadWithoutMask, where the speculation relies on loading present members on both sides of missing ones - gaps.

This revision is now accepted and ready to land.Apr 5 2023, 4:11 AM
fhahn updated this revision to Diff 511657.Apr 7 2023, 4:00 AM

Rebase and address nits, thanks! I am planning to land this soon.

fhahn marked 3 inline comments as done.Apr 7 2023, 5:12 AM
fhahn added inline comments.
llvm/lib/Transforms/Vectorize/LoopVectorize.cpp
2670–2671

Moved inside the load handling: 3f36b9b456ac4bfa695e253926daa87cd9838550

9041

Should be adjusted, thanks!

llvm/lib/Transforms/Vectorize/VPlan.h
1398

Added comments, thanks!