Re: Does the gcc optimizer rearrange floating point expressions?

dje@cygnus.com (Doug Evans)
Thu, 30 Jun 1994 06:19:46 GMT

          From comp.compilers

Related articles
Does the gcc optimizer rearrange floating point expressions? jrs+@cs.cmu.edu (1994-06-26)
Re: Does the gcc optimizer rearrange floating point expressions? dmoore@reed.edu (1994-06-28)
Re: Does the gcc optimizer rearrange floating point expressions? drtr@mailer.astronomy.cambridge.ac.uk (1994-06-29)
Re: Does the gcc optimizer rearrange floating point expressions? dje@cygnus.com (1994-06-30)
| List of all articles for this month |

Newsgroups: comp.compilers
From: dje@cygnus.com (Doug Evans)
Keywords: GCC, arithmetic
Organization: Cygnus Support
References: 94-06-219
Date: Thu, 30 Jun 1994 06:19:46 GMT

Jonathan R Shewchuk <jrs+@cs.cmu.edu> wrote:
>[Does gcc rearrange floating point expressions?]


Dave Moore (dmoore@reed.edu) wrote:
>[looks like it does]


As usual with gcc, it is always important to mention version and platform
when stating anything about what gcc does and doesn't do (platform isn't
always useful, but ya' never know).


Consider the following code:


int i (int skip, int x, int y) { return (x + y) - y; }
float f (float x, float y) { return (x + y) - y; }


With gcc 2.5.6 (sparc-sun-solaris2) I get:
(gcc -S -O2 foo.c)


                .file "foo.c"
section ".text"
                .align 4
                .global i
                .type i,#function
                .proc 04
i:
                !#PROLOGUE# 0
                !#PROLOGUE# 1
                retl
                mov %o1,%o0
LLfe1:
                .size i,.LLfe1-i
                .align 4
                .global f
                .type f,#function
                .proc 06
f:
                !#PROLOGUE# 0
                !#PROLOGUE# 1
                st %o0,[%sp-16]
                ld [%sp-16],%f3
                st %o1,[%sp-16]
                ld [%sp-16],%f2
                fadds %f3,%f2,%f0
                retl
                fsubs %f0,%f2,%f0
LLfe2:
                .size f,.LLfe2-f
                .ident "GCC: (GNU) cygnus-2.5.6-931206"


gcc collapsed the int version of (x+y)-x but it
did not collapse the float version. Progress is being made in making
gcc "do the right thing" with regard to floating point operations,
though I'm not sure how far the powers that be wish to carry this.


There is an option to take short cuts when such things aren't wanted:


`-ffast-math'
          This option allows GCC to violate some ANSI or IEEE rules and/or
          specifications in the interest of optimizing code for speed. For
          example, it allows the compiler to assume arguments to the `sqrt'
          function are non-negative numbers.


          This option should never be turned on by any `-O' option since it
          can result in incorrect output for programs which depend on an
          exact implementation of IEEE or ANSI rules/specifications for math
          functions.


This gives a clue as to what rules gcc is committed to adhering to.


--
Doug Evans
dje@cygnus.com
Cygnus Support, Mountain View, CA
+1 415 903 1412
--


Post a followup to this message

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