Re: Automatically transform or expand do loop in a subroutine



Thanks for replies from all of you, especially from Arjen, James and
***.

I knew algorithm optimization is much more important absolutely. But
here we are trying to do further optimization with code generation
assuming the algorithm has been fully optimized (only assume, we can
never say this in reality I guess but this is not my point). I wrote
that piece of code in a minute for purpose of demonstration of the
idea of loop unrolling in the situation. So we do not need to care its
detail. James proposed a situation where loop unrolling might not a
good choice. I do not know to what extent we will reach that
situation. Anyway, my real problem is probably not the case.

***, are you sure compilers can handle this case? Because two steps
will be involved, first the compiler inlines the function and then
notices the argument is known before run-time and does the loop
unrolling. I need to test this.

Thanks.

On Jan 31, 11:44 am, *** Hendrickson <***.hendrick...@xxxxxxx>
wrote:

Two other things to try. Many commercial compilers have some
sort of option to "inline" external procedures. Often controlled
by a command line switch. Look for this. You'll probably have to
have the program and function in the same file. If the code is
inlined, then the compiler will see the 10. Another way to
do the same thing is to make the function be an internal procedure
to the main program. The compiler is more likely to be able to
do optimizations.

Finally, as others have suggested, it's not a good idea to have
functions modify their arguments. If nothing else, it just gives
the optimizer one more reason to not do things. Make it a
subroutine.

*** Hendrickson


.