[llvm] [InstCombine] simplify `(X * C0) / (X * C1)` into `C0 / C1`. (PR #73204)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 22 20:31:34 PST 2023


================
@@ -1207,6 +1207,18 @@ Instruction *InstCombinerImpl::commonIDivTransforms(BinaryOperator &I) {
     }
   }
 
+  // (X * C0) / (X * C1) --> C0 / C1
+  Constant *C0, *C1;
+  if (match(Op0, m_c_Mul(m_Value(X), m_Constant(C0))) &&
+      match(Op1, m_c_Mul(m_Specific(X), m_Constant(C1)))) {
+    auto OB0HasNSW = cast<OverflowingBinaryOperator>(Op0)->hasNoSignedWrap();
+    auto OB0HasNUW = cast<OverflowingBinaryOperator>(Op0)->hasNoUnsignedWrap();
----------------
dtcxzyw wrote:

`udiv (X *nuw Y), (X *nuw Z) -> udiv Y, Z` has been handled.
https://github.com/llvm/llvm-project/blob/dc683d2e66de79bbea786f51788961eec5d0b793/llvm/lib/Transforms/InstCombine/InstCombineMulDivRem.cpp#L1380-L1393

Could you please remove this and implement the fold for both `sdiv` and `udiv` in `commonIDivTransforms`?

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


More information about the llvm-commits mailing list