PGI not inlining function across files

Questions on using the PGI Compilers and Tools
mkcolg
Posts: 8137
Joined: Jun 30 2004

Re: PGI not inlining function across files

Post by mkcolg » Wed Dec 04, 2019 8:25 am

Hi Yannick,

No, LLVM is expected to have the same behavior as the non-LLVM back-end. Are you able to share the code? If so, I can write-up an issue report and have our engineers take a look.

Thanks,
Mat

yboetzel
Posts: 7
Joined: Nov 26 2019

Re: PGI not inlining function across files

Post by yboetzel » Wed Dec 04, 2019 8:31 am

Hi Mat

Thanks for the quick reply. I'm not able to share the code here, though I'll try to see if I can reproduce it in a simple example. I'll also check if we can make the code available to you directly somehow. I'll update tomorrow.

Thanks
Yannick

yboetzel
Posts: 7
Joined: Nov 26 2019

Re: PGI not inlining function across files

Post by yboetzel » Thu Dec 05, 2019 1:13 am

Hi Mat

I prepared a small example to reproduce the behavior I observed, you can find in on my github:
https://github.com/yboetz/pgi-inline-example

There is a simple main function with a do loop, and in this loop there is a call to another function defined in the file utils.f90. The Makefile is copied from the PGI documentation to first extract an inline library and then inline the function into main.f90. Here is what I observed:

When compiling on PGI 18.5, I get the following output:

Code: Select all

$ make
pgfortran -O2 -Minfo=all -Mllvm -Mextract=15 -o utils.il utils.f90
pgfortran -O2 -Minfo=all -Mllvm -Minline=utils.il -c main.f90
main:
     17, Memory set idiom, loop replaced by call to __c_mset4
     23, Loop not vectorized: may not be beneficial
         Loop unrolled 4 times
     24, pow2 inlined, size=2, file utils.f90 (12)
pgfortran -O2 -Minfo=all -Mllvm -c utils.f90
pgfortran -o myprog main.o utils.o
The function pow2 is thus correctly inlined. I can also remove the -Mllvm flag and get the same result.

When compiling with PGI 19.5/7/9 I get the following output:

Code: Select all

$ make
pgfortran -O2 -Minfo=all -Mllvm -Mextract=15 -o utils.il utils.f90
pgfortran -O2 -Minfo=all -Mllvm -Minline=utils.il -c main.f90
main:
     17, Memory set idiom, loop replaced by call to __c_mset4
     23, Loop not vectorized/parallelized: contains call
pgfortran -O2 -Minfo=all -Mllvm -c utils.f90
pgfortran -o myprog main.o utils.o
The function pow2 is not inlined here! Once I set the flag '-Mnollvm' for PGI 19.x, I get the same behavior as for PGI 18.5 though, with the function pow2 inlined correctly:

Code: Select all

$ make
pgfortran -O2 -Minfo=all -Mnollvm -Mextract=15 -o utils.il utils.f90
pgfortran -O2 -Minfo=all -Mnollvm -Minline=utils.il -c main.f90
main:
     17, Memory set idiom, loop replaced by call to __c_mset4
     23, Loop not vectorized: loop count too small
         Loop unrolled 8 times
     24, pow2 inlined, size=2, file utils.f90 (12)
pgfortran -O2 -Minfo=all -Mnollvm -c utils.f90
pgfortran -o myprog main.o utils.o
Can you confirm this? Or is there something wrong with our PGI 19.x installation? I tried on two different machines of CSCS (https://www.cscs.ch/) and get the same result.


Thanks
Yannick

mkcolg
Posts: 8137
Joined: Jun 30 2004

Re: PGI not inlining function across files

Post by mkcolg » Thu Dec 05, 2019 9:28 am

Thanks Yannick. I was able to reproduce the problem and have filed a report (TPR #27904). Looks like something changed in the compiler around the 18.7 release that prevents it from inlining when using the LLVM back-end. The older non-LLVM based compilers seem to be able to inline it so you can use them as a work around for now.

-Mat

Post Reply