[llvm-commits] [llvm] r60399 - in /llvm/trunk/lib: Target/README.txt Transforms/Scalar/InstructionCombining.cpp

Bill Wendling isanbard at gmail.com
Mon Dec 1 21:12:48 PST 2008


Author: void
Date: Mon Dec  1 23:12:47 2008
New Revision: 60399

URL: http://llvm.org/viewvc/llvm-project?rev=60399&view=rev
Log:
- 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.

Modified:
    llvm/trunk/lib/Target/README.txt
    llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp

Modified: llvm/trunk/lib/Target/README.txt
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/README.txt?rev=60399&r1=60398&r2=60399&view=diff

==============================================================================
--- llvm/trunk/lib/Target/README.txt (original)
+++ llvm/trunk/lib/Target/README.txt Mon Dec  1 23:12:47 2008
@@ -1242,3 +1242,13 @@
 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.
+
+//===---------------------------------------------------------------------===//

Modified: llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp?rev=60399&r1=60398&r2=60399&view=diff

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Mon Dec  1 23:12:47 2008
@@ -2929,18 +2929,6 @@
     // 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





More information about the llvm-commits mailing list