public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "wvangulik at xs4all dot nl" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/31644] [avr] can't find a register in class 'BASE_POINTER_REGS' while reloading 'asm'
Date: Thu, 01 Nov 2007 21:50:00 -0000	[thread overview]
Message-ID: <20071101215045.30813.qmail@sourceware.org> (raw)
In-Reply-To: <bug-31644-9601@http.gcc.gnu.org/bugzilla/>



------- Comment #5 from wvangulik at xs4all dot nl  2007-11-01 21:50 -------
It seems that this is caused by the fact that eeprom_read_word is actually a
piece of inline assembler returning it's value in the Z register, using z as
"pointer class" description.

This then somehow eliminates the compiler's ability allocate a pointer.

Here is my test file source:
compile using: -Wall, -Os -mmcu=atmega16

===========================================================
#define u16 unsigned int

//If both are defined it will not compile

#define EXTRA_VAR   //Use this to create extra variable parsing
#define USE_REG_Z   //Use this to make use of Z register

static inline u16 eeprom_read_word(u16* p)
{

#ifdef USE_REG_Z
  register u16 result asm("r30");
#else
  register u16 result asm("r24");
#endif  

  asm volatile (
  " ; Do nothing, just fake write to result"
      : "+x" (p),
         "=r" (result)
      :  );    
  return result;  

}


extern void foo(  u16 in0,
                  u16 in1, 
                  u16 in2, 
                  u16 in3, 
                  u16 in4, 
#ifdef EXTRA_VAR
                  u16 in5, 
#endif
                  u16 in6);


void bar(void) 
{
  u16 in0 = eeprom_read_word((u16*)0);
  u16 in1 = eeprom_read_word((u16*)1);
  u16 in2 = eeprom_read_word((u16*)2);
  u16 in3 = eeprom_read_word((u16*)3);
  u16 in4 = eeprom_read_word((u16*)4);
  u16 in5 = eeprom_read_word((u16*)5);
  u16 in6 = eeprom_read_word((u16*)6);

  foo(  in0,
        in1,
        in2,
        in3,
        in4,
#ifdef EXTRA_VAR
        in5, 
#endif
        in6 );

  foo(  in0,
        in1,
        in2,
        in3,
        in4,
#ifdef EXTRA_VAR
        in5, 
#endif
        in6  );  

}

When compiling you can see that adding an extra variable gives the problem. But
then changing the return variable to r24 solves the problem.

Hmm while typing I found another fishy thing:
Compiling for r24 with and without extra_var gives pushes of all registers.
However r12 is not used when compiled for non extra var. But using extra stack
instead

And trying -mcall-prologues does not invoke the prologue call when using extra
var and r24... it does for the other 2 ok compiling combinations.

I hope someone can make something out of this.

Oh and the r30 instead of z gives the following (more descriptive) error:

(insn 14 12 16 0 (set (reg/v:HI 54 [ in0 ])
        (reg/v:HI 30 r30 [ result ])) 12 {*movhi} (insn_list:REG_DEP_TRUE 12
(ni
l))
    (expr_list:REG_DEAD (reg/v:HI 30 r30 [ result ])
        (nil)))
test.c:67: confused by earlier errors, bailing out

This involves movhi* which is in other bugreports as well, maybe this is the
vital clue?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31644


  parent reply	other threads:[~2007-11-01 21:50 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-21  7:25 [Bug c/31644] New: Code snippet that fails to compile with optimization enabled dhylands at gmail dot com
2007-04-21  8:55 ` [Bug target/31644] " j at uriah dot heep dot sax dot de
2007-05-03 15:57 ` [Bug target/31644] [avr] can't find a register in class 'BASE_POINTER_REGS' while reloading 'asm' eweddington at cso dot atmel dot com
2007-05-30 19:34 ` eweddington at cso dot atmel dot com
2007-07-28 20:24 ` pavel dot petrovic at gmail dot com
2007-11-01 21:50 ` wvangulik at xs4all dot nl [this message]
2007-11-01 21:53 ` wvangulik at xs4all dot nl
2008-01-08 19:50 ` sascha-web-gcc dot gnu dot org at silbe dot org
2008-01-08 20:24 ` eric dot weddington at atmel dot com
2008-09-14 12:53 ` aesok at gcc dot gnu dot org
2010-01-29 17:47 ` eric dot weddington at atmel dot com

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=20071101215045.30813.qmail@sourceware.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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).