public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jim MacArthur <jim.macarthur@arm.com>
To: gcc-patches@gcc.gnu.org
Cc: rdsandiford@googlemail.com
Subject: Re: [patch] More thorough checking in reg_fits_class_p
Date: Thu, 17 May 2012 13:24:00 -0000	[thread overview]
Message-ID: <4FB4FBE3.5050207@arm.com> (raw)
In-Reply-To: <g4d36mg00j.fsf@richards-thinkpad.stglab.manchester.uk.ibm.com>

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

On 02/05/12 14:55, Richard Sandiford wrote:
> Richard Earnshaw<rearnsha@arm.com>  writes:
>> On 02/05/12 14:00, Richard Sandiford wrote:
>>> Jim MacArthur<jim.macarthur@arm.com>  writes:
>>>> New Changelog text:
>>>>
>>>> 2012-05-02 Jim MacArthur<jim.macarthur@arm.com>
>>>> * recog.c (reg_fits_class_p): Check both regno and regno + offset are
>>>> hard registers.
>>> Thanks.  I still think the final:
>>>
>>>> +	&&  HARD_REGISTER_NUM_P (end_hard_regno (regno + offset, mode))
>>> check belongs in in_hard_reg_set_p, since most callers don't (and IMO
>>> shouldn't need to) check this.  The idea behind adding these functions
>>> was to commonise various bits of code that were doing the same checks
>>> in slightly different ways.  Requiring each caller to check the end
>>> register would go against that to some extent.
>>>
>> If you're going to do that (which is fine, BTW), I think
>> in_hard_reg_set_p should gcc_assert() that regno is a valid hard reg.
> Sounds good.
>
> Richard
>

Sorry for the delay in responding to this, I had a few problems with 
end_hard_regno. Here's a new version of the patch, which adds to 
in_hard_reg_set_p the assert and a check for the hardness of end_regno.  
end_hard_regno is the exclusive upper bound of the range, so not 
actually a meaningful reg no. HARD_REGNO_NREGS is required to return a 
positive value, so (end_regno - 1) is always safe, as I understand it.

I've tested this with an x86 bootstrap which shows no errors, and with 
our own AArch64 back end.

Jim

New ChangeLog text:

2012-05-17  Jim MacArthur<jim.macarthur@arm.com>
       * recog.c (reg_fits_class_p): Check both regno and regno + offset are  
hard registers.
       * regs.h (in_hard_reg_set_p): Assert that regno is a hard register and
check end_regno - 1 is a hard register.


[-- Attachment #2: reg-fits-class-16 --]
[-- Type: text/plain, Size: 1541 bytes --]

diff --git a/gcc/recog.c b/gcc/recog.c
index c5725d2..d664594 100644
--- a/gcc/recog.c
+++ b/gcc/recog.c
@@ -2792,14 +2792,16 @@ bool
 reg_fits_class_p (const_rtx operand, reg_class_t cl, int offset,
 		  enum machine_mode mode)
 {
-  int regno = REGNO (operand);
+  unsigned int regno = REGNO (operand);
 
   if (cl == NO_REGS)
     return false;
 
+  /* Regno must not be a pseudo register.  Offset may be negative.  */
   return (HARD_REGISTER_NUM_P (regno)
-	  && in_hard_reg_set_p (reg_class_contents[(int) cl],
-				mode, regno + offset));
+	  && HARD_REGISTER_NUM_P (regno + offset)
+	  && in_hard_reg_set_p (reg_class_contents[(int) cl], mode, 
+				regno + offset));
 }
 \f
 /* Split single instruction.  Helper function for split_all_insns and
diff --git a/gcc/regs.h b/gcc/regs.h
index 328b839..d18bf0a 100644
--- a/gcc/regs.h
+++ b/gcc/regs.h
@@ -24,6 +24,7 @@ along with GCC; see the file COPYING3.  If not see
 
 #include "machmode.h"
 #include "hard-reg-set.h"
+#include "rtl.h"
 
 #define REG_BYTES(R) mode_size[(int) GET_MODE (R)]
 
@@ -367,10 +368,16 @@ in_hard_reg_set_p (const HARD_REG_SET regs, enum machine_mode mode,
 {
   unsigned int end_regno;
 
+  gcc_assert (HARD_REGISTER_NUM_P (regno));
+  
   if (!TEST_HARD_REG_BIT (regs, regno))
     return false;
 
   end_regno = end_hard_regno (mode, regno);
+
+  if (!HARD_REGISTER_NUM_P (end_regno - 1))
+    return false;
+
   while (++regno < end_regno)
     if (!TEST_HARD_REG_BIT (regs, regno))
       return false;

  reply	other threads:[~2012-05-17 13:24 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-26 13:21 Jim MacArthur
2012-04-30 13:45 ` Richard Earnshaw
2012-04-30 14:08   ` Richard Sandiford
2012-04-30 14:13     ` Richard Earnshaw
2012-04-30 14:39       ` Richard Sandiford
2012-04-30 14:57         ` Richard Earnshaw
2012-04-30 15:19           ` Richard Sandiford
2012-05-02 12:04             ` Jim MacArthur
2012-05-02 13:00               ` Richard Sandiford
2012-05-02 13:52                 ` Richard Earnshaw
2012-05-02 13:56                   ` Richard Sandiford
2012-05-17 13:24                     ` Jim MacArthur [this message]
2012-05-18  9:11                       ` Richard Sandiford
2012-05-21 14:48                       ` Richard Earnshaw
2012-05-24 11:35                         ` Marcus Shawcroft
2012-04-30 14:32     ` Richard Earnshaw
2012-04-30 15:37       ` Georg-Johann Lay
2012-04-30 15:45         ` Richard Earnshaw

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=4FB4FBE3.5050207@arm.com \
    --to=jim.macarthur@arm.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=rdsandiford@googlemail.com \
    /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).