public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Georg-Johann Lay <avr@gjlay.de>
To: gcc-patches@gcc.gnu.org
Cc: Anatoly Sokolov <aesok@post.ru>,
	 Denis Chertykov <chertykov@gmail.com>,
	"Eric B. Weddington" <eric.weddington@atmel.com>
Subject: [Patch, AVR]: Fix PR46779
Date: Thu, 09 Jun 2011 17:24:00 -0000	[thread overview]
Message-ID: <4DF0FAB5.6070704@gjlay.de> (raw)

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

This is a tentative patch to fix PR46779 and hopefully also related
issues like PR45291.

In the present version of avr_hard_regno_mode_ok, QImode is forbidden
in r29/r28. If a 16-bit value or composite is allocated to r28, this
can lead to odd subregs like
  (set (subreg:QI (reg:HI r28) 0) ...)
These subregs are produced by IRA and reload treats the subreg with a
RELOAD_WRITE. As reload spills r28 to another hard reg that can access
QI, there will be no input reload. Therefore, if r29 already contains
data that data will get garbaged. See also the discussion around

http://gcc.gnu.org/ml/gcc/2011-06/msg00005.html

Tested with two regressions less compared to unpatched compiler.
Testcases that now pass are:

* gcc.target/avr/pr46779-1.c
* gcc.target/avr/pr46779-2.c

Johann

--
	PR target/46779
	* config/avr/avr.c (avr_hard_regno_mode_ok): Rewrite.
	In particular, allow 8-bit values in r28 and r29.
	(avr_hard_regno_scratch_ok): Disallow any register that might be
	part of the frame pointer.
	(avr_hard_regno_rename_ok): Same.

[-- Attachment #2: pr46779.diff --]
[-- Type: text/x-patch, Size: 3357 bytes --]

Index: config/avr/avr.c
===================================================================
--- config/avr/avr.c	(Revision 174701)
+++ config/avr/avr.c	(Arbeitskopie)
@@ -6276,26 +6276,35 @@ jump_over_one_insn_p (rtx insn, rtx dest
 int
 avr_hard_regno_mode_ok (int regno, enum machine_mode mode)
 {
-  /* Disallow QImode in stack pointer regs.  */
-  if ((regno == REG_SP || regno == (REG_SP + 1)) && mode == QImode)
+  /* Don't allocate data to non-GENERAL_REGS registers.  */
+  
+  if (regno >= 32)
     return 0;
 
-  /* The only thing that can go into registers r28:r29 is a Pmode.  */
-  if (regno == REG_Y && mode == Pmode)
+  /* Any GENERAL_REGS register can hold 8-bit values.  */
+  /* FIXME:
+     8-bit values must not be disallowed for R28 or R29.  Disallowing
+     QI et al. in these registers might lead to code like
+         (set (subreg:QI (reg:HI 28)) ...)
+     which will result in wrong code because reload does not handle
+     SUBREGs of hard regsisters like this.  This could be fixed in reload.
+     However, it appears that fixing reload is not wanted by reload people.  */
+  
+  if (GET_MODE_SIZE (mode) == 1)
     return 1;
+  
+  /* Disallow big registers that overlap the frame pointer.
+     This will hopefully reduce the number of spill failures.  */
+  
+  if (GET_MODE_SIZE (mode) > 2
+      && regno <= REG_Y
+      && regno + GET_MODE_SIZE (mode) >= REG_Y + 1)
+    {
+      return 0;
+    }
 
-  /* Otherwise disallow all regno/mode combinations that span r28:r29.  */
-  if (regno <= (REG_Y + 1) && (regno + GET_MODE_SIZE (mode)) >= (REG_Y + 1))
-    return 0;
-
-  if (mode == QImode)
-    return 1;
-
-  /* Modes larger than QImode occupy consecutive registers.  */
-  if (regno + GET_MODE_SIZE (mode) > FIRST_PSEUDO_REGISTER)
-    return 0;
-
-  /* All modes larger than QImode should start in an even register.  */
+  /* All modes larger than 8 bits should start in an even register.  */
+  
   return !(regno & 1);
 }
 
@@ -6422,13 +6431,23 @@ avr_hard_regno_scratch_ok (unsigned int
       && !df_regs_ever_live_p (regno))
     return false;
 
+  /* Don't allow hard registers that might be part of the frame pointer.
+     Some places in the compiler just test for [HARD_]FRAME_POINTER_REGNUM
+     and don't care for a frame pointer that spans more than one register.  */
+
+  if ((!reload_completed || frame_pointer_needed)
+      && (regno == REG_Y || regno == REG_Y + 1))
+    {
+      return false;
+    }
+
   return true;
 }
 
 /* Return nonzero if register OLD_REG can be renamed to register NEW_REG.  */
 
 int
-avr_hard_regno_rename_ok (unsigned int old_reg ATTRIBUTE_UNUSED,
+avr_hard_regno_rename_ok (unsigned int old_reg,
 			  unsigned int new_reg)
 {
   /* Interrupt functions can only use registers that have already been
@@ -6439,6 +6458,17 @@ avr_hard_regno_rename_ok (unsigned int o
       && !df_regs_ever_live_p (new_reg))
     return 0;
 
+  /* Don't allow hard registers that might be part of the frame pointer.
+     Some places in the compiler just test for [HARD_]FRAME_POINTER_REGNUM
+     and don't care for a frame pointer that spans more than one register.  */
+
+  if ((!reload_completed || frame_pointer_needed)
+      && (old_reg == REG_Y || old_reg == REG_Y + 1
+          || new_reg == REG_Y || new_reg == REG_Y + 1))
+    {
+      return 0;
+    }
+  
   return 1;
 }
 

             reply	other threads:[~2011-06-09 17:02 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-09 17:24 Georg-Johann Lay [this message]
2011-06-09 18:50 ` Denis Chertykov
2011-06-09 19:43   ` Georg-Johann Lay
2011-06-09 19:51     ` Denis Chertykov
2011-06-10 10:23       ` Georg-Johann Lay
2011-06-12 10:34         ` Denis Chertykov
2011-06-13 18:10           ` Georg-Johann Lay
2011-06-13 22:37             ` Denis Chertykov
2011-06-14 10:39               ` Georg-Johann Lay
2011-06-14 11:38                 ` Denis Chertykov
2011-06-14 21:38                   ` Georg-Johann Lay
2011-06-14 23:04                     ` Richard Henderson
2011-06-15 17:58                     ` Richard Henderson
2011-06-15 21:58                       ` Georg-Johann Lay
2011-06-15 22:20                         ` Richard Henderson
2011-06-16  3:46                           ` Richard Henderson
2011-06-16 11:37                             ` Denis Chertykov
2011-06-16 12:01                               ` Denis Chertykov
2011-06-16 14:07                                 ` Richard Henderson
2011-06-16 18:18                                   ` Denis Chertykov
2011-06-16 18:57                                     ` Richard Henderson
2011-06-16 19:33                                       ` Denis Chertykov
2011-06-16 19:42                                         ` Richard Henderson
2011-06-16 20:04                                           ` Denis Chertykov
2011-06-16 14:36                               ` Richard Henderson
2011-06-16 14:52                                 ` Bernd Schmidt
2011-06-16 15:13                                   ` Richard Henderson
2011-06-16 18:57                                 ` Denis Chertykov
2011-06-23 20:48                             ` Denis Chertykov
2011-06-23 22:04                               ` Richard Henderson
2011-06-26 20:03                                 ` Denis Chertykov
2011-06-26 20:51                                   ` Georg-Johann Lay
2011-06-27  8:41                                     ` Denis Chertykov
2011-06-27  9:19                                       ` Georg-Johann Lay
2011-06-27 10:17                                         ` Denis Chertykov
2011-07-07  9:59                                           ` Georg-Johann Lay
2011-07-07 18:21                                             ` Denis Chertykov
2011-07-08 10:12                                               ` Georg-Johann Lay
2011-07-08 10:25                                                 ` Denis Chertykov
2011-07-08 12:16                                                   ` Georg-Johann Lay
2011-06-22  3:28             ` Hans-Peter Nilsson
2011-06-22 17:03               ` Georg-Johann Lay
2011-06-23 12:51                 ` Hans-Peter Nilsson
2011-06-23 13:00                 ` Hans-Peter Nilsson
2011-06-09 20:03     ` Georg-Johann Lay
2011-06-10  9:27   ` Georg-Johann Lay
2011-06-21 17:17     ` Georg-Johann Lay

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4DF0FAB5.6070704@gjlay.de \
    --to=avr@gjlay.de \
    --cc=aesok@post.ru \
    --cc=chertykov@gmail.com \
    --cc=eric.weddington@atmel.com \
    --cc=gcc-patches@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).