aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2021-09-01 12:06:25 +0200
committerJakub Jelinek <jakub@redhat.com>2021-09-01 12:06:25 +0200
commit45ff12512e568089a4c7b85b5322ab8019723cd9 (patch)
tree00ada361aa22b887d2ac8591a4608a8c303047a5 /gcc
parente6bd9c42b0ad0cc4a615135612599adb829f2d9c (diff)
downloadgcc-45ff12512e568089a4c7b85b5322ab8019723cd9.zip
gcc-45ff12512e568089a4c7b85b5322ab8019723cd9.tar.gz
gcc-45ff12512e568089a4c7b85b5322ab8019723cd9.tar.bz2
bswap: Fix up bswap_view_convert handling [PR102141]
bswap_view_convert is used twice in spots where gsi_insert_before is the right thing, but in the last one it wants to insert preparation stmts for the VIEW_CONVERT_EXPR emitted with gsi_insert_after, where at the gsi we still need to insert bswap_stmt and maybe mask_stmt whose lhs the preparation stmts will use. So, this patch adds a BEFORE argument to the function and emits the preparation statements before or after depending on that. 2021-09-01 Jakub Jelinek <jakub@redhat.com> PR tree-optimization/102141 * gimple-ssa-store-merging.c (bswap_view_convert): Add BEFORE argument. If false, emit stmts after gsi instead of before, and with GSI_NEW_STMT. (bswap_replace): Adjust callers. When converting output of bswap, emit VIEW_CONVERT prepratation stmts after a copy of gsi instead of before it. * gcc.dg/pr102141.c: New test.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/gimple-ssa-store-merging.c27
-rw-r--r--gcc/testsuite/gcc.dg/pr102141.c11
2 files changed, 28 insertions, 10 deletions
diff --git a/gcc/gimple-ssa-store-merging.c b/gcc/gimple-ssa-store-merging.c
index 781c02d..4efa200 100644
--- a/gcc/gimple-ssa-store-merging.c
+++ b/gcc/gimple-ssa-store-merging.c
@@ -1020,7 +1020,8 @@ public:
first. */
static tree
-bswap_view_convert (gimple_stmt_iterator *gsi, tree type, tree val)
+bswap_view_convert (gimple_stmt_iterator *gsi, tree type, tree val,
+ bool before)
{
gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (val))
|| POINTER_TYPE_P (TREE_TYPE (val)));
@@ -1032,12 +1033,18 @@ bswap_view_convert (gimple_stmt_iterator *gsi, tree type, tree val)
gimple *g
= gimple_build_assign (make_ssa_name (pointer_sized_int_node),
NOP_EXPR, val);
- gsi_insert_before (gsi, g, GSI_SAME_STMT);
+ if (before)
+ gsi_insert_before (gsi, g, GSI_SAME_STMT);
+ else
+ gsi_insert_after (gsi, g, GSI_NEW_STMT);
val = gimple_assign_lhs (g);
}
tree itype = build_nonstandard_integer_type (prec, 1);
gimple *g = gimple_build_assign (make_ssa_name (itype), NOP_EXPR, val);
- gsi_insert_before (gsi, g, GSI_SAME_STMT);
+ if (before)
+ gsi_insert_before (gsi, g, GSI_SAME_STMT);
+ else
+ gsi_insert_after (gsi, g, GSI_NEW_STMT);
val = gimple_assign_lhs (g);
}
return build1 (VIEW_CONVERT_EXPR, type, val);
@@ -1165,7 +1172,8 @@ bswap_replace (gimple_stmt_iterator gsi, gimple *ins_stmt, tree fndecl,
gimple_set_vuse (load_stmt, n->vuse);
gsi_insert_before (&gsi, load_stmt, GSI_SAME_STMT);
if (conv_code == VIEW_CONVERT_EXPR)
- val_tmp = bswap_view_convert (&gsi, TREE_TYPE (tgt), val_tmp);
+ val_tmp = bswap_view_convert (&gsi, TREE_TYPE (tgt), val_tmp,
+ true);
gimple_assign_set_rhs_with_ops (&gsi, conv_code, val_tmp);
update_stmt (cur_stmt);
}
@@ -1209,7 +1217,7 @@ bswap_replace (gimple_stmt_iterator gsi, gimple *ins_stmt, tree fndecl,
if (!is_gimple_val (src))
return NULL_TREE;
if (conv_code == VIEW_CONVERT_EXPR)
- src = bswap_view_convert (&gsi, TREE_TYPE (tgt), src);
+ src = bswap_view_convert (&gsi, TREE_TYPE (tgt), src, true);
g = gimple_build_assign (tgt, conv_code, src);
}
else if (cur_stmt)
@@ -1296,14 +1304,13 @@ bswap_replace (gimple_stmt_iterator gsi, gimple *ins_stmt, tree fndecl,
/* Convert the result if necessary. */
if (!useless_type_conversion_p (TREE_TYPE (tgt), bswap_type))
{
- gimple *convert_stmt;
-
tmp = make_temp_ssa_name (bswap_type, NULL, "bswapdst");
tree atmp = tmp;
+ gimple_stmt_iterator gsi2 = gsi;
if (conv_code == VIEW_CONVERT_EXPR)
- atmp = bswap_view_convert (&gsi, TREE_TYPE (tgt), tmp);
- convert_stmt = gimple_build_assign (tgt, conv_code, atmp);
- gsi_insert_after (&gsi, convert_stmt, GSI_SAME_STMT);
+ atmp = bswap_view_convert (&gsi2, TREE_TYPE (tgt), tmp, false);
+ gimple *convert_stmt = gimple_build_assign (tgt, conv_code, atmp);
+ gsi_insert_after (&gsi2, convert_stmt, GSI_SAME_STMT);
}
gimple_set_lhs (mask_stmt ? mask_stmt : bswap_stmt, tmp);
diff --git a/gcc/testsuite/gcc.dg/pr102141.c b/gcc/testsuite/gcc.dg/pr102141.c
new file mode 100644
index 0000000..f3fc8d8
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr102141.c
@@ -0,0 +1,11 @@
+/* PR tree-optimization/102141 */
+/* { dg-do compile } */
+/* { dg-options "-O2" } */
+
+unsigned int __attribute__((__vector_size__ (4))) v;
+
+void
+foo (unsigned long long x)
+{
+ v &= (unsigned) (x >> 56 | x >> 40 & 0xff00);
+}