auto-inc-dec: Don't add incs/decs to bare CLOBBERs [PR93124]
diff mbox series

Message ID mpty2tzsnc8.fsf@arm.com
State New
Headers show
Series
  • auto-inc-dec: Don't add incs/decs to bare CLOBBERs [PR93124]
Related show

Commit Message

Richard Sandiford Jan. 22, 2020, 12:11 p.m. UTC
In this PR, auto-inc-dec was trying to turn:

    (set (reg X) (plus (reg X) (const_int N)))
    (clobber (mem (reg X)))

into:

    (clobber (mem (pre_modify (reg X) ...)))

But bare clobber insns are just there to describe dataflow.  They're
not supposed to generate any code.

This is part 2 of the fix for PR93124.  The reason we have the
clobber above is that cprop replaced (reg sp) with (reg X) in:

    (clobber (mem (reg sp)))

Part 1 stops that from happening, but I still think we should
prevent auto-inc-dec from "optimising" bare USEs and CLOBBERs
as a belt-and-braces fix.

Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?

Richard


2020-01-22  Richard Sandiford  <richard.sandiford@arm.com>

gcc/
	PR rtl-optimization/93124
	* auto-inc-dec.c (merge_in_block): Don't add auto inc/decs to
	bare USE and CLOBBER insns.

gcc/testsuite/
	* gcc.dg/torture/pr93124.c: New test.
---
 gcc/auto-inc-dec.c                     | 12 +++++--
 gcc/testsuite/gcc.dg/torture/pr93124.c | 44 ++++++++++++++++++++++++++
 2 files changed, 53 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/torture/pr93124.c

Comments

Jeff Law Jan. 22, 2020, 8:10 p.m. UTC | #1
On Wed, 2020-01-22 at 12:11 +0000, Richard Sandiford wrote:
> In this PR, auto-inc-dec was trying to turn:
> 
>     (set (reg X) (plus (reg X) (const_int N)))
>     (clobber (mem (reg X)))
> 
> into:
> 
>     (clobber (mem (pre_modify (reg X) ...)))
> 
> But bare clobber insns are just there to describe dataflow.  They're
> not supposed to generate any code.
> 
> This is part 2 of the fix for PR93124.  The reason we have the
> clobber above is that cprop replaced (reg sp) with (reg X) in:
> 
>     (clobber (mem (reg sp)))
> 
> Part 1 stops that from happening, but I still think we should
> prevent auto-inc-dec from "optimising" bare USEs and CLOBBERs
> as a belt-and-braces fix.
> 
> Tested on aarch64-linux-gnu and x86_64-linux-gnu.  OK to install?
> 
> Richard
> 
> 
> 2020-01-22  Richard Sandiford  <richard.sandiford@arm.com>
> 
> gcc/
> 	PR rtl-optimization/93124
> 	* auto-inc-dec.c (merge_in_block): Don't add auto inc/decs to
> 	bare USE and CLOBBER insns.
> 
> gcc/testsuite/
> 	* gcc.dg/torture/pr93124.c: New test.
OK. 

Jeff
>

Patch
diff mbox series

diff --git a/gcc/auto-inc-dec.c b/gcc/auto-inc-dec.c
index 268231ecaff..7d0d91403f3 100644
--- a/gcc/auto-inc-dec.c
+++ b/gcc/auto-inc-dec.c
@@ -1602,9 +1602,15 @@  merge_in_block (int max_reg, basic_block bb)
       else
 	{
 	  insn_is_add_or_inc = false;
-	  mem_insn.insn = insn;
-	  if (find_mem (&PATTERN (insn)))
-	    success_in_block++;
+	  /* We can't use auto inc/dec for bare USEs and CLOBBERs,
+	     since they aren't supposed to generate any code.  */
+	  rtx_code code = GET_CODE (PATTERN (insn));
+	  if (code != USE && code != CLOBBER)
+	    {
+	      mem_insn.insn = insn;
+	      if (find_mem (&PATTERN (insn)))
+		success_in_block++;
+	    }
 	}
 
       /* If the inc insn was merged with a mem, the inc insn is gone
diff --git a/gcc/testsuite/gcc.dg/torture/pr93124.c b/gcc/testsuite/gcc.dg/torture/pr93124.c
new file mode 100644
index 00000000000..16bc8b54f14
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/torture/pr93124.c
@@ -0,0 +1,44 @@ 
+/* { dg-additional-options "-fno-rerun-cse-after-loop -fno-guess-branch-probability -fno-tree-fre" } */
+
+int x;
+
+void fn2 ();
+void fn3 ();
+void fn4 ();
+void fn5 ();
+void fn6 ();
+
+void
+fn1 (void)
+{
+  int n;
+  for (n = 0;; ++n) {
+    {
+      struct { char a[n]; } s;
+      fn2 (s);
+    }
+    struct { unsigned a[x]; } s;
+    int i, b;
+    for (i = 0; i < n; ++i)
+      ;
+    fn2 (s);
+    {
+      struct { char a[n]; } s;
+      int i;
+      for (i = 0; i < n; ++i)
+        s.a[i] = i;
+      fn3 (s, s);
+    }
+    fn4 ();
+    {
+      struct { unsigned a[n]; } s;
+      fn5 (s);
+    }
+    {
+      struct { char a[b]; } s;
+      for (; i < n;)
+        s.a[i] = i;
+      fn6 (s);
+    }
+  }
+}