[LoopPredication] Fix where we generate widened condition. PR61963
authorAnna Thomas <anna@azul.com>
Thu, 6 Apr 2023 18:42:14 +0000 (14:42 -0400)
committerAnna Thomas <anna@azul.com>
Mon, 10 Apr 2023 14:37:05 +0000 (10:37 -0400)
commit27f8a62a541e650d8d6ee4b7001b78e976519306
tree888134b17da23bc5f8809f7d22d4467da6d67d14
parent975cc76020a0a5f4a272a6888548307dabfb0b52
[LoopPredication] Fix where we generate widened condition. PR61963

Loop predication's predicateLoopExit pass does two incorrect things:

It sinks the widenable call into the loop, thereby converting an invariant condition to a variant one
It widens the widenable call at a branch thereby converting the branch into a loop-varying one.

The latter is problematic when the branch may have been loop-invariant
and prior optimizations (such as indvars) may have relied on this
fact, and updated the deopt state accordingly.

Now, when we widen this with a loop-varying condition, the deopt state
is no longer correct.
https://github.com/llvm/llvm-project/issues/61963 fixed.

Differential Revision: https://reviews.llvm.org/D147662
llvm/lib/Transforms/Scalar/LoopPredication.cpp
llvm/test/Transforms/LoopPredication/pr61963.ll
llvm/test/Transforms/LoopPredication/predicate-exits.ll