public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* List of optimizations enabled by -O1 seems incorrect
@ 2009-08-13 18:25 Nikos Chantziaras
  2009-08-13 19:02 ` Andrew Haley
  2009-08-13 19:38 ` John (Eljay) Love-Jensen
  0 siblings, 2 replies; 13+ messages in thread
From: Nikos Chantziaras @ 2009-08-13 18:25 UTC (permalink / raw)
  To: gcc-help

I'm trying to discover which GCC optimization is responsive for a 
runtime error reported by Valgrind:

   "Conditional jump or move depends on uninitialised value(s)"

This pops up when compiling with -O1 and above.  The code in question is 
C++ and is of this form:

   if (!foo && !bar)

The uninitialized variable is 'bar'.  However, it shouldn't be evaluated 
at all due to short-circuit if rules.  Of course the optimizer is free 
to evaluate it anyway if there are no side-effects when doing so.

So just out of interest, I'm trying to find out which optimization is 
responsible for this.  I looked up the GCC info pages and I compiled 
with -O1 and then disabled the optimizations enabled by -O1 one by one, 
in hope to hit the one that triggers the error, until all of them were 
disabled in the end:

   -O1 -fno-auto-inc-dec -fno-cprop-registers -fno-dce -fno-defer-pop
   -fno-delayed-branch -fno-dse -fno-guess-branch-probability
   -fno-if-conversion2 -fno-if-conversion -fno-inline-small-functions
   -fno-ipa-pure-const -fno-ipa-reference -fno-merge-constants
   -fno-split-wide-types -fno-tree-ccp -fno-tree-ch -fno-tree-copyrename
   -fno-tree-dce -fno-tree-dominator-opts -fno-tree-dse -fno-tree-fre
   -fno-tree-sra -fno-tree-ter -fno-unit-at-a-time

However, the error still appears which makes me conclude that the above 
list of -O1 optimizations is not complete.  Which ones am I missing?

I tested with GCC 4.3.4 and 4.4.1.

^ permalink raw reply	[flat|nested] 13+ messages in thread
* Re: List of optimizations enabled by -O1 seems incorrect
@ 2009-08-14 18:51 Bill McEnaney
  0 siblings, 0 replies; 13+ messages in thread
From: Bill McEnaney @ 2009-08-14 18:51 UTC (permalink / raw)
  To: Kevin P. Fleming, Andrew Haley, Ian Lance Taylor, gcc-help

What would it turn this into, Andrew?

if (!(foo || bar))

> Andrew Haley wrote:
> 
> > gcc looks at
> > 
> >   if (!foo && !bar)
> >     ...
> > 
> > and turns it into
> > 
> >   if (foo|bar)
> >     goto x;
> >   ...
> >  x:
> > 
> > So, from Valgrind's point of view, the branch depends on the value of
> > bar, which is uninitialized.  We know that if foo is nonzero there is
> > no such dependency, but Valgrind would have to do some heavyweight
> > dependency analysis to figure that one out.
> 
> Ding-ding-ding... and the winner is, I'm not awake enough yet this
> morning :-) Thanks for the explanation!
> 
> -- 
> Kevin P. Fleming
> Digium, Inc. | Director of Software Technologies
> 445 Jan Davis Drive NW - Huntsville, AL 35806 - USA
> skype: kpfleming | jabber: kpfleming@digium.com
> Check us out at www.digium.com & www.asterisk.org
> 
> 

________________________________________________________________
Please visit a saintly hero:
http://www.jakemoore.org

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

end of thread, other threads:[~2009-08-14 16:58 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-08-13 18:25 List of optimizations enabled by -O1 seems incorrect Nikos Chantziaras
2009-08-13 19:02 ` Andrew Haley
2009-08-13 20:15   ` Nikos Chantziaras
2009-08-13 20:18     ` Kevin P. Fleming
2009-08-13 20:56       ` Andrew Haley
2009-08-13 22:01         ` Kevin P. Fleming
2009-08-14 10:53           ` Ian Lance Taylor
2009-08-14 14:22             ` Kevin P. Fleming
2009-08-14 16:58               ` Andrew Haley
2009-08-14 18:23                 ` Kevin P. Fleming
2009-08-13 21:36       ` Nikos Chantziaras
2009-08-13 19:38 ` John (Eljay) Love-Jensen
2009-08-14 18:51 Bill McEnaney

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