This is an archive of the discontinued LLVM Phabricator instance.

[VPlan] Fold (MUL A, 1) -> A as VPlan2VPlan transform.
ClosedPublic

Authored by fhahn on Aug 30 2023, 7:01 AM.

Details

Summary

Add first VPlan-based recipe simplification to fold (MUL A, 1) -> A.
Among other things, this enables additional simplifications after
applying versioned strides, as follow up to D147783.

Diff Detail

Event Timeline

fhahn created this revision.Aug 30 2023, 7:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 30 2023, 7:01 AM
fhahn requested review of this revision.Aug 30 2023, 7:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 30 2023, 7:01 AM
Ayal accepted this revision.Sep 18 2023, 5:28 AM

LGTM, adding various nits and thoughts.

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
803

nit: could become a method of VPValue?

811

Also handle VPInstruction via its getOpcode()?

nit: could become a method of VPRecipeBase?

819

nit: would "constantFold" be more accurate than the general "simplify"?

Comment that collecting R's folded into their operands is left for subsequent DCE.

May be worth indicating if any change was made, at some point - relevant for VPlan2VPlan passes in general.

May be worth testing that Mul 1, 1 gets optimized into a live-in.

832

nit: would "constantFold" be more accurate than the general "simplify"?

This revision is now accepted and ready to land.Sep 18 2023, 5:28 AM
fhahn marked 4 inline comments as done.Sep 18 2023, 1:45 PM
fhahn added inline comments.
llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp
803

I am planning to follow up by adding/extending PatternMatcher.h support for VPlan, which seems like an appropriate place for it to live

811

Updated to also handle VPInstruction, thanks!

I am planning to follow up by adding/extending PatternMatcher.h support for VPlan, which seems like an appropriate place for it to live, in particular because there are various recipes that cannot be mapped to an opcode at the moment or it is at least not entirely clear to which opcode they should be matched, e.g. interleave or canonical IV recipes.

819

I think constantFold would be too narrow, as other 'instcombine' style simplifications would be a good fit here as needed.

fhahn marked 3 inline comments as done.Sep 18 2023, 1:45 PM
This revision was automatically updated to reflect the committed changes.