Hi Steve,
subroutine foo(n)
integer n
integer i, j
i = 2
j = 4
n = i**j ! <-- This should evaluate to 16 without a function call.
end subroutine foo
To do this in the Fortran front end would require constant propagation,
which we currently do not do.
We do not do this because the general case would be quite hard without
doing the same kind of thing the middle end does - splitting into
basic blocks, converting to single static assignment, etc.
I suspect the best way would be to teach the back end about how
Fortran's library functions behave with constant arguments. This
would sort of duplicate simplification, but could still be
beneficial.
We could implement this as a Fortran-specific pass to be called
after constant propagation.
Comments?
Regards
Thomas