public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] tree-optimization/112767 - spurious diagnostic after sccp/loop-split swap
@ 2023-11-30 12:30 Richard Biener
  0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2023-11-30 12:30 UTC (permalink / raw)
  To: gcc-patches

We are diagnosing an unreachable loop which we only manage to elide
after the copyprop pass after sccp which leaves the code open for
diagnosing by the intermittent ivcanon pass.  The following makes sure
to clean things up a bit earlier, propagating constant final values
to uses immediately.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	PR tree-optimization/112767
	* tree-scalar-evolution.cc (final_value_replacement_loop):
	Propagate constants to immediate uses immediately.

	* gcc.dg/tree-ssa/pr112767.c: New testcase.
	* gcc.dg/graphite/pr83255.c: Disable SCCP.
---
 gcc/testsuite/gcc.dg/graphite/pr83255.c  |  2 +-
 gcc/testsuite/gcc.dg/tree-ssa/pr112767.c | 18 ++++++++++++++++++
 gcc/tree-scalar-evolution.cc             | 11 ++++++++++-
 3 files changed, 29 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr112767.c

diff --git a/gcc/testsuite/gcc.dg/graphite/pr83255.c b/gcc/testsuite/gcc.dg/graphite/pr83255.c
index cb376fa61be..07532632787 100644
--- a/gcc/testsuite/gcc.dg/graphite/pr83255.c
+++ b/gcc/testsuite/gcc.dg/graphite/pr83255.c
@@ -1,5 +1,5 @@
 /* { dg-do run } */
-/* { dg-options "-O -floop-nest-optimize -fdump-tree-graphite-details" } */
+/* { dg-options "-O -floop-nest-optimize -fno-tree-scev-cprop -fdump-tree-graphite-details" } */
 
 int rx, in;
 
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr112767.c b/gcc/testsuite/gcc.dg/tree-ssa/pr112767.c
new file mode 100644
index 00000000000..3f9bc061ee1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr112767.c
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O3" } */
+
+double reg_dict[32];
+
+void foo(int);
+
+void initialize()
+{
+  int i=8;
+  for (int phi=0; phi<8; ++phi) {
+    reg_dict[i]=0; /* { dg-bogus "undefined behavior" } */
+    int sn = 0;
+    if (i < 16) sn = 20;
+    foo(sn);
+    ++i;
+  }
+}
diff --git a/gcc/tree-scalar-evolution.cc b/gcc/tree-scalar-evolution.cc
index f61277c32df..065bcd0743d 100644
--- a/gcc/tree-scalar-evolution.cc
+++ b/gcc/tree-scalar-evolution.cc
@@ -3841,11 +3841,20 @@ final_value_replacement_loop (class loop *loop)
 	  print_gimple_stmt (dump_file, phi, 0);
 	  fprintf (dump_file, " with expr: ");
 	  print_generic_expr (dump_file, def);
+	  fprintf (dump_file, "\n");
 	}
       any = true;
       def = unshare_expr (def);
       remove_phi_node (&psi, false);
 
+      /* Propagate constants immediately.  */
+      if (CONSTANT_CLASS_P (def))
+	{
+	  replace_uses_by (rslt, def);
+	  release_ssa_name (rslt);
+	  continue;
+	}
+
       /* Create the replacement statements.  */
       gimple_seq stmts;
       def = force_gimple_operand (def, &stmts, false, NULL_TREE);
@@ -3877,7 +3886,7 @@ final_value_replacement_loop (class loop *loop)
       gsi_insert_seq_before (&gsi, stmts, GSI_SAME_STMT);
       if (dump_file)
 	{
-	  fprintf (dump_file, "\n final stmt:\n  ");
+	  fprintf (dump_file, " final stmt:\n  ");
 	  print_gimple_stmt (dump_file, SSA_NAME_DEF_STMT (rslt), 0);
 	  fprintf (dump_file, "\n");
 	}
-- 
2.35.3

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-11-30 12:34 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-11-30 12:30 [PATCH] tree-optimization/112767 - spurious diagnostic after sccp/loop-split swap Richard Biener

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).