Re: array manipulations and optimisation

Re: array manipulations and optimisation

Steve Lionel (Intel)'s picture

Semantically, the language establishes that the right side of the assignment is fully evaluated before the left side is modified. This in effect means two (at least) loops - one to create a temporary array with the expression result, then one to store the result. Early F90 compilers in fact did it this way.

Over the years, compiler writers have enhanced dependence analysis techniques that can often let a compiler detect that there is no overlap or loop-carried dependence and the operation can be simplified using direct stores as the computation progresses. Then the two loops can be combined into one in an optimization called loop fusion.

In the particular cases you mention, additional optimizations such as "strength reduction" can make the array operation as efficient as a DO loop, but sometimes a temp may still be created if the compiler isn't able to determine that it can be avoided.

Steve

Steve
2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.
Steve Lionel (Intel)'s picture

I don't know of any rules to suggest. My recommendation is to write the code in a clear manner and let the compiler worry about it. If you find you need more performance, use a profiler to find the hot spots and look more closely at what those hot spots are doing.

Steve

Steve

Login to leave a comment.