From 0af1fab019fba132f40748fe549cf6b1d5d8672b Mon Sep 17 00:00:00 2001 From: Chris Lattner Date: Wed, 25 Jun 2003 17:09:20 +0000 Subject: [PATCH] Instcombine: X * -1 -> -X git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6904 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Transforms/Scalar/InstructionCombining.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp index 505313ba9c3..696575e3d6b 100644 --- a/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/lib/Transforms/Scalar/InstructionCombining.cpp @@ -361,10 +361,11 @@ Instruction *InstCombiner::visitMul(BinaryOperator &I) { if (Constant *Op1 = dyn_cast(I.getOperand(1))) { if (ConstantInt *CI = dyn_cast(Op1)) { const Type *Ty = CI->getType(); - uint64_t Val = Ty->isSigned() ? - (uint64_t)cast(CI)->getValue() : - cast(CI)->getValue(); + int64_t Val = Ty->isSigned() ? cast(CI)->getValue() : + (int64_t)cast(CI)->getValue(); switch (Val) { + case -1: // X * -1 -> -X + return BinaryOperator::createNeg(Op0, I.getName()); case 0: return ReplaceInstUsesWith(I, Op1); // Eliminate 'mul double %X, 0' case 1: