Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!zaphod.mps.ohio-state.edu!wuarchive!udel!haven!uvaarpa!murdoch!astsun7.astro.Virginia.EDU!gl8f From: gl8f@astsun7.astro.Virginia.EDU (Greg Lindahl) Newsgroups: comp.lang.fortran Subject: Re: strength reduction of array address calculations Message-ID: <1990Nov28.213735.25563@murdoch.acc.Virginia.EDU> Date: 28 Nov 90 21:37:35 GMT References: <17680:Nov2806:04:1090@kramden.acf.nyu.edu> <1990Nov28.065242.10154@murdoch.acc.Virginia.EDU> Sender: news@murdoch.acc.Virginia.EDU Organization: Department of Astronomy, University of Virginia Lines: 24 In article burley@pogo.ai.mit.edu (Craig Burley) writes: >Hmm, could you explain to me how to strength-reduce multiplication to addition >for random references to array elements within loops, as in You can't. But many references are regular. So in this loop: do j = 1, 100 do i = 1, 100 bleah = a( i, j ) enddo ^^^^ - all loop vars enddo you know that you can *always* strength-reduce the address calculation, without any fancy analysis whatsoever. Moreover, even with a 1-d array, you can often easily see that an address is being incremented by 4 or 8 bytes, and avoid having to calculate an index and shift it left 2 or 4 bits. A C compiler, on the other hand, would have to verify that the loop variables weren't modified inside the loop. Since you're working with a sophisticated compiler, the last point isn't that important to you, but if you are working on a simple compiler, simple optimization possibilities are nice to have around.