diff options
author | David Bolvansky <david.bolvansky@gmail.com> | 2019-04-03 08:08:44 +0000 |
---|---|---|
committer | David Bolvansky <david.bolvansky@gmail.com> | 2019-04-03 08:08:44 +0000 |
commit | 937720e75b4692d6ec394fda3e23675d14449c86 (patch) | |
tree | 6af554d14d7ae01dc1378376a798b12d57211a4e /llvm/lib | |
parent | 94b867dc7c202162f587fd3345eccdb09bff2a77 (diff) | |
download | bcm5719-llvm-937720e75b4692d6ec394fda3e23675d14449c86.tar.gz bcm5719-llvm-937720e75b4692d6ec394fda3e23675d14449c86.zip |
[InstCombine] Simplify ctpop with bitreverse/bswap
Summary: Fixes PR41337
Reviewers: spatel
Reviewed By: spatel
Subscribers: llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D60148
llvm-svn: 357564
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index c2506798660..afcd878ebc7 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -1383,6 +1383,14 @@ static Instruction *foldCtpop(IntrinsicInst &II, InstCombiner &IC) { assert(II.getIntrinsicID() == Intrinsic::ctpop && "Expected ctpop intrinsic"); Value *Op0 = II.getArgOperand(0); + Value *X; + // ctpop(bitreverse(x)) -> ctpop(x) + // ctpop(bswap(x)) -> ctpop(x) + if (match(Op0, m_BitReverse(m_Value(X))) || match(Op0, m_BSwap(m_Value(X)))) { + II.setOperand(0, X); + return &II; + } + // FIXME: Try to simplify vectors of integers. auto *IT = dyn_cast<IntegerType>(Op0->getType()); if (!IT) |