https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125700

--- Comment #2 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jeff Law <[email protected]>:

https://gcc.gnu.org/g:ed9f5bf1c1288168b14edd3e35f4d32330bef66d

commit r17-4500-ged9f5bf1c1288168b14edd3e35f4d32330bef66d
Author: Samarth Tandale <[email protected]>
Date:   Sun Sep 20 17:18:25 2026 -0600

    [PATCH v2] match: Simplify value-range guarded min/max expressions
[PR125700]

    For MIN_EXPR, if x is TYPE_MAX_VALUE, then min (x, y) is y.
    So:
            x == TYPE_MAX_VALUE ? y : min (x, y)
    can be simplified to:
            min (x, y)

    Similarly for MAX_EXPR, if x is TYPE_MIN_VALUE, then max (x, y)
    is y.
    So:
            x == TYPE_MIN_VALUE ? y : max (x, y)
    can be simplified to:
            max (x, y)

    This adds a combined match.pd pattern for MIN_EXPR and MAX_EXPR.

    Changes since v1:
    - Extended the optimization beyond fixed type limits. It now handles
constants when Ranger proves their relationship with y's value range and
conservatively falls back when no useful range is available.
    - Added positive and negative test cases for Ranger-derived ranges.

            PR tree-optimization/125700

    gcc/ChangeLog:

            * match.pd: Fold type-bound guarded min/max expressions.

    gcc/testsuite/ChangeLog:

            * gcc.dg/tree-ssa/pr125700.c: New test.
            * gcc.dg/tree-ssa/pr125700-int-width.c: New test.
            * gcc.dg/tree-ssa/pr125700-negative.c: New test.
            * gcc.dg/tree-ssa/pr125700-range.c: New test.

    Signed-off-by: Samarth Tandale <[email protected]>

Reply via email to