This is an archive of the discontinued LLVM Phabricator instance.

[IndVars] Replace PHIs if loop exits on 1st iteration
ClosedPublic

Authored by dmakogon on Sep 10 2021, 4:53 AM.

Details

Summary

This is a part of https://reviews.llvm.org/D108910
We replace all loop PHIs with values coming from the loop preheader if we proved that backedge is never taken.

Diff Detail

Event Timeline

dmakogon created this revision.Sep 10 2021, 4:53 AM
dmakogon requested review of this revision.Sep 10 2021, 4:53 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 10 2021, 4:53 AM
lebedev.ri accepted this revision.Sep 10 2021, 5:04 AM
lebedev.ri added a subscriber: lebedev.ri.

LG

This revision is now accepted and ready to land.Sep 10 2021, 5:04 AM
This revision was landed with ongoing or failed builds.Sep 12 2021, 8:50 PM
This revision was automatically updated to reflect the committed changes.
reames added a subscriber: reames.Sep 13 2021, 10:13 AM

Reverted patch due to issue caught in post commit review. See inline.

llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
1317

As written, this code does not preserve LCSSA. Consider the case where we have two sibling loops and the header of the second is directly an exit block of the first. This is not loop simplify form (i.e. no preheader), but it is a possible case.

mkazantsev added inline comments.Sep 17 2021, 2:44 AM
llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
1317

Philip, there is an assert on line 1741 that the loop is in simplify form. I don't think the situation you are referring to is even possible.

Just to close the loop here, I agree with Max that the case I was concerned about was not possible due to an earlier bail out. The reapply of the reverted patch and the added assert resolve my concern entirely. Thanks.

(Sorry for delayed response, took a vacation last week and thus only seeing this now.)