From: George Neuner Newsgroups: comp.compilers Subject: Re: GCC/G++ compiler: Error goes away when run through debugger Date: Thu, 31 Mar 2011 01:34:30 -0400 Organization: A noiseless patient Spider Lines: 30 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <11-04-002@comp.compilers> References: <11-03-054@comp.compilers> <11-03-061@comp.compilers> <11-03-063@comp.compilers> NNTP-Posting-Host: news.iecc.com X-Trace: gal.iecc.com 1301787952 41631 64.57.183.58 (2 Apr 2011 23:45:52 GMT) X-Complaints-To: abuse@iecc.com NNTP-Posting-Date: Sat, 2 Apr 2011 23:45:52 +0000 (UTC) Keywords: GCC, debug, optimize Posted-Date: 02 Apr 2011 19:45:52 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.stben.net!border3.nntp.ams.giganews.com!border1.nntp.ams.giganews.com!nntp.giganews.com!feeder.news-service.com!2001:1418:1:101::c.MISMATCH!itgate.net!nntp1.phx1.gblx.net!nntp.gblx.net!nntp.gblx.net!rahul.net!wasp.rahul.net!rahul.net!news.lightlink.com!news.iecc.com!nerds-end Xref: x330-a1.tempe.blueboxinc.net comp.compilers:69 On Tue, 29 Mar 2011 21:42:12 +0000 (UTC), ike@localhost.claranet.nl (Ike Naar) wrote: >George Neuner wrote: >>GCC's -O3 optimization level is widely known to cause strange problems >>... almost always because the program is violating assumptions made by >>the more advanced optimizations. >> >>The -O2 level typically is safe. If you think you need the -O3 >>optimizations, you should individually enable them to see if any >>breaks the program. Specify -O3 only if you find they all work. > >Sometimes using -O3 makes the program run slower than when using -O2. Yes, inlining and function cloning can greatly increase the code size. But in particular -O3 enables the "predictive-commoning" and "tree-vectorize" optimizations. "predictive-commoning" is an extension of loop unrolling which tries to identify and avoid recomputing and/or reloading values that are common to two or more (not necessarily consecutive) iterations of a loop but which overall are not loop invariant. "tree-vectorize" tries to map a loop of serial operations into an equivalent, but shorter, loop of SIMD operations. Both of these optimizations can break badly - and in quite unexpected ways - when indexed locations are aliased or when there are iterative data dependencies. The compiler can't always figure out when NOT to perform the optimization ... and the results when the compiler guesses wrong are unpredictable. George