[PATCH] D37209: [LSR] Fix Shadow IV in case of integer overflow

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 28 04:20:33 PDT 2017


mkazantsev created this revision.

When LSR processes code like

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

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 `nw` flag.


https://reviews.llvm.org/D37209

Files:
  lib/Transforms/Scalar/LoopStrengthReduce.cpp
  test/Transforms/LoopStrengthReduce/X86/2008-08-14-ShadowIV.ll
  test/Transforms/LoopStrengthReduce/dont_turn_int_overflow_to_fp.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37209.112878.patch
Type: text/x-patch
Size: 4475 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170828/33470fb6/attachment.bin>


More information about the llvm-commits mailing list