[PATCH] D28485: [ValueTracking] recognize a 'not' of an assumed condition as false

Sanjay Patel via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 17 10:27:08 PST 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL292239: [ValueTracking] recognize a 'not' of an assumed condition as false (authored by spatel).

Changed prior to commit:
  https://reviews.llvm.org/D28485?vs=83721&id=84697#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D28485

Files:
  llvm/trunk/lib/Analysis/AssumptionCache.cpp
  llvm/trunk/lib/Analysis/ValueTracking.cpp
  llvm/trunk/test/Transforms/InstCombine/assume.ll
  llvm/trunk/test/Transforms/InstCombine/select.ll


Index: llvm/trunk/lib/Analysis/AssumptionCache.cpp
===================================================================
--- llvm/trunk/lib/Analysis/AssumptionCache.cpp
+++ llvm/trunk/lib/Analysis/AssumptionCache.cpp
@@ -47,9 +47,11 @@
     } else if (auto *I = dyn_cast<Instruction>(V)) {
       Affected.push_back(I);
 
-      if (I->getOpcode() == Instruction::BitCast ||
-          I->getOpcode() == Instruction::PtrToInt) {
-        auto *Op = I->getOperand(0);
+      // Peek through unary operators to find the source of the condition.
+      Value *Op;
+      if (match(I, m_BitCast(m_Value(Op))) ||
+          match(I, m_PtrToInt(m_Value(Op))) ||
+          match(I, m_Not(m_Value(Op)))) {
         if (isa<Instruction>(Op) || isa<Argument>(Op))
           Affected.push_back(Op);
       }
Index: llvm/trunk/lib/Analysis/ValueTracking.cpp
===================================================================
--- llvm/trunk/lib/Analysis/ValueTracking.cpp
+++ llvm/trunk/lib/Analysis/ValueTracking.cpp
@@ -553,6 +553,13 @@
       KnownOne.setAllBits();
       return;
     }
+    if (match(Arg, m_Not(m_Specific(V))) &&
+        isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
+      assert(BitWidth == 1 && "assume operand is not i1?");
+      KnownZero.setAllBits();
+      KnownOne.clearAllBits();
+      return;
+    }
 
     // The remaining tests are all recursive, so bail out if we hit the limit.
     if (Depth == MaxDepth)
Index: llvm/trunk/test/Transforms/InstCombine/assume.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/assume.ll
+++ llvm/trunk/test/Transforms/InstCombine/assume.ll
@@ -176,13 +176,13 @@
   ret i32 %lnot.ext
 }
 
-; FIXME: If the 'not' of a condition is known true, then the condition must be false. 
+; If the 'not' of a condition is known true, then the condition must be false.
 
 define i1 @assume_not(i1 %cond) {
 ; CHECK-LABEL: @assume_not(
 ; CHECK-NEXT:    [[NOTCOND:%.*]] = xor i1 [[COND:%.*]], true
 ; CHECK-NEXT:    call void @llvm.assume(i1 [[NOTCOND]])
-; CHECK-NEXT:    ret i1 [[COND]]
+; CHECK-NEXT:    ret i1 false
 ;
   %notcond = xor i1 %cond, true
   call void @llvm.assume(i1 %notcond)
Index: llvm/trunk/test/Transforms/InstCombine/select.ll
===================================================================
--- llvm/trunk/test/Transforms/InstCombine/select.ll
+++ llvm/trunk/test/Transforms/InstCombine/select.ll
@@ -1344,14 +1344,13 @@
   ret i8 %sel
 }
 
-; FIXME: computeKnownBitsFromAssume() should understand the 'not' of an assumed condition.
+; computeKnownBitsFromAssume() understands the 'not' of an assumed condition.
 
 define i8 @assume_cond_false(i1 %cond, i8 %x, i8 %y) {
 ; CHECK-LABEL: @assume_cond_false(
 ; CHECK-NEXT:    [[NOTCOND:%.*]] = xor i1 %cond, true
 ; CHECK-NEXT:    call void @llvm.assume(i1 [[NOTCOND]])
-; CHECK-NEXT:    [[SEL:%.*]] = select i1 %cond, i8 %x, i8 %y
-; CHECK-NEXT:    ret i8 [[SEL]]
+; CHECK-NEXT:    ret i8 %y
 ;
   %notcond = xor i1 %cond, true
   call void @llvm.assume(i1 %notcond)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D28485.84697.patch
Type: text/x-patch
Size: 3053 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170117/d24a1974/attachment.bin>


More information about the llvm-commits mailing list