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

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

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

commit r17-2699-gf6b00aefc25a25ade7524649605fa83fba80c119
Author: Kyrylo Tkachov <[email protected]>
Date:   Wed Jul 22 16:45:51 2026 +0200

    ifcvt: Keep only reaching definitions when rewiring sets [PR126184]

    init_noce_multiple_sets_info records earlier SET destinations that are
    mentioned by a later SET source.  When a pseudo is set more than once, only
    its most recent prior definition reaches that source.

    Recording every definition is unsafe in the second
    noce_convert_multiple_sets_1 attempt.  The newest definition can be emitted
    directly into its target pseudo, making its replacement a no-op.  A later
    replacement using an older definition then substitutes a stale value.

    PR126184 contains the following dependency chain:

      c = x + 1;
      x = c * y;
      c = z + 3;
      y = c * x;

    The unfixed conversion computes the last multiply with the temporary that
    holds `x + 1`, rather than the reaching `z + 3` value.

    The unfixed final sequence forms `x + 1` in x0 and later uses x0 as the
    multiply operand:

      add     x0, x1, 1
      csel    x1, x1, x3, eq
      mul     x0, x1, x0

    With the fix, x3 retains z until `z + 3` is formed and used by the
multiply:

      add     x3, x3, 3
      csel    x0, x0, x1, ne
      mul     x3, x0, x3

    Walk definitions from newest to oldest and record only the first match for
    each pseudo.  Add an AArch64 execution test for the reported dependency.

    Bootstrapped and tested on aarch64-none-linux-gnu and
    x86_64-pc-linux-gnu.

    gcc/ChangeLog:

            PR rtl-optimization/126184
            * ifcvt.cc (init_noce_multiple_sets_info): Record only the most
            recent prior definition of each pseudo register.

    gcc/testsuite/ChangeLog:

            PR rtl-optimization/126184
            * gcc.target/aarch64/pr126184.c: New test.

    Signed-off-by: Kyrylo Tkachov <[email protected]>

Reply via email to