From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Vickers To: Joern Rennecke Cc: egcs@cygnus.com Subject: Re: Was: Re: Loop optimizer misses simple optimisation? Date: Thu, 07 May 1998 05:15:00 -0000 Message-id: References: <199805061729.SAA25923@phal.cygnus.co.uk> X-SW-Source: 1998-05/msg00236.html On Wed 06 May, Joern Rennecke wrote: > > int a, b, c, d; > > ... > > c = b / c; > > d = b % c; > > > > becomes: > > > > c = a / b; > > d = a - c * b; Ho hum. Perhaps the transformation above is not necessarily to the advantage of the user. > This would have to depend on the cost of the modulo operation - and if b > is constant or can be made constant by constant-propagation, this also > ight make a difference to the cost. Yes indeed. We have a lot of ways of skinning the cat, and we should check the costs, assuming sensible costs are available ;-). I should say that I haven't investigated what egcs is doing in more than a rather cursory way. I think I was over-generalising without checking my facts - the targets I'm interested in don't have either SImode divide or divmod. If the div needs a libcall, it looks like expmed.c::expand_divmod gives up on trying to optimise the mod. This is what I was really getting at. By the way, it seems like there are a few odd tricks which expand_divmod misses e.g. divisor so big that repeated subtraction is efficient, or mod when the divisor is (2^n +/-1)*2^m. John.