vectorizer: Correctly commit base alignment in costing
Fixes a bug in the vectorizer where base alignment was incorrectly enlarged during costing, leading to suboptimal alignment choices.
The vectorizer had a bug where it erroneously committed an enlarged base alignment during the costing phase, stemming from a recent refactoring. This meant that alignment decisions were based on potentially larger vector types than ultimately used, leading to incorrect alignment computations. This commit corrects the logic to only commit the recorded base alignment when the transformation is actually applied, ensuring more accurate alignment for vectorized loads and stores and fixing PR middle-end/126410.
In Details
Corrects a bug in the vectorizer's costing phase related to alignment, identified in PR middle-end/126410. The vectorizable_store and vectorizable_load functions were incorrectly committing the recorded_base_alignment on every costing, regardless of whether a transformation was applied. This commit modifies these functions to only commit the alignment when transforming, addressing the issue where alignment was computed based on potentially larger vector types than used.
- vectorizer
- A compiler component that automatically transforms loops or sequences of operations to use SIMD (Single Instruction, Multiple Data) instructions, executing the same operation on multiple data elements simultaneously.
- costing
- In compiler optimization, the process of evaluating the potential performance impact or resource usage of different transformation options to select the best one.
- alignment
- The placement of data in memory at an address that is a multiple of a specified value (e.g., a 4-byte boundary for 32-bit integers). Proper alignment can improve memory access performance.
- SIMD
- Single Instruction, Multiple Data. A class of parallel computers in Flynn's taxonomy that perform the same operation on multiple data points simultaneously. Vector instructions in CPUs are an example of SIMD.