This is an archive of the discontinued LLVM Phabricator instance.

[SimpleLoopUnswitch] Fix SCEV invalidation issue
ClosedPublic

Authored by bjope on Mar 28 2023, 9:19 AM.

Details

Summary

This patch is making sure that we use getTopMostExitingLoop when
finding out which loops to forget, when dealing with
unswitchNontrivialInvariants and unswitchTrivialSwitch. It seems
to at least be needed for unswitchNontrivialInvariants as detected
by the included test case.

Note that unswitchTrivialBranch already used getTopMostExitingLoop.
This was done in commit 4a9cde5a791cd49b96993e6. The commit
message in that commit says "If the patch makes sense, I will also
update those places to a similar approach ...", referring to these
functions mentioned above. As far as I can tell that never happened,
but this is an attempt to finally fix that.

Fixes https://github.com/llvm/llvm-project/issues/61080

Diff Detail

Event Timeline

bjope created this revision.Mar 28 2023, 9:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 28 2023, 9:19 AM
bjope requested review of this revision.Mar 28 2023, 9:19 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 28 2023, 9:19 AM
Ka-Ka added a subscriber: Ka-Ka.Mar 28 2023, 9:37 PM
bjope added inline comments.Mar 29 2023, 4:43 AM
llvm/test/Transforms/SimpleLoopUnswitch/update-scev-3.ll
8–9

nit: that calculate

(Adding some more reviewers based on people who have been doing changes in this pass.)

fhahn accepted this revision.Apr 5 2023, 9:30 PM

LGTM, thanks! It would be nice to have a test for the switch case as well, but it’s fine to avoid the crash preemptively

This revision is now accepted and ready to land.Apr 5 2023, 9:30 PM
This revision was automatically updated to reflect the committed changes.
bjope added a comment.Apr 6 2023, 12:58 AM

LGTM, thanks! It would be nice to have a test for the switch case as well, but it’s fine to avoid the crash preemptively

Thanks.
Unfortunately I do not have a test case for the switch case. Maybe we could trigger it by some more fuzzy testing with random input directed at this pass (knowing that there also has to be some pass before it that has computed scev for the outer loops, so maybe using a passes string similar to the lit test I added here), if we really want to hunt down such a test case. Right here and now I do prefer to avoid the crash preemptively, so I've landed this patch.