[PATCH] match: Combine two patterns into for.

Kael Andrew Franco <[email protected]>
Newsgroups gmane.comp.gcc.patches
Message-ID <CACAb0qcyDOrY5_5TrDkyFdudgd443Omjt8JOvSxt3dFv9MSAXA@mail.gmail.com>
From 874de2e32a942619608766c78bef37d280488a08 Mon Sep 17 00:00:00 2001
From: Kael Andrew Alonzo Franco <[email protected]>
Date: Thu, 30 Jul 2026 07:33:12 -0400
Subject: [PATCH] match: Combine two patterns into for.

This simplify r6-4336 so genmatch outputs
less C++ code.

Bootstrapped and regtested on x86_64-pc-linux-gnu.

gcc/ChangeLog:

	* match.pd: Combine two patterns into for.

Signed-off-by: Kael Andrew Franco <[email protected]>
---
 gcc/match.pd | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/gcc/match.pd b/gcc/match.pd
index ce02ebf2699..93c72c94bf0 100644
--- a/gcc/match.pd
+++ b/gcc/match.pd
@@ -4507,27 +4507,27 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT)
 /* Simplifications of MIN_EXPR, MAX_EXPR, fmin() and fmax().  */

 (for minmax (min max)
+     maxmin (max min)
  (simplify
   (minmax @0 @0)
   @0)
 /* max(max(x,y),x) -> max(x,y)  */
  (simplify
   (minmax:c (minmax:c@2 @0 @1) @0)
-  @2))
+  @2)
+
+/* min(max(x,y),y) -> y.
+   max(min(x,y),y) -> y.  */
+ (simplify
+  (minmax:c (maxmin:c @0 @1) @1)
+  @1))
+
 /* For fmin() and fmax(), skip folding when both are sNaN.  */
 (for minmax (FMIN_ALL FMAX_ALL)
  (simplify
   (minmax @0 @0)
   (if (!tree_expr_maybe_signaling_nan_p (@0))
     @0)))
-/* min(max(x,y),y) -> y.  */
-(simplify
- (min:c (max:c @0 @1) @1)
- @1)
-/* max(min(x,y),y) -> y.  */
-(simplify
- (max:c (min:c @0 @1) @1)
- @1)
 /* max(a,-a) -> abs(a).  */
 (simplify
  (max:c @0 (negate @0))
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.