Unshare load destination when re-applying store-forwarding extension.
Fixes a resource sharing issue in the store-forwarding avoidance pass that could lead to compiler internal errors.
The avoid-store-forwarding pass in GCC could incorrectly share a destination register (rtx) between two instructions when a load was preserved after a partial store-forwarding avoidance. This was particularly problematic when the destination was a SUBREG, leading to an verify_rtx_sharing ICE. The fix ensures the destination is unshared using copy_rtx when rebuilding the affected move instruction, resolving the ICE and passing new test cases.
In Details
In avoid-store-forwarding.cc, when store forwarding is avoided but the load instruction is not eliminated (i.e., the store only partially covers the load), the extension wrapping the load's MEM is reapplied. This reapplication previously reused the SET_DEST of the load as the destination for the new move instruction. If this destination was a SUBREG, it resulted in rtx sharing between the load and the new move, violating verify_rtx_sharing. This commit resolves this by ensuring copy_rtx is used to create a distinct destination rtx for the move instruction, preventing the ICE r…
- avoid-store-forwarding
- A compiler optimization or pass that prevents or manages the speculative forwarding of data from a store operation to a subsequent load operation within the same instruction stream. This is often done to preserve program correctness in specific scenarios, such as when aliasing is complex or when memory ordering needs to be strictly controlled.
- store forwarding
- An optimization where the result of a store operation is immediately made available to subsequent load operations, potentially bypassing the memory subsystem for performance gains.
- ICE
- Internal Compiler Error. A serious error occurs within the compiler itself, preventing it from completing the compilation process. These typically indicate bugs in the compiler.
- rtx
- Register Transfer. The fundamental data structure in GCC's RTL intermediate representation, representing registers, memory locations, constants, and operations.
- SUBREG
- A machine-dependent RTL construct representing a portion of a larger register. For example, using the lower 32 bits of a 64-bit register.
- verify_rtx_sharing
- An internal GCC function or assertion that checks if the same RTL object is being shared by multiple instruction objects, which can lead to incorrect code generation if not handled properly.