This is an archive of the discontinued LLVM Phabricator instance.

[VPlan] Simplify logical OR operations within the VPlan.
Needs ReviewPublic

Authored by paulwalker-arm on Aug 8 2023, 9:40 AM.

Details

Summary

When LoopVectorize if-converts loops it creates instructions that
were no present within the original IR. These instructions make
the VPlan look more costly that it actually is and typically makes
it hard to reason about accurate use counts for blend operations.

This patch add a cut down version of PatternMatch that can operate
on VPInstructions and use this interface to allow VPInstruction
simplification. Specifically, it is used to simplify VPlan IR
related to predicate mask construction.

Diff Detail

Event Timeline

paulwalker-arm created this revision.Aug 8 2023, 9:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 8 2023, 9:40 AM
paulwalker-arm requested review of this revision.Aug 8 2023, 9:40 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 8 2023, 9:40 AM

I need to tighten up some of the matching and write tests but I'm pushing this out now to gauge opinion.

The core problem I'm trying to solve is to reduce the places where LoopVectorize makes poor decisions based on the IR that only exists at the point of vectorisation (i.e. not present within the scalar loop or perhaps just substantially different). One such example is D157412 that builds on top of this patch.

My position is that whilst the result of vectorisation can be cleaned up by later passes, there are instances like D157412 where the data has already been striped of knowledge required for optimal IR. There's also a matter of having a more accurate cost model whereby having a more optimal VPlan allows the vectoriser to make better cost based decisions.

I created VPlanPatternMatch.h because I honestly fine VPlan awkward to work with and figured hiding the awkwardness behind a PatternMatch like interface leads to more readable code.

Matt added a subscriber: Matt.Aug 22 2023, 2:25 PM

Providing a PatternMatch implementation for VPlan recipes would be great, thanks for sharing the patch! In terms of where to apply the simplification, I think it would be a beneficial to have a separate simplification transform to handle this and other cases, e.g. see D159200, D159202

llvm/lib/Transforms/Vectorize/VPlanPatternMatch.h
84

This probably should also match VPWidenRecipe & VPReplicateRecipe with Select/And/Or and VPWidenSelectRecipe.