diff options
author | Sanjay Patel <spatel@rotateright.com> | 2019-07-01 22:00:00 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2019-07-01 22:00:00 +0000 |
commit | ddc1b40f26b210a1650454e1ef232cf5f1b6775f (patch) | |
tree | 4025f200622f8c8427b677092a766ee0d3b9ad9d /llvm/lib | |
parent | fc18b7cbc12d82968d881d00ed8bdc25561daa34 (diff) | |
download | bcm5719-llvm-ddc1b40f26b210a1650454e1ef232cf5f1b6775f.tar.gz bcm5719-llvm-ddc1b40f26b210a1650454e1ef232cf5f1b6775f.zip |
[InstCombine] reduce more checks for power-of-2-or-zero using ctpop
Extends the transform from:
rL364341
...to include another (more common?) pattern that tests whether a
value is a power-of-2 (including or excluding zero).
llvm-svn: 364856
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 664edc7c9e5..4c818193ced 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -3926,9 +3926,15 @@ Instruction *InstCombiner::foldICmpEquality(ICmpInst &I) { return new ICmpInst(Pred, A, B); // Canonicalize checking for a power-of-2-or-zero value: + // (A & (A-1)) == 0 --> ctpop(A) < 2 (two commuted variants) + // ((A-1) & A) != 0 --> ctpop(A) > 1 (two commuted variants) + if (!match(Op0, m_OneUse(m_c_And(m_Add(m_Value(A), m_AllOnes()), + m_Deferred(A)))) || + !match(Op1, m_ZeroInt())) + A = nullptr; + // (A & -A) == A --> ctpop(A) < 2 (four commuted variants) // (-A & A) != A --> ctpop(A) > 1 (four commuted variants) - A = nullptr; if (match(Op0, m_OneUse(m_c_And(m_Neg(m_Specific(Op1)), m_Specific(Op1))))) A = Op1; else if (match(Op1, |