public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Christian Iseli <chris@lslsun.epfl.ch>
To: law@cygnus.com
Cc: egcs@cygnus.com
Subject: Re: Infinite loop in init_alias_analysis
Date: Tue, 04 Nov 1997 12:32:00 -0000	[thread overview]
Message-ID: <199711042032.VAA16414@Rivendell.MiddleEarth.net> (raw)
In-Reply-To: <8225.878651459@hurl.cygnus.com>

law@hurl.cygnus.com said:
>  > Things happen in the following way: - During the first iteration 
>  > of the loop, new_reg_base_value[24] is set to  (address (reg:HI 1 %r3))
> OK.

>   >   (reg 1 is a FUNCTION_ARG_REGNO_P) while copying_arguments is 
>   > true. - Later in the function, new_reg_base_value[1] is set to (reg/v:HI 24)
> OK.

>   > - Now the first iteration terminates and the values from 
>   >   new_reg_base_value
> OK.

>   >   are copied into   reg_base_value. - In the next loop iteration, 
>   > find_base_value is called and promptly returns the values it finds in 
>   > reg_base_value, which yields to new_reg_base_value[24] => (reg/v:HI 
>   > 24> )  and   new_reg_base_value[1] => (address (reg:HI 1 %r3)) - And 
>   > so on...
> Sorry, this is where you lost me.  Can you describe this better? 

I'll try :-)

We seem to agree on the state of things after the first iteration through the 
loop;
we have:
  reg_base_value[1]  == (reg/v:HI 24)
  ...
  reg_base_value[24] == (address (reg:HI 1 %r3))
which were copied from new_reg_base_value.

Now we start a new iteration.  find_base_value is called (line 269 of alias.c) 
with
(reg:HI 1 %r3) and, since reg_base_value[1]  contains (reg/v:HI 24), returns 
(reg/v:HI 24).
Thus new_reg_base_value[24] is set to (reg/v:HI 24).
Later, find_base_value is called with (reg/v:HI 24) and, since 
reg_base_value[24]  contains
(address (reg:HI 1 %r3)), returns (address (reg:HI 1 %r3)).
Thus new_reg_base_value[1] is set to (address (reg:HI 1 %r3)).
At the end of the while loop, things are copied from new_reg_base_value to 
reg_base_value
and so, at the end of the second iteration we have:
  reg_base_value[1]  == (address (reg:HI 1 %r3))
  ...
  reg_base_value[24] == (reg/v:HI 24)
i.e., 1 and 24 were swapped.

So we start the 3rd iteration. find_base_value is called with (reg:HI 1 %r3) 
and, since
reg_base_value[1]  contains (address (reg:HI 1 %r3)), returns (address (reg:HI 
1 %r3)).
Thus new_reg_base_value[24] is set to (address (reg:HI 1 %r3)).
Later, find_base_value is called with (reg/v:HI 24) and, since 
reg_base_value[24]  contains
(reg/v:HI 24), returns (reg/v:HI 24).
Thus new_reg_base_value[1] is set to (reg/v:HI 24).
At the end of the while loop, things are copied from new_reg_base_value to 
reg_base_value
and so, at the end of the third iteration we have:
  reg_base_value[1]  == (reg/v:HI 24)
  ...
  reg_base_value[24] == (address (reg:HI 1 %r3))
i.e., 1 and 24 were swapped again.

So we have an endless loop.

The C routine that causes a problem looks like
  char *foo(char *str, const char *p, int n)
  {
    some loop doing *str++ = something;
    *str = '\0';
    return str;
  }
str is passed in (reg:HI 1 %r3) and copied into (reg/v:HI 24).
The first setting of (reg:HI 1 %r3) occurs for the return statement.

>   > I'm not sure what's the best fix...
>   >   - do some clever testing of new_reg_base_value and reg_base_value ?
> Such as?

Not allowing to return reg_base_value when it is the same as the argument of 
find_base_value...

At the moment, the following patch is my preferred proposition.

I hope I was more clear this time.

Let me know what you think.
					Christian


*** alias.c~	Tue Nov  4 10:52:17 1997
--- alias.c	Tue Nov  4 14:04:27 1997
*************** find_base_value (src)
*** 95,110 ****
        return src;
  
      case REG:
-       /* If this REG is related to a known base value, return it.  */
-       if (reg_base_value[REGNO (src)])
- 	return reg_base_value[REGNO (src)];
- 
        /* At the start of a function argument registers have known base
  	 values which may be lost later.  Returning an ADDRESS
  	 expression here allows optimization based on argument values
  	 even when the argument registers are used for other purposes.  */
        if (REGNO (src) < FIRST_PSEUDO_REGISTER && copying_arguments)
  	return new_reg_base_value[REGNO (src)];
        return src;
  
      case MEM:
--- 95,110 ----
        return src;
  
      case REG:
        /* At the start of a function argument registers have known base
  	 values which may be lost later.  Returning an ADDRESS
  	 expression here allows optimization based on argument values
  	 even when the argument registers are used for other purposes.  */
        if (REGNO (src) < FIRST_PSEUDO_REGISTER && copying_arguments)
  	return new_reg_base_value[REGNO (src)];
+ 
+       /* If this REG is related to a known base value, return it.  */
+       if (reg_base_value[REGNO (src)])
+ 	return reg_base_value[REGNO (src)];
        return src;
  
      case MEM:



  reply	other threads:[~1997-11-04 12:32 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-11-04  4:26 Christian Iseli
1997-11-04  5:49 ` Jeffrey A Law
1997-11-04 12:32   ` Christian Iseli [this message]
1997-11-04 15:39     ` Jeffrey A Law
1997-11-05  4:30 Christian Iseli
1997-11-05  9:26 ` Jeffrey A Law
1997-11-05  9:26 Christian Iseli

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=199711042032.VAA16414@Rivendell.MiddleEarth.net \
    --to=chris@lslsun.epfl.ch \
    --cc=egcs@cygnus.com \
    --cc=law@cygnus.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).