combine: Fold constant comparison into CC user
combine: Optimizes folding constant comparisons into their condition code users.
This commit improves the combine pass by enabling the folding of constant comparison results directly into their condition code (CC) users. Previously, when a comparison setting the CC register resolved to a constant, the compiler would replace the comparison with the constant but struggled to propagate this into subsequent operations like ZERO_EXTEND. This led to missed optimizations, particularly on architectures like AArch64. The change uses subst to perform the replacement, correctly handling extensions of constants and simplifying subsequent RTL operations, thus enabling more effective constant folding.
In Details
The simplify_set function in combine.cc now uses subst for replacing a comparison that yields a constant result within its CC user. Previously, direct replacement followed by simplification could fail when the comparison was an operand to an extension (e.g., ZERO_EXTEND). The subst mechanism folds extensions of constants while the operand's mode is still known, allowing subsequent simplification. This also correctly manages n_occurrences count for try_combine by saving and restoring it around nested calls to simplify_set.
- combine
- A GCC optimization pass that attempts to combine multiple RTL (Register Transfer Language) instructions into a single, more efficient instruction.
- CC
- Condition Code. Special processor registers that store the result of comparisons or arithmetic operations, used by conditional branch instructions.
- RTL
- Register Transfer Language. An intermediate representation used by GCC to describe the operations performed by the program at a low level, between the front-end and the back-end.
- ZERO_EXTEND
- An RTL operation that extends a smaller integer value to a larger one by filling the most significant bits with zeros.
- AArch64
- The 64-bit ARM architecture. GCC's backend for this architecture.
- subst
- A function or mechanism within GCC used for substitution, typically to replace parts of an RTL expression with other expressions, often during optimization.
- constant folding
- An optimization technique where expressions with constant operands are evaluated at compile time rather than runtime.