[llvm] [ValueTracking] Handle assume( trunc x to i1) (PR #118406)

via llvm-commits llvm-commits at lists.llvm.org
Sun Feb 9 08:53:02 PST 2025


================
@@ -868,10 +873,9 @@ void llvm::computeKnownBitsFromContext(const Value *V, KnownBits &Known,
 
     Value *Arg = I->getArgOperand(0);
 
-    if (Arg == V && isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
-      assert(BitWidth == 1 && "assume operand is not i1?");
-      (void)BitWidth;
-      Known.setAllOnes();
+    if (match(Arg, m_TruncOrSelf(m_Specific(V))) &&
+        isValidAssumeForContext(I, Q.CxtI, Q.DT)) {
+      Known.One.setBit(0);
----------------
goldsteinn wrote:

You can `sext`/`zext` if you have `nsw`/`nuw` on the trunc: https://alive2.llvm.org/ce/z/dx38fL

https://github.com/llvm/llvm-project/pull/118406


More information about the llvm-commits mailing list