[SCEV] Use umin_seq for BECount of multi-exit loops
authorNikita Popov <nikita.ppv@gmail.com>
Sat, 21 May 2022 13:39:08 +0000 (15:39 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Sat, 21 May 2022 13:48:14 +0000 (15:48 +0200)
commitc8b675eaa1de1d4edebd0292ca6de3180c687127
treefe8d4841d50aa520c6b1296e12d35e9cf3985653
parent295d032762ad284068c72cc1904680a4db5e80d3
[SCEV] Use umin_seq for BECount of multi-exit loops

When computing the BECount for multi-exit loops, we need to combine
individual exit counts using umin_seq rather than umin. This is
because an earlier exit may exit on the first iteration, in which
case later exit expressions will not be evaluated and could be
poisonous. We cannot propagate potential poison values from later
exits.

In particular, this avoids the introduction of "branch on poison"
UB when optimizing multi-exit loops.

Differential Revision: https://reviews.llvm.org/D124910
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/test/Transforms/IndVarSimplify/ARM/code-size.ll
llvm/test/Transforms/IndVarSimplify/loop-predication.ll
llvm/test/Transforms/IndVarSimplify/post-inc-range.ll
llvm/test/Transforms/PhaseOrdering/AArch64/peel-multiple-unreachable-exits-for-vectorization.ll