[LICM] Reassociate & hoist sub expressions
authorMax Kazantsev <mkazantsev@azul.com>
Mon, 29 May 2023 05:05:50 +0000 (12:05 +0700)
committerMax Kazantsev <mkazantsev@azul.com>
Mon, 29 May 2023 05:52:43 +0000 (12:52 +0700)
commitdd0cf23e4a87765b03bb1003d4cc37445d8217b4
treef4d7c5483ca5a2e167376ff230154df0d2d02d11
parent0a6aec2fb3faad9d5d7f9f353606bdfe298209a8
[LICM] Reassociate & hoist sub expressions

LICM could reassociate mixed variant/invariant comparison/arithmetic operations
and hoist invariant parts out of loop if it can prove that they can be computed
without overflow. Motivating example here:
```
  INV1 - VAR1 < INV2
```
can be turned into
```
  VAR > INV1 - INV2
```
if we can prove no-signed-overflow here. Then `INV1 - INV2` can be computed
out of loop, so we save one arithmetic operation in-loop.

Reviewed By: skatkov
Differential Revision: https://reviews.llvm.org/D148001
llvm/lib/Transforms/Scalar/LICM.cpp
llvm/test/Transforms/LICM/hoist-add-sub.ll