one more instcombine variant that is needed to work with future changes,
authorChris Lattner <sabre@nondot.org>
Sat, 15 Jan 2011 05:50:18 +0000 (05:50 +0000)
committerChris Lattner <sabre@nondot.org>
Sat, 15 Jan 2011 05:50:18 +0000 (05:50 +0000)
no functionality change currently.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123517 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/InstCombine/InstCombineAddSub.cpp

index c4132b2435cb00adf4ef5836b2dc6ea20d1248b6..e5d9a8b9618d80e46b475930fd4cf1d1a646cfb2 100644 (file)
@@ -672,6 +672,15 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
         Value *NewMul = Builder->CreateMul(A, B);
         return BinaryOperator::CreateAdd(Op0, NewMul);
       }
+      
+      // X - A*Cst -> X + A*-Cst
+      // X - Cst*A -> X + A*-Cst
+      ConstantInt *BCst;
+      if (match(Op1I, m_Mul(m_Value(A), m_ConstantInt(BCst))) ||
+          match(Op1I, m_Mul(m_ConstantInt(BCst), m_Value(A)))) {
+        Value *NewMul = Builder->CreateMul(A, ConstantExpr::getNeg(BCst));
+        return BinaryOperator::CreateAdd(Op0, NewMul);
+      }
     }
   }