aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2009-10-11 07:53:15 +0000
committerChris Lattner <sabre@nondot.org>2009-10-11 07:53:15 +0000
commit6438c58898936351337a02c6f3d89dbefcf8d6c1 (patch)
tree9d478f579ba3d3d7677b277081edc2a8e54f9eff /lib
parent0c7a6448809f6dc46ba73d35edfe8710c9758f64 (diff)
downloadexternal_llvm-6438c58898936351337a02c6f3d89dbefcf8d6c1.zip
external_llvm-6438c58898936351337a02c6f3d89dbefcf8d6c1.tar.gz
external_llvm-6438c58898936351337a02c6f3d89dbefcf8d6c1.tar.bz2
implement rdar://7293527, a trivial instcombine that llvm-gcc
gets but clang doesn't, because it is implemented in GCC's fold routine. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@83761 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp13
1 files changed, 12 insertions, 1 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index bb0e099..06a5660 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -2661,7 +2661,7 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
if (isa<UndefValue>(I.getOperand(1))) // undef * X -> 0
return ReplaceInstUsesWith(I, Constant::getNullValue(I.getType()));
- // Simplify mul instructions with a constant RHS...
+ // Simplify mul instructions with a constant RHS.
if (Constant *Op1 = dyn_cast<Constant>(I.getOperand(1))) {
if (ConstantInt *CI = dyn_cast<ConstantInt>(Op1)) {
@@ -2765,9 +2765,20 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) {
}
}
+ /// i1 mul -> i1 and.
if (I.getType() == Type::getInt1Ty(*Context))
return BinaryOperator::CreateAnd(Op0, I.getOperand(1));
+ // X*(1 << Y) --> X << Y
+ // (1 << Y)*X --> X << Y
+ {
+ Value *Y;
+ if (match(Op0, m_Shl(m_One(), m_Value(Y))))
+ return BinaryOperator::CreateShl(I.getOperand(1), Y);
+ if (match(I.getOperand(1), m_Shl(m_One(), m_Value(Y))))
+ return BinaryOperator::CreateShl(Op0, Y);
+ }
+
// If one of the operands of the multiply is a cast from a boolean value, then
// we know the bool is either zero or one, so this is a 'masking' multiply.
// See if we can simplify things based on how the boolean was originally