diff options
author | Nikita Popov <npopov@redhat.com> | 2024-07-01 09:26:01 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-01 09:26:01 +0200 |
commit | 77eb05683082dd3751ccfab963f5160f1852058d (patch) | |
tree | 6a89cd8f3c7ef764d97ce50436d78c0a4ebcff45 /llvm/lib/Analysis/ValueTracking.cpp | |
parent | 6859e5a169aa235ac04005aaa86ed5ae11372c4c (diff) | |
download | llvm-77eb05683082dd3751ccfab963f5160f1852058d.zip llvm-77eb05683082dd3751ccfab963f5160f1852058d.tar.gz llvm-77eb05683082dd3751ccfab963f5160f1852058d.tar.bz2 |
[InstCombine] Simplify select using KnownBits of condition (#95923)
Simplify the arms of a select based on the KnownBits implied by its condition.
For now this only handles the case where the select arm folds to a constant,
but this can be generalized to handle other patterns by using
SimplifyDemandedBits instead (in that case we would also have to limit to
non-undef conditions).
This is implemented by adding a new member to SimplifyQuery that can be used
to inject an additional condition. The affected values are pre-computed and
we don't call computeKnownBits() if the select arms don't contain affected
values. This reduces the cost in some pathological cases.
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 7deb7bd..c0d49ca 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -771,6 +771,10 @@ static void computeKnownBitsFromCond(const Value *V, Value *Cond, void llvm::computeKnownBitsFromContext(const Value *V, KnownBits &Known, unsigned Depth, const SimplifyQuery &Q) { + // Handle injected condition. + if (Q.CC && Q.CC->AffectedValues.contains(V)) + computeKnownBitsFromCond(V, Q.CC->Cond, Known, Depth, Q, Q.CC->Invert); + if (!Q.CxtI) return; |