diff options
author | Chris Lattner <sabre@nondot.org> | 2003-09-11 22:24:54 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2003-09-11 22:24:54 +0000 |
commit | cce81be1e19c7125695bc673a3b69afa7fdb2f25 (patch) | |
tree | 5ab0ff5b772601f731f7e8f431d34b58b708372a /llvm | |
parent | 80e8c466fb511cbdf7cf5b2b7a595aafc93ea932 (diff) | |
download | bcm5719-llvm-cce81be1e19c7125695bc673a3b69afa7fdb2f25.tar.gz bcm5719-llvm-cce81be1e19c7125695bc673a3b69afa7fdb2f25.zip |
Simplify code
Implement InstCombine/mul.ll:test9
llvm-svn: 8488
Diffstat (limited to 'llvm')
-rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index eddde0caf17..47e53b56f39 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -527,17 +527,14 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) { return BinaryOperator::create(Instruction::Mul, SI->getOperand(0), *CI << *ShOp); - const Type *Ty = CI->getType(); - int64_t Val = (int64_t)cast<ConstantInt>(CI)->getRawValue(); - switch (Val) { - case -1: // X * -1 -> -X + if (CI->isNullValue()) + return ReplaceInstUsesWith(I, Op1); // X * 0 == 0 + if (CI->equalsInt(1)) // X * 1 == X + return ReplaceInstUsesWith(I, Op0); + if (CI->isAllOnesValue()) // X * -1 == 0 - X return BinaryOperator::createNeg(Op0, I.getName()); - case 0: - return ReplaceInstUsesWith(I, Op1); // Eliminate 'mul double %X, 0' - case 1: - return ReplaceInstUsesWith(I, Op0); // Eliminate 'mul int %X, 1' - } + int64_t Val = (int64_t)cast<ConstantInt>(CI)->getRawValue(); if (uint64_t C = Log2(Val)) // Replace X*(2^C) with X << C return new ShiftInst(Instruction::Shl, Op0, ConstantUInt::get(Type::UByteTy, C)); |