Re: Possible ANSI C Optimisation Done in Practice?

nmm1@cus.cam.ac.uk (Nick Maclaren)
22 Dec 2001 22:54:42 -0500

          From comp.compilers

Related articles
[5 earlier articles]
Re: Possible ANSI C Optimisation Done in Practice? ralph@inputplus.demon.co.uk (2001-12-20)
Re: Possible ANSI C Optimisation Done in Practice? ralph@inputplus.demon.co.uk (2001-12-20)
Re: Possible ANSI C Optimisation Done in Practice? ralph@inputplus.demon.co.uk (2001-12-20)
Re: Possible ANSI C Optimisation Done in Practice? RLWatkins@CompuServe.Com (R. L. Watkins) (2001-12-20)
Re: Possible ANSI C Optimisation Done in Practice? ralph@inputplus.demon.co.uk (2001-12-20)
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)
[2 later articles]
| List of all articles for this month |
From: nmm1@cus.cam.ac.uk (Nick Maclaren)
Newsgroups: comp.compilers
Date: 22 Dec 2001 22:54:42 -0500
Organization: University of Cambridge, England
References: 01-12-050 <200112120335.fBC3ZMg01140@budgie.cs.uwa.edu.au> 01-12-065 01-12-104 01-12-118 01-12-121
Keywords: C, optimize
Posted-Date: 22 Dec 2001 22:54:42 EST

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.
|>
|> The compiler is allowed to know about strlen, but this sort of
|> thing means that it is usually almost impossible to determine
|> whether aliasing can occur without at least global analysis (which,
|> inter alia, means no pre-compiled, external libraries). Not nice.
|>
|> [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. What this often means is that (say) replacing strcmp
by your own version of strcasecmp can unexpectedly reduce performance
by a very large factor, even if that call is not in the critical loop
and it is faster than the system supplied version of strcmp! The
performance can often be restored by including the function in the
module you are using it from, or by similar tricks.


This means that optimisation of C90 is very dependent on the
programmer having written his code in the right way for that
particular compiler, and that writing efficient code is very dependent
on knowing how the optimiser works. Much more so than for (say)
Fortran.


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.