This is an archive of the discontinued LLVM Phabricator instance.

[IndVarSimplify] Lift limitations on IV being a Phi for turn-to-invariant
ClosedPublic

Authored by mkazantsev on Nov 21 2022, 3:36 AM.

Details

Summary

These limitations are too strict, and their only purpose is to avoid code
size explosion. These restrictions seem obsolete, and the size problem
is solved in other places through cheap expansion limits.

The motivation is that the old code cannot deal with comparisons against
induction variant's increment.

Diff Detail

Event Timeline

mkazantsev created this revision.Nov 21 2022, 3:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 21 2022, 3:36 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
mkazantsev requested review of this revision.Nov 21 2022, 3:36 AM
Herald added a project: Restricted Project. · View Herald TranscriptNov 21 2022, 3:36 AM
mkazantsev updated this revision to Diff 476847.
lebedev.ri accepted this revision.Nov 21 2022, 7:36 AM

The test changes seem like improvements to me.
Since we expand into preheader (which might be some other's loop body),
i guess size growth shouldn't be too much of an issue.
LG, but maybe wait for another opinion for a few days.

llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
224–229

I guess this is slightly broken, if rhs is constant but lhs needs 2x the SCEVCheapExpansionBudget,
we'd still want to expand. (Well, or they both in total should fit into SCEVCheapExpansionBudget).
But that is a separate issue.

This revision is now accepted and ready to land.Nov 21 2022, 7:36 AM

LGTM

I do want to warn that this may be a subtler perf tradeoff than it looks. I'm fine with landing this, but be alert for perf regressions and be prepared to investigate and revert if needed. Despite that, I think this is generally the right idea.

LGTM

I do want to warn that this may be a subtler perf tradeoff than it looks. I'm fine with landing this, but be alert for perf regressions and be prepared to investigate and revert if needed. Despite that, I think this is generally the right idea.

ACK, all such expansions are dormant performance regressions.

mkazantsev added inline comments.Nov 21 2022, 8:35 PM
llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
224–229

We can improve isHighCostExpansion to take several SCEVs and compute at once, I'll see how hard it is to do it.

This revision was landed with ongoing or failed builds.Nov 21 2022, 10:09 PM
This revision was automatically updated to reflect the committed changes.