]> granicus.if.org Git - llvm/commit
[IRCE] Fix intersection between signed and unsigned ranges
authorMax Kazantsev <max.kazantsev@azul.com>
Wed, 25 Oct 2017 06:47:39 +0000 (06:47 +0000)
committerMax Kazantsev <max.kazantsev@azul.com>
Wed, 25 Oct 2017 06:47:39 +0000 (06:47 +0000)
commit3b1ffff65b6c6fe27f5b849732113fe09e708b4c
treef09e1914bb67664d369ed4f9d8f63edc7db94e1e
parent30b21c38749c82a734c797beeb7af71468ce8e83
[IRCE] Fix intersection between signed and unsigned ranges

IRCE for unsigned latch conditions was temporarily disabled by 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.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@316552 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
test/Transforms/IRCE/clamp.ll
test/Transforms/IRCE/correct-loop-info.ll
test/Transforms/IRCE/empty_ranges.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