Passing intent(in) to the midend

Consider the following code:

integer :: arr1(42), arr2(42) ! global

recursive subroutine foo(a)

integer, intent(in) :: a

! first load of “a” here

if (a > 20) then



arr1(0) = a

call foo(a + 1)

arr2(0) = a ! ← redundant load here

end subroutine foo

As per the Fortran 90 standard [1], intent(in) for variable a “specifies that the dummy argument must not be redefined or become undefined during the execution of the procedure”. Thus, we can assume that the call to foo() does not modify a, so the redundant load can be safely removed (e.g., by the GVN pass in the midend).

How can we pass the intent(in) information to the midend so we could take advantage of it?

[1] The Fortran 90 standard, section



Hi Alexey,

If you mark the argument as

  noalias, readonly, nofree, dereferenceable(4)

in LLVM-IR you should see the desired effects, e.g. load coalescing.

The way I understand `intent(in)` the above should be valid.

I hope this helps,