one more instcombine variant that is needed to work with future changes,
no functionality change currently.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123517 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index c4132b2..e5d9a8b 100644
--- a/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -672,6 +672,15 @@
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);
+ }
}
}