aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/ValueTracking.cpp
diff options
context:
space:
mode:
authorNoah Goldstein <goldstein.w.n@gmail.com>2023-08-22 10:57:51 -0500
committerNoah Goldstein <goldstein.w.n@gmail.com>2023-08-22 10:59:03 -0500
commit7c9fe735d440feeed09877b741492725c483bb55 (patch)
treef80073e59302ee77e61f605d69f1724eabe40fc8 /llvm/lib/Analysis/ValueTracking.cpp
parent39e9862e6b9f3134911813782663462fc29f8ff3 (diff)
downloadllvm-7c9fe735d440feeed09877b741492725c483bb55.zip
llvm-7c9fe735d440feeed09877b741492725c483bb55.tar.gz
llvm-7c9fe735d440feeed09877b741492725c483bb55.tar.bz2
[ValueTracking] Strengthen analysis in `computeKnownBits` of phi
Use the comparison based analysis to strengthen the standard knownbits analysis rather than choosing either/or. Reviewed By: nikic Differential Revision: https://reviews.llvm.org/D157807
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r--llvm/lib/Analysis/ValueTracking.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
index bdf2bc8..54539d2 100644
--- a/llvm/lib/Analysis/ValueTracking.cpp
+++ b/llvm/lib/Analysis/ValueTracking.cpp
@@ -1459,11 +1459,13 @@ static void computeKnownBitsFromOperator(const Operator *I,
// Recurse, but cap the recursion to one level, because we don't
// want to waste time spinning around in loops.
+ // TODO: See if we can base recursion limiter on number of incoming phi
+ // edges so we don't overly clamp analysis.
computeKnownBits(IncValue, Known2, MaxAnalysisRecursionDepth - 1, RecQ);
- // If this failed, see if we can use a conditional branch into the phi
+ // See if we can further use a conditional branch into the phi
// to help us determine the range of the value.
- if (Known2.isUnknown()) {
+ if (!Known2.isConstant()) {
ICmpInst::Predicate Pred;
const APInt *RHSC;
BasicBlock *TrueSucc, *FalseSucc;
@@ -1478,7 +1480,7 @@ static void computeKnownBitsFromOperator(const Operator *I,
Pred = CmpInst::getInversePredicate(Pred);
// Get the knownbits implied by the incoming phi condition.
auto CR = ConstantRange::makeExactICmpRegion(Pred, *RHSC);
- Known2 = CR.toKnownBits();
+ Known2 = Known2.unionWith(CR.toKnownBits());
}
}
}