[SimpleLoopUnswitch] Fix SCEV invalidation issue
authorBjorn Pettersson <bjorn.a.pettersson@ericsson.com>
Tue, 28 Mar 2023 16:07:52 +0000 (18:07 +0200)
committerBjorn Pettersson <bjorn.a.pettersson@ericsson.com>
Thu, 6 Apr 2023 07:46:42 +0000 (09:46 +0200)
commit44773b798a024d39084fe710ccfb2851eb0df5d4
tree901e2bbe6e4e0043f18b65f99a15a794672f2d12
parenta162ddf7f2f66af5a797d2bc0c78e628bb8c43fe
[SimpleLoopUnswitch] Fix SCEV invalidation issue

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

Differential Revision: https://reviews.llvm.org/D147058
llvm/lib/Transforms/Scalar/SimpleLoopUnswitch.cpp
llvm/test/Transforms/SimpleLoopUnswitch/update-scev-3.ll [new file with mode: 0644]