Improve factoring and merging of operations involving certain builtins
PHI optimization pass now correctly handles factoring and merging of operations involving CRC, expect, object_size, clz, ctz, prefetch, and frame address built…
The PHI optimization pass has been enhanced to correctly factor and merge operations involving several builtins that require constant arguments. Previously, operations like CRC builtins could not be factored out if their third argument differed, leading to errors. This change consolidates logic into a new factor_operation_ok function and extends its checks to cover CRC, expect, object_size, clz, ctz, prefetch, and frame address builtins, enabling better optimization while maintaining correctness.
In Details
This commit refactors tree-if-conv.cc, tree-ssa-phiopt.cc, and tree-ssa-tail-merge.cc to consolidate the logic for determining if an operation can be factored or commoned. It introduces factor_operation_ok which centralizes checks for builtins like CRC, BIT_INSERT_EXPR, etc., that have strict requirements on constant operands. This addresses PR126977 and PR113609-2.c.
- PHI optimization
- A compiler optimization pass that deals with PHI nodes in SSA form, aiming to simplify code by identifying and merging common subexpressions and conditional operations.
- SSA form
- Static Single Assignment form is an intermediate representation where every variable is assigned a value exactly once. PHI nodes are used to represent values that can come from multiple control flow paths.
- builtins
- Functions provided by the compiler that have a special meaning and can be translated directly into efficient machine code. They often correspond to specific hardware instructions or common low-level operations.
- CRC
- Cyclic Redundancy Check is an error-detection code used to detect accidental changes to raw data. GCC provides builtins for efficient CRC computation.
- factor out
- In optimization, 'factoring out' refers to extracting a common subexpression from multiple places in the code so it's computed only once.
- commonialization
- Similar to factoring out, this optimization identifies identical computations that can be replaced by a single computation, sharing the result.
- BIT_INSERT_EXPR
- An expression that inserts a sequence of bits from one value into another at a specified position.