Re: Possible ANSI C Optimisation Done in Practice?

nmm1@cus.cam.ac.uk (Nick Maclaren)
27 Dec 2001 00:12:08 -0500

          From comp.compilers

Related articles
[10 earlier articles]
Re: Possible ANSI C Optimisation Done in Practice? nmm1@cus.cam.ac.uk (2001-12-20)
Re: Possible ANSI C Optimisation Done in Practice? nmm1@cus.cam.ac.uk (2001-12-22)
Re: Possible ANSI C Optimisation Done in Practice? ralph@inputplus.demon.co.uk (2001-12-22)
Re: Possible ANSI C Optimisation Done in Practice? ralph@inputplus.demon.co.uk (2001-12-24)
Re: Possible ANSI C Optimisation Done in Practice? nmm1@cus.cam.ac.uk (2001-12-24)
Re: Possible ANSI C Optimisation Done in Practice? toon@moene.indiv.nluug.nl (Toon Moene) (2001-12-24)
Re: Possible ANSI C Optimisation Done in Practice? nmm1@cus.cam.ac.uk (2001-12-27)
Re: Possible ANSI C Optimisation Done in Practice? david.thompson1@worldnet.att.net (David Thompson) (2001-12-27)
Re: Possible ANSI C Optimisation Done in Practice? david.thompson1@worldnet.att.net (David Thompson) (2002-01-03)
Re: Possible ANSI C Optimisation Done in Practice? ralph@inputplus.demon.co.uk (2002-01-05)
| List of all articles for this month |

From: nmm1@cus.cam.ac.uk (Nick Maclaren)
Newsgroups: comp.compilers
Date: 27 Dec 2001 00:12:08 -0500
Organization: University of Cambridge, England
References: 01-12-050 01-12-121 01-12-123 01-12-144
Keywords: C, optimize
Posted-Date: 27 Dec 2001 00:12:08 EST

Ralph Corderoy <ralph@inputplus.demon.co.uk> wrote:
>Hi Nick,
>
>> nmm1@cus.cam.ac.uk (Nick Maclaren) writes:
>> > This is legal, if insane. What is worse, is that strlen is allowed
>> > to set errno at whim (C99 7.5 paragraph 3), which makes the whole
>> > function effectively unoptimisable.
>> >
>> > [It seems to me that since the compiler is allowed to treat
>> > strlen() as a special case, part of the special case could include
>> > knowledge that its version of strlen doesn't change errno. -John]
>>
>> Yes, precisely.
>
>First it's said that because strlen is allowed to set errno the whole
>function is effectively unoptimisable. Then, when John points out
>that the compiler is allowed to know whether its strlen alters errno,
>a possibility not previously allowed for, it's accepted. Doesn't it
>completely invalidate the earlier `effectively unoptimisable' point?


Not in general, though it does in this case. I was assuming that the
original poster was providing a simplified example, rather than a real
problem.


>AFAICS as an ANSI compiler can know the semantics of strlen, it's not
>an obstacle to knowing whether modifying *t affects s.


It starts getting hairy once you bring in <math.h> and <stdio.h>. The
point is that quite a lot of systems have compilers developed by one
team and libraries by another, and that makes it difficult to the
compiler to make such assumptions and get them right.


My real point isn't that ALL functions are effectively unoptimisable
but that there are a sufficient number of "gotchas" as to make it an
impossible task in practice, especially when the compiler and library
may be separate products. This is precisely the problem that C99
restrict is intended to solve.




Regards,
Nick Maclaren,
University of Cambridge Computing Service,
New Museums Site, Pembroke Street, Cambridge CB2 3QH, England.
Email: nmm1@cam.ac.uk
Tel.: +44 1223 334761 Fax: +44 1223 334679


Post a followup to this message

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