Path: csiph.com!4.us.feeder.erje.net!feeder.erje.net!feeder.usenetexpress.com!feeder-in1.iad1.usenetexpress.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: David Brown Newsgroups: comp.compilers Subject: Re: Optimization techniques Date: Sun, 28 Apr 2019 17:22:26 +0200 Organization: A noiseless patient Spider Lines: 18 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <19-04-036@comp.compilers> References: <19-04-004@comp.compilers> <19-04-012@comp.compilers> <19-04-018@comp.compilers> <19-04-028@comp.compilers> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="17815"; mail-complaints-to="abuse@iecc.com" Keywords: arithmetic, optimize Posted-Date: 28 Apr 2019 18:31:37 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Content-Language: en-GB Xref: csiph.com comp.compilers:2220 On 26/04/2019 21:10, Martin Ward wrote: > On 23/04/19 08:43, David Brown wrote: >> 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)". > > If b is large and c has a value close to -b then a * (b + c) > might be OK while (a * b) will overflow and cause undefined > behaviour. > You are right. The compiler can go the other way, but not that way. It can ignore the possibility of overflows or other errors (like divide by zero) in the expression you give it, but it can't manipulate things in a way that might introduce new errors. Obviously compiler writers are expected to pay more attention to these details than someone making a Usenet post!