aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/AssumptionCache.cpp
diff options
context:
space:
mode:
authorNoah Goldstein <goldstein.w.n@gmail.com>2023-01-11 10:18:46 +0100
committerNikita Popov <npopov@redhat.com>2023-01-11 10:21:15 +0100
commitcc845e9de8c87c74d494f4e90e8fcf4fca264989 (patch)
tree455984444a9ca41c0b4ee4b5127736450ac1b5e5 /llvm/lib/Analysis/AssumptionCache.cpp
parent43cf2f8103f9ef0f292c2cd12e89c55406182e1a (diff)
downloadllvm-cc845e9de8c87c74d494f4e90e8fcf4fca264989.zip
llvm-cc845e9de8c87c74d494f4e90e8fcf4fca264989.tar.gz
llvm-cc845e9de8c87c74d494f4e90e8fcf4fca264989.tar.bz2
[InstCombine] Handle assume(X & Pow2 != 0) in computeKnownBits()
If we know that X & Pow2 != 0, then the bit at that position is known one. Differential Revision: https://reviews.llvm.org/D140851
Diffstat (limited to 'llvm/lib/Analysis/AssumptionCache.cpp')
-rw-r--r--llvm/lib/Analysis/AssumptionCache.cpp25
1 files changed, 16 insertions, 9 deletions
diff --git a/llvm/lib/Analysis/AssumptionCache.cpp b/llvm/lib/Analysis/AssumptionCache.cpp
index e7e476d..11796ef 100644
--- a/llvm/lib/Analysis/AssumptionCache.cpp
+++ b/llvm/lib/Analysis/AssumptionCache.cpp
@@ -105,7 +105,7 @@ findAffectedValues(CallBase *CI, TargetTransformInfo *TTI,
if (match(V, m_BitwiseLogic(m_Value(A), m_Value(B)))) {
AddAffected(A);
AddAffected(B);
- // (A << C) or (A >>_s C) or (A >>_u C) where C is some constant.
+ // (A << C) or (A >>_s C) or (A >>_u C) where C is some constant.
} else if (match(V, m_Shift(m_Value(A), m_ConstantInt()))) {
AddAffected(A);
}
@@ -113,15 +113,22 @@ findAffectedValues(CallBase *CI, TargetTransformInfo *TTI,
AddAffectedFromEq(A);
AddAffectedFromEq(B);
+ } else if (Pred == ICmpInst::ICMP_NE) {
+ Value *X, *Y;
+ // Handle (a & b != 0). If a/b is a power of 2 we can use this
+ // information.
+ if (match(A, m_And(m_Value(X), m_Value(Y))) && match(B, m_Zero())) {
+ AddAffected(X);
+ AddAffected(Y);
+ }
+ } else if (Pred == ICmpInst::ICMP_ULT) {
+ Value *X;
+ // Handle (A + C1) u< C2, which is the canonical form of A > C3 && A < C4,
+ // and recognized by LVI at least.
+ if (match(A, m_Add(m_Value(X), m_ConstantInt())) &&
+ match(B, m_ConstantInt()))
+ AddAffected(X);
}
-
- Value *X;
- // Handle (A + C1) u< C2, which is the canonical form of A > C3 && A < C4,
- // and recognized by LVI at least.
- if (Pred == ICmpInst::ICMP_ULT &&
- match(A, m_Add(m_Value(X), m_ConstantInt())) &&
- match(B, m_ConstantInt()))
- AddAffected(X);
}
if (TTI) {