diff options
author | Sanjay Patel <spatel@rotateright.com> | 2017-05-25 14:13:57 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2017-05-25 14:13:57 +0000 |
commit | 5150612012beab0065080fce0507755a7e325099 (patch) | |
tree | 5d003c75bdb9bf4e08e8304ffddedf07797f3260 /llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | |
parent | 32d0d3867949e1c0c00e76f440a2b67f8b09c7b0 (diff) | |
download | bcm5719-llvm-5150612012beab0065080fce0507755a7e325099.tar.gz bcm5719-llvm-5150612012beab0065080fce0507755a7e325099.zip |
[InstCombine] make icmp-mul fold more efficient
There's probably a lot more like this (see also comments in D33338 about responsibility),
but I suspect we don't usually get a visible manifestation.
Given the recent interest in improving InstCombine efficiency, another potential micro-opt
that could be repeated several times in this function: morph the existing icmp pred/operands
instead of creating a new instruction.
llvm-svn: 303860
Diffstat (limited to 'llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp')
-rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index a855a0dd2d1..30c5abbdbbb 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -3057,19 +3057,21 @@ Instruction *InstCombiner::foldICmpBinOp(ICmpInst &I) { break; const APInt *C; - if (match(BO0->getOperand(1), m_APInt(C))) { + if (match(BO0->getOperand(1), m_APInt(C)) && *C != 0 && *C != 1) { // icmp eq/ne (X * C), (Y * C) --> icmp (X & Mask), (Y & Mask) // Mask = -1 >> count-trailing-zeros(C). - if (*C != 0 && *C != 1) { - // FIXME: If trailing zeros is 0, don't bother creating Mask. + if (unsigned TZs = C->countTrailingZeros()) { Constant *Mask = ConstantInt::get( BO0->getType(), - APInt::getLowBitsSet(C->getBitWidth(), - C->getBitWidth() - C->countTrailingZeros())); + APInt::getLowBitsSet(C->getBitWidth(), C->getBitWidth() - TZs)); Value *And1 = Builder->CreateAnd(BO0->getOperand(0), Mask); Value *And2 = Builder->CreateAnd(BO1->getOperand(0), Mask); return new ICmpInst(Pred, And1, And2); } + // If there are no trailing zeros in the multiplier, just eliminate + // the multiplies (no masking is needed): + // icmp eq/ne (X * C), (Y * C) --> icmp eq/ne X, Y + return new ICmpInst(Pred, BO0->getOperand(0), BO1->getOperand(0)); } break; } |