[llvm] [InstCombine] Factorise Add and Min/Max using Distributivity (PR #101717)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 2 08:21:21 PDT 2024
================
@@ -1503,6 +1503,76 @@ 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 leftDistributesOverRight(Instruction::BinaryOps LOp, bool HasNUW,
+ bool HasNSW, Intrinsic::ID ROp) {
+ switch (ROp) {
+ case Intrinsic::umax:
+ case Intrinsic::umin:
+ return hasNUW && LOp == Instruction::Add;
+ case Intrinsic::smax:
+ case Intrinsic::smin:
+ return hasNSW && LOp == Instruction::Add;
----------------
nikic wrote:
```suggestion
return HasNUW && LOp == Instruction::Add;
case Intrinsic::smax:
case Intrinsic::smin:
return HasNSW && LOp == Instruction::Add;
```
https://github.com/llvm/llvm-project/pull/101717
More information about the llvm-commits
mailing list