GCC Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
ifcvt Performance Win

ifcvt, aarch64: Make the outside-loop profitability rule work

AArch64 if-conversion now correctly applies profitability rules to code outside loops.

This commit fixes an issue where GCC’s AArch64 if-conversion optimization incorrectly applied its cost limit to code blocks residing outside of loops. The original logic failed to identify these blocks as candidates for conversion because the loop tree was either still present or already freed by the time the check occurred. The patch records natural loop membership before loop tree finalization and passes this information to the target hook, allowing the AArch64 profitability rule to be applied only when optimizing for speed and when the code is indeed outside a loop, thus enabling more effective if-conversion in non-loop contexts.

In Details

The AArch64 if_convert pass in GCC has a profitability heuristic (aarch64_noce_conversion_profitable_p) intended to apply less strict cost limits to code outside of loops, assuming poorer branch predictor performance in such scenarios. However, this rule never fired due to issues with loop tree management. In ce1, blocks outside loops were still part of the root loop, and in ce2/ce3, the loop tree was freed prematurely. This patch modifies ifcvt.cc to record natural loop membership (in_loop flag in noce_if_info) before the loop tree is freed. The AArch64 target hook then uses…

For Context
if-conversion
A compiler optimization technique that transforms conditional control flow (like if-else statements) into data flow using conditional instructions (like conditional selects) to potentially improve performance by reducing branch prediction misses.
AArch64
A 64-bit ARM architecture, commonly used in mobile devices and servers.
profitability rule
A heuristic used by compilers to decide whether applying an optimization is likely to improve performance or code size.
loop tree
A data structure used by the compiler to represent the hierarchical structure of loops within the code.
natural loop
A loop in control flow graphs that has a single entry point (header).
Filed Under: ifcvtaarch64optimizationgcc