[llvm] [ValueTracking] Support dominating known bits condition in and/or (PR #74728)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Sat Dec 9 00:56:42 PST 2023


================
@@ -705,28 +705,40 @@ static void computeKnownBitsFromCmp(const Value *V, CmpInst::Predicate Pred,
   }
 }
 
+static void computeKnownBitsFromCond(const Value *V, Value *Cond,
+                                     KnownBits &Known, unsigned Depth,
+                                     const SimplifyQuery &SQ, bool Invert) {
+  Value *A, *B;
+  if (Depth < MaxAnalysisRecursionDepth &&
+      (Invert ? match(Cond, m_LogicalOr(m_Value(A), m_Value(B)))
+              : match(Cond, m_LogicalAnd(m_Value(A), m_Value(B))))) {
+    computeKnownBitsFromCond(V, A, Known, Depth + 1, SQ, Invert);
+    computeKnownBitsFromCond(V, B, Known, Depth + 1, SQ, Invert);
----------------
nikic wrote:

> Can we potentially return conflict if we are analyzing something like `if(A > 0 || A < 0)`? Seems `computeKNownBitsFromCmp` will set both signbit in both zero/one.

Yes, this can happen and is handled here: https://github.com/llvm/llvm-project/blob/01448920bb40392cb0f09e4a736ab199a65cdebb/llvm/lib/Analysis/ValueTracking.cpp#L744 Just like with assumes we discard all information in that case.

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


More information about the llvm-commits mailing list