summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/InstCombine/icmp-shr.ll
diff options
context:
space:
mode:
authorAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>2014-09-17 11:32:31 +0000
committerAndrea Di Biagio <Andrea_DiBiagio@sn.scee.net>2014-09-17 11:32:31 +0000
commit5b92b4971a49afc5ab1e405d834bbeef29eabd72 (patch)
tree744029a66ad25438a11ad8acab1b1f228d4c397f /llvm/test/Transforms/InstCombine/icmp-shr.ll
parent5e6bc9e162f650d8d95282fab102995e8b289dcd (diff)
downloadbcm5719-llvm-5b92b4971a49afc5ab1e405d834bbeef29eabd72.tar.gz
bcm5719-llvm-5b92b4971a49afc5ab1e405d834bbeef29eabd72.zip
[InstCombine] Fix wrong folding of constant comparison involving ahsr and negative quantities (PR20945).
Example: define i1 @foo(i32 %a) { %shr = ashr i32 -9, %a %cmp = icmp ne i32 %shr, -5 ret i1 %cmp } Before this fix, the instruction combiner wrongly thought that %shr could have never been equal to -5. Therefore, %cmp was always folded to 'true'. However, when %a is equal to 1, then %cmp evaluates to 'false'. Therefore, in this example, it is not valid to fold %cmp to 'true'. The problem was only affecting the case where the comparison was between negative quantities where one of the quantities was obtained from arithmetic shift of a negative constant. This patch fixes the problem with the wrong folding (fixes PR20945). With this patch, the 'icmp' from the example is now simplified to a comparison between %a and 1. This still allows us to get rid of the arithmetic shift (%shr). llvm-svn: 217950
Diffstat (limited to 'llvm/test/Transforms/InstCombine/icmp-shr.ll')
-rw-r--r--llvm/test/Transforms/InstCombine/icmp-shr.ll15
1 files changed, 15 insertions, 0 deletions
diff --git a/llvm/test/Transforms/InstCombine/icmp-shr.ll b/llvm/test/Transforms/InstCombine/icmp-shr.ll
index 36490e5d10a..41009d24c31 100644
--- a/llvm/test/Transforms/InstCombine/icmp-shr.ll
+++ b/llvm/test/Transforms/InstCombine/icmp-shr.ll
@@ -675,3 +675,18 @@ define i1 @nonexact_ashr_ne_noexactlog(i8 %a) {
%cmp = icmp ne i8 %shr, -30
ret i1 %cmp
}
+
+; Don't try to fold the entire body of function @PR20945 into a
+; single `ret i1 true` statement.
+; If %B is equal to 1, then this function would return false.
+; As a consequence, the instruction combiner is not allowed to fold %cmp
+; to 'true'. Instead, it should replace %cmp with a simpler comparison
+; between %B and 1.
+
+; CHECK-LABEL: @PR20945(
+; CHECK: icmp ne i32 %B, 1
+define i1 @PR20945(i32 %B) {
+ %shr = ashr i32 -9, %B
+ %cmp = icmp ne i32 %shr, -5
+ ret i1 %cmp
+}
OpenPOWER on IntegriCloud