summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2017-05-24 22:58:17 +0000
committerSanjay Patel <spatel@rotateright.com>2017-05-24 22:58:17 +0000
commit07b1ba54b5403617523b0501adc83c2b91d782ab (patch)
treeb41546dbcd8341ed0f94ad2f69452d0ec096d334 /llvm/lib/Transforms
parent3c8f953f6193f9199a2b9b69834a4b3a2ad44701 (diff)
downloadbcm5719-llvm-07b1ba54b5403617523b0501adc83c2b91d782ab.tar.gz
bcm5719-llvm-07b1ba54b5403617523b0501adc83c2b91d782ab.zip
[InstCombine] use m_APInt to allow icmp-mul-mul vector fold
The swapped operands in the first test is a manifestation of an inefficiency for vectors that doesn't exist for scalars because the IRBuilder checks for an all-ones mask for scalars, but not vectors. llvm-svn: 303818
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r--llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp23
1 files changed, 12 insertions, 11 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index 5ca0ed25675..a855a0dd2d1 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -3052,26 +3052,27 @@ Instruction *InstCombiner::foldICmpBinOp(ICmpInst &I) {
}
break;
}
- case Instruction::Mul:
+ case Instruction::Mul: {
if (!I.isEquality())
break;
- if (ConstantInt *CI = dyn_cast<ConstantInt>(BO0->getOperand(1))) {
- // a * Cst icmp eq/ne b * Cst --> a & Mask icmp b & Mask
- // Mask = -1 >> count-trailing-zeros(Cst).
- if (!CI->isZero() && !CI->isOne()) {
- const APInt &AP = CI->getValue();
- ConstantInt *Mask = ConstantInt::get(
- I.getContext(),
- APInt::getLowBitsSet(AP.getBitWidth(),
- AP.getBitWidth() - AP.countTrailingZeros()));
+ const APInt *C;
+ if (match(BO0->getOperand(1), m_APInt(C))) {
+ // 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.
+ Constant *Mask = ConstantInt::get(
+ BO0->getType(),
+ APInt::getLowBitsSet(C->getBitWidth(),
+ C->getBitWidth() - C->countTrailingZeros()));
Value *And1 = Builder->CreateAnd(BO0->getOperand(0), Mask);
Value *And2 = Builder->CreateAnd(BO1->getOperand(0), Mask);
return new ICmpInst(Pred, And1, And2);
}
}
break;
-
+ }
case Instruction::UDiv:
case Instruction::LShr:
if (I.isSigned() || !BO0->isExact() || !BO1->isExact())
OpenPOWER on IntegriCloud