[llvm] [InstCombine] Simplification for (-a * b) / (a * b) and (a - b) / (b - a). (PR #71768)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 8 21:37:17 PST 2023
================
@@ -1544,6 +1544,20 @@ Instruction *InstCombinerImpl::visitSDiv(BinaryOperator &I) {
}
}
+ // -(X * Y) / (X * Y) --> -1
+ if ((match(Op0, m_Neg(m_c_Mul(m_Value(X), m_Value(Y)))) &&
+ match(Op1, m_c_Mul(m_Specific(X), m_Specific(Y)))) ||
+ (match(Op0, m_c_Mul(m_Value(X), m_Value(Y))) &&
+ match(Op1, m_Neg(m_c_Mul(m_Specific(X), m_Specific(Y)))))) {
+ return BinaryOperator::CreateNeg(ConstantInt::get(Ty, 1));
+ };
+
+ // (Y - X) / (X - Y) --> -1
+ if (match(Op0, m_Sub(m_Value(Y), m_Value(X))) &&
+ match(Op1, m_Sub(m_Specific(X), m_Specific(Y)))) {
----------------
dtcxzyw wrote:
```suggestion
if (match(Op0, m_NSWSub(m_Value(Y), m_Value(X))) &&
match(Op1, m_NSWSub(m_Specific(X), m_Specific(Y)))) {
```
https://github.com/llvm/llvm-project/pull/71768
More information about the llvm-commits
mailing list