diff options
author | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2017-09-18 10:13:54 +0000 |
---|---|---|
committer | rguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4> | 2017-09-18 10:13:54 +0000 |
commit | 6bdc021ec26a650e16a4233a1f9636384ca23675 (patch) | |
tree | cfb848772f4c90335b7748f93ad55e8bd556ca37 | |
parent | b8da2e0b0fa6955b670670b53458b97d7e1bd9ec (diff) | |
download | gcc-6bdc021ec26a650e16a4233a1f9636384ca23675.tar.gz |
2017-09-18 Richard Biener <rguenther@suse.de>
Backport from mainline
2017-09-04 Richard Biener <rguenther@suse.de>
PR tree-optimization/82084
* fold-const.h (can_native_encode_string_p): Declare.
* fold-const.c (can_native_encode_string_p): Factor out from ...
(native_encode_string): ... here.
* tree-vect-stmts.c (vectorizable_store): Call it to avoid
vectorizing stores from constants we later cannot handle.
* g++.dg/torture/pr82084.C: New testcase.
2017-09-06 Richard Biener <rguenther@suse.de>
PR tree-optimization/82108
* tree-vect-stmts.c (vectorizable_load): Fix pointer adjustment
for gap in the non-permutation SLP case.
* gcc.dg/vect/pr82108.c: New testcase.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-7-branch@252918 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 18 | ||||
-rw-r--r-- | gcc/fold-const.c | 27 | ||||
-rw-r--r-- | gcc/fold-const.h | 1 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 13 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/torture/pr82084.C | 9 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/vect/pr82108.c | 47 | ||||
-rw-r--r-- | gcc/tree-vect-stmts.c | 10 |
7 files changed, 115 insertions, 10 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 67ca1a75ed3..9909c3c7c34 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,21 @@ +2017-09-18 Richard Biener <rguenther@suse.de> + + Backport from mainline + 2017-09-04 Richard Biener <rguenther@suse.de> + + PR tree-optimization/82084 + * fold-const.h (can_native_encode_string_p): Declare. + * fold-const.c (can_native_encode_string_p): Factor out from ... + (native_encode_string): ... here. + * tree-vect-stmts.c (vectorizable_store): Call it to avoid + vectorizing stores from constants we later cannot handle. + + 2017-09-06 Richard Biener <rguenther@suse.de> + + PR tree-optimization/82108 + * tree-vect-stmts.c (vectorizable_load): Fix pointer adjustment + for gap in the non-permutation SLP case. + 2017-09-15 Jakub Jelinek <jakub@redhat.com> Backported from mainline diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 66a494d5ca6..a634fc90cae 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -7203,15 +7203,10 @@ native_encode_vector (const_tree expr, unsigned char *ptr, int len, int off) static int native_encode_string (const_tree expr, unsigned char *ptr, int len, int off) { - tree type = TREE_TYPE (expr); - HOST_WIDE_INT total_bytes; - - if (TREE_CODE (type) != ARRAY_TYPE - || TREE_CODE (TREE_TYPE (type)) != INTEGER_TYPE - || GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (type))) != BITS_PER_UNIT - || !tree_fits_shwi_p (TYPE_SIZE_UNIT (type))) + if (! can_native_encode_string_p (expr)) return 0; - total_bytes = tree_to_shwi (TYPE_SIZE_UNIT (type)); + + HOST_WIDE_INT total_bytes = tree_to_shwi (TYPE_SIZE_UNIT (TREE_TYPE (expr))); if ((off == -1 && total_bytes > len) || off >= total_bytes) return 0; @@ -7505,6 +7500,22 @@ can_native_encode_type_p (tree type) } } +/* Return true iff a STRING_CST S is accepted by + native_encode_expr. */ + +bool +can_native_encode_string_p (const_tree expr) +{ + tree type = TREE_TYPE (expr); + + if (TREE_CODE (type) != ARRAY_TYPE + || TREE_CODE (TREE_TYPE (type)) != INTEGER_TYPE + || (GET_MODE_BITSIZE (TYPE_MODE (TREE_TYPE (type))) != BITS_PER_UNIT) + || !tree_fits_shwi_p (TYPE_SIZE_UNIT (type))) + return false; + return true; +} + /* Fold a VIEW_CONVERT_EXPR of a constant expression EXPR to type TYPE at compile-time. If we're unable to perform the conversion return NULL_TREE. */ diff --git a/gcc/fold-const.h b/gcc/fold-const.h index 7abf4d1bc06..4ba0e4550ad 100644 --- a/gcc/fold-const.h +++ b/gcc/fold-const.h @@ -28,6 +28,7 @@ extern int folding_initializer; extern int native_encode_expr (const_tree, unsigned char *, int, int off = -1); extern tree native_interpret_expr (tree, const unsigned char *, int); extern bool can_native_encode_type_p (tree); +extern bool can_native_encode_string_p (const_tree); /* Fold constants as much as possible in an expression. Returns the simplified expression. diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b8b5f2eacff..049e2188a56 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,16 @@ +2017-09-18 Richard Biener <rguenther@suse.de> + + Backport from mainline + 2017-09-04 Richard Biener <rguenther@suse.de> + + PR tree-optimization/82084 + * g++.dg/torture/pr82084.C: New testcase. + + 2017-09-06 Richard Biener <rguenther@suse.de> + + PR tree-optimization/82108 + * gcc.dg/vect/pr82108.c: New testcase. + 2017-09-15 Jakub Jelinek <jakub@redhat.com> Backported from mainline diff --git a/gcc/testsuite/g++.dg/torture/pr82084.C b/gcc/testsuite/g++.dg/torture/pr82084.C new file mode 100644 index 00000000000..416684d2cb8 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr82084.C @@ -0,0 +1,9 @@ +// { dg-do compile } + +#include <string> +int main() +{ + wchar_t strs[4][2]= { L"A", L"B", L"C" , L"D"}; + std::wstring ss(strs[0]); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/vect/pr82108.c b/gcc/testsuite/gcc.dg/vect/pr82108.c new file mode 100644 index 00000000000..5b8faf1aefb --- /dev/null +++ b/gcc/testsuite/gcc.dg/vect/pr82108.c @@ -0,0 +1,47 @@ +/* { dg-do run } */ +/* { dg-require-effective-target vect_float } */ + +#include "tree-vect.h" + +void __attribute__((noinline,noclone)) +downscale_2 (const float* src, int src_n, float* dst) +{ + int i; + + for (i = 0; i < src_n; i += 2) { + const float* a = src; + const float* b = src + 4; + + dst[0] = (a[0] + b[0]) / 2; + dst[1] = (a[1] + b[1]) / 2; + dst[2] = (a[2] + b[2]) / 2; + dst[3] = (a[3] + b[3]) / 2; + + src += 2 * 4; + dst += 4; + } +} + +int main () +{ + const float in[4 * 4] = { + 1, 2, 3, 4, + 5, 6, 7, 8, + + 1, 2, 3, 4, + 5, 6, 7, 8 + }; + float out[2 * 4]; + + check_vect (); + + downscale_2 (in, 4, out); + + if (out[0] != 3 || out[1] != 4 || out[2] != 5 || out[3] != 6 + || out[4] != 3 || out[5] != 4 || out[6] != 5 || out[7] != 6) + __builtin_abort (); + + return 0; +} + +/* { dg-final { scan-tree-dump-times "vectorized 1 loops" 1 "vect" } } */ diff --git a/gcc/tree-vect-stmts.c b/gcc/tree-vect-stmts.c index 50f11de7bbe..5096d03b625 100644 --- a/gcc/tree-vect-stmts.c +++ b/gcc/tree-vect-stmts.c @@ -5702,6 +5702,12 @@ vectorizable_store (gimple *stmt, gimple_stmt_iterator *gsi, gimple **vec_stmt, op = gimple_assign_rhs1 (stmt); + /* In the case this is a store from a STRING_CST make sure + native_encode_expr can handle it. */ + if (TREE_CODE (op) == STRING_CST + && ! can_native_encode_string_p (op)) + return false; + if (!vect_is_simple_use (op, vinfo, &def_stmt, &dt, &rhs_vectype)) { if (dump_enabled_p ()) @@ -7109,7 +7115,6 @@ vectorizable_load (gimple *stmt, gimple_stmt_iterator *gsi, gimple **vec_stmt, { first_stmt = GROUP_FIRST_ELEMENT (stmt_info); group_size = GROUP_SIZE (vinfo_for_stmt (first_stmt)); - int group_gap = GROUP_GAP (vinfo_for_stmt (first_stmt)); /* For SLP vectorization we directly vectorize a subchain without permutation. */ if (slp && ! SLP_TREE_LOAD_PERMUTATION (slp_node).exists ()) @@ -7152,7 +7157,8 @@ vectorizable_load (gimple *stmt, gimple_stmt_iterator *gsi, gimple **vec_stmt, else { vec_num = SLP_TREE_NUMBER_OF_VEC_STMTS (slp_node); - group_gap_adj = group_gap; + group_gap_adj + = group_size - SLP_INSTANCE_GROUP_SIZE (slp_node_instance); } } else |