aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Transforms
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2008-12-01 07:47:02 +0000
committerBill Wendling <isanbard@gmail.com>2008-12-01 07:47:02 +0000
commitf2e0efd309bdb08bec9aca8a18b62914eca995ec (patch)
treea738708e582ae3271e528ec68728ada3abe080ca /lib/Transforms
parent66a3a3e0dbe3f2341999a7d8a1b0b3527f38a411 (diff)
downloadexternal_llvm-f2e0efd309bdb08bec9aca8a18b62914eca995ec.zip
external_llvm-f2e0efd309bdb08bec9aca8a18b62914eca995ec.tar.gz
external_llvm-f2e0efd309bdb08bec9aca8a18b62914eca995ec.tar.bz2
Move pattern check outside of the if-then statement. This prevents us from fiddling with constants unless we have to.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60340 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Transforms')
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp22
1 files changed, 12 insertions, 10 deletions
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index bc87444..aae1e14 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -2928,17 +2928,19 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) {
if (RHS->isAllOnesValue())
return BinaryOperator::CreateNeg(Op0);
- 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));
-
// -X/C -> X/-C, if and only if negation doesn't overflow.
- if ((RHS->getValue().isNegative() && RHSNegAPI.slt(TwoToExp - 1)) ||
- (RHS->getValue().isNonNegative() && RHSNegAPI.sgt(TwoToExp * NegOne))) {
- if (Value *LHSNeg = dyn_castNegVal(Op0)) {
- if (ConstantInt *CI = dyn_cast<ConstantInt>(LHSNeg)) {
+ 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))) {
ConstantInt *CINeg = cast<ConstantInt>(ConstantExpr::getNeg(CI));
APInt CINegAPI(CINeg->getValue());