]> granicus.if.org Git - llvm/commit
[LSR] Fix Shadow IV in case of integer overflow
authorMax Kazantsev <max.kazantsev@azul.com>
Tue, 29 Aug 2017 07:32:20 +0000 (07:32 +0000)
committerMax Kazantsev <max.kazantsev@azul.com>
Tue, 29 Aug 2017 07:32:20 +0000 (07:32 +0000)
commitb074309e7051d5e5eddcacf317a50a2424e3dc41
tree591668ea2a1848aec0246fda31431737dba5b196
parenta540c13df1290b643724a00f26a67c1636633c10
[LSR] Fix Shadow IV in case of integer overflow

When LSR processes code like

  int accumulator = 0;
  for (int i = 0; i < N; i++) {
    accummulator += i;
    use((double) accummulator);
  }

It may decide to replace integer `accumulator` with a double Shadow IV to get rid
of casts.  The problem with that is that the `accumulator`'s value may overflow.
Starting from this moment, the behavior of integer and double accumulators
will differ.

This patch strenghtens up the conditions of Shadow IV mechanism applicability.
We only allow it for IVs that are proved to be `AddRec`s with `nsw`/`nuw` flag.

Differential Revision: https://reviews.llvm.org/D37209

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311986 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Scalar/LoopStrengthReduce.cpp
test/Transforms/LoopStrengthReduce/X86/2008-08-14-ShadowIV.ll