GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
gcc

Fix incorrect optimization of non-byte-aligned array components

Loop distribution optimization now correctly handles non-byte-aligned array components, preventing incorrect memcpy generation.

The -ftree-loop-distribute-patterns optimization pass could incorrectly generate memcpy calls for non-byte-aligned array components. This happened because the pass would consider partitions containing such data references as addressable, leading to erroneous loop distribution. This commit modifies the loop_distribution::classify_partition function to disqualify partitions containing non-addressable data references, ensuring correct optimization.

In Details

The loop_distribution::classify_partition function within tree-loop-distribution.cc previously failed to properly disqualify partitions that contained non-addressable data references when deciding whether to generate builtins, specifically memcpy. This led to situations where loops containing such references could be selected for distribution, potentially resulting in incorrect code generation. This commit adds a check to ensure that partitions with non-addressable data references are disqualified, preventing this incorrect optimization.

For Context
-ftree-loop-distribute-patterns
A GCC optimization flag that enables the distribution of loop bodies into separate loops, potentially improving instruction scheduling and other optimizations. It can also involve pattern recognition for specific loop structures.
memcpy
A standard C library function used for copying a block of memory from one location to another. Compilers may generate calls to memcpy during optimization for efficient memory block transfers.
non-byte-aligned
Refers to data or memory addresses that are not aligned to a multiple of one byte. For certain architectures and data types, accessing non-aligned data can be slower or even cause errors.
tree
In GCC, 'tree' refers to the internal representation of code after the initial parsing and before the generation of machine code. It's an abstract syntax tree-like structure that optimizations operate on.
Filed Under: gccoptimizationbugfix