aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-vectorizer.h
diff options
context:
space:
mode:
authorRobin Dapp <rdapp@ventanamicro.com>2025-07-03 11:04:29 +0200
committerRobin Dapp <rdapp@ventanamicro.com>2025-07-24 16:12:39 +0200
commit83afbe552e6b0baff37210dd1f344cfee4b26a2f (patch)
tree0356834df439bcfea700c31cb9fb73a8f8f49069 /gcc/tree-vectorizer.h
parentde75875d6779d7dc144aea2c5d26fb9aa2373d04 (diff)
downloadgcc-83afbe552e6b0baff37210dd1f344cfee4b26a2f.zip
gcc-83afbe552e6b0baff37210dd1f344cfee4b26a2f.tar.gz
gcc-83afbe552e6b0baff37210dd1f344cfee4b26a2f.tar.bz2
vect: Misalign checks for gather/scatter.
This patch adds simple misalignment checks for gather/scatter operations. Previously, we assumed that those perform element accesses internally so alignment does not matter. The riscv vector spec however explicitly states that vector operations are allowed to fault on element-misaligned accesses. Reasonable uarchs won't, but... For gather/scatter we have two paths in the vectorizer: (1) Regular analysis based on datarefs. Here we can also create strided loads. (2) Non-affine access where each gather index is relative to the initial address. The assumption this patch works on is that once the alignment for the first scalar is correct, all others will fall in line, as the index is always a multiple of the first element's size. For (1) we have a dataref and can check it for alignment as in other cases. For (2) this patch checks the object alignment of BASE and compares it against the natural alignment of the current vectype's unit. The patch also adds a pointer argument to the gather/scatter IFNs that contains the necessary alignment. Most of the patch is thus mechanical in that it merely adjusts indices. I tested the riscv version with a custom qemu version that faults on element-misaligned vector accesses. With this patch applied, there is just a single fault left, which is due to PR120782 and which will be addressed separately. Bootstrapped and regtested on x86 and aarch64. Regtested on rv64gcv_zvl512b with and without unaligned vector support. gcc/ChangeLog: * internal-fn.cc (internal_fn_len_index): Adjust indices for new alias_ptr param. (internal_fn_else_index): Ditto. (internal_fn_mask_index): Ditto. (internal_fn_stored_value_index): Ditto. (internal_fn_alias_ptr_index): Ditto. (internal_fn_offset_index): Ditto. (internal_fn_scale_index): Ditto. (internal_gather_scatter_fn_supported_p): Ditto. * internal-fn.h (internal_fn_alias_ptr_index): Ditto. * optabs-query.cc (supports_vec_gather_load_p): Ditto. * tree-vect-data-refs.cc (vect_check_gather_scatter): Add alias pointer. * tree-vect-patterns.cc (vect_recog_gather_scatter_pattern): Add alias pointer. * tree-vect-slp.cc (vect_get_operand_map): Adjust for alias pointer. * tree-vect-stmts.cc (vect_truncate_gather_scatter_offset): Add alias pointer and misalignment handling. (get_load_store_type): Move from here... (get_group_load_store_type): ...To here. (vectorizable_store): Add alias pointer. (vectorizable_load): Ditto. * tree-vectorizer.h (struct gather_scatter_info): Ditto.
Diffstat (limited to 'gcc/tree-vectorizer.h')
-rw-r--r--gcc/tree-vectorizer.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index 0f9b529..c94418f 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -1557,6 +1557,10 @@ struct gather_scatter_info {
/* The loop-invariant base value. */
tree base;
+ /* The TBBA alias pointer the value of which determines the alignment
+ of the scalar accesses. */
+ tree alias_ptr;
+
/* The original scalar offset, which is a non-loop-invariant SSA_NAME. */
tree offset;
@@ -2542,7 +2546,8 @@ extern bool ref_within_array_bound (gimple *, tree);
/* In tree-vect-data-refs.cc. */
extern bool vect_can_force_dr_alignment_p (const_tree, poly_uint64);
extern enum dr_alignment_support vect_supportable_dr_alignment
- (vec_info *, dr_vec_info *, tree, int);
+ (vec_info *, dr_vec_info *, tree, int,
+ gather_scatter_info * = nullptr);
extern tree vect_get_smallest_scalar_type (stmt_vec_info, tree);
extern opt_result vect_analyze_data_ref_dependences (loop_vec_info, unsigned int *);
extern bool vect_slp_analyze_instance_dependence (vec_info *, slp_instance);