On Mon, Nov 09, 2026 at 03:37:09PM +0100, [email protected] wrote: > From: Kyrylo Tkachov <[email protected]> > > 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. > Ok for trunk?
LGTM, thanks. Just be aware that bitint-147.c test needs renaming. > 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-147.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]> Jakub
