diff options
| author | David Bolvansky <david.bolvansky@gmail.com> | 2019-06-21 15:26:22 +0000 |
|---|---|---|
| committer | David Bolvansky <david.bolvansky@gmail.com> | 2019-06-21 15:26:22 +0000 |
| commit | 4b284783898cacd36a1f2bc8a849278bf3a0d57c (patch) | |
| tree | afd421f6b803bfb1467a69f56d8a2200d677a026 /llvm/lib/Transforms | |
| parent | 000f25a37e76317aa78b0f6dd9283ba41af94591 (diff) | |
| download | bcm5719-llvm-4b284783898cacd36a1f2bc8a849278bf3a0d57c.tar.gz bcm5719-llvm-4b284783898cacd36a1f2bc8a849278bf3a0d57c.zip | |
[InstCombine] cttz(abs(x)) -> cttz(x)
Summary: Signedness does not change number of trailing zeros.
Reviewers: spatel, lebedev.ri, nikic
Reviewed By: lebedev.ri
Differential Revision: https://reviews.llvm.org/D63546
llvm-svn: 364064
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp index 4bd1246cbf7..1b247245c4c 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp @@ -1194,10 +1194,21 @@ static Instruction *foldCttzCtlz(IntrinsicInst &II, InstCombiner &IC) { return CallInst::Create(F, {X, II.getArgOperand(1)}); } - // cttz(-x) -> cttz(x) - if (IsTZ && match(Op0, m_Neg(m_Value(X)))) { - II.setOperand(0, X); - return &II; + if (IsTZ) { + // cttz(-x) -> cttz(x) + if (match(Op0, m_Neg(m_Value(X)))) { + II.setOperand(0, X); + return &II; + } + + // cttz(abs(x)) -> cttz(x) + // cttz(nabs(x)) -> cttz(x) + Value *Y; + SelectPatternFlavor SPF = matchSelectPattern(Op0, X, Y).Flavor; + if (SPF == SPF_ABS || SPF == SPF_NABS) { + II.setOperand(0, X); + return &II; + } } KnownBits Known = IC.computeKnownBits(Op0, 0, &II); |

