[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
Mon Jan 9 15:26:46 PST 2017


spatel updated this revision to Diff 83721.
spatel added a comment.

Patch updated:
Use clearAllBits/setAllBits as suggested by David.


https://reviews.llvm.org/D28485

Files:
  lib/Analysis/ValueTracking.cpp
  test/Transforms/InstCombine/assume.ll


Index: test/Transforms/InstCombine/assume.ll
===================================================================
--- test/Transforms/InstCombine/assume.ll
+++ 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: lib/Analysis/ValueTracking.cpp
===================================================================
--- lib/Analysis/ValueTracking.cpp
+++ lib/Analysis/ValueTracking.cpp
@@ -550,6 +550,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)


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


More information about the llvm-commits mailing list