This is an archive of the discontinued LLVM Phabricator instance.

[IndVars] Teach replaceCongruentIVs to avoid scrambling induction variables
ClosedPublic

Authored by efriedma on Mar 17 2022, 2:04 PM.

Details

Summary

replaceCongruentIVs analysis is based on ScalarEvolution; this makes comparing different PHIs and performing the replacement straightforward. However, it can have some side-effects: it isn't aware whether an induction variable is in canonical form, so it can perform replacements which obscure the meaning of the IR.

In test22 in widen-loop-comp.ll, the resulting loop can't be analyzed by ScalarEvolution at all.

My attempted solution is to restrict the transform: don't try to replace induction variables using PHI nodes that don't represent simple induction variables.

I'm not sure if this is the best solution; suggestions welcome.

Diff Detail

Event Timeline

efriedma created this revision.Mar 17 2022, 2:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2022, 2:04 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
efriedma requested review of this revision.Mar 17 2022, 2:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 17 2022, 2:04 PM
fhahn accepted this revision.Mar 30 2022, 1:53 PM

However, it can have some side-effects: it isn't aware whether an induction variable is in canonical form, so it can perform replacements which obscure the meaning of the IR.

Agreed, it seems like the restriction should keep loops more analyzable throughout the pipeline. Aggressively removing phis would probably make more sense late in the pipeline/the backend, if it turns out to be needed.

LGTM, but please wait a day or so with committing in case there are additional opinions.

llvm/lib/Transforms/Utils/ScalarEvolutionExpander.cpp
2074

Could you add a comment with an explanation why this is restricted here?

This revision is now accepted and ready to land.Mar 30 2022, 1:53 PM
sanjoy resigned from this revision.Oct 10 2022, 2:43 PM
This revision was landed with ongoing or failed builds.Jul 12 2023, 12:28 PM
This revision was automatically updated to reflect the committed changes.