ifcvt: Avoid clobbering live condition-code register
Fixes miscompilations on SPARC by preventing if-conversion from overwriting live condition codes.
The if-conversion pass’s find_cond_trap function has been updated to prevent it from overwriting a live condition-code register. Previously, on SPARC, this could lead to incorrect program behavior when a condition code set earlier in the code was needed by a later branch, causing miscompilations, particularly for switch statements with unreachable default cases. The fix reuses an existing check (noce_clobbers_live_cc_p) to ensure condition codes are not clobbered, resolving issues on SPARC64.
In Details
The find_cond_trap function in ifcvt.cc previously emitted gen_cond_trap before cond_earliest. On SPARC, this sequence involves a comparison followed by a trap based on condition codes. If a branch later in the control flow (specifically, one testing general registers) relied on condition codes that were live across the TEST_BB boundary, find_cond_trap's actions could overwrite these live codes. This commit reuses noce_clobbers_live_cc_p to detect and reject such sequences, preventing miscompilations where condition codes are live out of TEST_BB and clobbered by the trap seque…
- if-conversion
- An optimization technique that transforms conditional branches into conditional instructions, reducing control flow complexity and potentially improving performance.
- condition code
- Special processor registers that store the result of a comparison or arithmetic operation, typically used by subsequent conditional branch instructions.
- SPARC
- A RISC instruction set architecture developed by Sun Microsystems. SPARC processors often feature condition code registers.
- TEST_BB
- Likely refers to a basic block within the compiler's intermediate representation, often associated with testing conditions.