aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2003-09-11 22:24:54 +0000
committerChris Lattner <sabre@nondot.org>2003-09-11 22:24:54 +0000
commit515c97c2301ac56f00f3acc443fc823e3153942e (patch)
treed072792cc98381a28d69157d1c40d17c9e8c5f91 /lib
parent53dce0c43f25c64935ea5f26b19b04b0e533ef83 (diff)
downloadexternal_llvm-515c97c2301ac56f00f3acc443fc823e3153942e.zip
external_llvm-515c97c2301ac56f00f3acc443fc823e3153942e.tar.gz
external_llvm-515c97c2301ac56f00f3acc443fc823e3153942e.tar.bz2
Simplify code
Implement InstCombine/mul.ll:test9 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@8488 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp15
1 files changed, 6 insertions, 9 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index eddde0c..47e53b5 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/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));