This is an archive of the discontinued LLVM Phabricator instance.

[BreakCritEdges] Add option to opt-out of perserving loop-simplify.
ClosedPublic

Authored by fhahn on Jun 10 2020, 9:09 AM.

Details

Summary

This patch adds a new option to CriticalEdgeSplittingOptions to control
whether loop-simplify form must be preserved. It is them used by GVN to
indicate that loop-simplify form does not have to be preserved.

This fixes a crash exposed by 189efe295b6e.

If the critical edge we are splitting goes from a block inside a loop to
a block outside the loop, splitting the edge will create a new exit
block. As a result, the new block will branch to the original exit
block, which will add a non-loop predecessor, breaking loop-simplify
form. To preserve loop-simplify form, the predecessor blocks of the
original exit are split, but that does not work for blocks with
indirectbr terminators. If preserving loop-simplify form is requested,
bail out , before making any changes.

Diff Detail

Event Timeline

fhahn created this revision.Jun 10 2020, 9:09 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 10 2020, 9:09 AM
Herald added a subscriber: hiraditya. · View Herald Transcript
fhahn updated this revision to Diff 269968.Jun 10 2020, 2:20 PM

Only compute LoopPreds once.

fhahn updated this revision to Diff 270158.Jun 11 2020, 8:40 AM

Updated to introduce new CriticalEdgeSPlittingOption to disable preserving loop-simplify form and use it in GVN.

efriedma accepted this revision.Jun 11 2020, 11:09 AM

I'm a little uncomfortable with making SplitCriticalEdge fail rarely... but I guess if this is the least-nasty solution, it's okay for now. LGTM

This revision is now accepted and ready to land.Jun 11 2020, 11:09 AM
efriedma added inline comments.Jun 11 2020, 11:33 AM
llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp
193

Really, I'd prefer if the if (Options.PreserveLoopSimplify) return nullptr; check wasn't guarded by the check for indirectbrinsts.

fhahn retitled this revision from [BreakCritEdges] Check if we need to split blocks with indirectbr terms. to [BreakCritEdges] Add option to opt-out of perserving loop-simplify..Jun 12 2020, 3:15 AM
fhahn edited the summary of this revision. (Show Details)
This revision was automatically updated to reflect the committed changes.
fhahn marked an inline comment as done.Jun 12 2020, 4:35 AM
fhahn added inline comments.
llvm/lib/Transforms/Utils/BreakCriticalEdges.cpp
193

Unfortunately there are some places, like LoopRotate & LoopUnswtich that rely on the splitting to happen (and loop-simplify form being preserved here). In most cases they probably reject the indirectbr cases up-front. I'll continue on D81584, which should hopefully eliminate this particular issue.