]> granicus.if.org Git - llvm/commit
[IRCE] Fix buggy behavior in Clamp
authorMax Kazantsev <max.kazantsev@azul.com>
Fri, 18 Aug 2017 22:50:29 +0000 (22:50 +0000)
committerMax Kazantsev <max.kazantsev@azul.com>
Fri, 18 Aug 2017 22:50:29 +0000 (22:50 +0000)
commitde4770b949a56546ad9a75d918217623f412a8c3
tree8dccedc383867aedb46fb165748eadae3343cbaa
parentb251a7588a5447aa29263fe8c0a6435ef805e820
[IRCE] Fix buggy behavior in Clamp

Clamp function was too optimistic when choosing signed or unsigned min/max function for calculations.
In fact, `!IsSignedPredicate` guarantees us that `Smallest` and `Greatest` can be compared safely using unsigned
predicates, but we did not check this for `S` which can in theory be negative.

This patch makes Clamp use signed min/max for cases when it fails to prove `S` being non-negative,
and it adds a test where such situation may lead to incorrect conditions calculation.

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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@311205 91177308-0d34-0410-b5e6-96231b3b80d8
lib/Transforms/Scalar/InductiveRangeCheckElimination.cpp
test/Transforms/IRCE/clamp.ll [new file with mode: 0644]