diff options
author | Pengfei Li <Pengfei.Li2@arm.com> | 2025-07-30 10:51:11 +0100 |
---|---|---|
committer | Tamar Christina <tamar.christina@arm.com> | 2025-07-30 10:53:10 +0100 |
commit | 46a862ef08f3c44780c8d9043ce16382d8a70ada (patch) | |
tree | 05d9979dc4ed4cfa4201fc1c61a0e3af1f1a4566 /gcc/gimple-loop-interchange.cc | |
parent | 483326615ee2c9b33b7a1690faf95bcd31167219 (diff) | |
download | gcc-46a862ef08f3c44780c8d9043ce16382d8a70ada.zip gcc-46a862ef08f3c44780c8d9043ce16382d8a70ada.tar.gz gcc-46a862ef08f3c44780c8d9043ce16382d8a70ada.tar.bz2 |
vect: Fix insufficient alignment requirement for speculative loads [PR121190]
This patch fixes a segmentation fault issue that can occur in vectorized
loops with an early break. When GCC vectorizes such loops, it may insert
a versioning check to ensure that data references (DRs) with speculative
loads are aligned. The check normally requires DRs to be aligned to the
vector mode size, which prevents generated vector load instructions from
crossing page boundaries.
However, this is not sufficient when a single scalar load is vectorized
into multiple loads within the same iteration. In such cases, even if
none of the vector loads crosses page boundaries, subsequent loads after
the first one may still access memory beyond current valid page.
Consider the following loop as an example:
while (i < MAX_COMPARE) {
if (*(p + i) != *(q + i))
return i;
i++;
}
When compiled with "-O3 -march=znver2" on x86, the vectorized loop may
include instructions like:
vmovdqa (%rcx,%rax), %ymm0
vmovdqa 32(%rcx,%rax), %ymm1
vpcmpeqq (%rdx,%rax), %ymm0, %ymm0
vpcmpeqq 32(%rdx,%rax), %ymm1, %ymm1
Note two speculative vector loads are generated for each DR (p and q).
The first vmovdqa and vpcmpeqq are safe due to the vector size (32-byte)
alignment, but the following ones (at offset 32) may not be safe because
they could read from the beginning of the next memory page, potentially
leading to segmentation faults.
To avoid the issue, this patch increases the alignment requirement for
speculative loads to DR_TARGET_ALIGNMENT. It ensures all vector loads in
the same vector iteration access memory within the same page.
gcc/ChangeLog:
PR tree-optimization/121190
* tree-vect-data-refs.cc (vect_enhance_data_refs_alignment):
Increase alignment requirement for speculative loads.
gcc/testsuite/ChangeLog:
PR tree-optimization/121190
* gcc.dg/vect/vect-early-break_52.c: Update an unsafe test.
* gcc.dg/vect/vect-early-break_137-pr121190.c: New test.
Diffstat (limited to 'gcc/gimple-loop-interchange.cc')
0 files changed, 0 insertions, 0 deletions