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]>
THanks.  I've pushed this to the trunk.

ISTM like you ought to go ahead and get commit privs since you're doing great work and are clearly engaged on improving GCC.

https://gcc.gnu.org/gitwrite.html#authenticated

Should have a link to this form:

https://sourceware.org/cgi-bin/pdw/ps_form.cgi

Fill it out, you can list me as sponsoring your request.

Jeff

Reply via email to