[llvm] [InstCombine] Simplification for (-a * b) / (a * b). (PR #71768)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 15 00:47:07 PST 2023


================
@@ -1544,6 +1544,14 @@ Instruction *InstCombinerImpl::visitSDiv(BinaryOperator &I) {
     }
   }
 
+  // -X / X --> X == INT_MIN ? 1 : -1
+  if ((match(Op0, m_Sub(m_Zero(), m_Value(X))) && match(Op1, m_Specific(X)))) {
+    APInt MinVal = APInt::getSignedMinValue(Ty->getScalarSizeInBits());
+    Value *Cond =
+        Builder.CreateICmpEQ(X, ConstantExpr::getIntegerValue(Ty, MinVal));
----------------
dtcxzyw wrote:

```suggestion
        Builder.CreateICmpEQ(X, ConstantInt::get(Ty, MinVal));
```

https://github.com/llvm/llvm-project/pull/71768


More information about the llvm-commits mailing list