public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, rtl]: Remove invalid assert from caller-save.c
@ 2009-11-24 20:28 Uros Bizjak
  2009-11-24 21:52 ` Eric Botcazou
  0 siblings, 1 reply; 7+ messages in thread
From: Uros Bizjak @ 2009-11-24 20:28 UTC (permalink / raw)
  To: GCC Patches

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

Hello!

In function reg_save_code, we detect availability of certain move insns 
with:

   ...
   cached_reg_save_code[reg][mode] = recog_memoized (saveinsn);
   ...

and further down the code, we assert that:

   ...
   gcc_assert (cached_reg_save_code[reg][mode]);
   ...

However, value of 0 is perfectly valid return value for recog_memoized. 
I learned this the hard way, as shown from generated insn-recog.c:

static int
recog_1 (rtx x0 ATTRIBUTE_UNUSED,
     rtx insn ATTRIBUTE_UNUSED,
     int *pnum_clobbers ATTRIBUTE_UNUSED)
{
   ...
     {
       return 0;  /* *movqi */
     }
   x1 = XEXP (x0, 0);
   goto L237;
   ...
  ret0:
   return -1;
}

Attached one-liner fixes this oversight.

2009-11-24  Uros Bizjak <ubizjak@gmail.com>

     * caller-save.c (reg_save_code): Remove invalid gcc_assert.

Patch was tested on x86_64-pc-linux-gnu.

OK for 4.3, 4.4 and mainline?

Uros.

[-- Attachment #2: p.diff.txt --]
[-- Type: text/plain, Size: 416 bytes --]

Index: caller-save.c
===================================================================
--- caller-save.c	(revision 154503)
+++ caller-save.c	(working copy)
@@ -175,7 +175,6 @@ reg_save_code (int reg, enum machine_mod
       cached_reg_save_code[reg][mode] = -1;
       cached_reg_restore_code[reg][mode] = -1;
     }
-  gcc_assert (cached_reg_save_code[reg][mode]);
   return cached_reg_save_code[reg][mode];
 }
 

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

* Re: [PATCH, rtl]: Remove invalid assert from caller-save.c
  2009-11-24 20:28 [PATCH, rtl]: Remove invalid assert from caller-save.c Uros Bizjak
@ 2009-11-24 21:52 ` Eric Botcazou
  2009-11-24 23:25   ` Uros Bizjak
  2009-11-28 20:44   ` Richard Henderson
  0 siblings, 2 replies; 7+ messages in thread
From: Eric Botcazou @ 2009-11-24 21:52 UTC (permalink / raw)
  To: Uros Bizjak; +Cc: gcc-patches

> However, value of 0 is perfectly valid return value for recog_memoized.
> I learned this the hard way, as shown from generated insn-recog.c:
>
> static int
> recog_1 (rtx x0 ATTRIBUTE_UNUSED,
>      rtx insn ATTRIBUTE_UNUSED,
>      int *pnum_clobbers ATTRIBUTE_UNUSED)
> {
>    ...
>      {
>        return 0;  /* *movqi */
>      }
>    x1 = XEXP (x0, 0);
>    goto L237;
>    ...
>   ret0:
>    return -1;
> }
>
> Attached one-liner fixes this oversight.

Well, all the logic would need to be rewritten then:

static int
reg_save_code (int reg, enum machine_mode mode)
{
  bool ok;
  if (cached_reg_save_code[reg][mode])
     return cached_reg_save_code[reg][mode];

static int
reg_restore_code (int reg, enum machine_mode mode)
{
  if (cached_reg_restore_code[reg][mode])
     return cached_reg_restore_code[reg][mode];

Can't you just avoid having "movqi" associated with 0?

-- 
Eric Botcazou

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

* Re: [PATCH, rtl]: Remove invalid assert from caller-save.c
  2009-11-24 21:52 ` Eric Botcazou
@ 2009-11-24 23:25   ` Uros Bizjak
  2009-11-28 20:44   ` Richard Henderson
  1 sibling, 0 replies; 7+ messages in thread
From: Uros Bizjak @ 2009-11-24 23:25 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: gcc-patches

On 11/24/2009 10:42 PM, Eric Botcazou wrote:
>> However, value of 0 is perfectly valid return value for recog_memoized.
>> I learned this the hard way, as shown from generated insn-recog.c:
>>
>> static int
>> recog_1 (rtx x0 ATTRIBUTE_UNUSED,
>>       rtx insn ATTRIBUTE_UNUSED,
>>       int *pnum_clobbers ATTRIBUTE_UNUSED)
>> {
>>     ...
>>       {
>>         return 0;  /* *movqi */
>>       }
>>     x1 = XEXP (x0, 0);
>>     goto L237;
>>     ...
>>    ret0:
>>     return -1;
>> }
>>
>> Attached one-liner fixes this oversight.
>>      
> Well, all the logic would need to be rewritten then:
>
> static int
> reg_save_code (int reg, enum machine_mode mode)
> {
>    bool ok;
>    if (cached_reg_save_code[reg][mode])
>       return cached_reg_save_code[reg][mode];
>
> static int
> reg_restore_code (int reg, enum machine_mode mode)
> {
>    if (cached_reg_restore_code[reg][mode])
>       return cached_reg_restore_code[reg][mode];
>
> Can't you just avoid having "movqi" associated with 0?
>    

No problem for me now, but some other poor soul will surely hit this bug 
again. ;)

Uros.

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

* Re: [PATCH, rtl]: Remove invalid assert from caller-save.c
  2009-11-24 21:52 ` Eric Botcazou
  2009-11-24 23:25   ` Uros Bizjak
@ 2009-11-28 20:44   ` Richard Henderson
  2009-11-28 20:52     ` Eric Botcazou
  1 sibling, 1 reply; 7+ messages in thread
From: Richard Henderson @ 2009-11-28 20:44 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: Uros Bizjak, gcc-patches

On 11/24/2009 01:42 PM, Eric Botcazou wrote:
> Well, all the logic would need to be rewritten then:
>
> static int
> reg_save_code (int reg, enum machine_mode mode)
> {
>    bool ok;
>    if (cached_reg_save_code[reg][mode])
>       return cached_reg_save_code[reg][mode];
>
> static int
> reg_restore_code (int reg, enum machine_mode mode)
> {
>    if (cached_reg_restore_code[reg][mode])
>       return cached_reg_restore_code[reg][mode];
>
> Can't you just avoid having "movqi" associated with 0?

Can't we simply arrange for cached_reg_restore_code to
be initialized to -1?


r~

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

* Re: [PATCH, rtl]: Remove invalid assert from caller-save.c
  2009-11-28 20:44   ` Richard Henderson
@ 2009-11-28 20:52     ` Eric Botcazou
  2009-11-28 22:19       ` Richard Henderson
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Botcazou @ 2009-11-28 20:52 UTC (permalink / raw)
  To: Richard Henderson; +Cc: gcc-patches, Uros Bizjak

> Can't we simply arrange for cached_reg_restore_code to
> be initialized to -1?

Not really, -1 already means something else.  No doubt this can be fixed, but 
it's no one-liner so can certainly wait for 4.6.

-- 
Eric Botcazou

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

* Re: [PATCH, rtl]: Remove invalid assert from caller-save.c
  2009-11-28 20:52     ` Eric Botcazou
@ 2009-11-28 22:19       ` Richard Henderson
  2009-11-28 22:37         ` Uros Bizjak
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Henderson @ 2009-11-28 22:19 UTC (permalink / raw)
  To: Eric Botcazou; +Cc: gcc-patches, Uros Bizjak

On 11/28/2009 12:45 PM, Eric Botcazou wrote:
>> Can't we simply arrange for cached_reg_restore_code to
>> be initialized to -1?
>
> Not really, -1 already means something else.  No doubt this can be fixed, but
> it's no one-liner so can certainly wait for 4.6.

Ah.  In which case for 4.5 it might be best to just
rearrange a pattern in i386.md to the top.  Perhaps
something like "blockage" or "nop" would be best.


r~

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

* Re: [PATCH, rtl]: Remove invalid assert from caller-save.c
  2009-11-28 22:19       ` Richard Henderson
@ 2009-11-28 22:37         ` Uros Bizjak
  0 siblings, 0 replies; 7+ messages in thread
From: Uros Bizjak @ 2009-11-28 22:37 UTC (permalink / raw)
  To: Richard Henderson; +Cc: Eric Botcazou, gcc-patches

On 11/28/2009 09:51 PM, Richard Henderson wrote:

>>> be initialized to -1?
>>
>> Not really, -1 already means something else.  No doubt this can be 
>> fixed, but
>> it's no one-liner so can certainly wait for 4.6.
> Can't we simply arrange for cached_reg_restore_code to
>
> Ah.  In which case for 4.5 it might be best to just
> rearrange a pattern in i386.md to the top.  Perhaps
> something like "blockage" or "nop" would be best.

The problem is not directly related to x86, it was triggered by testing 
some other stuff. I just thought that the problem is not yet widely 
known, and it might be of interest to other people.

I have "fixed" this by putting "nop" as the first insn. IMO, it is also 
somehow intuitive to have "nop" at place 0.

Uros.


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

end of thread, other threads:[~2009-11-28 22:19 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-24 20:28 [PATCH, rtl]: Remove invalid assert from caller-save.c Uros Bizjak
2009-11-24 21:52 ` Eric Botcazou
2009-11-24 23:25   ` Uros Bizjak
2009-11-28 20:44   ` Richard Henderson
2009-11-28 20:52     ` Eric Botcazou
2009-11-28 22:19       ` Richard Henderson
2009-11-28 22:37         ` Uros Bizjak

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