[PATCH] D38581: [IRCE] Fix intersection between signed and unsigned ranges

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 5 04:39:08 PDT 2017


mkazantsev created this revision.

IRCE for unsigned latch conditions was temporarily disabled by https://reviews.llvm.org/rL314881. The motivating
example contained an unsigned latch condition and a signed range check. One of the safe
iteration ranges was `[1, SINT_MAX + 1]`. Its right border was incorrectly interpreted as a negative
value in `IntersectRange` function, this lead to a miscompile under which we deleted a range check
without inserting a postloop where it was needed.

This patch brings back IRCE for unsigned latch conditions. Now we treat range intersection more
carefully. If the latch condition was unsigned, we only try to consider a range check for deletion if:

1. The range check is also unsigned, or
2. Safe iteration range of the range check lies within `[0, SINT_MAX]`.

The same is done for signed latch.

Values from `[0, SINT_MAX]` are unambiguous, these values are non-negative under any interpretation,
and all values of a range intersected with such range are also non-negative.

We also use signed/unsigned min/max functions for range intersection depending on type of the
latch condition.


https://reviews.llvm.org/D38581

Files:
  lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
  test/Transforms/IRCE/clamp.ll
  test/Transforms/IRCE/correct-loop-info.ll
  test/Transforms/IRCE/eq_ne.ll
  test/Transforms/IRCE/range_intersect_miscompile.ll
  test/Transforms/IRCE/stride_more_than_1.ll
  test/Transforms/IRCE/unsigned_comparisons_ugt.ll
  test/Transforms/IRCE/unsigned_comparisons_ult.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38581.117797.patch
Type: text/x-patch
Size: 26696 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171005/7f80e0c0/attachment-0001.bin>


More information about the llvm-commits mailing list