cprop: Do not queue dead CC setters when bypassing jumps.
Constant propagation pass avoids queuing unnecessary flag-setting instructions during jump bypassing.
The constant propagation pass (cprop) now avoids queuing dead condition code (CC) setters when bypassing jumps. In code with long chains of conditional checks, previously, the compiler would insert redundant flag-setting compare instructions, consuming significant compile time. This change ensures that setters are only copied if they are truly needed at the destination block (e.g., for side effects, exceptions, or if they set a live register not otherwise handled). This optimization dramatically reduces compile times, by up to 95% in the tested scenario.
In Details
This patch addresses performance regressions in cprop caused by queuing dead CC setters during jump bypassing. In code with sequential conditional checks (e.g., if (v == 0) ...; if (v == 1) ...;), the bypass_block function would redirect edges and queue copies of the bypassed block's flag setters. These setters were often redundant because the next block would re-evaluate the flags. The reg_killed_on_edge and insert_insn_on_edge functions then processed these dead setters, leading to excessive compile times. The fix introduces bypass_setcc_needed_p to conditionally copy setters on…
- cprop
- Constant Propagation. A compiler optimization that replaces variables or expressions with their known constant values.
- Condition Code (CC)
- Special registers in a CPU that store the status of arithmetic and logical operations, such as whether the result was zero, negative, or caused an overflow. These are often used in conditional branching.
- Jump Bypassing
- An optimization technique where conditional jumps are analyzed and potentially eliminated or simplified by rearranging code or propagating constants.
- Basic Block
- A sequence of instructions with a single entry point and a single exit point. Control flow enters at the beginning and proceeds without halt or possibility of diversion until the end.
- Liveness analysis
- A compiler analysis that determines which variables hold a value that might be used in the future. This is crucial for register allocation and dead code elimination.