RISC-V: Model memory effects of cbo.zero instruction
RISC-V compiler now correctly models memory clobbering for the `cbo.zero` instruction.
This commit improves the RISC-V backend’s understanding of the cbo.zero instruction by modeling the memory it writes to. Previously, the compiler could incorrectly assume memory blocks remained available for reuse after cbo.zero, leading to loads returning stale data. By clobbering memory in the instruction pattern, the compiler ensures that subsequent loads accurately reflect the instruction’s side effects.
In Details
The RISC-V cbo.zero instruction, part of the Zicboz extension, zeros out a cache block. The previous machine description for riscv_zero_<mode> only specified an address operand, failing to indicate that the entire cache block was modified. This change adds a clobber(memory) attribute to the instruction pattern to correctly model the side effect, preventing incorrect load optimizations that might reuse data from before the clear.
- cbo.zero
- A RISC-V instruction that zeros out a specified cache block. It's part of the Zicboz extension for cache management operations.
- Zicboz
- A RISC-V extension that provides instructions for cache management operations, including cache block zeroing.
- cache block
- A contiguous chunk of memory managed by the CPU's cache hierarchy.
- clobber memory
- In compiler instruction descriptions, this signifies that an instruction modifies memory, invalidating any prior assumptions about its contents for subsequent operations.
- inlined memset
- A
memsetfunction call that has been directly expanded into its constituent operations by the compiler, rather than being left as a function call.