public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/redhat/heads/gcc-9-branch)] tree-dse: Fix mem* head trimming if call has lhs [PR94130]
@ 2020-03-17 19:24 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2020-03-17 19:24 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:a545ffafa380fa958393e1dfbf7f5f8f129bc5cf
commit a545ffafa380fa958393e1dfbf7f5f8f129bc5cf
Author: Jakub Jelinek <jakub@redhat.com>
Date: Thu Mar 12 09:34:00 2020 +0100
tree-dse: Fix mem* head trimming if call has lhs [PR94130]
As the testcase shows, if DSE decides to head trim {mem{set,cpy,move},strncpy}
and the call has lhs, it is incorrect to leave the lhs as is, because it
will then point to the adjusted address (base + head_trim) instead of the
original base.
The following patch fixes that by dropping the lhs of the call and assigning
lhs the original base in a following statement.
2020-03-12 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/94130
* tree-ssa-dse.c: Include gimplify.h.
(increment_start_addr): If stmt has lhs, drop the lhs from call and
set it after the call to the original value of the first argument.
Formatting fixes.
(decrement_count): Formatting fix.
* gcc.c-torture/execute/pr94130.c: New test.
Diff:
---
gcc/ChangeLog | 9 +++++++++
gcc/testsuite/ChangeLog | 5 +++++
gcc/testsuite/gcc.c-torture/execute/pr94130.c | 16 ++++++++++++++++
gcc/tree-ssa-dse.c | 22 ++++++++++++++++------
4 files changed, 46 insertions(+), 6 deletions(-)
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 57f959604f6..ec8d51f388c 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,6 +1,15 @@
2020-03-17 Jakub Jelinek <jakub@redhat.com>
Backported from mainline
+ 2020-03-12 Jakub Jelinek <jakub@redhat.com>
+
+ PR tree-optimization/94130
+ * tree-ssa-dse.c: Include gimplify.h.
+ (increment_start_addr): If stmt has lhs, drop the lhs from call and
+ set it after the call to the original value of the first argument.
+ Formatting fixes.
+ (decrement_count): Formatting fix.
+
2020-03-11 Jakub Jelinek <jakub@redhat.com>
PR target/94134
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index b2ae72c3c0c..10026d55a58 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,6 +1,11 @@
2020-03-17 Jakub Jelinek <jakub@redhat.com>
Backported from mainline
+ 2020-03-12 Jakub Jelinek <jakub@redhat.com>
+
+ PR tree-optimization/94130
+ * gcc.c-torture/execute/pr94130.c: New test.
+
2020-03-11 Jakub Jelinek <jakub@redhat.com>
PR target/94134
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr94130.c b/gcc/testsuite/gcc.c-torture/execute/pr94130.c
new file mode 100644
index 00000000000..044e578d373
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr94130.c
@@ -0,0 +1,16 @@
+/* PR tree-optimization/94130 */
+
+int
+main ()
+{
+ int a[8];
+ char *b = __builtin_memset (a, 0, sizeof (a));
+ a[0] = 1;
+ a[1] = 2;
+ a[2] = 3;
+ if (b != (char *) a)
+ __builtin_abort ();
+ else
+ asm volatile ("" : : "g" (a) : "memory");
+ return 0;
+}
diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c
index efe5b31cc0a..26376ecf8de 100644
--- a/gcc/tree-ssa-dse.c
+++ b/gcc/tree-ssa-dse.c
@@ -36,6 +36,7 @@ along with GCC; see the file COPYING3. If not see
#include "params.h"
#include "alias.h"
#include "tree-ssa-loop.h"
+#include "gimplify.h"
/* This file implements dead store elimination.
@@ -394,29 +395,38 @@ decrement_count (gimple *stmt, int decrement)
gcc_assert (TREE_CODE (*countp) == INTEGER_CST);
*countp = wide_int_to_tree (TREE_TYPE (*countp), (TREE_INT_CST_LOW (*countp)
- decrement));
-
}
static void
increment_start_addr (gimple *stmt, tree *where, int increment)
{
+ if (tree lhs = gimple_call_lhs (stmt))
+ if (where == gimple_call_arg_ptr (stmt, 0))
+ {
+ gassign *newop = gimple_build_assign (lhs, unshare_expr (*where));
+ gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
+ gsi_insert_after (&gsi, newop, GSI_SAME_STMT);
+ gimple_call_set_lhs (stmt, NULL_TREE);
+ update_stmt (stmt);
+ }
+
if (TREE_CODE (*where) == SSA_NAME)
{
tree tem = make_ssa_name (TREE_TYPE (*where));
gassign *newop
- = gimple_build_assign (tem, POINTER_PLUS_EXPR, *where,
+ = gimple_build_assign (tem, POINTER_PLUS_EXPR, *where,
build_int_cst (sizetype, increment));
gimple_stmt_iterator gsi = gsi_for_stmt (stmt);
gsi_insert_before (&gsi, newop, GSI_SAME_STMT);
*where = tem;
- update_stmt (gsi_stmt (gsi));
+ update_stmt (stmt);
return;
}
*where = build_fold_addr_expr (fold_build2 (MEM_REF, char_type_node,
- *where,
- build_int_cst (ptr_type_node,
- increment)));
+ *where,
+ build_int_cst (ptr_type_node,
+ increment)));
}
/* STMT is builtin call that writes bytes in bitmap ORIG, some bytes are dead
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-03-17 19:24 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-17 19:24 [gcc(refs/vendors/redhat/heads/gcc-9-branch)] tree-dse: Fix mem* head trimming if call has lhs [PR94130] Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).