[llvm] [InstCombine] Factorise Add and Min/Max using Distributivity (PR #101717)

Jorge Botto via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 19 14:21:09 PDT 2024


================
@@ -1505,6 +1505,80 @@ foldMinimumOverTrailingOrLeadingZeroCount(Value *I0, Value *I1,
       ConstantInt::getTrue(ZeroUndef->getType()));
 }
 
+/// Return whether "X LOp (Y ROp Z)" is always equal to
+/// "(X LOp Y) ROp (X LOp Z)".
+static bool foldIntrinsicUsingDistributiveLaws(Instruction::BinaryOps LOp,
+                                               bool hasNUW, bool hasNSW,
+                                               Intrinsic::ID ROp) {
+  switch (ROp) {
+  case Intrinsic::umax:
+    return hasNUW && LOp == Instruction::Add;
+  case Intrinsic::umin:
+    return hasNUW && LOp == Instruction::Add;
----------------
jf-botto wrote:

Completely understand. Fixed.

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


More information about the llvm-commits mailing list