[SCEV] Prove condition invariance via context
authorMax Kazantsev <mkazantsev@azul.com>
Fri, 12 Aug 2022 06:27:01 +0000 (13:27 +0700)
committerMax Kazantsev <mkazantsev@azul.com>
Fri, 12 Aug 2022 07:23:35 +0000 (14:23 +0700)
commita3d1fb3b59b473e4f262a05f187de6474b7721e7
tree8e8995fd72cb135c7a887ec92bbd962b6ed8e489
parent90736babcaeb5222ee5ba50a823b7acffdd5a4dd
[SCEV] Prove condition invariance via context

Contextual knowledge may be used to prove invariance of some conditions.
For example, in this case:
```
  ; %len >= 0
  guard(%iv = {start,+,1}<nuw> <s %len)
  guard(%iv = {start,+,1}<nuw> <u %len)
```
the 2nd check always fails if `start` is negative and always passes otherwise.

It looks like there are more opportunities of this kind that are still to be
implemented in the future.

Differential Revision: https://reviews.llvm.org/D129753
Reviewed By: apilipenko
llvm/include/llvm/Analysis/ScalarEvolution.h
llvm/lib/Analysis/ScalarEvolution.cpp
llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
llvm/test/Transforms/IndVarSimplify/cycled_phis.ll
llvm/test/Transforms/IndVarSimplify/outer_phi.ll