aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorNoah Goldstein <goldstein.w.n@gmail.com>2024-02-23 12:54:11 -0600
committerNoah Goldstein <goldstein.w.n@gmail.com>2024-02-25 12:44:23 -0600
commit6f9b0a7095cbb7781e1f387f99d5725c950ce79b (patch)
tree21729b62eefc0fc68b04852a4240feb75017d876 /llvm/lib/Analysis/ValueTracking.cpp
parenteca0bd171e6ab0f1c60e3950f5fa5fa1eaf1fa32 (diff)
downloadllvm-6f9b0a7095cbb7781e1f387f99d5725c950ce79b.zip
llvm-6f9b0a7095cbb7781e1f387f99d5725c950ce79b.tar.gz
llvm-6f9b0a7095cbb7781e1f387f99d5725c950ce79b.tar.bz2
[ValueTracking] Compute knownbits for `(and/or cond0, cond1)` on both sides of branch
The false branch for `and` and true branch for `or` provide less information (intersection as opposed to union), but still can give some useful information. Closes #82818
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index de105df..e591ac5 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -711,10 +711,17 @@ static void computeKnownBitsFromCond(const Value *V, Value *Cond,
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);
+ match(Cond, m_LogicalOp(m_Value(A), m_Value(B)))) {
+ KnownBits Known2(Known.getBitWidth());
+ KnownBits Known3(Known.getBitWidth());
+ computeKnownBitsFromCond(V, A, Known2, Depth + 1, SQ, Invert);
+ computeKnownBitsFromCond(V, B, Known3, Depth + 1, SQ, Invert);
+ if (Invert ? match(Cond, m_LogicalOr(m_Value(), m_Value()))
+ : match(Cond, m_LogicalAnd(m_Value(), m_Value())))
+ Known2 = Known2.unionWith(Known3);
+ else
+ Known2 = Known2.intersectWith(Known3);
+ Known = Known.unionWith(Known2);
}
if (auto *Cmp = dyn_cast<ICmpInst>(Cond))