Re: array index checking optimizations?

bill@amber.ssd.hcsc.com (Bill Leonard)
30 Apr 1996 23:54:02 -0400

          From comp.compilers

Related articles
array index checking optimizations? adams@yaroslav.ai.mit.edu (1996-04-29)
Re: array index checking optimizations? bill@amber.ssd.hcsc.com (1996-04-30)
Re: array index checking optimizations? kik@zia.cray.com (1996-04-30)
Re: array index checking optimizations? tmb@best.com (1996-05-01)
Re: array index checking optimizations? Laurent.Guerby@enst-bretagne.fr (Laurent Guerby) (1996-05-01)
Re: array index checking optimizations? markt@harlequin.co.uk (1996-05-01)
array index checking optimizations? dave@occl-cam.demon.co.uk (Dave Lloyd) (1996-05-02)
Re: array index checking optimizations? mad@math.keio.ac.jp (1996-05-03)
[5 later articles]
| List of all articles for this month |

From: bill@amber.ssd.hcsc.com (Bill Leonard)
Newsgroups: comp.compilers
Date: 30 Apr 1996 23:54:02 -0400
Organization: Harris Computer Systems, Ft. Lauderdale FL
References: 96-04-140
Keywords: optimize

adams@yaroslav.ai.mit.edu (Stephen Adams) writes:
> I am curious if there are any compilers out there that can detect that
> all the array references in the following program are safe, and thus
> no array indexes need to be checked.


The Harris Ada compiler does this sort of optimization. In fact, it
optimizes all range checks required by the language.


> 1. How does the analysis determine that the array indexes
> are in range?


The analysis actually determines that a test of 'i' against the range
of allowed array indices would always be true. It does this by
performing interval arithmetic on operations involving 'i' and using
flow analysis to propagate the results of assignments to 'i' to its
uses.


> 2. How fragile is the analysis, for example, does it still
> work if the condition in the while loop is changed to
> `while i <> last do'


Your example, not being legal Ada, is difficult to analyze to answer
your question. The main difficulty is that you haven't declared any
bounds on the arrays, so it's hard to know what information the
compiler has available.


If the bounds are compile-time constants (unlikely for array
arguments, at least in Ada), then I believe our compiler would
correctly eliminate the index tests, assuming that the initial value
of 'i' is within bounds.


--
Bill Leonard
Harris Computer Systems Corporation
2101 W. Cypress Creek Road
Fort Lauderdale, FL 33309
Bill.Leonard@mail.hcsc.com
--


Post a followup to this message

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