Re: eliminating array bounds checking overhead

Mark Williams <markw65@my-deja.com>
30 Apr 2000 00:17:24 -0400

          From comp.compilers

Related articles
[6 earlier articles]
Re: eliminating array bounds checking overhead rhyde@shoe-size.com (Randall Hyde) (2000-04-27)
Re: eliminating array bounds checking overhead nr@labrador.eecs.harvard.edu (2000-04-27)
Re: eliminating array bounds checking overhead terryg@uswest.net (Terry Greyzck) (2000-04-27)
Re: eliminating array bounds checking overhead fjscipio@rochester.rr.com (Fred J. Scipione) (2000-04-27)
Re: eliminating array bounds checking overhead sandeep@ddi.com (Sandeep Dutta) (2000-04-29)
Re: eliminating array bounds checking overhead tej@melbpc.org.au (Tim Josling) (2000-04-30)
Re: eliminating array bounds checking overhead markw65@my-deja.com (Mark Williams) (2000-04-30)
Re: eliminating array bounds checking overhead d95josef@dtek.chalmers.se (2000-04-30)
Re: eliminating array bounds checking overhead mayur_naik@my-deja.com (2000-04-30)
Re: eliminating array bounds checking overhead terryg@uswest.net (Terry Greyzck) (2000-05-01)
Re: eliminating array bounds checking overhead monnier+comp/compilers/news/@flint.cs.yale.edu (Stefan Monnier) (2000-05-01)
Re: eliminating array bounds checking overhead r_c_chapman@my-deja.com (2000-05-01)
Re: eliminating array bounds checking overhead markw65@my-deja.com (Mark Williams) (2000-05-04)
[4 later articles]
| List of all articles for this month |

From: Mark Williams <markw65@my-deja.com>
Newsgroups: comp.compilers
Date: 30 Apr 2000 00:17:24 -0400
Organization: Deja.com - Before you buy.
References: 00-04-194 00-04-211
Keywords: optimize

> It is possible to direct the compiler to avoid a second branch
> instruction by rewriting the test as follows:
>
> if ((unsigned)(i - (lo+1)) < hi)
>
> Of course, if "lo" is not a constant, the savings is likely to be very
> marginal (in-line flow for an addition and subtraction vs a comparison
> and a conditional branch which usually flows in-line). It is probably
> not reasonable to expect a compiler to always make this transformation
> during optimization. However, the generated output for an "array
> bounds checking" operation probably should produce the equivalent
> code, espically when "lo" and "hi" are known constants.
> [It's still pretty fast if you can put lo+1 ad hi in registers. -John]


If hi & lo are constants, then it is a very reasonable transformation
to expect the compiler to perform (on architectures where it is
beneficial). If not, then it is unlikely to be able to. Its not a
performance issue, its a correctness one: the two forms are only
equivalent when hi > lo.


Of course an intelligent optimizing compiler could look at the names of
the variables and deduce that that was indeed the case :-)
-------------
Mark Williams


Post a followup to this message

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