[llvm] [InstCombine] Factorise add/sub and max/min using distributivity (PR #101507)

via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 1 09:08:36 PDT 2024


================
@@ -1751,9 +1830,18 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
     }
     // If both operands of unsigned min/max are sign-extended, it is still ok
     // to narrow the operation.
+
+    if (Instruction *I = foldCallUsingDistributiveLaws(II, Builder))
+      return I;
+
+    [[fallthrough]];
+  }
+  case Intrinsic::smax: {
+    if (Instruction *I = foldCallUsingDistributiveLaws(II, Builder))
+      return I;
+
----------------
goldsteinn wrote:

Don't think you need the call in the `umin`/`umax`/`smax` cases, they all fallthrough to `smin` (and it seems a bit silly to potentially fail 4x times on the same call).

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


More information about the llvm-commits mailing list