Disable partial vectors for loads not covering whole vectors to prevent faults
Fixes vectorization by disabling partial vector loads when they don't align with vector boundaries, preventing memory access faults.
This commit resolves an issue in GCC’s vectorization optimization where partial vector loads could lead to memory access faults. The problem occurred when permuted SLP loads accessed a number of elements that did not perfectly fill a whole number of vectors. The check_load_store_for_partial_vectors function incorrectly rounded up the number of vectors and applied masks, causing out-of-bounds memory access. The fix disables the use of partial vectors in such cases, ensuring correct memory access and preventing program crashes.
In Details
This commit addresses PR tree-optimization/128433 by preventing the use of partial vectors for SLP (Short-Loop Parallelization) loads where the accessed group of scalars per vector iteration does not precisely fill a whole number of target vectors. Previously, check_load_store_for_partial_vectors in tree-vect-stmts.cc would round the vector count up and generate loop masks, leading to incorrect scalar counts per iteration. This could cause faults when the accesses crossed page boundaries or if loop lengths were misinterpreted. The fix ensures that such ambiguous loads do not enable partia…
- Vectorization
- An optimization technique that allows the processor to perform the same operation on multiple data elements simultaneously using special vector instructions (SIMD).
- Partial Vectors
- Vector operations that do not operate on a full vector width of data, often used when the data size is not a multiple of the vector width.
- SLP (Short-Loop Parallelization)
- A compiler optimization technique that vectorizes sequences of identical or similar operations that occur close together in the code, even if they are not in a traditional loop.
- tree-vect-stmts.cc
- A GCC source file containing routines related to statement transformations for vectorization.
- loop mask
- A bitmask used in vector operations to control which elements within a vector are processed or updated, typically used to handle vectorized loops with non-vector-aligned trip counts.
- VF
- Vector Factor. Represents the number of elements a vector instruction can process simultaneously.