public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [pushed][LRA] Check input insn pattern hard regs against early clobber hard regs for live info
@ 2023-08-04 13:16 Vladimir Makarov
  2023-08-09 10:47 ` SenthilKumar.Selvaraj
  0 siblings, 1 reply; 2+ messages in thread
From: Vladimir Makarov @ 2023-08-04 13:16 UTC (permalink / raw)
  To: gcc-patches, SenthilKumar.Selvaraj

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

The following patch fixes a problem found by LRA port for avr target.  
The problem description is in the commit message.

The patch was successfully bootstrapped and tested on x86-64 and aarch64.

[-- Attachment #2: lra-cpymem.patch --]
[-- Type: text/x-patch, Size: 2576 bytes --]

commit abf953042ace471720c1dc284b5f38e546fc0595
Author: Vladimir N. Makarov <vmakarov@redhat.com>
Date:   Fri Aug 4 08:04:44 2023 -0400

    LRA: Check input insn pattern hard regs against early clobber hard regs for live info
    
    For the test case LRA generates wrong code for AVR cpymem_qi insn:
    
            (insn 16 15 17 3 (parallel [
                (set (mem:BLK (reg:HI 26 r26) [0  A8])
                    (mem:BLK (reg:HI 30 r30) [0  A8]))
                (unspec [
                        (const_int 0 [0])
                    ] UNSPEC_CPYMEM)
                (use (reg:QI 52))
                (clobber (reg:HI 26 r26))
                (clobber (reg:HI 30 r30))
                (clobber (reg:QI 0 r0))
                (clobber (reg:QI 52))
            ]) "t.c":16:22 132 {cpymem_qi}
    
    The insn gets the same value in r26 and r30.  The culprit is clobbering
    r30 and using r30 as input.  For such situation LRA wrongly assumes that
    r30 does not live before the insn.  The patch is fixing it.
    
    gcc/ChangeLog:
    
            * lra-lives.cc (process_bb_lives): Check input insn pattern hard regs
            against early clobber hard regs.
    
    gcc/testsuite/ChangeLog:
    
            * gcc.target/avr/lra-cpymem_qi.c: New.

diff --git a/gcc/lra-lives.cc b/gcc/lra-lives.cc
index f7a3ba8d76a..f60e564da82 100644
--- a/gcc/lra-lives.cc
+++ b/gcc/lra-lives.cc
@@ -989,7 +989,7 @@ process_bb_lives (basic_block bb, int &curr_point, bool dead_insn_p)
 	    /* We can have early clobbered non-operand hard reg and
 	       the same hard reg as an insn input.  Don't make hard
 	       reg dead before the insns.  */
-	    for (reg2 = curr_id->regs; reg2 != NULL; reg2 = reg2->next)
+	    for (reg2 = curr_static_id->hard_regs; reg2 != NULL; reg2 = reg2->next)
 	      if (reg2->type != OP_OUT && reg2->regno == reg->regno)
 		break;
 	    if (reg2 == NULL)
diff --git a/gcc/testsuite/gcc.target/avr/lra-cpymem_qi.c b/gcc/testsuite/gcc.target/avr/lra-cpymem_qi.c
new file mode 100644
index 00000000000..fdffb445b45
--- /dev/null
+++ b/gcc/testsuite/gcc.target/avr/lra-cpymem_qi.c
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-options "-mmcu=avr51 -Os" } */
+
+#include <stdbool.h>
+
+struct A
+{
+  unsigned int a;
+  unsigned char c1, c2;
+  bool b1 : 1;
+};
+
+void
+foo (const struct A *x, int y)
+{
+  int s = 0, i;
+  for (i = 0; i < y; ++i)
+    {
+      const struct A a = x[i];
+      s += a.b1 ? 1 : 0;
+    }
+  if (s != 0)
+    __builtin_abort ();
+}
+
+/* { dg-final { scan-assembler-not "movw\[^\n\r]*r26,r30" } } */

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

* Re: [pushed][LRA] Check input insn pattern hard regs against early clobber hard regs for live info
  2023-08-04 13:16 [pushed][LRA] Check input insn pattern hard regs against early clobber hard regs for live info Vladimir Makarov
@ 2023-08-09 10:47 ` SenthilKumar.Selvaraj
  0 siblings, 0 replies; 2+ messages in thread
From: SenthilKumar.Selvaraj @ 2023-08-09 10:47 UTC (permalink / raw)
  To: gcc-patches, vmakarov

On Fri, 2023-08-04 at 09:16 -0400, Vladimir Makarov wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> The following patch fixes a problem found by LRA port for avr target.
> The problem description is in the commit message.
> 
> The patch was successfully bootstrapped and tested on x86-64 and aarch64.

I can confirm it fixes the problem on avr - thank you.

Regards
Senthil

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

end of thread, other threads:[~2023-08-09 10:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-04 13:16 [pushed][LRA] Check input insn pattern hard regs against early clobber hard regs for live info Vladimir Makarov
2023-08-09 10:47 ` SenthilKumar.Selvaraj

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