Path: csiph.com!eternal-september.org!feeder.eternal-september.org!news.iecc.com!.POSTED.news.iecc.com!nerds-end From: Thomas Koenig Newsgroups: comp.compilers Subject: Re: Algorithm Optimization Date: Thu, 17 Sep 2020 06:39:30 -0000 (UTC) Organization: news.netcologne.de Lines: 36 Sender: news@iecc.com Approved: comp.compilers@iecc.com Message-ID: <20-09-043@comp.compilers> References: <20-09-032@comp.compilers> <20-09-037@comp.compilers> <20-09-040@comp.compilers> Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="52729"; mail-complaints-to="abuse@iecc.com" Keywords: optimize, arithmetic Posted-Date: 19 Sep 2020 21:06:10 EDT X-submission-address: compilers@iecc.com X-moderator-address: compilers-request@iecc.com X-FAQ-and-archives: http://compilers.iecc.com Xref: csiph.com comp.compilers:2614 gah4 schrieb: > On Wednesday, September 16, 2020 at 8:14:44 AM UTC-7, > mwmar...@gmail.com wrote: > > (snip) > >> This approaches the issue more from a "I want to replace serial >> algorithms with parallel algorithms." if I recall correctly so it may >> not be exactly what you are looking for. > > That might make more sense. So, an algorithm that it mathematically > equivalent, but not necessarily numerically equivalent. Hic sunt dracones. Re-arranging mathematically equivalent operation can lead to surprising side effects, and are prohibited by many language standards. Yet, compilers very often have optimizations to switch off the guarantees of these standards, and they are often used by users ignorant of the issues (and for benchmarks). An example is Kahan summation, which is an algorithm for reducing numerical errors in summing up terms. It is mathematically equivalent to straightforward summation, so a compiler which operates on mathematical equivalence across statements can in fact convert Kahan summation back to simple summation. This, of course, loses the benefit that the programmer (presumably) wanted. Gcc, for example, will happily do that transformation if given the -funsafe-math-optimization flag (which, despite what the name implies, is neither fun nor safe). The problem is that this is one of the flags enabled with the catch-all option with the suggestive name -Ofast.