public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Adrian Bentley <adruab@voria.com>
To: Eljay Love-Jensen <eljay@adobe.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: Weird optimization bug...?
Date: Thu, 03 Jun 2004 23:06:00 -0000	[thread overview]
Message-ID: <1086303996.13949.12.camel@localhost> (raw)
In-Reply-To: <6.0.3.0.2.20040603132957.02031898@iplan-mn.corp.adobe.com>

Ok ok... I think I found why it's crashing (although it doesn't actually
crash when I run it because I'm calling a print function).  Anyways, I
re-expanded the if statement to check the bounds on the array
indirections....

//see other code for the rest...
if (y>length) 
{
	typename T1::value_type &v = iter[-length-1];
	if( (char*)&v < beginptr || (char*)&v >= endptr)
		printf("crap! %d (%p off %p)\n",y,&v,&*iter);
	tot-=iter[-length-1];
}
else
{
	tot-=val;
}

And I'm indirecting off of iter which is being incremented every
iteration.  But for some reason it looks like gcc decided to use the
original value of iter for the 10th iteration (1 greater than the value
for length my example is using) inside the sample case I have... (i.e.
rather than using the incremented value).  So it looks like it was
trying to optimize out an expression that wasn't constant (either in
attempting to optimize the first if statement out of the loop).  It
doesn't do this when I turn optimization off... so it definitely looks
like an optimizer bug.

Anyways, I'm not sure why it would do this as iter is being changed
every iteration.  Oh well, I'm gonna manually do some unrolling and
hopefully it won't break any more.  Hope that helps anyone interested in
the issue.

Thanks again all,
Adruab


On Thu, 2004-06-03 at 11:36, Eljay Love-Jensen wrote:
> Hi Adruab.
> 
>  >However, if that was the case, inserting a random function into the code 
> certain shouldn't fix the problem :P.
> 
> Inserting a random function into the code can affect the optimizer, which 
> can mask the problem.
> 
> I recommend taking a look at the assembly file to see what's different 
> between having and not having the extra function present, in the optimized 
> code.
> 
> You can use the "-save-temps" to keep the assembly file around, and 
> "-fverbose-asm" for extra blather.
> 
> HTH,
> --Eljay
> 
> 
> 

  parent reply	other threads:[~2004-06-03 23:06 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-02 20:24 Adrian Bentley
2004-06-03 11:26 ` Eljay Love-Jensen
2004-06-03 17:24   ` Adrian Bentley
2004-06-03 18:37     ` Eljay Love-Jensen
2004-06-03 19:11       ` Adrian Bentley
2004-06-03 21:17       ` Adrian Bentley
2004-06-03 23:06       ` Adrian Bentley [this message]
2004-06-04  3:00         ` Ian Lance Taylor
2004-06-05 19:09           ` Adrian Bentley
2004-06-05 23:31             ` Ian Lance Taylor
2004-06-06  0:47             ` Ken Foskey
2004-06-05 20:21           ` Adrian Bentley
     [not found]             ` <m3aczh4m55.fsf@gossamer.airs.com>
2004-06-06 16:44               ` Adrian Bentley
2004-06-06 22:23                 ` Ian Lance Taylor
2004-06-03 19:13 lrtaylor

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=1086303996.13949.12.camel@localhost \
    --to=adruab@voria.com \
    --cc=eljay@adobe.com \
    --cc=gcc-help@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).