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

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 5 15:19:39 PST 2024


================
@@ -705,28 +705,40 @@ static void computeKnownBitsFromCmp(const Value *V, CmpInst::Predicate Pred,
   }
 }
 
+static void computeKnownBitsFromCond(const Value *V, Value *Cond,
----------------
dtcxzyw wrote:

Should we add a template helper to avoid duplicating the decomposition?
```
template<typename Callable>
void decomposeLogicalAndOr(Value *Cond, const Callable& Callback, unsigned Depth, 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))))) {
    decomposeLogicalAndOr(A, Callback, Depth + 1, Invert);
    decomposeLogicalAndOr(B, Callback, Depth + 1, Invert);
    }
    // TODO: match logical not
    else
        Callback(Cond, Invert);
}

template<typename Callable>
void decomposeLogicalAndOrWithWorkList(Value *Cond, const Callable& Callback) {
    ...
}
```


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


More information about the llvm-commits mailing list