aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2008-12-01 19:46:27 +0000
committerBill Wendling <isanbard@gmail.com>2008-12-01 19:46:27 +0000
commitc25c68305c5d595c5428f75280cfb56e4f623eb3 (patch)
tree8b3b03ab0e84a1a4e77aadee70364f03d54031c8
parent7b6113c6e2f23f3bf8b2505bf13bc15b4995c82a (diff)
Use a simple comparison. Overflow on integer negation can only occur when the
integer is "minint". git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60366 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp15
1 files changed, 2 insertions, 13 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 9c6ff8acc5..e4ddecf756 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/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));
}