Do pointers keep the ban on compiler optimization?

I tried to pass an array to a subroutine declared in the subroutine as the intended array of the form. This gave me some problems that I could solve by passing a pointer instead.

But some high-profile user tells me in a comment:

Adding a pointer is also a smart way to tell the compiler optimizer that it should not do any work today.

Can anyone suggest a short explanation for this? Fortran 95 language, although I believe this applies to other languages.

+6
source share
1 answer

Yes, Fortran compilers should assume that pointers can be an alias with other pointers and with target variables.

If you have pointer arrays a and b , then in

  a(i) = a(i) + b(i) 

the compiler should assume that these two arrays may partially overlap and it should block certain optimizations, since changing the value of a may change some value of b at some unknown index.

See also the C restrict keyword and a more in-depth discussion in Is Fortran optimized better than C for heavy computing? . Do not repeat all the points associated with the pointer alias raised there.

IanH's comment was intentionally, perhaps too strong, but it contains a lot of truth.

+4
source

Source: https://habr.com/ru/post/1013012/


All Articles