Hi,
As reported in PR85804, bump step is wrongly computed for vector(1) load of
single-element group access. This patch fixes the issue by correcting bump
step computation for the specific VMAT_CONTIGUOUS case.
Bootstrap and test on x86_64 and AArch64 ongoing, is it OK?
Thanks,
bin
2018-05-17 Bin Cheng <bin.ch...@arm.com>
PR tree-optimization/85804
* tree-vect-stmts.c (vectorizable_load): Compute correct bump step
for vector(1) load in single-element group access.
gcc/testsuite
2018-05-17 Bin Cheng <bin.ch...@arm.com>
PR tree-optimization/85804
* gcc.c-torture/execute/pr85804.c: New test.
From 502bcd1e445186a56b6ea254a0cd2406fb62f08c Mon Sep 17 00:00:00 2001
From: Bin Cheng <binch...@e108451-lin.cambridge.arm.com>
Date: Fri, 18 May 2018 14:18:14 +0100
Subject: [PATCH] pr85804-20180517
---
gcc/testsuite/gcc.c-torture/execute/pr85804.c | 22 ++++++++++++++++++++++
gcc/tree-vect-stmts.c | 15 +++++++++++++++
2 files changed, 37 insertions(+)
create mode 100644 gcc/testsuite/gcc.c-torture/execute/pr85804.c
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr85804.c b/gcc/testsuite/gcc.c-torture/execute/pr85804.c
new file mode 100644
index 0000000..b8929b1
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr85804.c
@@ -0,0 +1,22 @@
+/* { dg-options "-O2 -ftree-vectorize -fno-vect-cost-model" } */
+
+long d[64] = {0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
+};
+
+void abort ();
+void __attribute__((noinline)) foo (int b)
+{
+ if (b)
+ abort ();
+}
+int main() {
+ int b = 0;
+ for (int c = 0; c <= 5; c++)
+ b ^= d[c * 5 + 1];
+ foo (b);
+ return 0;
+}
+
diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c
index 64a157d..e6b95b3 100644
--- a/gcc/tree-vect-stmts.c
+++ b/gcc/tree-vect-stmts.c
@@ -7262,6 +7262,7 @@ vectorizable_load (gimple *stmt, gimple_stmt_iterator *gsi, gimple **vec_stmt,
gphi *phi = NULL;
vec<tree> dr_chain = vNULL;
bool grouped_load = false;
+ bool single_element = false;
gimple *first_stmt;
gimple *first_stmt_for_drptr = NULL;
bool inv_p;
@@ -7822,6 +7823,15 @@ vectorizable_load (gimple *stmt, gimple_stmt_iterator *gsi, gimple **vec_stmt,
first_stmt = stmt;
first_dr = dr;
group_size = vec_num = 1;
+ /* For single-element vector in a single-element group, record the group
+ size in order to compute correct bump size. */
+ if (!slp
+ && memory_access_type == VMAT_CONTIGUOUS
+ && STMT_VINFO_GROUPED_ACCESS (stmt_info))
+ {
+ single_element = true;
+ group_size = GROUP_SIZE (vinfo_for_stmt (first_stmt));
+ }
group_gap_adj = 0;
ref_type = reference_alias_ptr_type (DR_REF (first_dr));
}
@@ -7992,6 +8002,11 @@ vectorizable_load (gimple *stmt, gimple_stmt_iterator *gsi, gimple **vec_stmt,
else
aggr_type = vectype;
bump = vect_get_data_ptr_increment (dr, aggr_type, memory_access_type);
+ /* Multiply bump size by group size for single-element vector in single-
+ element group. */
+ if (single_element && group_size > 1)
+ bump = fold_build2 (MULT_EXPR, TREE_TYPE (bump), bump,
+ build_int_cst (TREE_TYPE (bump), group_size));
}
tree vec_mask = NULL_TREE;
--
1.9.1