Re: programmer optimizations?

jhowat@lucifer.cs.waikato.ac.nz
Mon, 2 Jan 1995 00:04:57 GMT

          From comp.compilers

Related articles
programmer optimizations? afsal@genius.tisl.soft.net (Afsal C. Majeed) (1994-12-28)
Re: programmer optimizations? davidm@Rational.COM (1994-12-31)
Re: programmer optimizations? fjh@munta.cs.mu.OZ.AU (1995-01-01)
Re: programmer optimizations? jhowat@lucifer.cs.waikato.ac.nz (1995-01-02)
Re: programmer optimizations? jbuck@Synopsys.COM (1995-01-02)
Re: programmer optimizations? eru@tele.nokia.fi (Erkki Ruohtula) (1995-01-11)
Re: programmer optimizations? conway@munta.cs.mu.OZ.AU (1995-01-05)
Re: programmer optimizations? bill@amber.ssd.csd.harris.com (1995-01-05)
Re: programmer optimizations? kerch@albion.camb.inmet.com (1995-01-12)
Re: programmer optimizations? monnier@di.epfl.ch (Stefan Monnier) (1995-01-21)
[10 later articles]
| List of all articles for this month |

Newsgroups: comp.compilers
From: jhowat@lucifer.cs.waikato.ac.nz
Keywords: optimize, architecture
Organization: Compilers Central
References: 94-12-145
Date: Mon, 2 Jan 1995 00:04:57 GMT

Afsal C. Majeed wrote:
: We are having small debate here as to the use of some of the
: code optimizations by the programmer himself.


: e.g.
: replacing if ((i < 0) || (j < 0) || (k < 0))
: by if ((i | j | k) < 0)


I was thinking about this one with regard to the ARM's RISC-like
architecture, and I tried passing it through the Norcroft C compiler (v4).


It came up with the following:


normal
                CMPS a1, #0
                BLT |L00001c.J5.normal|
                CMPS a2, #0
                BLT |L00001c.J5.normal|
                CMPS a3, #0
                MOVGES pc, lr ; else statement is return from function
|L00001c.J5.normal|
                ...


... and ...


opt
                ORR a4, a1, a2
                ORR a4, a4, a3
                CMPS a4, #0
                MOVGES pc, lr ; else statement is return from function
                ...


In both cases variables i,j,k are in registers a1,a2,a3. It would appear
that in this case the optimised code is smaller and avoids using the
branch instructions.


If the compiler used conditional execution on the compare instructions,
then the "unoptimised" version could be recoded as:


normal
                CMPS a1, #0
                CMPGES a2, #0
                CMPGES a3, #0
                MOVGES pc, lr ; else statement is return from function
                ...


which uses the same number of instructions as the "optimised" version but
one less register.


: Since this produces somewhat non portable code, the view is that
: such optimizations should be discouraged.


I would have to agree with this statement. It is best to leave the
optimizing up to the compiler, because then it can make the optimisations
that are best for the target architecture.


: What I want to know is [...] whether any of the commercial compilers
: attempt to do such "target machine" specific optimizations.


We've just seen that v4 of the Norcroft compiler doesn't do this one, maybe
v5 (due out RSN) will do better. ;-)




Jason.


--


Post a followup to this message

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