[llvm-commits] [llvm] r60340 - /llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp

Bill Wendling isanbard at gmail.com
Sun Nov 30 23:47:03 PST 2008


Author: void
Date: Mon Dec  1 01:47:02 2008
New Revision: 60340

URL: http://llvm.org/viewvc/llvm-project?rev=60340&view=rev
Log:
Move pattern check outside of the if-then statement. This prevents us from fiddling with constants unless we have to.

Modified:
    llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp

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

==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/InstructionCombining.cpp Mon Dec  1 01:47:02 2008
@@ -2928,17 +2928,19 @@
     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());
 





More information about the llvm-commits mailing list