diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2021-03-26 20:12:55 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2021-03-26 20:21:05 +0100 |
commit | 9666e89d577887cf574507207484a066588fc9ca (patch) | |
tree | 6fbddf0fb093d4075dc578fb50466ba97b022d83 /llvm/lib/Analysis/ValueTracking.cpp | |
parent | 5c85c37c87d6c79bf2ee29c3c25456133861333e (diff) | |
download | llvm-9666e89d577887cf574507207484a066588fc9ca.zip llvm-9666e89d577887cf574507207484a066588fc9ca.tar.gz llvm-9666e89d577887cf574507207484a066588fc9ca.tar.bz2 |
[ValueTracking] Handle shl in isKnownNonEqual()
This handles the pattern X != X << C for non-zero X and C and a
non-overflowing shift. This establishes parity with the corresponing
fold for multiplies.
Diffstat (limited to 'llvm/lib/Analysis/ValueTracking.cpp')
-rw-r--r-- | llvm/lib/Analysis/ValueTracking.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp index 1c3d5df..6f89ba9 100644 --- a/llvm/lib/Analysis/ValueTracking.cpp +++ b/llvm/lib/Analysis/ValueTracking.cpp @@ -2564,6 +2564,19 @@ static bool isNonEqualMul(const Value *V1, const Value *V2, unsigned Depth, return false; } +/// Return true if V2 == V1 << C, where V1 is known non-zero, C is not 0 and +/// the shift is nuw or nsw. +static bool isNonEqualShl(const Value *V1, const Value *V2, unsigned Depth, + const Query &Q) { + if (auto *OBO = dyn_cast<OverflowingBinaryOperator>(V2)) { + const APInt *C; + return match(OBO, m_Shl(m_Specific(V1), m_APInt(C))) && + (OBO->hasNoUnsignedWrap() || OBO->hasNoSignedWrap()) && + !C->isNullValue() && isKnownNonZero(V1, Depth + 1, Q); + } + return false; +} + static bool isNonEqualPHIs(const PHINode *PN1, const PHINode *PN2, unsigned Depth, const Query &Q) { // Check two PHIs are in same block. @@ -2665,6 +2678,9 @@ static bool isKnownNonEqual(const Value *V1, const Value *V2, unsigned Depth, if (isNonEqualMul(V1, V2, Depth, Q) || isNonEqualMul(V2, V1, Depth, Q)) return true; + if (isNonEqualShl(V1, V2, Depth, Q) || isNonEqualShl(V2, V1, Depth, Q)) + return true; + if (V1->getType()->isIntOrIntVectorTy()) { // Are any known bits in V1 contradictory to known bits in V2? If V1 // has a known zero where V2 has a known one, they must not be equal. |