diff options
author | Nikita Popov <npopov@redhat.com> | 2023-07-05 15:22:01 +0200 |
---|---|---|
committer | Nikita Popov <npopov@redhat.com> | 2023-07-05 16:15:47 +0200 |
commit | 2e0af16c9383bb5ed0eda236eb34b92dfb570235 (patch) | |
tree | 07d12820fd9d3012e7db7bf876843249c8714cbf /llvm/lib/Analysis/ValueTracking.cpp | |
parent | 07630da36a31596594a1ba3b9f000dc57d5382f3 (diff) | |
download | llvm-2e0af16c9383bb5ed0eda236eb34b92dfb570235.zip llvm-2e0af16c9383bb5ed0eda236eb34b92dfb570235.tar.gz llvm-2e0af16c9383bb5ed0eda236eb34b92dfb570235.tar.bz2 |
[ValueTracking] Support add+icmp assumes for KnownBits
Support the canonical range check pattern for KnownBits assumptions.
This is the same as the generic ConstantRange handling, just shifted
by an offset.
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index b98615d..412699e 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -766,12 +766,16 @@ static void computeKnownBitsFromCmp(const Value *V, const ICmpInst *Cmp, break; } default: - if (match(Cmp, m_ICmp(Pred, m_V, m_Value(A)))) { + const APInt *Offset = nullptr; + if (match(Cmp, m_ICmp(Pred, m_CombineOr(m_V, m_Add(m_V, m_APInt(Offset))), + m_Value(A)))) { KnownBits RHSKnown = computeKnownBits(A, Depth + 1, QueryNoAC); ConstantRange RHSRange = ConstantRange::fromKnownBits(RHSKnown, Cmp->isSigned()); ConstantRange LHSRange = ConstantRange::makeAllowedICmpRegion(Pred, RHSRange); + if (Offset) + LHSRange = LHSRange.sub(*Offset); Known = Known.unionWith(LHSRange.toKnownBits()); } break; |