Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs have moved to the Altera Community. Existing Intel Community members can sign in with their current credentials.

Optimisation Past Subroutine Calls

Ben3
Beginner
926 Views

Hi All,

This might be a silly question, but I can't seem to decide on the answer myself. Is a compiler allowed to optimise past a call to a subroutine? For example, consider this:

subroutine sub ( l, r )
  real(8), intent(inout) :: l(*), r(*)
  l(2) = 2.0_8
  call other_sub(l(1), r(1))
  l(2) = r(2)
end subroutine sub

Is the compiler allowed to remove the first assignment, since other_sub is called with only the first elements of the arrays?

I'm most considering the case when there's no interface for other_sub. I often see calls like this for MPI calls in some of our old code, passing the first element of an array section as the buffer with a non-unit buffer size. I'm worried this might eventually break things if extra optimisations are used.

Cheers,

Ben

0 Kudos
1 Solution
Steven_L_Intel1
Employee
926 Views

I would say no, because "sequence association" allows other_sub to access additional elements of the array.

View solution in original post

0 Kudos
4 Replies
Steven_L_Intel1
Employee
927 Views

I would say no, because "sequence association" allows other_sub to access additional elements of the array.

0 Kudos
Ben3
Beginner
926 Views

Steve Lionel (Intel) wrote:

I would say no, because "sequence association" allows other_sub to access additional elements of the array.

Thanks, I had forgotten about sequence association.

0 Kudos
jimdempseyatthecove
Honored Contributor III
926 Views

Steve,

With IPO enabled, and where the source to other_sub is discoverable (and can be inlined), the compiler optimization code should be able to see if there are any dependencies on the l(2) = 2.0_8, and if none, remove the unnecessary statement.

Jim Dempsey

0 Kudos
Steven_L_Intel1
Employee
926 Views

Jim, sure, but I think that is not the situation being asked about.

0 Kudos
Reply