[InstCombine] FoldICmpCstShrCst failed for ashr when comparing against -1
authorDavid Majnemer <david.majnemer@gmail.com>
Sat, 19 Sep 2015 00:48:31 +0000 (00:48 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Sat, 19 Sep 2015 00:48:31 +0000 (00:48 +0000)
(icmp eq (ashr C1, %V) -1) may have multiple answers if C1 is not a
power of two and has the sign bit set.

This fixes PR24873.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@248074 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineCompares.cpp
test/Transforms/InstCombine/icmp-shr.ll

index ac94cdb93b0b6e8961ceaa38d20e0c9d7518d366..06c5b3a88c76b4c2e8782446469856428740e6a4 100644 (file)
@@ -1083,7 +1083,7 @@ Instruction *InstCombiner::FoldICmpCstShrCst(ICmpInst &I, Value *Op, Value *A,
   if (Shift > 0) {
     if (IsAShr && AP1 == AP2.ashr(Shift)) {
       // There are multiple solutions if we are comparing against -1 and the LHS
-      // of the ashr is not a power of two..
+      // of the ashr is not a power of two.
       if (AP1.isAllOnesValue() && !AP2.isPowerOf2())
         return getICmp(I.ICMP_UGE, A, ConstantInt::get(A->getType(), Shift));
       return getICmp(I.ICMP_EQ, A, ConstantInt::get(A->getType(), Shift));
index 52414b99cca7bca5577a9f98ba8537b3b7cc78b6..4fa85a72baf739ab5709c992d853d4d312e6ef95 100644 (file)
@@ -376,3 +376,12 @@ define i1 @PR21222(i32 %B) {
   %cmp = icmp eq i32 %shr, -2
   ret i1 %cmp
 }
+
+; CHECK-LABEL: @PR24873(
+; CHECK:      %[[icmp:.*]] = icmp ugt i64 %V, 61
+; CHECK-NEXT: ret i1 %[[icmp]]
+define i1 @PR24873(i64 %V) {
+  %ashr = ashr i64 -4611686018427387904, %V
+  %icmp = icmp eq i64 %ashr, -1
+  ret i1 %icmp
+}