www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/07/04/23:20:08

Sender: nate AT cartsys DOT com
Message-ID: <359EECBB.568845F8@cartsys.com>
Date: Sat, 04 Jul 1998 20:02:19 -0700
From: Nate Eldredge <nate AT cartsys DOT com>
MIME-Version: 1.0
To: Brian Bacon <kyberteknik AT geocities DOT com>
CC: djgpp AT delorie DOT com
Subject: Re: Optimization Question
References: <00a901bda7b0$31be9c20$ea023ace AT alpha>

Brian Bacon wrote:
> 
>  Hello,
>   I have a small problem.  I need to know how to tell gcc NOT to optimize a
> certain section of code, it keeps doing it wrong!  I am using -O2, my
> application is graphic-intensive, so I want to at least keep the -O2.  Is
> there something I can put around my code to tell it to leave it the way it
> should be?

No, you can't.  If you don't want optimization, you'll have to disable
it for the entire file.

> 
> The code looks something like this:
> 
> b=(a_computed_number);
> f=b*c;
> 
> f always comes out wrong!  I looked at the .S file gcc produces (with the -S
> option) and it looks like it isn't doing anything at all to f.  I just
> copies something for one portion of memory to another (there isn't even any
> multiplication!).

That could be correct.  GCC is very smart, and if it can solve something
at compile time, it will.  So if the values of `b' and `c' are constant,
then no multiplication will be required to find `f's value.  In fact, in
that case, `f' might be optimized completely out of existence.

However, if you are *absolutely* sure that you are calculating a value
correctly, and it comes out wrong, it could be a compiler bug.  In that
case, upgrade to GCC 2.8.1 if you haven't, or report it if you have. 
(Instructions on how to do so are in the GCC docs.)

Be careful, though; always suspect your own code first.  The other day,
I was compiling a piece of code like this:

if (complicated_expression)
  {
     /* stuff... */
  }

But it didn't work.  I looked at the assembly.  Without -O the test
culminated in a conditional jump to the next instruction, which would
work the same either way.  And with -O2, the test was completely
missing!  Finally I discovered that I had mistakenly put a semicolon
after the `if' line.


> 
> "All in all you were all just bricks in the wall" Pink Floyd - The Wall
> ----------------------------------------------------------------------------
> -------------------------------
> Brian Bacon  -  kyberteknik AT geocities DOT com
> ICQ: 3218637
> http://trr.home.ml.org/
> GCS d- p- c++++ l- u e* m++(+++/---)@ s+/- n---@ h-- f+ g+ w++ t+ r x?

-- 

Nate Eldredge
nate AT cartsys DOT com


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019