This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PR63185][RFC] Improve DSE with branches
- From: Kugan Vivekanandarajah <kugan dot vivekanandarajah at linaro dot org>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: Richard Biener <rguenther at suse dot de>, Jeff Law <law at redhat dot com>
- Date: Mon, 14 May 2018 13:37:23 +1000
- Subject: [PR63185][RFC] Improve DSE with branches
Hi,
Attached patch handles PR63185 when we reach PHI with temp != NULLL.
We could see the PHI and if there isn't any uses for PHI that is
interesting, we could ignore that ?
Bootstrapped and regression tested on x86_64-linux-gnu.
Is this OK?
Thanks,
Kugan
gcc/ChangeLog:
2018-05-14 Kugan Vivekanandarajah <kuganv@linaro.org>
* tree-ssa-dse.c (phi_dosent_define_nor_use_p): New.
(dse_classify_store): Use phi_dosent_define_nor_use_p.
gcc/testsuite/ChangeLog:
2018-05-14 Kugan Vivekanandarajah <kuganv@linaro.org>
* gcc.dg/tree-ssa/ssa-dse-33.c: New test.
From a69caa24d9c1914b7617a937e84c3b612ffe6d9b Mon Sep 17 00:00:00 2001
From: Kugan Vivekanandarajah <kugan.vivekanandarajah@linaro.org>
Date: Wed, 9 May 2018 16:26:16 +1000
Subject: [PATCH] PR63185
Change-Id: I9d307884add10d5b5ff07aa31dd86cb83b2388ec
---
gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-33.c | 13 +++++++++++++
gcc/tree-ssa-dse.c | 30 +++++++++++++++++++++++++++++-
2 files changed, 42 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-33.c
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-33.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-33.c
new file mode 100644
index 0000000..46cb7d1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-dse-33.c
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-dse-details" } */
+
+void g();
+void f(int n)
+{
+ char *p = malloc(1024);
+ memset (p, 8, 1024);
+ if (n)
+ g();
+}
+
+/* { dg-final { scan-tree-dump-times "Deleted dead calls" 1 "dse1"} } */
diff --git a/gcc/tree-ssa-dse.c b/gcc/tree-ssa-dse.c
index 9220fea..e7a4637 100644
--- a/gcc/tree-ssa-dse.c
+++ b/gcc/tree-ssa-dse.c
@@ -515,6 +515,30 @@ live_bytes_read (ao_ref use_ref, ao_ref *ref, sbitmap live)
return true;
}
+/* Return true if there isnt any VDEF or VUSE by following PHI. */
+
+static bool
+phi_dosent_define_nor_use_p (ao_ref *ref, gphi *phi)
+{
+ gimple *phi_use;
+ imm_use_iterator ui;
+ tree def = PHI_RESULT (phi);
+ bool ok = true;
+
+ FOR_EACH_IMM_USE_STMT (phi_use, ui, def)
+ {
+ if (ref_maybe_used_by_stmt_p (phi_use, ref)
+ || gimple_vdef (phi_use)
+ || gimple_code (phi_use) == GIMPLE_PHI)
+ {
+ ok = false;
+ BREAK_FROM_IMM_USE_STMT (ui);
+ }
+ }
+
+ return ok;
+}
+
/* A helper of dse_optimize_stmt.
Given a GIMPLE_ASSIGN in STMT that writes to REF, find a candidate
statement *USE_STMT that may prove STMT to be dead.
@@ -570,6 +594,9 @@ dse_classify_store (ao_ref *ref, gimple *stmt, gimple **use_stmt,
else if (gimple_code (use_stmt) == GIMPLE_PHI)
{
if (temp
+ && phi_dosent_define_nor_use_p (ref, as_a <gphi *> (use_stmt)))
+ ;
+ else if (temp
/* Make sure we are not in a loop latch block. */
|| gimple_bb (stmt) == gimple_bb (use_stmt)
|| dominated_by_p (CDI_DOMINATORS,
@@ -585,7 +612,8 @@ dse_classify_store (ao_ref *ref, gimple *stmt, gimple **use_stmt,
/* Do not consider the PHI as use if it dominates the
stmt defining the virtual operand we are processing,
we have processed it already in this case. */
- if (gimple_bb (defvar_def) != gimple_bb (use_stmt)
+ if (!temp
+ && gimple_bb (defvar_def) != gimple_bb (use_stmt)
&& !dominated_by_p (CDI_DOMINATORS,
gimple_bb (defvar_def),
gimple_bb (use_stmt)))
--
2.7.4