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

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

https://gcc.gnu.org/g:7da4eb256f169fdc6bf3849b247d81f2e9404eb3

commit r17-2788-g7da4eb256f169fdc6bf3849b247d81f2e9404eb3
Author: Philipp Tomsich <[email protected]>
Date:   Tue Jul 28 15:28:33 2026 +0200

    tree-optimization/126415 - perform inverse converted +- lookup in VN

    The match.pd rewrite (T)a +- X -> (T)(a +- X') from
    r17-2078-g8395fa7c79eecf creates the narrow operation, assuming the
    absence of overflow for an operation the program does not execute;
    this results in wrong code (PR126415).  Revert it and implement the
    equivalence in visit_nary_op instead.

    visit_nary_op value-numbers (T)(a +- b) <- (T)a +- (T)b.  Add the
    inverse, (T)a +- X <- (T)(a +- X'), looking up the narrow a +- X'
    and converting the result.  This makes the equivalence independent
    of the order the two forms appear in the IL.

    The transform is valid for sign changes and for widening conversions
    from a type with undefined overflow when the narrow operation
    dominates the statement being visited.  The narrow operation is only
    looked up, never created.  X may be an integer constant that narrows
    and extends back unchanged, or a conversion from the same narrow
    type.

    The sign-change case makes the fold apply to ilp32 targets as well;
    remove the ilp32 xfail from the pr124545.c scan (PR116845).

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

            PR tree-optimization/126415
            PR tree-optimization/124545

    gcc/ChangeLog:

            * match.pd ((T)A +- CST -> (T)(A +- CST')): Revert.
            * tree-ssa-sccvn.cc (ssa_integral_conversion_op): New function.
            (vn_nary_result_avail_or_insertable_p): New function, split out
            from ...
            (visit_nary_op): ... here.  Handle ((T)p) +- X by looking up
            (p +- X') and converting the result, for X an integer constant
            that narrows and extends back unchanged or a conversion from
            the same narrow type.

    gcc/testsuite/ChangeLog:

            * gcc.dg/torture/pr126415.c: New testcase.
            * gcc.dg/tree-ssa/ssa-fre-113.c: New testcase.
            * gcc.dg/tree-ssa/ssa-fre-114.c: New testcase.
            * gcc.dg/pr124545.c: Remove the ilp32 xfail.

Reply via email to