https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107819
--- Comment #8 from Mikael Morin <mikael at gcc dot gnu.org> --- (In reply to anlauf from comment #3) > Could need help by some expert on this... I guess I qualify as expert. Reading the code again after years, it is not exactly crystal clear... Here is a dump of what I could gather about the gfc_check_fncall_dependency and friends functions. The different gfc_dep_check cases are the following: ELEM_DONT_CHECK_VARIABLE: This is the simple case of direct subroutine call. As per the 15.5.2.13 I quoted above, this is invalid: call elem_sub(a(2:n), a(1:n-1)) while this isn't call elem_sub(a, a) so we can always generate: do i = ... call elem_sub(a(...), a(...)) end do without caring for temporaries ELEM_CHECK_VARIABLE: This is the case of multiple elemental procedures. For example: call elem_sub(a, elem_func(a)) The semantics is like: tmp = elem_func(a) call elem_sub(a, tmp) Here, elem_sub can write to a without modifying tmp, and we have to preserve that. We generate code like this: do i = ... call elem_sub(tmp(i), elem_func(a(i))) end do a = tmp and try to avoid the temporary tmp if possible. we explore the second argument to elem_sub and look for the same variable as the expression from the first one, and we generate a temporary if we find it. But there is no need if they are strictly the same variable reference. NOT_ELEMENTAL: This is the case of the presence of transpose in the expression For example, for elem_sub(var, elem_func(transpose(var))), the semantics is: tmp1 = transpose(var) tmp2 = elem_func(tmp1) call elem_sub(var, tmp2) which we try to preserve, but with less temporaries. We try to generate do i = ..., j = ... call elem_sub(tmp(i,j), elem_func(var(j,i))) end do var = tmp and try to avoid the temporary tmp if possible (it's not with this example). We have to make sure that if the same variable appears in a subexpression of the argument, a temporary is generated. Contrary to the previous case, we have to generate the temporary even if the variable references are strictly the same.