diff options
| author | Arnaud A. de Grandmaison <arnaud.adegm@gmail.com> | 2013-02-15 14:35:47 +0000 |
|---|---|---|
| committer | Arnaud A. de Grandmaison <arnaud.adegm@gmail.com> | 2013-02-15 14:35:47 +0000 |
| commit | 61c167c62b6852351102cdbcc80a5207d7fef1bb (patch) | |
| tree | 5b59b3c0b2786c9dd1516ed7832d59a752cba3cb /llvm/lib/Transforms | |
| parent | 2e44769ed21b9190ff288e3c4e0a90a59a60f576 (diff) | |
| download | bcm5719-llvm-61c167c62b6852351102cdbcc80a5207d7fef1bb.tar.gz bcm5719-llvm-61c167c62b6852351102cdbcc80a5207d7fef1bb.zip | |
Teach InstCombine to work with smaller legal types in icmp (shl %v, C1), C2
It enables to work with a smaller constant, which is target friendly for those which can compare to immediates.
It also avoids inserting a shift in favor of a trunc, which can be free on some targets.
This used to work until LLVM-3.1, but regressed with the 3.2 release.
llvm-svn: 175270
Diffstat (limited to 'llvm/lib/Transforms')
| -rw-r--r-- | llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp index 40e559eda5e..2e7bd922a27 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp @@ -1331,6 +1331,25 @@ Instruction *InstCombiner::visitICmpInstWithInstAndIntCst(ICmpInst &ICI, return new ICmpInst(TrueIfSigned ? ICmpInst::ICMP_NE : ICmpInst::ICMP_EQ, And, Constant::getNullValue(And->getType())); } + + // Transform (icmp pred iM (shl iM %v, N), CI) + // -> (icmp pred i(M-N) (trunc %v iM to i(N-N)), (trunc (CI>>N)) + // Transform the shl to a trunc if (trunc (CI>>N)) has no loss. + // This enables to get rid of the shift in favor of a trunc which can be + // free on the target. It has the additional benefit of comparing to a + // smaller constant, which will be target friendly. + unsigned Amt = ShAmt->getLimitedValue(TypeBits-1); + if (Amt != 0 && RHSV.countTrailingZeros() >= Amt) { + Type *NTy = IntegerType::get(ICI.getContext(), TypeBits - Amt); + Constant *NCI = ConstantExpr::getTrunc( + ConstantExpr::getAShr(RHS, + ConstantInt::get(RHS->getType(), Amt)), + NTy); + return new ICmpInst(ICI.getPredicate(), + Builder->CreateTrunc(LHSI->getOperand(0), NTy), + ConstantExpr::getTrunc(NCI, NTy)); + } + break; } |

