Lower PHI copies for _BitInt as parallel copy
Fixes incorrect _BitInt computations by lowering PHI copies edge-by-edge as parallel operations.
This commit addresses an issue in the lowering of large and huge _BitInt type PHI nodes. Previously, copies for incoming edges were processed sequentially, leading to race conditions where one copy could overwrite a value needed by a subsequent copy on the same edge. The fix processes these copies edge by edge as a parallel operation, using temporaries to safeguard values if necessary, thus preventing incorrect results and ensuring the integrity of _BitInt computations.
In Details
The gimple-lower-bitint.cc pass, gimple_lower_bitint, was found to lower PHI copies for incoming edges sequentially. This is problematic for _BitInt types when multiple PHI nodes share the same underlying partition, as an earlier copy can overwrite a value read by a later copy on the same edge. The corrected implementation lowers PHI copies edge-by-edge, queuing them as a parallel copy operation and employing temporaries to resolve read-after-write dependencies within an edge's set of copies.
- _BitInt
- _BitInt is a GCC extension that allows users to specify integer types with arbitrary bit widths, going beyond standard C integer types like
intorlong long. GCC's middle-end needs to lower these arbitrary-precision integers into operations on machine-supported types. - PHI node
- In SSA form, a PHI node (or Phi function) is used to merge values from different control flow paths. It takes multiple arguments, each corresponding to a predecessor block in the control flow graph, and selects the appropriate value based on which predecessor was executed.
- parallel copy
- A parallel copy is a set of assignments where the destination of one assignment may be the source of another, but all assignments are conceptually performed simultaneously. This is often used by compilers to efficiently move data between registers or memory locations without intermediate temporary variables, provided there are no read-after-write conflicts within the set.
- partition
- In the context of lowering arbitrary-precision types like _BitInt, a 'partition' refers to a machine-level register or memory location used to store a portion of the larger _BitInt value. The compiler breaks down the _BitInt into these smaller, machine-native pieces.