ifcvt: Do not clobber live condition-code register
Fixes if-conversion to avoid destroying condition codes needed by later branches.
The if-conversion pass incorrectly destroyed condition-code registers that were still live, causing incorrect flag values to be used by subsequent instructions. This change ensures that if-conversion respects the liveness of condition-code registers, preventing it from clobbering them and thus fixing bugs like PR126501 and PR126747.
In Details
The ifcvt pass transforms conditional sequences into conditional moves. It previously failed to correctly identify condition-code registers that were live-out of the test block, especially when the test itself used a general-purpose register (like AArch64's CBZ). This commit enhances end_ifcvt_sequence to recognize and preserve condition-code registers based on destination modes and target-specific hooks, preventing the destruction of live flags and ensuring correct behavior with downstream passes like late-combine.
- if-conversion
- A compiler optimization that transforms conditional control flow (if-else statements) into conditional data movement instructions (like conditional selects or moves), often leading to simpler and faster code by avoiding branches.
- condition-code register
- A special register in a CPU that stores the results of comparisons or arithmetic operations, typically used by conditional branch instructions to decide program flow.
- liveness analysis
- A compiler analysis that determines for each point in a program whether a variable or register holds a value that might be used in the future. This is crucial for optimizations like dead code elimination and register allocation.
- AArch64
- The 64-bit instruction set architecture for ARM processors, commonly found in mobile devices and servers.
- late-combine
- A GCC optimization pass that attempts to combine multiple machine instructions into a single, more efficient instruction, often occurring late in the compilation pipeline.