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

--- Comment #3 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:d08f45336781c4fb2244c48a3504da2a3c2fc13b

commit r17-6466-gd08f45336781c4fb2244c48a3504da2a3c2fc13b
Author: Kyrylo Tkachov <[email protected]>
Date:   Mon Nov 9 13:59:47 2026 +0100

    bitintlower: Lower the PHI copies of an edge as a parallel copy [PR121722]

    The PHIs of a block read their arguments from an incoming edge in
    parallel, but the lowering of large and huge _BitInt PHIs emits the
    copies for an edge one after another in the order of the PHIs.  A copy
    can then read a partition that an earlier copy or constant store on the
    same edge has already overwritten.  In the PR testcase

      # prevFib_14 = PHI <currentFib_15(5), 0(3)>
      # currentFib_15 = PHI <newFib_8(5), 1(3)>

    newFib_8 and prevFib_14 share the partition bitint.4, currentFib_15 has
    bitint.5, and the latch gets

      bitint.4 = bitint.5;
      bitint.5 = bitint.4;

    so fib (10) returns 2 instead of 55.  A rotation through the loop PHIs,
    or a constant store before a copy that reads the old value, gives wrong
    code even with -fno-tree-coalesce-vars.

    Lower the PHI copies edge by edge.  For each edge, queue the copies in
    the order of the PHIs and then the constant stores, which read no
    partition.  If a copy reads a partition that an earlier copy on the edge
    writes, save the partition to a temporary before all the copies and end
    the storage of the temporary after them.  The latch above becomes

      D.4439 = bitint.4;
      bitint.4 = bitint.5;
      bitint.5 = D.4439;
      D.4439 ={v} {CLOBBER(eos)};

    An edge on which no copy reads an overwritten partition gets the same
    statements as before, with the constant stores after the copies.

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

    gcc/ChangeLog:

            PR tree-optimization/121722
            * gimple-lower-bitint.cc (gimple_lower_bitint): Lower the PHI
            copies edge by edge, with the constant stores after the copies.
            Save a partition that an earlier copy on the edge writes to a
            temporary and let the later copies read the temporary.

    gcc/testsuite/ChangeLog:

            PR tree-optimization/121722
            * gcc.dg/bitint-148.c: New test.
            * gcc.dg/torture/bitint-116.c: New test.
            * gcc.dg/torture/bitint-117.c: New test.

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

Reply via email to