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

via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 8 21:16:27 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);
----------------
goldsteinn wrote:

Also I'm probably missing something, but `computeKnownBitsFromCmp` seems to do analysis assuming the condition is true. But for something like `if (A || B)` can we actually take the implied known bits from condition `B`?

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


More information about the llvm-commits mailing list