diff options
author | Bill Wendling <isanbard@gmail.com> | 2008-12-01 19:46:27 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2008-12-01 19:46:27 +0000 |
commit | e6c87a49528322404524662cf17733224ef5514e (patch) | |
tree | 68edc6e10eb2337f527dcbc95ea3cdc4542a0f59 /llvm/lib/Transforms | |
parent | e74e210a3f82fffde390bfa9234a0184a2241333 (diff) | |
download | bcm5719-llvm-e6c87a49528322404524662cf17733224ef5514e.tar.gz bcm5719-llvm-e6c87a49528322404524662cf17733224ef5514e.zip |
Use a simple comparison. Overflow on integer negation can only occur when the
integer is "minint".
llvm-svn: 60366
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Scalar/InstructionCombining.cpp | 15 |
1 files changed, 2 insertions, 13 deletions
diff --git a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp index 9c6ff8acc57..e4ddecf7563 100644 --- a/llvm/lib/Transforms/Scalar/InstructionCombining.cpp +++ b/llvm/lib/Transforms/Scalar/InstructionCombining.cpp @@ -2934,20 +2934,9 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) { if (Value *LHSNeg = dyn_castNegVal(Op0)) { if (ConstantInt *CI = dyn_cast<ConstantInt>(LHSNeg)) { ConstantInt *RHSNeg = cast<ConstantInt>(ConstantExpr::getNeg(RHS)); - APInt RHSNegAPI(RHSNeg->getValue()); - - APInt NegOne = -APInt(RHSNeg->getBitWidth(), 1, true); - APInt TwoToExp(RHSNeg->getBitWidth(), 1 << (RHSNeg->getBitWidth() - 1)); - - if ((RHS->getValue().isNegative() && - RHSNegAPI.slt(TwoToExp - 1)) || - (RHS->getValue().isNonNegative() && - RHSNegAPI.sgt(TwoToExp * NegOne))) { + if (RHS != RHSNeg) { ConstantInt *CINeg = cast<ConstantInt>(ConstantExpr::getNeg(CI)); - APInt CINegAPI(CINeg->getValue()); - - if ((CI->getValue().isNegative() && CINegAPI.slt(TwoToExp - 1)) || - (CI->getValue().isNonNegative() && CINegAPI.sgt(TwoToExp*NegOne))) + if (CI != CINeg) return BinaryOperator::CreateSDiv(LHSNeg, ConstantExpr::getNeg(RHS)); } |