On 9/13/26 1:57 PM, Dominic P wrote:
   A - MIN (B, C) -> A + MAX (-B, -C)
   A - MAX (B, C) -> A + MIN (-B, -C)

when B and C are negatable.  TYPE_OVERFLOW_UNDEFINED is required as well:
for a wrapping type negate_expr_p accepts X - Y, which can be the type
minimum.  This catches A - MIN (-x, 5), which min (-A, -B) -> -max (A, B)
does not.

Bootstrapped and regression tested on x86_64-pc-linux-gnu.

Assisted-by: Claude Opus 5 (Anthropic)

gcc/ChangeLog:

        * match.pd (A - MIN (B, C), A - MAX (B, C)): New patterns.

gcc/testsuite/ChangeLog:

        * gcc.dg/torture/minmax-negate-1.c: New test.
        * gcc.dg/tree-ssa/minmax-negate-1.c: New test.
        * gcc.dg/tree-ssa/minmax-negate-2.c: New test.
        * gcc.dg/tree-ssa/minmax-negate-3.c: New test.

Signed-off-by: Dominic P <[email protected]>
So my worry here is this violates the cost model we have for gimple.  The original form has two expression evaluations, the new form has 4.   So before going forward I'd really like to hear from Andrea & Richi.

jeff

Reply via email to