public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] LRA: Make fixed eliminable registers live
@ 2020-09-15 13:23 H.J. Lu
  2020-09-15 14:44 ` Richard Sandiford
  0 siblings, 1 reply; 12+ messages in thread
From: H.J. Lu @ 2020-09-15 13:23 UTC (permalink / raw)
  To: gcc-patches

commit 1bcb4c4faa4bd6b1c917c75b100d618faf9e628c
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Wed Oct 2 07:37:10 2019 +0000

    [LRA] Don't make eliminable registers live (PR91957)

didn't make eliminable registers live which breaks

register void *cur_pro asm("reg");

where "reg" is an eliminable register.  Make fixed eliminable registers
live to fix it.

Tested on Linux/x86-64 as well as csky-linux-gnuabiv2 soft-float and
hard-float glibc builds.

gcc/

	PR middle-end/91957
	* lra-lives.c (make_hard_regno_dead): Record conflicts for fixed
	eliminable registers.
	(make_hard_regno_live): Likewise, and make them live.

gcc/testsuite/

	PR middle-end/91957
	* g++.target/i386/pr97054.C: New test.
---
 gcc/lra-lives.c                         |  5 +-
 gcc/testsuite/g++.target/i386/pr97054.C | 96 +++++++++++++++++++++++++
 2 files changed, 99 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/g++.target/i386/pr97054.C

diff --git a/gcc/lra-lives.c b/gcc/lra-lives.c
index 917c617903f..226fe6a69f0 100644
--- a/gcc/lra-lives.c
+++ b/gcc/lra-lives.c
@@ -282,7 +282,8 @@ make_hard_regno_live (int regno)
 {
   lra_assert (HARD_REGISTER_NUM_P (regno));
   if (TEST_HARD_REG_BIT (hard_regs_live, regno)
-      || TEST_HARD_REG_BIT (eliminable_regset, regno))
+      || (!fixed_regs[regno]
+	  && TEST_HARD_REG_BIT (eliminable_regset, regno)))
     return;
   SET_HARD_REG_BIT (hard_regs_live, regno);
   sparseset_set_bit (start_living, regno);
@@ -296,7 +297,7 @@ make_hard_regno_live (int regno)
 static void
 make_hard_regno_dead (int regno)
 {
-  if (TEST_HARD_REG_BIT (eliminable_regset, regno))
+  if (!fixed_regs[regno] && TEST_HARD_REG_BIT (eliminable_regset, regno))
     return;
 
   lra_assert (HARD_REGISTER_NUM_P (regno));
diff --git a/gcc/testsuite/g++.target/i386/pr97054.C b/gcc/testsuite/g++.target/i386/pr97054.C
new file mode 100644
index 00000000000..d0693af2a42
--- /dev/null
+++ b/gcc/testsuite/g++.target/i386/pr97054.C
@@ -0,0 +1,96 @@
+// { dg-do run { target { ! ia32 } } }
+// { dg-require-effective-target fstack_protector }
+// { dg-options "-O2 -fno-strict-aliasing -msse4.2 -mfpmath=sse -fPIC -fstack-protector-strong -O2" }
+
+struct p2_icode *ipc;
+register int pars asm("r13");
+register struct processor *cur_pro asm("rbp");
+register int a asm("rbx");
+register int c asm("r14");
+typedef long lina_t;
+typedef long la_t;
+typedef processor processor_t;
+typedef p2_icode p2_icode_t;
+typedef enum {
+  P2_Return_Action_Next,
+} p2_return_action_t;
+typedef struct p2_icode {
+  int ic_Parameters;
+}  icode_t;
+extern "C" icode_t *x86_log_to_icode_exec(processor_t *, la_t);
+typedef struct {
+  icode_t *ipc;
+} b;
+typedef struct {
+  char ma_thread_signal;
+  int event_counter;
+  b instrumentation;
+} d;
+
+extern "C" lina_t int2linaddr(processor_t *cpu, const p2_icode_t *ic)
+{
+  return 0;
+}
+
+typedef struct e {
+  long i64;
+  char LMA;
+} f;
+
+struct processor {
+  d common;
+  e pc_RIP;
+  f pc_EFER;
+  p2_icode_t *saved_ipc;
+};
+inline la_t code_lin_to_log(processor_t *, long) { return 0; }
+void turbo_clear(processor_t *) {}
+
+p2_return_action_t p2_ep_REBIND_IPC(void)
+{
+  processor_t *cpu = cur_pro;
+  la_t vaddr = cpu->pc_RIP.i64;
+  cur_pro->saved_ipc = (p2_icode_t *) ipc;
+  cur_pro->common.instrumentation.ipc = ipc;
+  cur_pro->pc_RIP.i64 = code_lin_to_log(cur_pro, int2linaddr(cur_pro, ipc));
+  turbo_clear(cur_pro);
+
+  cpu->saved_ipc = x86_log_to_icode_exec(cur_pro, vaddr);
+  ipc++;
+  (cur_pro->common.event_counter -= (1));
+  if (__builtin_expect((!((cur_pro->common.event_counter <= 0)
+			  | cur_pro->common.ma_thread_signal)), 1))
+    {
+      ((pars = ((ipc)->ic_Parameters)));
+      return P2_Return_Action_Next;
+    } else {
+      return (p2_return_action_t) 0;
+    }
+  return P2_Return_Action_Next;
+}
+
+struct p2_icode fake_ipc = { 0 };
+struct processor fake_proc ={{ 0 } };
+
+extern "C" icode_t *
+x86_log_to_icode_exec(processor_t *cpu, la_t la)
+{
+  return 0;
+}
+
+extern "C" void
+turbo_threshold_reached(processor_t *c, p2_icode_t *i, int s)
+{
+}
+
+int main()
+{
+  if (!__builtin_cpu_supports ("sse4.2"))
+    return 0;
+  fake_proc.pc_RIP.i64 = 0xbaadc0de;
+  fake_proc.pc_EFER.LMA = 0xf;
+  ipc = &fake_ipc;
+  cur_pro = &fake_proc;
+  p2_ep_REBIND_IPC();
+  return 0;
+}
-- 
2.26.2


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] LRA: Make fixed eliminable registers live
  2020-09-15 13:23 [PATCH] LRA: Make fixed eliminable registers live H.J. Lu
@ 2020-09-15 14:44 ` Richard Sandiford
  2020-09-15 14:56   ` H.J. Lu
  2020-09-16 13:37   ` [PATCH] IRA: Don't make a global register eliminable H.J. Lu
  0 siblings, 2 replies; 12+ messages in thread
From: Richard Sandiford @ 2020-09-15 14:44 UTC (permalink / raw)
  To: H.J. Lu; +Cc: gcc-patches, Vladimir Makarov

Thanks for looking at this.

"H.J. Lu" <hjl.tools@gmail.com> writes:
> commit 1bcb4c4faa4bd6b1c917c75b100d618faf9e628c
> Author: Richard Sandiford <richard.sandiford@arm.com>
> Date:   Wed Oct 2 07:37:10 2019 +0000
>
>     [LRA] Don't make eliminable registers live (PR91957)
>
> didn't make eliminable registers live which breaks
>
> register void *cur_pro asm("reg");
>
> where "reg" is an eliminable register.  Make fixed eliminable registers
> live to fix it.

I don't think fixedness itself is the issue here: it's usual for at
least some registers involved in eliminations to be fixed registers.

I think what makes this case different is instead that cur_pro/ebp
is a global register.  But IMO things have already gone wrong if we
think that a global register is eliminable.

So I wonder if instead we should check global_regs at the beginning of:

      for (i = 0; i < fp_reg_count; i++)
	if (!TEST_HARD_REG_BIT (crtl->asm_clobbers,
				HARD_FRAME_POINTER_REGNUM + i))
	  {
	    SET_HARD_REG_BIT (eliminable_regset,
			      HARD_FRAME_POINTER_REGNUM + i);
	    if (frame_pointer_needed)
	      SET_HARD_REG_BIT (ira_no_alloc_regs,
				HARD_FRAME_POINTER_REGNUM + i);
	  }
	else if (frame_pointer_needed)
	  error ("%s cannot be used in %<asm%> here",
		 reg_names[HARD_FRAME_POINTER_REGNUM + i]);
	else
	  df_set_regs_ever_live (HARD_FRAME_POINTER_REGNUM + i, true);

(ira_setup_eliminable_regset), and handle the global_regs[] case in
the same way as the else case, i.e. short-circuiting both of the ifs.

Thanks,
Richard

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] LRA: Make fixed eliminable registers live
  2020-09-15 14:44 ` Richard Sandiford
@ 2020-09-15 14:56   ` H.J. Lu
  2020-09-16 13:37   ` [PATCH] IRA: Don't make a global register eliminable H.J. Lu
  1 sibling, 0 replies; 12+ messages in thread
From: H.J. Lu @ 2020-09-15 14:56 UTC (permalink / raw)
  To: GCC Patches, Vladimir Makarov, Richard Sandiford

On Tue, Sep 15, 2020 at 7:44 AM Richard Sandiford
<richard.sandiford@arm.com> wrote:
>
> Thanks for looking at this.
>
> "H.J. Lu" <hjl.tools@gmail.com> writes:
> > commit 1bcb4c4faa4bd6b1c917c75b100d618faf9e628c
> > Author: Richard Sandiford <richard.sandiford@arm.com>
> > Date:   Wed Oct 2 07:37:10 2019 +0000
> >
> >     [LRA] Don't make eliminable registers live (PR91957)
> >
> > didn't make eliminable registers live which breaks
> >
> > register void *cur_pro asm("reg");
> >
> > where "reg" is an eliminable register.  Make fixed eliminable registers
> > live to fix it.
>
> I don't think fixedness itself is the issue here: it's usual for at
> least some registers involved in eliminations to be fixed registers.
>
> I think what makes this case different is instead that cur_pro/ebp
> is a global register.  But IMO things have already gone wrong if we
> think that a global register is eliminable.
>
> So I wonder if instead we should check global_regs at the beginning of:
>
>       for (i = 0; i < fp_reg_count; i++)
>         if (!TEST_HARD_REG_BIT (crtl->asm_clobbers,
>                                 HARD_FRAME_POINTER_REGNUM + i))
>           {
>             SET_HARD_REG_BIT (eliminable_regset,
>                               HARD_FRAME_POINTER_REGNUM + i);
>             if (frame_pointer_needed)
>               SET_HARD_REG_BIT (ira_no_alloc_regs,
>                                 HARD_FRAME_POINTER_REGNUM + i);
>           }
>         else if (frame_pointer_needed)
>           error ("%s cannot be used in %<asm%> here",
>                  reg_names[HARD_FRAME_POINTER_REGNUM + i]);
>         else
>           df_set_regs_ever_live (HARD_FRAME_POINTER_REGNUM + i, true);
>
> (ira_setup_eliminable_regset), and handle the global_regs[] case in
> the same way as the else case, i.e. short-circuiting both of the ifs.
>

Can you send me a patch for me to try?

Thanks.

-- 
H.J.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [PATCH] IRA: Don't make a global register eliminable
  2020-09-15 14:44 ` Richard Sandiford
  2020-09-15 14:56   ` H.J. Lu
@ 2020-09-16 13:37   ` H.J. Lu
  2020-09-16 14:46     ` Richard Sandiford
  1 sibling, 1 reply; 12+ messages in thread
From: H.J. Lu @ 2020-09-16 13:37 UTC (permalink / raw)
  To: GCC Patches, Vladimir Makarov, Richard Sandiford

[-- Attachment #1: Type: text/plain, Size: 1877 bytes --]

On Tue, Sep 15, 2020 at 7:44 AM Richard Sandiford
<richard.sandiford@arm.com> wrote:
>
> Thanks for looking at this.
>
> "H.J. Lu" <hjl.tools@gmail.com> writes:
> > commit 1bcb4c4faa4bd6b1c917c75b100d618faf9e628c
> > Author: Richard Sandiford <richard.sandiford@arm.com>
> > Date:   Wed Oct 2 07:37:10 2019 +0000
> >
> >     [LRA] Don't make eliminable registers live (PR91957)
> >
> > didn't make eliminable registers live which breaks
> >
> > register void *cur_pro asm("reg");
> >
> > where "reg" is an eliminable register.  Make fixed eliminable registers
> > live to fix it.
>
> I don't think fixedness itself is the issue here: it's usual for at
> least some registers involved in eliminations to be fixed registers.
>
> I think what makes this case different is instead that cur_pro/ebp
> is a global register.  But IMO things have already gone wrong if we
> think that a global register is eliminable.
>
> So I wonder if instead we should check global_regs at the beginning of:
>
>       for (i = 0; i < fp_reg_count; i++)
>         if (!TEST_HARD_REG_BIT (crtl->asm_clobbers,
>                                 HARD_FRAME_POINTER_REGNUM + i))
>           {
>             SET_HARD_REG_BIT (eliminable_regset,
>                               HARD_FRAME_POINTER_REGNUM + i);
>             if (frame_pointer_needed)
>               SET_HARD_REG_BIT (ira_no_alloc_regs,
>                                 HARD_FRAME_POINTER_REGNUM + i);
>           }
>         else if (frame_pointer_needed)
>           error ("%s cannot be used in %<asm%> here",
>                  reg_names[HARD_FRAME_POINTER_REGNUM + i]);
>         else
>           df_set_regs_ever_live (HARD_FRAME_POINTER_REGNUM + i, true);
>
> (ira_setup_eliminable_regset), and handle the global_regs[] case in
> the same way as the else case, i.e. short-circuiting both of the ifs.
>

Like this?

Thanks.

-- 
H.J.

[-- Attachment #2: 0001-IRA-Don-t-make-a-global-register-eliminable.patch --]
[-- Type: text/x-patch, Size: 5083 bytes --]

From d1c852691d245d90666c1b977775fc7f8db2b241 Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Tue, 15 Sep 2020 04:17:54 -0700
Subject: [PATCH] IRA: Don't make a global register eliminable

commit 1bcb4c4faa4bd6b1c917c75b100d618faf9e628c
Author: Richard Sandiford <richard.sandiford@arm.com>
Date:   Wed Oct 2 07:37:10 2019 +0000

    [LRA] Don't make eliminable registers live (PR91957)

didn't make eliminable registers live which breaks

register void *cur_pro asm("reg");

where "reg" is an eliminable register.  Update ira_setup_eliminable_regset
to avoid making global registers eliminable.

gcc/

	PR middle-end/97054
	* ira.c (ira_setup_eliminable_regset): Don't make a global
	register eliminable.

gcc/testsuite/

	PR middle-end/97054
	* g++.target/i386/pr97054.C: New test.
---
 gcc/ira.c                               | 30 ++++----
 gcc/testsuite/g++.target/i386/pr97054.C | 96 +++++++++++++++++++++++++
 2 files changed, 114 insertions(+), 12 deletions(-)
 create mode 100644 gcc/testsuite/g++.target/i386/pr97054.C

diff --git a/gcc/ira.c b/gcc/ira.c
index a759f3c2aa8..506c6e6783e 100644
--- a/gcc/ira.c
+++ b/gcc/ira.c
@@ -2309,21 +2309,27 @@ ira_setup_eliminable_regset (void)
     }
   if (!HARD_FRAME_POINTER_IS_FRAME_POINTER)
     {
+      /* NB: Don't make a global register eliminable.  */
       for (i = 0; i < fp_reg_count; i++)
-	if (!TEST_HARD_REG_BIT (crtl->asm_clobbers,
-				HARD_FRAME_POINTER_REGNUM + i))
+	if (global_regs[HARD_FRAME_POINTER_REGNUM + i])
+	  df_set_regs_ever_live (HARD_FRAME_POINTER_REGNUM + i, true);
+	else
 	  {
-	    SET_HARD_REG_BIT (eliminable_regset,
-			      HARD_FRAME_POINTER_REGNUM + i);
-	    if (frame_pointer_needed)
-	      SET_HARD_REG_BIT (ira_no_alloc_regs,
-				HARD_FRAME_POINTER_REGNUM + i);
+	    if (!TEST_HARD_REG_BIT (crtl->asm_clobbers,
+				    HARD_FRAME_POINTER_REGNUM + i))
+	      {
+		SET_HARD_REG_BIT (eliminable_regset,
+				  HARD_FRAME_POINTER_REGNUM + i);
+		if (frame_pointer_needed)
+		  SET_HARD_REG_BIT (ira_no_alloc_regs,
+				    HARD_FRAME_POINTER_REGNUM + i);
+	      }
+	    else if (frame_pointer_needed)
+	      error ("%s cannot be used in %<asm%> here",
+		     reg_names[HARD_FRAME_POINTER_REGNUM + i]);
+	    else
+	      df_set_regs_ever_live (HARD_FRAME_POINTER_REGNUM + i, true);
 	  }
-	else if (frame_pointer_needed)
-	  error ("%s cannot be used in %<asm%> here",
-		 reg_names[HARD_FRAME_POINTER_REGNUM + i]);
-	else
-	  df_set_regs_ever_live (HARD_FRAME_POINTER_REGNUM + i, true);
     }
 }
 
diff --git a/gcc/testsuite/g++.target/i386/pr97054.C b/gcc/testsuite/g++.target/i386/pr97054.C
new file mode 100644
index 00000000000..d0693af2a42
--- /dev/null
+++ b/gcc/testsuite/g++.target/i386/pr97054.C
@@ -0,0 +1,96 @@
+// { dg-do run { target { ! ia32 } } }
+// { dg-require-effective-target fstack_protector }
+// { dg-options "-O2 -fno-strict-aliasing -msse4.2 -mfpmath=sse -fPIC -fstack-protector-strong -O2" }
+
+struct p2_icode *ipc;
+register int pars asm("r13");
+register struct processor *cur_pro asm("rbp");
+register int a asm("rbx");
+register int c asm("r14");
+typedef long lina_t;
+typedef long la_t;
+typedef processor processor_t;
+typedef p2_icode p2_icode_t;
+typedef enum {
+  P2_Return_Action_Next,
+} p2_return_action_t;
+typedef struct p2_icode {
+  int ic_Parameters;
+}  icode_t;
+extern "C" icode_t *x86_log_to_icode_exec(processor_t *, la_t);
+typedef struct {
+  icode_t *ipc;
+} b;
+typedef struct {
+  char ma_thread_signal;
+  int event_counter;
+  b instrumentation;
+} d;
+
+extern "C" lina_t int2linaddr(processor_t *cpu, const p2_icode_t *ic)
+{
+  return 0;
+}
+
+typedef struct e {
+  long i64;
+  char LMA;
+} f;
+
+struct processor {
+  d common;
+  e pc_RIP;
+  f pc_EFER;
+  p2_icode_t *saved_ipc;
+};
+inline la_t code_lin_to_log(processor_t *, long) { return 0; }
+void turbo_clear(processor_t *) {}
+
+p2_return_action_t p2_ep_REBIND_IPC(void)
+{
+  processor_t *cpu = cur_pro;
+  la_t vaddr = cpu->pc_RIP.i64;
+  cur_pro->saved_ipc = (p2_icode_t *) ipc;
+  cur_pro->common.instrumentation.ipc = ipc;
+  cur_pro->pc_RIP.i64 = code_lin_to_log(cur_pro, int2linaddr(cur_pro, ipc));
+  turbo_clear(cur_pro);
+
+  cpu->saved_ipc = x86_log_to_icode_exec(cur_pro, vaddr);
+  ipc++;
+  (cur_pro->common.event_counter -= (1));
+  if (__builtin_expect((!((cur_pro->common.event_counter <= 0)
+			  | cur_pro->common.ma_thread_signal)), 1))
+    {
+      ((pars = ((ipc)->ic_Parameters)));
+      return P2_Return_Action_Next;
+    } else {
+      return (p2_return_action_t) 0;
+    }
+  return P2_Return_Action_Next;
+}
+
+struct p2_icode fake_ipc = { 0 };
+struct processor fake_proc ={{ 0 } };
+
+extern "C" icode_t *
+x86_log_to_icode_exec(processor_t *cpu, la_t la)
+{
+  return 0;
+}
+
+extern "C" void
+turbo_threshold_reached(processor_t *c, p2_icode_t *i, int s)
+{
+}
+
+int main()
+{
+  if (!__builtin_cpu_supports ("sse4.2"))
+    return 0;
+  fake_proc.pc_RIP.i64 = 0xbaadc0de;
+  fake_proc.pc_EFER.LMA = 0xf;
+  ipc = &fake_ipc;
+  cur_pro = &fake_proc;
+  p2_ep_REBIND_IPC();
+  return 0;
+}
-- 
2.26.2


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] IRA: Don't make a global register eliminable
  2020-09-16 13:37   ` [PATCH] IRA: Don't make a global register eliminable H.J. Lu
@ 2020-09-16 14:46     ` Richard Sandiford
  2020-09-16 15:11       ` H.J. Lu
  2020-09-17 22:52       ` Jeff Law
  0 siblings, 2 replies; 12+ messages in thread
From: Richard Sandiford @ 2020-09-16 14:46 UTC (permalink / raw)
  To: H.J. Lu; +Cc: GCC Patches, Vladimir Makarov

[-- Attachment #1: Type: text/plain, Size: 2078 bytes --]

"H.J. Lu" <hjl.tools@gmail.com> writes:
> On Tue, Sep 15, 2020 at 7:44 AM Richard Sandiford
> <richard.sandiford@arm.com> wrote:
>>
>> Thanks for looking at this.
>>
>> "H.J. Lu" <hjl.tools@gmail.com> writes:
>> > commit 1bcb4c4faa4bd6b1c917c75b100d618faf9e628c
>> > Author: Richard Sandiford <richard.sandiford@arm.com>
>> > Date:   Wed Oct 2 07:37:10 2019 +0000
>> >
>> >     [LRA] Don't make eliminable registers live (PR91957)
>> >
>> > didn't make eliminable registers live which breaks
>> >
>> > register void *cur_pro asm("reg");
>> >
>> > where "reg" is an eliminable register.  Make fixed eliminable registers
>> > live to fix it.
>>
>> I don't think fixedness itself is the issue here: it's usual for at
>> least some registers involved in eliminations to be fixed registers.
>>
>> I think what makes this case different is instead that cur_pro/ebp
>> is a global register.  But IMO things have already gone wrong if we
>> think that a global register is eliminable.
>>
>> So I wonder if instead we should check global_regs at the beginning of:
>>
>>       for (i = 0; i < fp_reg_count; i++)
>>         if (!TEST_HARD_REG_BIT (crtl->asm_clobbers,
>>                                 HARD_FRAME_POINTER_REGNUM + i))
>>           {
>>             SET_HARD_REG_BIT (eliminable_regset,
>>                               HARD_FRAME_POINTER_REGNUM + i);
>>             if (frame_pointer_needed)
>>               SET_HARD_REG_BIT (ira_no_alloc_regs,
>>                                 HARD_FRAME_POINTER_REGNUM + i);
>>           }
>>         else if (frame_pointer_needed)
>>           error ("%s cannot be used in %<asm%> here",
>>                  reg_names[HARD_FRAME_POINTER_REGNUM + i]);
>>         else
>>           df_set_regs_ever_live (HARD_FRAME_POINTER_REGNUM + i, true);
>>
>> (ira_setup_eliminable_regset), and handle the global_regs[] case in
>> the same way as the else case, i.e. short-circuiting both of the ifs.
>>
>
> Like this?

Sorry for the delay.  I was testing this in parallel.

Bootstrapped & regression-tested on x86_64-linux-gnu.

Thanks,
Richard


[-- Attachment #2: 0001-ira-Fix-elimination-for-global-hard-FPs-PR91957.patch --]
[-- Type: text/plain, Size: 5372 bytes --]

From af4499845d26fe65573b21197a79fd22fd38694e Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Tue, 15 Sep 2020 06:23:26 -0700
Subject: [PATCH] ira: Fix elimination for global hard FPs [PR91957]
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

If the hard frame pointer is being used as a global register,
we should skip the usual handling for eliminations.  As the
comment says, the register cannot in that case be eliminated
(or eliminated to) and is already marked live where appropriate.

Doing this removes the duplicate error for gcc.target/i386/pr82673.c.
The “cannot be used in 'asm' here” message is meant to be for asm
statements rather than register asms, and the function that the
error is reported against doesn't use asm.

gcc/
2020-09-16  Richard Sandiford  <richard.sandiford@arm.com>

	PR middle-end/91957
	* ira.c (ira_setup_eliminable_regset): Skip the special elimination
	handling of the hard frame pointer if the hard frame pointer is fixed.

gcc/testsuite/
2020-09-16  H.J. Lu  <hjl.tools@gmail.com>
	    Richard Sandiford  <richard.sandiford@arm.com>

	PR middle-end/91957
	* g++.target/i386/pr97054.C: New test.
	* gcc.target/i386/pr82673.c: Remove redundant extra message.
---
 gcc/ira.c                               |  8 ++-
 gcc/testsuite/g++.target/i386/pr97054.C | 96 +++++++++++++++++++++++++
 gcc/testsuite/gcc.target/i386/pr82673.c |  2 +-
 3 files changed, 103 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.target/i386/pr97054.C

diff --git a/gcc/ira.c b/gcc/ira.c
index a759f3c2aa8..27d1b3c857d 100644
--- a/gcc/ira.c
+++ b/gcc/ira.c
@@ -2310,8 +2310,12 @@ ira_setup_eliminable_regset (void)
   if (!HARD_FRAME_POINTER_IS_FRAME_POINTER)
     {
       for (i = 0; i < fp_reg_count; i++)
-	if (!TEST_HARD_REG_BIT (crtl->asm_clobbers,
-				HARD_FRAME_POINTER_REGNUM + i))
+	if (global_regs[HARD_FRAME_POINTER_REGNUM + i])
+	  /* Nothing to do: the register is already treated as live
+	     where appropriate, and cannot be eliminated.  */
+	  ;
+	else if (!TEST_HARD_REG_BIT (crtl->asm_clobbers,
+				     HARD_FRAME_POINTER_REGNUM + i))
 	  {
 	    SET_HARD_REG_BIT (eliminable_regset,
 			      HARD_FRAME_POINTER_REGNUM + i);
diff --git a/gcc/testsuite/g++.target/i386/pr97054.C b/gcc/testsuite/g++.target/i386/pr97054.C
new file mode 100644
index 00000000000..d0693af2a42
--- /dev/null
+++ b/gcc/testsuite/g++.target/i386/pr97054.C
@@ -0,0 +1,96 @@
+// { dg-do run { target { ! ia32 } } }
+// { dg-require-effective-target fstack_protector }
+// { dg-options "-O2 -fno-strict-aliasing -msse4.2 -mfpmath=sse -fPIC -fstack-protector-strong -O2" }
+
+struct p2_icode *ipc;
+register int pars asm("r13");
+register struct processor *cur_pro asm("rbp");
+register int a asm("rbx");
+register int c asm("r14");
+typedef long lina_t;
+typedef long la_t;
+typedef processor processor_t;
+typedef p2_icode p2_icode_t;
+typedef enum {
+  P2_Return_Action_Next,
+} p2_return_action_t;
+typedef struct p2_icode {
+  int ic_Parameters;
+}  icode_t;
+extern "C" icode_t *x86_log_to_icode_exec(processor_t *, la_t);
+typedef struct {
+  icode_t *ipc;
+} b;
+typedef struct {
+  char ma_thread_signal;
+  int event_counter;
+  b instrumentation;
+} d;
+
+extern "C" lina_t int2linaddr(processor_t *cpu, const p2_icode_t *ic)
+{
+  return 0;
+}
+
+typedef struct e {
+  long i64;
+  char LMA;
+} f;
+
+struct processor {
+  d common;
+  e pc_RIP;
+  f pc_EFER;
+  p2_icode_t *saved_ipc;
+};
+inline la_t code_lin_to_log(processor_t *, long) { return 0; }
+void turbo_clear(processor_t *) {}
+
+p2_return_action_t p2_ep_REBIND_IPC(void)
+{
+  processor_t *cpu = cur_pro;
+  la_t vaddr = cpu->pc_RIP.i64;
+  cur_pro->saved_ipc = (p2_icode_t *) ipc;
+  cur_pro->common.instrumentation.ipc = ipc;
+  cur_pro->pc_RIP.i64 = code_lin_to_log(cur_pro, int2linaddr(cur_pro, ipc));
+  turbo_clear(cur_pro);
+
+  cpu->saved_ipc = x86_log_to_icode_exec(cur_pro, vaddr);
+  ipc++;
+  (cur_pro->common.event_counter -= (1));
+  if (__builtin_expect((!((cur_pro->common.event_counter <= 0)
+			  | cur_pro->common.ma_thread_signal)), 1))
+    {
+      ((pars = ((ipc)->ic_Parameters)));
+      return P2_Return_Action_Next;
+    } else {
+      return (p2_return_action_t) 0;
+    }
+  return P2_Return_Action_Next;
+}
+
+struct p2_icode fake_ipc = { 0 };
+struct processor fake_proc ={{ 0 } };
+
+extern "C" icode_t *
+x86_log_to_icode_exec(processor_t *cpu, la_t la)
+{
+  return 0;
+}
+
+extern "C" void
+turbo_threshold_reached(processor_t *c, p2_icode_t *i, int s)
+{
+}
+
+int main()
+{
+  if (!__builtin_cpu_supports ("sse4.2"))
+    return 0;
+  fake_proc.pc_RIP.i64 = 0xbaadc0de;
+  fake_proc.pc_EFER.LMA = 0xf;
+  ipc = &fake_ipc;
+  cur_pro = &fake_proc;
+  p2_ep_REBIND_IPC();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/i386/pr82673.c b/gcc/testsuite/gcc.target/i386/pr82673.c
index 161ec88e3a7..2248295a087 100644
--- a/gcc/testsuite/gcc.target/i386/pr82673.c
+++ b/gcc/testsuite/gcc.target/i386/pr82673.c
@@ -9,4 +9,4 @@ void
 bar (void) /* { dg-error "frame pointer required, but reserved" } */
 {
   B = &y;
-} /* { dg-error "bp cannot be used in 'asm' here" } */
+}
-- 
2.17.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] IRA: Don't make a global register eliminable
  2020-09-16 14:46     ` Richard Sandiford
@ 2020-09-16 15:11       ` H.J. Lu
  2020-09-17 22:52       ` Jeff Law
  1 sibling, 0 replies; 12+ messages in thread
From: H.J. Lu @ 2020-09-16 15:11 UTC (permalink / raw)
  To: H.J. Lu, GCC Patches, Vladimir Makarov, Richard Sandiford

On Wed, Sep 16, 2020 at 7:46 AM Richard Sandiford
<richard.sandiford@arm.com> wrote:
>
> "H.J. Lu" <hjl.tools@gmail.com> writes:
> > On Tue, Sep 15, 2020 at 7:44 AM Richard Sandiford
> > <richard.sandiford@arm.com> wrote:
> >>
> >> Thanks for looking at this.
> >>
> >> "H.J. Lu" <hjl.tools@gmail.com> writes:
> >> > commit 1bcb4c4faa4bd6b1c917c75b100d618faf9e628c
> >> > Author: Richard Sandiford <richard.sandiford@arm.com>
> >> > Date:   Wed Oct 2 07:37:10 2019 +0000
> >> >
> >> >     [LRA] Don't make eliminable registers live (PR91957)
> >> >
> >> > didn't make eliminable registers live which breaks
> >> >
> >> > register void *cur_pro asm("reg");
> >> >
> >> > where "reg" is an eliminable register.  Make fixed eliminable registers
> >> > live to fix it.
> >>
> >> I don't think fixedness itself is the issue here: it's usual for at
> >> least some registers involved in eliminations to be fixed registers.
> >>
> >> I think what makes this case different is instead that cur_pro/ebp
> >> is a global register.  But IMO things have already gone wrong if we
> >> think that a global register is eliminable.
> >>
> >> So I wonder if instead we should check global_regs at the beginning of:
> >>
> >>       for (i = 0; i < fp_reg_count; i++)
> >>         if (!TEST_HARD_REG_BIT (crtl->asm_clobbers,
> >>                                 HARD_FRAME_POINTER_REGNUM + i))
> >>           {
> >>             SET_HARD_REG_BIT (eliminable_regset,
> >>                               HARD_FRAME_POINTER_REGNUM + i);
> >>             if (frame_pointer_needed)
> >>               SET_HARD_REG_BIT (ira_no_alloc_regs,
> >>                                 HARD_FRAME_POINTER_REGNUM + i);
> >>           }
> >>         else if (frame_pointer_needed)
> >>           error ("%s cannot be used in %<asm%> here",
> >>                  reg_names[HARD_FRAME_POINTER_REGNUM + i]);
> >>         else
> >>           df_set_regs_ever_live (HARD_FRAME_POINTER_REGNUM + i, true);
> >>
> >> (ira_setup_eliminable_regset), and handle the global_regs[] case in
> >> the same way as the else case, i.e. short-circuiting both of the ifs.
> >>
> >
> > Like this?
>
> Sorry for the delay.  I was testing this in parallel.
>
> Bootstrapped & regression-tested on x86_64-linux-gnu.
>

Thanks.

-- 
H.J.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [PATCH] IRA: Don't make a global register eliminable
  2020-09-16 14:46     ` Richard Sandiford
  2020-09-16 15:11       ` H.J. Lu
@ 2020-09-17 22:52       ` Jeff Law
  2020-09-18 17:21         ` [GCC 10] " H.J. Lu
  1 sibling, 1 reply; 12+ messages in thread
From: Jeff Law @ 2020-09-17 22:52 UTC (permalink / raw)
  To: H.J. Lu, GCC Patches, Vladimir Makarov, richard.sandiford

[-- Attachment #1: Type: text/plain, Size: 3659 bytes --]


On 9/16/20 8:46 AM, Richard Sandiford wrote:
> "H.J. Lu" <hjl.tools@gmail.com> writes:
>> On Tue, Sep 15, 2020 at 7:44 AM Richard Sandiford
>> <richard.sandiford@arm.com> wrote:
>>> Thanks for looking at this.
>>>
>>> "H.J. Lu" <hjl.tools@gmail.com> writes:
>>>> commit 1bcb4c4faa4bd6b1c917c75b100d618faf9e628c
>>>> Author: Richard Sandiford <richard.sandiford@arm.com>
>>>> Date:   Wed Oct 2 07:37:10 2019 +0000
>>>>
>>>>     [LRA] Don't make eliminable registers live (PR91957)
>>>>
>>>> didn't make eliminable registers live which breaks
>>>>
>>>> register void *cur_pro asm("reg");
>>>>
>>>> where "reg" is an eliminable register.  Make fixed eliminable registers
>>>> live to fix it.
>>> I don't think fixedness itself is the issue here: it's usual for at
>>> least some registers involved in eliminations to be fixed registers.
>>>
>>> I think what makes this case different is instead that cur_pro/ebp
>>> is a global register.  But IMO things have already gone wrong if we
>>> think that a global register is eliminable.
>>>
>>> So I wonder if instead we should check global_regs at the beginning of:
>>>
>>>       for (i = 0; i < fp_reg_count; i++)
>>>         if (!TEST_HARD_REG_BIT (crtl->asm_clobbers,
>>>                                 HARD_FRAME_POINTER_REGNUM + i))
>>>           {
>>>             SET_HARD_REG_BIT (eliminable_regset,
>>>                               HARD_FRAME_POINTER_REGNUM + i);
>>>             if (frame_pointer_needed)
>>>               SET_HARD_REG_BIT (ira_no_alloc_regs,
>>>                                 HARD_FRAME_POINTER_REGNUM + i);
>>>           }
>>>         else if (frame_pointer_needed)
>>>           error ("%s cannot be used in %<asm%> here",
>>>                  reg_names[HARD_FRAME_POINTER_REGNUM + i]);
>>>         else
>>>           df_set_regs_ever_live (HARD_FRAME_POINTER_REGNUM + i, true);
>>>
>>> (ira_setup_eliminable_regset), and handle the global_regs[] case in
>>> the same way as the else case, i.e. short-circuiting both of the ifs.
>>>
>> Like this?
> Sorry for the delay.  I was testing this in parallel.
>
> Bootstrapped & regression-tested on x86_64-linux-gnu.
>
> Thanks,
> Richard
>
>
> 0001-ira-Fix-elimination-for-global-hard-FPs-PR91957.patch
>
> From af4499845d26fe65573b21197a79fd22fd38694e Mon Sep 17 00:00:00 2001
> From: "H.J. Lu" <hjl.tools@gmail.com>
> Date: Tue, 15 Sep 2020 06:23:26 -0700
> Subject: [PATCH] ira: Fix elimination for global hard FPs [PR91957]
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
>
> If the hard frame pointer is being used as a global register,
> we should skip the usual handling for eliminations.  As the
> comment says, the register cannot in that case be eliminated
> (or eliminated to) and is already marked live where appropriate.
>
> Doing this removes the duplicate error for gcc.target/i386/pr82673.c.
> The “cannot be used in 'asm' here” message is meant to be for asm
> statements rather than register asms, and the function that the
> error is reported against doesn't use asm.
>
> gcc/
> 2020-09-16  Richard Sandiford  <richard.sandiford@arm.com>
>
> 	PR middle-end/91957
> 	* ira.c (ira_setup_eliminable_regset): Skip the special elimination
> 	handling of the hard frame pointer if the hard frame pointer is fixed.
>
> gcc/testsuite/
> 2020-09-16  H.J. Lu  <hjl.tools@gmail.com>
> 	    Richard Sandiford  <richard.sandiford@arm.com>
>
> 	PR middle-end/91957
> 	* g++.target/i386/pr97054.C: New test.
> 	* gcc.target/i386/pr82673.c: Remove redundant extra message.

OK

jeff



[-- Attachment #2: pEpkey.asc --]
[-- Type: application/pgp-keys, Size: 1763 bytes --]

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [GCC 10] [PATCH] IRA: Don't make a global register eliminable
  2020-09-17 22:52       ` Jeff Law
@ 2020-09-18 17:21         ` H.J. Lu
  2020-09-22 17:48           ` PING " H.J. Lu
  0 siblings, 1 reply; 12+ messages in thread
From: H.J. Lu @ 2020-09-18 17:21 UTC (permalink / raw)
  To: Jeff Law, Jakub Jelinek, Richard Biener
  Cc: GCC Patches, Vladimir Makarov, Richard Sandiford

[-- Attachment #1: Type: text/plain, Size: 3680 bytes --]

On Thu, Sep 17, 2020 at 3:52 PM Jeff Law <law@redhat.com> wrote:
>
>
> On 9/16/20 8:46 AM, Richard Sandiford wrote:
>
> "H.J. Lu" <hjl.tools@gmail.com> writes:
>
> On Tue, Sep 15, 2020 at 7:44 AM Richard Sandiford
> <richard.sandiford@arm.com> wrote:
>
> Thanks for looking at this.
>
> "H.J. Lu" <hjl.tools@gmail.com> writes:
>
> commit 1bcb4c4faa4bd6b1c917c75b100d618faf9e628c
> Author: Richard Sandiford <richard.sandiford@arm.com>
> Date:   Wed Oct 2 07:37:10 2019 +0000
>
>     [LRA] Don't make eliminable registers live (PR91957)
>
> didn't make eliminable registers live which breaks
>
> register void *cur_pro asm("reg");
>
> where "reg" is an eliminable register.  Make fixed eliminable registers
> live to fix it.
>
> I don't think fixedness itself is the issue here: it's usual for at
> least some registers involved in eliminations to be fixed registers.
>
> I think what makes this case different is instead that cur_pro/ebp
> is a global register.  But IMO things have already gone wrong if we
> think that a global register is eliminable.
>
> So I wonder if instead we should check global_regs at the beginning of:
>
>       for (i = 0; i < fp_reg_count; i++)
>         if (!TEST_HARD_REG_BIT (crtl->asm_clobbers,
>                                 HARD_FRAME_POINTER_REGNUM + i))
>           {
>             SET_HARD_REG_BIT (eliminable_regset,
>                               HARD_FRAME_POINTER_REGNUM + i);
>             if (frame_pointer_needed)
>               SET_HARD_REG_BIT (ira_no_alloc_regs,
>                                 HARD_FRAME_POINTER_REGNUM + i);
>           }
>         else if (frame_pointer_needed)
>           error ("%s cannot be used in %<asm%> here",
>                  reg_names[HARD_FRAME_POINTER_REGNUM + i]);
>         else
>           df_set_regs_ever_live (HARD_FRAME_POINTER_REGNUM + i, true);
>
> (ira_setup_eliminable_regset), and handle the global_regs[] case in
> the same way as the else case, i.e. short-circuiting both of the ifs.
>
> Like this?
>
> Sorry for the delay.  I was testing this in parallel.
>
> Bootstrapped & regression-tested on x86_64-linux-gnu.
>
> Thanks,
> Richard
>
>
> 0001-ira-Fix-elimination-for-global-hard-FPs-PR91957.patch
>
> From af4499845d26fe65573b21197a79fd22fd38694e Mon Sep 17 00:00:00 2001
> From: "H.J. Lu" <hjl.tools@gmail.com>
> Date: Tue, 15 Sep 2020 06:23:26 -0700
> Subject: [PATCH] ira: Fix elimination for global hard FPs [PR91957]
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
>
> If the hard frame pointer is being used as a global register,
> we should skip the usual handling for eliminations.  As the
> comment says, the register cannot in that case be eliminated
> (or eliminated to) and is already marked live where appropriate.
>
> Doing this removes the duplicate error for gcc.target/i386/pr82673.c.
> The “cannot be used in 'asm' here” message is meant to be for asm
> statements rather than register asms, and the function that the
> error is reported against doesn't use asm.
>
> gcc/
> 2020-09-16  Richard Sandiford  <richard.sandiford@arm.com>
>
> PR middle-end/91957
> * ira.c (ira_setup_eliminable_regset): Skip the special elimination
> handling of the hard frame pointer if the hard frame pointer is fixed.
>
> gcc/testsuite/
> 2020-09-16  H.J. Lu  <hjl.tools@gmail.com>
>    Richard Sandiford  <richard.sandiford@arm.com>
>
> PR middle-end/91957
> * g++.target/i386/pr97054.C: New test.
> * gcc.target/i386/pr82673.c: Remove redundant extra message.
>
> OK

OK for GCC 10 branch?

Thanks.

-- 
H.J.

[-- Attachment #2: 0001-ira-Fix-elimination-for-global-hard-FPs-PR97054.patch --]
[-- Type: text/x-patch, Size: 5283 bytes --]

From 0f4a9cfe04c89c0aabe20e6c91932676704a6496 Mon Sep 17 00:00:00 2001
From: Richard Sandiford <richard.sandiford@arm.com>
Date: Fri, 18 Sep 2020 16:55:45 +0100
Subject: [PATCH] ira: Fix elimination for global hard FPs [PR97054]
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

If the hard frame pointer is being used as a global register,
we should skip the usual handling for eliminations.  As the
comment says, the register cannot in that case be eliminated
(or eliminated to) and is already marked live where appropriate.

Doing this removes the duplicate error for gcc.target/i386/pr82673.c.
The “cannot be used in 'asm' here” message is meant to be for asm
statements rather than register asms, and the function that the
error is reported against doesn't use asm.

gcc/
2020-09-18  Richard Sandiford  <richard.sandiford@arm.com>

	PR middle-end/97054
	* ira.c (ira_setup_eliminable_regset): Skip the special elimination
	handling of the hard frame pointer if the hard frame pointer is fixed.

gcc/testsuite/
2020-09-18  H.J. Lu  <hjl.tools@gmail.com>
	    Richard Sandiford  <richard.sandiford@arm.com>

	PR middle-end/97054
	* g++.target/i386/pr97054.C: New test.
	* gcc.target/i386/pr82673.c: Remove redundant extra message.

(cherry picked from commit 3c7c5f1d4a4b8328fb4c07483cdbfe4ea7762155)
---
 gcc/ira.c                               |  8 ++-
 gcc/testsuite/g++.target/i386/pr97054.C | 96 +++++++++++++++++++++++++
 gcc/testsuite/gcc.target/i386/pr82673.c |  2 +-
 3 files changed, 103 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.target/i386/pr97054.C

diff --git a/gcc/ira.c b/gcc/ira.c
index a655ae12eb2..681ec2f46f9 100644
--- a/gcc/ira.c
+++ b/gcc/ira.c
@@ -2310,8 +2310,12 @@ ira_setup_eliminable_regset (void)
   if (!HARD_FRAME_POINTER_IS_FRAME_POINTER)
     {
       for (i = 0; i < fp_reg_count; i++)
-	if (!TEST_HARD_REG_BIT (crtl->asm_clobbers,
-				HARD_FRAME_POINTER_REGNUM + i))
+	if (global_regs[HARD_FRAME_POINTER_REGNUM + i])
+	  /* Nothing to do: the register is already treated as live
+	     where appropriate, and cannot be eliminated.  */
+	  ;
+	else if (!TEST_HARD_REG_BIT (crtl->asm_clobbers,
+				     HARD_FRAME_POINTER_REGNUM + i))
 	  {
 	    SET_HARD_REG_BIT (eliminable_regset,
 			      HARD_FRAME_POINTER_REGNUM + i);
diff --git a/gcc/testsuite/g++.target/i386/pr97054.C b/gcc/testsuite/g++.target/i386/pr97054.C
new file mode 100644
index 00000000000..d0693af2a42
--- /dev/null
+++ b/gcc/testsuite/g++.target/i386/pr97054.C
@@ -0,0 +1,96 @@
+// { dg-do run { target { ! ia32 } } }
+// { dg-require-effective-target fstack_protector }
+// { dg-options "-O2 -fno-strict-aliasing -msse4.2 -mfpmath=sse -fPIC -fstack-protector-strong -O2" }
+
+struct p2_icode *ipc;
+register int pars asm("r13");
+register struct processor *cur_pro asm("rbp");
+register int a asm("rbx");
+register int c asm("r14");
+typedef long lina_t;
+typedef long la_t;
+typedef processor processor_t;
+typedef p2_icode p2_icode_t;
+typedef enum {
+  P2_Return_Action_Next,
+} p2_return_action_t;
+typedef struct p2_icode {
+  int ic_Parameters;
+}  icode_t;
+extern "C" icode_t *x86_log_to_icode_exec(processor_t *, la_t);
+typedef struct {
+  icode_t *ipc;
+} b;
+typedef struct {
+  char ma_thread_signal;
+  int event_counter;
+  b instrumentation;
+} d;
+
+extern "C" lina_t int2linaddr(processor_t *cpu, const p2_icode_t *ic)
+{
+  return 0;
+}
+
+typedef struct e {
+  long i64;
+  char LMA;
+} f;
+
+struct processor {
+  d common;
+  e pc_RIP;
+  f pc_EFER;
+  p2_icode_t *saved_ipc;
+};
+inline la_t code_lin_to_log(processor_t *, long) { return 0; }
+void turbo_clear(processor_t *) {}
+
+p2_return_action_t p2_ep_REBIND_IPC(void)
+{
+  processor_t *cpu = cur_pro;
+  la_t vaddr = cpu->pc_RIP.i64;
+  cur_pro->saved_ipc = (p2_icode_t *) ipc;
+  cur_pro->common.instrumentation.ipc = ipc;
+  cur_pro->pc_RIP.i64 = code_lin_to_log(cur_pro, int2linaddr(cur_pro, ipc));
+  turbo_clear(cur_pro);
+
+  cpu->saved_ipc = x86_log_to_icode_exec(cur_pro, vaddr);
+  ipc++;
+  (cur_pro->common.event_counter -= (1));
+  if (__builtin_expect((!((cur_pro->common.event_counter <= 0)
+			  | cur_pro->common.ma_thread_signal)), 1))
+    {
+      ((pars = ((ipc)->ic_Parameters)));
+      return P2_Return_Action_Next;
+    } else {
+      return (p2_return_action_t) 0;
+    }
+  return P2_Return_Action_Next;
+}
+
+struct p2_icode fake_ipc = { 0 };
+struct processor fake_proc ={{ 0 } };
+
+extern "C" icode_t *
+x86_log_to_icode_exec(processor_t *cpu, la_t la)
+{
+  return 0;
+}
+
+extern "C" void
+turbo_threshold_reached(processor_t *c, p2_icode_t *i, int s)
+{
+}
+
+int main()
+{
+  if (!__builtin_cpu_supports ("sse4.2"))
+    return 0;
+  fake_proc.pc_RIP.i64 = 0xbaadc0de;
+  fake_proc.pc_EFER.LMA = 0xf;
+  ipc = &fake_ipc;
+  cur_pro = &fake_proc;
+  p2_ep_REBIND_IPC();
+  return 0;
+}
diff --git a/gcc/testsuite/gcc.target/i386/pr82673.c b/gcc/testsuite/gcc.target/i386/pr82673.c
index 161ec88e3a7..2248295a087 100644
--- a/gcc/testsuite/gcc.target/i386/pr82673.c
+++ b/gcc/testsuite/gcc.target/i386/pr82673.c
@@ -9,4 +9,4 @@ void
 bar (void) /* { dg-error "frame pointer required, but reserved" } */
 {
   B = &y;
-} /* { dg-error "bp cannot be used in 'asm' here" } */
+}
-- 
2.26.2


^ permalink raw reply	[flat|nested] 12+ messages in thread

* PING [GCC 10] [PATCH] IRA: Don't make a global register eliminable
  2020-09-18 17:21         ` [GCC 10] " H.J. Lu
@ 2020-09-22 17:48           ` H.J. Lu
  2020-09-25 13:46             ` PING^2 " H.J. Lu
  0 siblings, 1 reply; 12+ messages in thread
From: H.J. Lu @ 2020-09-22 17:48 UTC (permalink / raw)
  To: Jeff Law, Jakub Jelinek, Richard Biener
  Cc: GCC Patches, Vladimir Makarov, Richard Sandiford

On Fri, Sep 18, 2020 at 10:21 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Thu, Sep 17, 2020 at 3:52 PM Jeff Law <law@redhat.com> wrote:
> >
> >
> > On 9/16/20 8:46 AM, Richard Sandiford wrote:
> >
> > "H.J. Lu" <hjl.tools@gmail.com> writes:
> >
> > On Tue, Sep 15, 2020 at 7:44 AM Richard Sandiford
> > <richard.sandiford@arm.com> wrote:
> >
> > Thanks for looking at this.
> >
> > "H.J. Lu" <hjl.tools@gmail.com> writes:
> >
> > commit 1bcb4c4faa4bd6b1c917c75b100d618faf9e628c
> > Author: Richard Sandiford <richard.sandiford@arm.com>
> > Date:   Wed Oct 2 07:37:10 2019 +0000
> >
> >     [LRA] Don't make eliminable registers live (PR91957)
> >
> > didn't make eliminable registers live which breaks
> >
> > register void *cur_pro asm("reg");
> >
> > where "reg" is an eliminable register.  Make fixed eliminable registers
> > live to fix it.
> >
> > I don't think fixedness itself is the issue here: it's usual for at
> > least some registers involved in eliminations to be fixed registers.
> >
> > I think what makes this case different is instead that cur_pro/ebp
> > is a global register.  But IMO things have already gone wrong if we
> > think that a global register is eliminable.
> >
> > So I wonder if instead we should check global_regs at the beginning of:
> >
> >       for (i = 0; i < fp_reg_count; i++)
> >         if (!TEST_HARD_REG_BIT (crtl->asm_clobbers,
> >                                 HARD_FRAME_POINTER_REGNUM + i))
> >           {
> >             SET_HARD_REG_BIT (eliminable_regset,
> >                               HARD_FRAME_POINTER_REGNUM + i);
> >             if (frame_pointer_needed)
> >               SET_HARD_REG_BIT (ira_no_alloc_regs,
> >                                 HARD_FRAME_POINTER_REGNUM + i);
> >           }
> >         else if (frame_pointer_needed)
> >           error ("%s cannot be used in %<asm%> here",
> >                  reg_names[HARD_FRAME_POINTER_REGNUM + i]);
> >         else
> >           df_set_regs_ever_live (HARD_FRAME_POINTER_REGNUM + i, true);
> >
> > (ira_setup_eliminable_regset), and handle the global_regs[] case in
> > the same way as the else case, i.e. short-circuiting both of the ifs.
> >
> > Like this?
> >
> > Sorry for the delay.  I was testing this in parallel.
> >
> > Bootstrapped & regression-tested on x86_64-linux-gnu.
> >
> > Thanks,
> > Richard
> >
> >
> > 0001-ira-Fix-elimination-for-global-hard-FPs-PR91957.patch
> >
> > From af4499845d26fe65573b21197a79fd22fd38694e Mon Sep 17 00:00:00 2001
> > From: "H.J. Lu" <hjl.tools@gmail.com>
> > Date: Tue, 15 Sep 2020 06:23:26 -0700
> > Subject: [PATCH] ira: Fix elimination for global hard FPs [PR91957]
> > MIME-Version: 1.0
> > Content-Type: text/plain; charset=UTF-8
> > Content-Transfer-Encoding: 8bit
> >
> > If the hard frame pointer is being used as a global register,
> > we should skip the usual handling for eliminations.  As the
> > comment says, the register cannot in that case be eliminated
> > (or eliminated to) and is already marked live where appropriate.
> >
> > Doing this removes the duplicate error for gcc.target/i386/pr82673.c.
> > The “cannot be used in 'asm' here” message is meant to be for asm
> > statements rather than register asms, and the function that the
> > error is reported against doesn't use asm.
> >
> > gcc/
> > 2020-09-16  Richard Sandiford  <richard.sandiford@arm.com>
> >
> > PR middle-end/91957
> > * ira.c (ira_setup_eliminable_regset): Skip the special elimination
> > handling of the hard frame pointer if the hard frame pointer is fixed.
> >
> > gcc/testsuite/
> > 2020-09-16  H.J. Lu  <hjl.tools@gmail.com>
> >    Richard Sandiford  <richard.sandiford@arm.com>
> >
> > PR middle-end/91957
> > * g++.target/i386/pr97054.C: New test.
> > * gcc.target/i386/pr82673.c: Remove redundant extra message.
> >
> > OK
>
> OK for GCC 10 branch?
>
> Thanks.

PING:

https://gcc.gnu.org/pipermail/gcc-patches/2020-September/554268.html

-- 
H.J.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* PING^2 [GCC 10] [PATCH] IRA: Don't make a global register eliminable
  2020-09-22 17:48           ` PING " H.J. Lu
@ 2020-09-25 13:46             ` H.J. Lu
  2020-09-29 12:38               ` PING^3 " H.J. Lu
  0 siblings, 1 reply; 12+ messages in thread
From: H.J. Lu @ 2020-09-25 13:46 UTC (permalink / raw)
  To: Jeff Law, Jakub Jelinek, Richard Biener
  Cc: GCC Patches, Vladimir Makarov, Richard Sandiford

On Tue, Sep 22, 2020 at 10:48 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Fri, Sep 18, 2020 at 10:21 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > On Thu, Sep 17, 2020 at 3:52 PM Jeff Law <law@redhat.com> wrote:
> > >
> > >
> > > On 9/16/20 8:46 AM, Richard Sandiford wrote:
> > >
> > > "H.J. Lu" <hjl.tools@gmail.com> writes:
> > >
> > > On Tue, Sep 15, 2020 at 7:44 AM Richard Sandiford
> > > <richard.sandiford@arm.com> wrote:
> > >
> > > Thanks for looking at this.
> > >
> > > "H.J. Lu" <hjl.tools@gmail.com> writes:
> > >
> > > commit 1bcb4c4faa4bd6b1c917c75b100d618faf9e628c
> > > Author: Richard Sandiford <richard.sandiford@arm.com>
> > > Date:   Wed Oct 2 07:37:10 2019 +0000
> > >
> > >     [LRA] Don't make eliminable registers live (PR91957)
> > >
> > > didn't make eliminable registers live which breaks
> > >
> > > register void *cur_pro asm("reg");
> > >
> > > where "reg" is an eliminable register.  Make fixed eliminable registers
> > > live to fix it.
> > >
> > > I don't think fixedness itself is the issue here: it's usual for at
> > > least some registers involved in eliminations to be fixed registers.
> > >
> > > I think what makes this case different is instead that cur_pro/ebp
> > > is a global register.  But IMO things have already gone wrong if we
> > > think that a global register is eliminable.
> > >
> > > So I wonder if instead we should check global_regs at the beginning of:
> > >
> > >       for (i = 0; i < fp_reg_count; i++)
> > >         if (!TEST_HARD_REG_BIT (crtl->asm_clobbers,
> > >                                 HARD_FRAME_POINTER_REGNUM + i))
> > >           {
> > >             SET_HARD_REG_BIT (eliminable_regset,
> > >                               HARD_FRAME_POINTER_REGNUM + i);
> > >             if (frame_pointer_needed)
> > >               SET_HARD_REG_BIT (ira_no_alloc_regs,
> > >                                 HARD_FRAME_POINTER_REGNUM + i);
> > >           }
> > >         else if (frame_pointer_needed)
> > >           error ("%s cannot be used in %<asm%> here",
> > >                  reg_names[HARD_FRAME_POINTER_REGNUM + i]);
> > >         else
> > >           df_set_regs_ever_live (HARD_FRAME_POINTER_REGNUM + i, true);
> > >
> > > (ira_setup_eliminable_regset), and handle the global_regs[] case in
> > > the same way as the else case, i.e. short-circuiting both of the ifs.
> > >
> > > Like this?
> > >
> > > Sorry for the delay.  I was testing this in parallel.
> > >
> > > Bootstrapped & regression-tested on x86_64-linux-gnu.
> > >
> > > Thanks,
> > > Richard
> > >
> > >
> > > 0001-ira-Fix-elimination-for-global-hard-FPs-PR91957.patch
> > >
> > > From af4499845d26fe65573b21197a79fd22fd38694e Mon Sep 17 00:00:00 2001
> > > From: "H.J. Lu" <hjl.tools@gmail.com>
> > > Date: Tue, 15 Sep 2020 06:23:26 -0700
> > > Subject: [PATCH] ira: Fix elimination for global hard FPs [PR91957]
> > > MIME-Version: 1.0
> > > Content-Type: text/plain; charset=UTF-8
> > > Content-Transfer-Encoding: 8bit
> > >
> > > If the hard frame pointer is being used as a global register,
> > > we should skip the usual handling for eliminations.  As the
> > > comment says, the register cannot in that case be eliminated
> > > (or eliminated to) and is already marked live where appropriate.
> > >
> > > Doing this removes the duplicate error for gcc.target/i386/pr82673.c.
> > > The “cannot be used in 'asm' here” message is meant to be for asm
> > > statements rather than register asms, and the function that the
> > > error is reported against doesn't use asm.
> > >
> > > gcc/
> > > 2020-09-16  Richard Sandiford  <richard.sandiford@arm.com>
> > >
> > > PR middle-end/91957
> > > * ira.c (ira_setup_eliminable_regset): Skip the special elimination
> > > handling of the hard frame pointer if the hard frame pointer is fixed.
> > >
> > > gcc/testsuite/
> > > 2020-09-16  H.J. Lu  <hjl.tools@gmail.com>
> > >    Richard Sandiford  <richard.sandiford@arm.com>
> > >
> > > PR middle-end/91957
> > > * g++.target/i386/pr97054.C: New test.
> > > * gcc.target/i386/pr82673.c: Remove redundant extra message.
> > >
> > > OK
> >
> > OK for GCC 10 branch?
> >
> > Thanks.
>
> PING:
>
> https://gcc.gnu.org/pipermail/gcc-patches/2020-September/554268.html
>

PING.


-- 
H.J.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* PING^3 [GCC 10] [PATCH] IRA: Don't make a global register eliminable
  2020-09-25 13:46             ` PING^2 " H.J. Lu
@ 2020-09-29 12:38               ` H.J. Lu
  2020-09-29 13:53                 ` Vladimir Makarov
  0 siblings, 1 reply; 12+ messages in thread
From: H.J. Lu @ 2020-09-29 12:38 UTC (permalink / raw)
  To: Jeff Law, Jakub Jelinek, Richard Biener
  Cc: GCC Patches, Vladimir Makarov, Richard Sandiford

On Fri, Sep 25, 2020 at 6:46 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Tue, Sep 22, 2020 at 10:48 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >
> > On Fri, Sep 18, 2020 at 10:21 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> > >
> > > On Thu, Sep 17, 2020 at 3:52 PM Jeff Law <law@redhat.com> wrote:
> > > >
> > > >
> > > > On 9/16/20 8:46 AM, Richard Sandiford wrote:
> > > >
> > > > "H.J. Lu" <hjl.tools@gmail.com> writes:
> > > >
> > > > On Tue, Sep 15, 2020 at 7:44 AM Richard Sandiford
> > > > <richard.sandiford@arm.com> wrote:
> > > >
> > > > Thanks for looking at this.
> > > >
> > > > "H.J. Lu" <hjl.tools@gmail.com> writes:
> > > >
> > > > commit 1bcb4c4faa4bd6b1c917c75b100d618faf9e628c
> > > > Author: Richard Sandiford <richard.sandiford@arm.com>
> > > > Date:   Wed Oct 2 07:37:10 2019 +0000
> > > >
> > > >     [LRA] Don't make eliminable registers live (PR91957)
> > > >
> > > > didn't make eliminable registers live which breaks
> > > >
> > > > register void *cur_pro asm("reg");
> > > >
> > > > where "reg" is an eliminable register.  Make fixed eliminable registers
> > > > live to fix it.
> > > >
> > > > I don't think fixedness itself is the issue here: it's usual for at
> > > > least some registers involved in eliminations to be fixed registers.
> > > >
> > > > I think what makes this case different is instead that cur_pro/ebp
> > > > is a global register.  But IMO things have already gone wrong if we
> > > > think that a global register is eliminable.
> > > >
> > > > So I wonder if instead we should check global_regs at the beginning of:
> > > >
> > > >       for (i = 0; i < fp_reg_count; i++)
> > > >         if (!TEST_HARD_REG_BIT (crtl->asm_clobbers,
> > > >                                 HARD_FRAME_POINTER_REGNUM + i))
> > > >           {
> > > >             SET_HARD_REG_BIT (eliminable_regset,
> > > >                               HARD_FRAME_POINTER_REGNUM + i);
> > > >             if (frame_pointer_needed)
> > > >               SET_HARD_REG_BIT (ira_no_alloc_regs,
> > > >                                 HARD_FRAME_POINTER_REGNUM + i);
> > > >           }
> > > >         else if (frame_pointer_needed)
> > > >           error ("%s cannot be used in %<asm%> here",
> > > >                  reg_names[HARD_FRAME_POINTER_REGNUM + i]);
> > > >         else
> > > >           df_set_regs_ever_live (HARD_FRAME_POINTER_REGNUM + i, true);
> > > >
> > > > (ira_setup_eliminable_regset), and handle the global_regs[] case in
> > > > the same way as the else case, i.e. short-circuiting both of the ifs.
> > > >
> > > > Like this?
> > > >
> > > > Sorry for the delay.  I was testing this in parallel.
> > > >
> > > > Bootstrapped & regression-tested on x86_64-linux-gnu.
> > > >
> > > > Thanks,
> > > > Richard
> > > >
> > > >
> > > > 0001-ira-Fix-elimination-for-global-hard-FPs-PR91957.patch
> > > >
> > > > From af4499845d26fe65573b21197a79fd22fd38694e Mon Sep 17 00:00:00 2001
> > > > From: "H.J. Lu" <hjl.tools@gmail.com>
> > > > Date: Tue, 15 Sep 2020 06:23:26 -0700
> > > > Subject: [PATCH] ira: Fix elimination for global hard FPs [PR91957]
> > > > MIME-Version: 1.0
> > > > Content-Type: text/plain; charset=UTF-8
> > > > Content-Transfer-Encoding: 8bit
> > > >
> > > > If the hard frame pointer is being used as a global register,
> > > > we should skip the usual handling for eliminations.  As the
> > > > comment says, the register cannot in that case be eliminated
> > > > (or eliminated to) and is already marked live where appropriate.
> > > >
> > > > Doing this removes the duplicate error for gcc.target/i386/pr82673.c.
> > > > The “cannot be used in 'asm' here” message is meant to be for asm
> > > > statements rather than register asms, and the function that the
> > > > error is reported against doesn't use asm.
> > > >
> > > > gcc/
> > > > 2020-09-16  Richard Sandiford  <richard.sandiford@arm.com>
> > > >
> > > > PR middle-end/91957
> > > > * ira.c (ira_setup_eliminable_regset): Skip the special elimination
> > > > handling of the hard frame pointer if the hard frame pointer is fixed.
> > > >
> > > > gcc/testsuite/
> > > > 2020-09-16  H.J. Lu  <hjl.tools@gmail.com>
> > > >    Richard Sandiford  <richard.sandiford@arm.com>
> > > >
> > > > PR middle-end/91957
> > > > * g++.target/i386/pr97054.C: New test.
> > > > * gcc.target/i386/pr82673.c: Remove redundant extra message.
> > > >
> > > > OK
> > >
> > > OK for GCC 10 branch?
> > >
> > > Thanks.
> >
> > PING:
> >
> > https://gcc.gnu.org/pipermail/gcc-patches/2020-September/554268.html
> >
>
> PING.
>

PING.

-- 
H.J.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: PING^3 [GCC 10] [PATCH] IRA: Don't make a global register eliminable
  2020-09-29 12:38               ` PING^3 " H.J. Lu
@ 2020-09-29 13:53                 ` Vladimir Makarov
  0 siblings, 0 replies; 12+ messages in thread
From: Vladimir Makarov @ 2020-09-29 13:53 UTC (permalink / raw)
  To: H.J. Lu, Jeff Law, Jakub Jelinek, Richard Biener
  Cc: GCC Patches, Richard Sandiford


On 2020-09-29 8:38 a.m., H.J. Lu wrote:
> On Fri, Sep 25, 2020 at 6:46 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>>>> OK for GCC 10 branch?
>>>>
>>>> Thanks.
>>> PING:
>>>
>>> https://gcc.gnu.org/pipermail/gcc-patches/2020-September/554268.html
>>>
>> PING.
>>
> PING.
>
Sorry, I thought Jeff Law already approved this.  In any case the patch 
is also ok for me for the trunk and gcc-10 branch.



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2020-09-29 13:54 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-15 13:23 [PATCH] LRA: Make fixed eliminable registers live H.J. Lu
2020-09-15 14:44 ` Richard Sandiford
2020-09-15 14:56   ` H.J. Lu
2020-09-16 13:37   ` [PATCH] IRA: Don't make a global register eliminable H.J. Lu
2020-09-16 14:46     ` Richard Sandiford
2020-09-16 15:11       ` H.J. Lu
2020-09-17 22:52       ` Jeff Law
2020-09-18 17:21         ` [GCC 10] " H.J. Lu
2020-09-22 17:48           ` PING " H.J. Lu
2020-09-25 13:46             ` PING^2 " H.J. Lu
2020-09-29 12:38               ` PING^3 " H.J. Lu
2020-09-29 13:53                 ` Vladimir Makarov

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