Re: Optimization techniques

Martin Ward <martin@gkc.org.uk>
Fri, 26 Apr 2019 19:46:53 +0100

          From comp.compilers

Related articles
[17 earlier articles]
Re: Optimization techniques david.brown@hesbynett.no (David Brown) (2019-04-25)
Re: Optimization techniques 847-115-0292@kylheku.com (Kaz Kylheku) (2019-04-25)
Re: Optimization techniques 847-115-0292@kylheku.com (Kaz Kylheku) (2019-04-26)
Re: Optimization techniques 847-115-0292@kylheku.com (Kaz Kylheku) (2019-04-26)
Re: Optimization techniques alexfrunews@gmail.com (2019-04-26)
Re: Optimization techniques derek@_NOSPAM_knosof.co.uk (Derek M. Jones) (2019-04-26)
Re: Optimization techniques martin@gkc.org.uk (Martin Ward) (2019-04-26)
Re: Optimization techniques martin@gkc.org.uk (Martin Ward) (2019-04-26)
Re: language design and Optimization techniques 847-115-0292@kylheku.com (Kaz Kylheku) (2019-04-26)
Re: Optimization techniques 847-115-0292@kylheku.com (Kaz Kylheku) (2019-04-26)
Re: Optimization techniques 0xe2.0x9a.0x9b@gmail.com (2019-04-27)
Re: Optimization techniques haberg-news@telia.com (Hans Aberg) (2019-04-27)
Re: Optimization techniques david.brown@hesbynett.no (David Brown) (2019-04-28)
[13 later articles]
| List of all articles for this month |

From: Martin Ward <martin@gkc.org.uk>
Newsgroups: comp.compilers
Date: Fri, 26 Apr 2019 19:46:53 +0100
Organization: Compilers Central
References: <72d208c9-169f-155c-5e73-9ca74f78e390@gkc.org.uk> <910eaf6f-f9ae-9c02-5052-f06474024d96@hesbynett.no>
Injection-Info: gal.iecc.com; posting-host="news.iecc.com:2001:470:1f07:1126:0:676f:7373:6970"; logging-data="54457"; mail-complaints-to="abuse@iecc.com"
Keywords: design, optimize
Posted-Date: 26 Apr 2019 15:14:19 EDT

On 25/04/19 20:58, David Brown wrote:
> It is a serious mistake to mix up "defined behaviour" and "correct
> behaviour". Only defined behaviour can be correct, but you can't fix
> incorrect code by making it defined behaviour.


"Defined behaviour" *can* be "correct behaviour"
"undefined behaviour" can *never* be correct and therefore
must be avoided at all costs.


You dismiss cases of security holes due to undefined behaviour
as "just program bugs, because programmers didn't do the right thing".
The C ANSI standard is over 500 pages long and includes 199
different cases of undefined behaviour. A quick quiz:
without referencing the standard, how many of the 199 cases
of undefined behaviour can you list off the top of your head?
Remember: a *good* programmer (one that you would describe
as an engineer who knows what they are doing) must avoid
all 199 cases of undefined behaviour in every line of code
that they write.


Dijkstra wrote this in his ACL Turing Award Lecture in 1972:


"Using PL/1 must be like flying a plane with 7000 buttons, switches
and handles to manipulate in the cockpit. I absolutely fail to see
how we can keep our growing programs firmly within our intellectual
grip when by its sheer baroqueness the programming language -- our
basic tool, mind you! -- already escapes our intellectual control."


Note that even knowing that there is undefined behaviour, you still
may not be able to avoid it by testing for its occurrence: the
optimiser might spot that you are testing for undefined behaviour and
optimise away your test, because it is allowed to assume that the
undefined behaviour can never happen! (This is what actually occurred
in the last example I gave).


You say "The trick is to write the tests correctly" but don't tell us
what clever tricks we can use in order to fool the optimised into
thinking we are testing for something *other* than undefined behaviour
and so head it off from optimising away our test. Even if we manage
this: how can we be sure that the next version of the compiler will
not include a cleverer optimiser which sees through our trickery and
optimises away the test once again? There seems to be an arms race
between programmers trying to write safe code and compiler writers
detecting and optimising away their safety nets.


--
Martin


Dr Martin Ward | Email: martin@gkc.org.uk | http://www.gkc.org.uk
G.K.Chesterton site: http://www.gkc.org.uk/gkc | Erdos number: 4


Post a followup to this message

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