On Thu, Jan 9, 2025 at 5:35 AM Jeff Law <jeffreya...@gmail.com> wrote:
>
>
>
> On 1/8/25 1:53 PM, H.J. Lu wrote:
> > Skip extension on stack pointer since we can't turn
> >
> > (insn 27 26 139 2 (parallel [
> >              (set (reg/f:SI 7 sp)
> >                  (plus:SI (reg/f:SI 7 sp)
> >                      (const_int 16 [0x10])))
> >              (clobber (reg:CC 17 flags))
> >          ]) "x.ii":14:17 discrim 1 283 {*addsi_1}
> >       (expr_list:REG_ARGS_SIZE (const_int 0 [0])
> >          (nil)))
> > ...
> > (insn 43 125 74 2 (set (reg/f:DI 6 bp [145])
> >          (zero_extend:DI (reg/f:SI 7 sp))) "x.ii":15:9 175 
> > {*zero_extendsidi2}
> >       (nil))
> >
> > into
> >
> > (insn 27 26 155 2 (parallel [
> >              (set (reg:DI 6 bp)
> >                  (zero_extend:DI (plus:SI (reg/f:SI 7 sp)
> >                          (const_int 16 [0x10]))))
> >              (clobber (reg:CC 17 flags))
> >          ]) "x.ii":14:17 discrim 1 296 {addsi_1_zext}
> >       (expr_list:REG_ARGS_SIZE (const_int 0 [0])
> >          (nil)))
> > (insn 155 27 139 2 (set (reg:DI 7 sp)
> >          (reg:DI 6 bp)) "x.ii":14:17 discrim 1 -1
> >       (nil))
> >
> > without updating stack frame info.
> >
> > gcc/
> >
> >       PR rtl-optimization/118266
> >       * ree.cc (add_removable_extension): Skip extension on stack
> >       pointer.
> >
> > gcc/testsuite/
> >
> >       PR rtl-optimization/118266
> >       * gcc.target/i386/pr118266.c: New test.
> Presumably there were no other uses of sp?

There are many uses of sp, including sp update, push and pop.

> Rather than special casing sp, it seems to me we should probably do this
> for any fixed register.
>
> OK with that change.
>

This is the patch I am testing.  I will commit it after regression
test on x86-64.

Thanks.

-- 
H.J.
From 62c85645f99e07d942e67b444e11713041941d17 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.to...@gmail.com>
Date: Wed, 8 Jan 2025 20:50:04 +0800
Subject: [PATCH] ree: Skip extension on fixed register

Skip extension on fixed register since we can't turn

(insn 27 26 139 2 (parallel [
            (set (reg/f:SI 7 sp)
                (plus:SI (reg/f:SI 7 sp)
                    (const_int 16 [0x10])))
            (clobber (reg:CC 17 flags))
        ]) "x.ii":14:17 discrim 1 283 {*addsi_1}
     (expr_list:REG_ARGS_SIZE (const_int 0 [0])
        (nil)))
...
(insn 43 125 74 2 (set (reg/f:DI 6 bp [145])
        (zero_extend:DI (reg/f:SI 7 sp))) "x.ii":15:9 175 {*zero_extendsidi2}
     (nil))

into

(insn 27 26 155 2 (parallel [
            (set (reg:DI 6 bp)
                (zero_extend:DI (plus:SI (reg/f:SI 7 sp)
                        (const_int 16 [0x10]))))
            (clobber (reg:CC 17 flags))
        ]) "x.ii":14:17 discrim 1 296 {addsi_1_zext}
     (expr_list:REG_ARGS_SIZE (const_int 0 [0])
        (nil)))
(insn 155 27 139 2 (set (reg:DI 7 sp)
        (reg:DI 6 bp)) "x.ii":14:17 discrim 1 -1
     (nil))

without updating stack frame info.

gcc/

	PR rtl-optimization/118266
	* ree.cc (add_removable_extension): Skip extension on fixed
	register.

gcc/testsuite/

	PR rtl-optimization/118266
	* gcc.target/i386/pr118266.c: New test.

Signed-off-by: H.J. Lu <hjl.to...@gmail.com>
---
 gcc/ree.cc                               | 12 +++++++++++
 gcc/testsuite/gcc.target/i386/pr118266.c | 27 ++++++++++++++++++++++++
 2 files changed, 39 insertions(+)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr118266.c

diff --git a/gcc/ree.cc b/gcc/ree.cc
index a44e8e5625b..bcce9da44af 100644
--- a/gcc/ree.cc
+++ b/gcc/ree.cc
@@ -1113,6 +1113,18 @@ add_removable_extension (const_rtx expr, rtx_insn *insn,
       struct df_link *defs, *def;
       ext_cand *cand;
 
+      if (fixed_regs[REGNO (reg)])
+	{
+	  if (dump_file)
+	    {
+	      fprintf (dump_file, "Cannot eliminate extension:\n");
+	      print_rtl_single (dump_file, insn);
+	      fprintf (dump_file, " because extension on fixed register"
+				  " isn't supported.\n");
+	    }
+	  return;
+	}
+
       /* Zero-extension of an undefined value is partly defined (it's
 	 completely undefined for sign-extension, though).  So if there exists
 	 a path from the entry to this zero-extension that leaves this register
diff --git a/gcc/testsuite/gcc.target/i386/pr118266.c b/gcc/testsuite/gcc.target/i386/pr118266.c
new file mode 100644
index 00000000000..4c83cd1a561
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr118266.c
@@ -0,0 +1,27 @@
+/* { dg-do compile { target { ! ia32 } } } */
+/* { dg-require-effective-target maybe_x32 } */
+/* { dg-require-effective-target fopenacc } */
+/* { dg-options "-O2 -mx32 -fopenacc" } */
+
+typedef struct {
+  int a;
+  int b;
+  int c;
+} mystruct;
+int main_j;
+int
+main()
+{
+  mystruct *m = (mystruct *)__builtin_malloc (2*sizeof (mystruct)), *mref = m;
+#pragma acc enter data copyin(m[1])
+  for (int i; i < 9; i++) {
+#pragma acc parallel
+    for (; main_j;)
+      ;
+#pragma acc parallel loop copy(mref->b, m->c)
+    for (main_j = 0; main_j < 4; main_j++)
+      ;
+  }
+#pragma acc data copyout(m[ : 1])
+  __builtin_free(m);
+}
-- 
2.47.1

Reply via email to