Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: David Brown Newsgroups: comp.compilers Subject: Re: Optimization techniques Date: Tue, 23 Apr 2019 09:43:17 +0200 Organization: A noiseless patient Spider Lines: 25 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <19-04-018@comp.compilers> References: <19-04-004@comp.compilers> <19-04-012@comp.compilers> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="73393"; mail-complaints-to="abuse@iecc.com" Keywords: C, optimize Posted-Date: 24 Apr 2019 10:20:51 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com In-Reply-To: <19-04-012@comp.compilers> Content-Language: en-GB Xref: csiph.com comp.compilers:2202 On 20/04/2019 00:27, Hans-Peter Diettrich wrote: > Am 17.04.2019 um 15:42 schrieb Rick C. Hodgin: >> Are there resources someone can point me to for learning more about >> time-honored, long-established, safely applied, optimization >> techniques for a C/C++ like language? > > I'm always a bit sceptic when C/C++ and "safe" occur in the same > sentence. C and C++ can certainly be used safely. But the programmer needs to know what they are doing, and want to write safe code. > AFAIR a C compiler is allowed to ignore parentheses when > reordering expressions, what can lead to numeric instabilities. For floating point operations, such re-arrangements could lead to numeric instabilities - and they are not allowed. For signed integer operations, brackets that affect calculations can't be removed. The compiler can't change "(a * b) / c" into "a * (b / c)". But mathematical identities such as associativity and commutativity are valid because signed integer overflow does not happen - thus "a * (b + c)" can be changed to "(a * b) + (a * c)". And of course the evaluation of sub-expressions can be done in any order.