Re: Algorithm Optimization

Thomas Koenig <>
Thu, 17 Sep 2020 06:39:30 -0000 (UTC)

          From comp.compilers

Related articles
[5 earlier articles]
Re: Algorithm Optimization ( (2020-09-16)
Re: Algorithm Optimization (Rick C. Hodgin) (2020-09-16)
Re: Algorithm Optimization (Derek M. Jones) (2020-09-16)
Re: Algorithm Optimization (gah4) (2020-09-16)
Re: Algorithm Optimization (Richard Harnden) (2020-09-16)
Re: Algorithm Optimization (Hans-Peter Diettrich) (2020-09-17)
Re: Algorithm Optimization (Thomas Koenig) (2020-09-17)
Re: Algorithm Optimization (A. K.) (2020-09-21)
Re: Algorithm Optimization (Hans-Peter Diettrich) (2020-12-13)
Re: Algorithm Optimization (gah4) (2020-12-20)
Re: Algorithm Optimization (Johann 'Myrkraverk' Oskarsson) (2021-04-21)
| List of all articles for this month |

From: Thomas Koenig <>
Newsgroups: comp.compilers
Date: Thu, 17 Sep 2020 06:39:30 -0000 (UTC)
References: 20-09-032 20-09-037 20-09-040
Injection-Info:; posting-host=""; logging-data="52729"; mail-complaints-to=""
Keywords: optimize, arithmetic
Posted-Date: 19 Sep 2020 21:06:10 EDT

gah4 <> schrieb:
> On Wednesday, September 16, 2020 at 8:14:44 AM UTC-7,
> 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)

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.

Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.