aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCong Hou <congh@google.com>2014-04-03 19:05:42 -0400
committerCong Hou <congh@gcc.gnu.org>2014-04-03 19:05:42 -0400
commit090cd8dc70b80183c83d9f43f1e6ab9970481efd (patch)
tree922c68d13315da3b6382d88c5012433e5c2649bc
parentbdc67fd6a4576a1867bb0af8cd47aa819da6e2b3 (diff)
downloadgcc-090cd8dc70b80183c83d9f43f1e6ab9970481efd.zip
gcc-090cd8dc70b80183c83d9f43f1e6ab9970481efd.tar.gz
gcc-090cd8dc70b80183c83d9f43f1e6ab9970481efd.tar.bz2
re PR tree-optimization/60505 (Warning caused by GCC vectorizer.)
2014-04-03 Cong Hou <congh@google.com> PR tree-optimization/60505 * tree-vectorizer.h (struct _stmt_vec_info): Add th field as the threshold of number of iterations below which no vectorization will be done. * tree-vect-loop.c (new_loop_vec_info): Initialize LOOP_VINFO_COST_MODEL_THRESHOLD. * tree-vect-loop.c (vect_analyze_loop_operations): Set LOOP_VINFO_COST_MODEL_THRESHOLD. * tree-vect-loop.c (vect_transform_loop): Use LOOP_VINFO_COST_MODEL_THRESHOLD. * tree-vect-loop.c (vect_analyze_loop_2): Check the maximum number of iterations of the loop and see if we should build the epilogue. 2014-04-03 Cong Hou <congh@google.com> PR tree-optimization/60505 * gcc.dg/vect/pr60505.c: New test. From-SVN: r209065
-rw-r--r--gcc/ChangeLog15
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/gcc.dg/vect/pr60505.c12
-rw-r--r--gcc/tree-vect-loop.c21
-rw-r--r--gcc/tree-vectorizer.h6
5 files changed, 55 insertions, 4 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 8d0c021..2a2e948 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,18 @@
+2014-04-03 Cong Hou <congh@google.com>
+
+ PR tree-optimization/60505
+ * tree-vectorizer.h (struct _stmt_vec_info): Add th field as the
+ threshold of number of iterations below which no vectorization will be
+ done.
+ * tree-vect-loop.c (new_loop_vec_info):
+ Initialize LOOP_VINFO_COST_MODEL_THRESHOLD.
+ * tree-vect-loop.c (vect_analyze_loop_operations):
+ Set LOOP_VINFO_COST_MODEL_THRESHOLD.
+ * tree-vect-loop.c (vect_transform_loop):
+ Use LOOP_VINFO_COST_MODEL_THRESHOLD.
+ * tree-vect-loop.c (vect_analyze_loop_2): Check the maximum number
+ of iterations of the loop and see if we should build the epilogue.
+
2014-04-03 Richard Biener <rguenther@suse.de>
* tree-streamer.h (struct streamer_tree_cache_d): Add next_idx
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 3a58dc2..d470b1e 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2014-04-03 Cong Hou <congh@google.com>
+
+ PR tree-optimization/60505
+ * gcc.dg/vect/pr60505.c: New test.
+
2014-04-03 Richard Biener <rguenther@suse.de>
PR tree-optimization/60740
diff --git a/gcc/testsuite/gcc.dg/vect/pr60505.c b/gcc/testsuite/gcc.dg/vect/pr60505.c
new file mode 100644
index 0000000..6940513
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr60505.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-additional-options "-Wall -Werror" } */
+
+void foo(char *in, char *out, int num)
+{
+ int i;
+ char ovec[16] = {0};
+
+ for(i = 0; i < num ; ++i)
+ out[i] = (ovec[i] = in[i]);
+ out[num] = ovec[num/2];
+}
diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index df6ab6f..1c78e11 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -933,6 +933,7 @@ new_loop_vec_info (struct loop *loop)
LOOP_VINFO_NITERS (res) = NULL;
LOOP_VINFO_NITERS_UNCHANGED (res) = NULL;
LOOP_VINFO_COST_MODEL_MIN_ITERS (res) = 0;
+ LOOP_VINFO_COST_MODEL_THRESHOLD (res) = 0;
LOOP_VINFO_VECTORIZABLE_P (res) = 0;
LOOP_VINFO_PEELING_FOR_ALIGNMENT (res) = 0;
LOOP_VINFO_VECT_FACTOR (res) = 0;
@@ -1579,6 +1580,8 @@ vect_analyze_loop_operations (loop_vec_info loop_vinfo, bool slp)
|| min_profitable_iters > min_scalar_loop_bound))
th = (unsigned) min_profitable_iters;
+ LOOP_VINFO_COST_MODEL_THRESHOLD (loop_vinfo) = th;
+
if (LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo)
&& LOOP_VINFO_INT_NITERS (loop_vinfo) <= th)
{
@@ -1625,6 +1628,7 @@ vect_analyze_loop_2 (loop_vec_info loop_vinfo)
bool ok, slp = false;
int max_vf = MAX_VECTORIZATION_FACTOR;
int min_vf = 2;
+ unsigned int th;
/* Find all data references in the loop (which correspond to vdefs/vuses)
and analyze their evolution in the loop. Also adjust the minimal
@@ -1769,6 +1773,10 @@ vect_analyze_loop_2 (loop_vec_info loop_vinfo)
/* Decide whether we need to create an epilogue loop to handle
remaining scalar iterations. */
+ th = ((LOOP_VINFO_COST_MODEL_THRESHOLD (loop_vinfo) + 1)
+ / LOOP_VINFO_VECT_FACTOR (loop_vinfo))
+ * LOOP_VINFO_VECT_FACTOR (loop_vinfo);
+
if (LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo)
&& LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo) > 0)
{
@@ -1779,7 +1787,14 @@ vect_analyze_loop_2 (loop_vec_info loop_vinfo)
}
else if (LOOP_VINFO_PEELING_FOR_ALIGNMENT (loop_vinfo)
|| (tree_ctz (LOOP_VINFO_NITERS (loop_vinfo))
- < (unsigned)exact_log2 (LOOP_VINFO_VECT_FACTOR (loop_vinfo))))
+ < (unsigned)exact_log2 (LOOP_VINFO_VECT_FACTOR (loop_vinfo))
+ /* In case of versioning, check if the maximum number of
+ iterations is greater than th. If they are identical,
+ the epilogue is unnecessary. */
+ && ((!LOOP_REQUIRES_VERSIONING_FOR_ALIAS (loop_vinfo)
+ && !LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT (loop_vinfo))
+ || (unsigned HOST_WIDE_INT)max_stmt_executions_int
+ (LOOP_VINFO_LOOP (loop_vinfo)) > th)))
LOOP_VINFO_PEELING_FOR_NITER (loop_vinfo) = true;
/* If an epilogue loop is required make sure we can create one. */
@@ -5775,9 +5790,7 @@ vect_transform_loop (loop_vec_info loop_vinfo)
by our caller. If the threshold makes all loops profitable that
run at least the vectorization factor number of times checking
is pointless, too. */
- th = ((PARAM_VALUE (PARAM_MIN_VECT_LOOP_BOUND)
- * LOOP_VINFO_VECT_FACTOR (loop_vinfo)) - 1);
- th = MAX (th, LOOP_VINFO_COST_MODEL_MIN_ITERS (loop_vinfo));
+ th = LOOP_VINFO_COST_MODEL_THRESHOLD (loop_vinfo);
if (th >= LOOP_VINFO_VECT_FACTOR (loop_vinfo) - 1
&& !LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo))
{
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index f8efe47..f2087e2 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -264,6 +264,11 @@ typedef struct _loop_vec_info {
values unknown at compile time. */
int min_profitable_iters;
+ /* Threshold of number of iterations below which vectorzation will not be
+ performed. It is calculated from MIN_PROFITABLE_ITERS and
+ PARAM_MIN_VECT_LOOP_BOUND. */
+ unsigned int th;
+
/* Is the loop vectorizable? */
bool vectorizable;
@@ -382,6 +387,7 @@ typedef struct _loop_vec_info {
cost model. */
#define LOOP_VINFO_NITERS_UNCHANGED(L) (L)->num_iters_unchanged
#define LOOP_VINFO_COST_MODEL_MIN_ITERS(L) (L)->min_profitable_iters
+#define LOOP_VINFO_COST_MODEL_THRESHOLD(L) (L)->th
#define LOOP_VINFO_VECTORIZABLE_P(L) (L)->vectorizable
#define LOOP_VINFO_VECT_FACTOR(L) (L)->vectorization_factor
#define LOOP_VINFO_PTR_MASK(L) (L)->ptr_mask