ifcvt: Improve conditional arithmetic conversion by looking through copy instructions
Enhances the conditional arithmetic conversion pass to look through single copy instructions, enabling more transformations.
The ifcvt (if-conversion) pass now improves its ability to transform conditional arithmetic operations by looking through extraneous copy instructions. The noce_try_cond_arith function can now pierce a single copy instruction if its definition is the first instruction in a block, provided certain conditions are met. This allows for more aggressive if-conversion, particularly in cases where the ‘else’ block was simple but a preceding copy instruction masked the simplicity of the ‘then’ block. This change aims to enable more optimizations without introducing regressions.
In Details
The ifcvt (if-conversion) pass's noce_try_cond_arith function has been enhanced to look through a single copy instruction when determining if a basic block is suitable for conditional arithmetic conversion. This is achieved by checking if the source of the copy is the definition of the first non-note/debug instruction. This patch addresses PR122335 by allowing the pass to see through such copies, making blocks that would otherwise appear complex 'simple' again. It includes checks for if_info->else_bb and ensures the original destination is a register to avoid dropping clobbers.
- ifcvt
- If-conversion pass in GCC. It attempts to replace conditional control flow (if statements) with conditional move or arithmetic instructions, potentially improving performance by reducing branching.
- copy insn
- An instruction that copies the value from one register to another.
- noce
- Negated and Conditional Execution. Refers to optimization passes that attempt to simplify code by using conditional execution features or negating conditions.
- basic block
- A sequence of instructions with a single entry point and a single exit point. Control flow graphs are composed of basic blocks.