aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2008-12-02 05:12:47 +0000
committerBill Wendling <isanbard@gmail.com>2008-12-02 05:12:47 +0000
commit3bdcda82a5e6650f6ba297e9e8bf1b511d79e4fb (patch)
tree8f318350141d6e909228a4914fe8b404b4c2f0c9
parenta8bb13f989a68030a30181823c58aab6e9c1cc0a (diff)
- Remove the buggy -X/C -> X/-C transform. This isn't valid when X isn't a
constant. If X is a constant, then this is folded elsewhere. - Added a note to Target/README.txt to indicate that we'd like to implement this when we're able. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@60399 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Target/README.txt10
-rw-r--r--lib/Transforms/Scalar/InstructionCombining.cpp12
2 files changed, 10 insertions, 12 deletions
diff --git a/lib/Target/README.txt b/lib/Target/README.txt
index fb6b0cd53d..3c689dbe46 100644
--- a/lib/Target/README.txt
+++ b/lib/Target/README.txt
@@ -1242,3 +1242,13 @@ Should combine to "20 * (((unsigned)x) & -2)". Currently not
optimized with "clang -emit-llvm-bc | opt -std-compile-opts".
//===---------------------------------------------------------------------===//
+
+We would like to do the following transform in the instcombiner:
+
+ -X/C -> X/-C
+
+However, this isn't valid if (-X) overflows. We can implement this when we
+have the concept of a "C signed subtraction" operator that which is undefined
+on overflow.
+
+//===---------------------------------------------------------------------===//
diff --git a/lib/Transforms/Scalar/InstructionCombining.cpp b/lib/Transforms/Scalar/InstructionCombining.cpp
index 7ad75d24b4..34c5fb3375 100644
--- a/lib/Transforms/Scalar/InstructionCombining.cpp
+++ b/lib/Transforms/Scalar/InstructionCombining.cpp
@@ -2929,18 +2929,6 @@ Instruction *InstCombiner::visitSDiv(BinaryOperator &I) {
// sdiv X, -1 == -X
if (RHS->isAllOnesValue())
return BinaryOperator::CreateNeg(Op0);
-
- // -X/C -> X/-C, if and only if negation doesn't overflow.
- if (Value *LHSNeg = dyn_castNegVal(Op0)) {
- if (ConstantInt *CI = dyn_cast<ConstantInt>(LHSNeg)) {
- Constant *RHSNeg = ConstantExpr::getNeg(RHS);
- if (RHS != RHSNeg) { // Check that there is no overflow.
- Constant *CINeg = ConstantExpr::getNeg(CI);
- if (CI != CINeg) // Check that there is no overflow.
- return BinaryOperator::CreateSDiv(LHSNeg, RHSNeg);
- }
- }
- }
}
// If the sign bits of both operands are zero (i.e. we can prove they are