aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorWill Schmidt <will_schmidt@vnet.ibm.com>2018-09-06 15:34:58 +0000
committerWill Schmidt <willschm@gcc.gnu.org>2018-09-06 15:34:58 +0000
commit6847c656b4153fbd0b552ac5051dc7b3ec44246a (patch)
tree0af563b1a424dbbd5d7539333d991d86b5b755f6 /gcc
parent84bde0bffe8b2d6291b196f3cd77398dea971c85 (diff)
downloadgcc-6847c656b4153fbd0b552ac5051dc7b3ec44246a.zip
gcc-6847c656b4153fbd0b552ac5051dc7b3ec44246a.tar.gz
gcc-6847c656b4153fbd0b552ac5051dc7b3ec44246a.tar.bz2
rs6000.c (rs6000_gimple_fold_builtin): Add support for early gimple folding of vec_splat().
[gcc] 2018-09-06 Will Schmidt <will_schmidt@vnet.ibm.com> * config/rs6000/rs6000.c (rs6000_gimple_fold_builtin): Add support for early gimple folding of vec_splat(). * tree-vect-generic.c: Remove static from tree_vec_extract() definition. * gimple-fold.h: Add an extern define for tree_vec_extract(). From-SVN: r264146
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/config/rs6000/rs6000.c42
-rw-r--r--gcc/gimple-fold.h1
-rw-r--r--gcc/tree-vect-generic.c2
4 files changed, 51 insertions, 1 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 7ac78dd..19800f5 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,12 @@
2018-09-06 Will Schmidt <will_schmidt@vnet.ibm.com>
+ * config/rs6000/rs6000.c (rs6000_gimple_fold_builtin): Add support for
+ early gimple folding of vec_splat().
+ * tree-vect-generic.c: Remove static from tree_vec_extract() definition.
+ * gimple-fold.h: Add an extern define for tree_vec_extract().
+
+2018-09-06 Will Schmidt <will_schmidt@vnet.ibm.com>
+
* config/rs6000/rs6000.c (fold_mergehl_helper): Add types_compatible_p
wrappers around TREE_TYPE comparisons.
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index cc69b5d..6f6c945 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -15772,6 +15772,48 @@ rs6000_gimple_fold_builtin (gimple_stmt_iterator *gsi)
gimple_set_location (g, gimple_location (stmt));
gsi_replace (gsi, g, true);
return true;
+ }
+
+ /* Flavors of vec_splat. */
+ /* a = vec_splat (b, 0x3) becomes a = { b[3],b[3],b[3],...}; */
+ case ALTIVEC_BUILTIN_VSPLTB:
+ case ALTIVEC_BUILTIN_VSPLTH:
+ case ALTIVEC_BUILTIN_VSPLTW:
+ case VSX_BUILTIN_XXSPLTD_V2DI:
+ case VSX_BUILTIN_XXSPLTD_V2DF:
+ {
+ arg0 = gimple_call_arg (stmt, 0); /* input vector. */
+ arg1 = gimple_call_arg (stmt, 1); /* index into arg0. */
+ /* Only fold the vec_splat_*() if arg1 is both a constant value and
+ is a valid index into the arg0 vector. */
+ unsigned int n_elts = VECTOR_CST_NELTS (arg0);
+ if (TREE_CODE (arg1) != INTEGER_CST
+ || TREE_INT_CST_LOW (arg1) > (n_elts -1))
+ return false;
+ lhs = gimple_call_lhs (stmt);
+ tree lhs_type = TREE_TYPE (lhs);
+ tree arg0_type = TREE_TYPE (arg0);
+ tree splat;
+ if (TREE_CODE (arg0) == VECTOR_CST)
+ splat = VECTOR_CST_ELT (arg0, TREE_INT_CST_LOW (arg1));
+ else
+ {
+ /* Determine (in bits) the length and start location of the
+ splat value for a call to the tree_vec_extract helper. */
+ int splat_elem_size = TREE_INT_CST_LOW (size_in_bytes (arg0_type))
+ * BITS_PER_UNIT / n_elts;
+ int splat_start_bit = TREE_INT_CST_LOW (arg1) * splat_elem_size;
+ tree len = build_int_cst (bitsizetype, splat_elem_size);
+ tree start = build_int_cst (bitsizetype, splat_start_bit);
+ splat = tree_vec_extract (gsi, TREE_TYPE (lhs_type), arg0,
+ len, start);
+ }
+ /* And finally, build the new vector. */
+ tree splat_tree = build_vector_from_val (lhs_type, splat);
+ g = gimple_build_assign (lhs, splat_tree);
+ gimple_set_location (g, gimple_location (stmt));
+ gsi_replace (gsi, g, true);
+ return true;
}
/* vec_mergel (integrals). */
diff --git a/gcc/gimple-fold.h b/gcc/gimple-fold.h
index e3fad83..fcb0d31 100644
--- a/gcc/gimple-fold.h
+++ b/gcc/gimple-fold.h
@@ -61,6 +61,7 @@ extern bool gimple_fold_builtin_snprintf (gimple_stmt_iterator *);
extern bool arith_code_with_undefined_signed_overflow (tree_code);
extern gimple_seq rewrite_to_defined_overflow (gimple *);
extern void replace_call_with_value (gimple_stmt_iterator *, tree);
+extern tree tree_vec_extract (gimple_stmt_iterator *, tree, tree, tree, tree);
/* gimple_build, functionally matching fold_buildN, outputs stmts
int the provided sequence, matching and simplifying them on-the-fly.
diff --git a/gcc/tree-vect-generic.c b/gcc/tree-vect-generic.c
index 909f790..1c9701d 100644
--- a/gcc/tree-vect-generic.c
+++ b/gcc/tree-vect-generic.c
@@ -120,7 +120,7 @@ typedef tree (*elem_op_func) (gimple_stmt_iterator *,
tree, tree, tree, tree, tree, enum tree_code,
tree);
-static inline tree
+tree
tree_vec_extract (gimple_stmt_iterator *gsi, tree type,
tree t, tree bitsize, tree bitpos)
{