Re: Common subexpression analysis (summary)

Bruce.Hoult@bbs.actrix.gen.nz
Mon, 13 Jul 1992 05:45:13 GMT

          From comp.compilers

Related articles
Common subexpression analysis (summary) mernst@theory.lcs.mit.edu (1992-06-26)
Re: Common subexpression analysis (summary) buzzard@eng.umd.edu (1992-07-07)
Re: Common subexpression analysis (summary) Bruce.Hoult@bbs.actrix.gen.nz (1992-07-13)
Re: Common subexpression analysis (summary) igor!voltaire!davidm@uunet.UU.NET (1992-07-13)
Re: Common subexpression analysis (summary) Dik.Winter@cwi.nl (1992-07-13)
Re: Common subexpression analysis f88ho@efd.lth.se (1992-07-14)
permissible numerical optimizations tmb@arolla.idiap.ch (1992-07-14)
Re: Common subexpression analysis (summary) preston@dawn.cs.rice.edu (1992-07-12)
| List of all articles for this month |

Newsgroups: comp.compilers
From: Bruce.Hoult@bbs.actrix.gen.nz
Organization: Actrix Information Exchange
Date: Mon, 13 Jul 1992 05:45:13 GMT
References: 92-06-135 92-07-021
Keywords: optimize

buzzard@eng.umd.edu (Sean Barrett) writes:
> TURN:
> while (y >= 0)
> if (x*x + y*y >= r*r)
> --y;
> else
> ++x;
> INTO:
> r2 = r*r;
> x2 = x*x;
> y2 = y*y;
> while (y >= 0)
> if (x2 + y2 > r2)
> --y, y2 = y*y;
> else
> ++x, x2 = x*x;


Why didn't you do strength reduction while you were at it?


          r2 = r*r;
          x2 = x*x;
          y2 = y*y;
          while (y >= 0)
              if (x2 + y2 > r2)
                      --y, y2 -= y+y-1;
              else
                      ++x, x2 += x+x+1;




... or even go whole hog and do...


          t = x*x + y*y - r*r;
          x2 = x+x+1;
          y2 = y+y-1;
          while (y2 >= 0)
              if (t > 0)
                      y2 -= 2, t -= y2;
              else
                      x2 += 2, t += x2;




I'll bet if there are any compilers that can do this, they're probably
for FORTRAN :-)


--
Bruce.Hoult@bbs.actrix.gen.nz Twisted pair: +64 4 477 2116
BIX: brucehoult Last Resort: PO Box 4145 Wellington, NZ
--


Post a followup to this message

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