llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.01k stars 11.96k forks source link

[Flang] Compilation of a chain of indirect accesses of arrays needs a lot of time #76477

Closed yus3710-fj closed 10 months ago

yus3710-fj commented 10 months ago

This is an issue from Fujitsu testsuite.

Flang-new needs a lot of time to compile the following code. (The compilation command is executed with ulimit -t 300 in Fujitsu testsuite.)

The following are the test program, the result of time command of flang-new and gfortran compilation.

! test.f90
subroutine sub(a,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16,c17,n)
real(8),dimension(1:n) :: a
integer,dimension(1:n) :: c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16,c17
do i=1,n
  a(c1(c2(c3(c4(c5(c6(c7(c8(c9(c10(c11(c12(c13(c14(c15(c16(c17(i)))))))))))))))))) = 1.0
enddo
end subroutine
$ time flang-new -v test.f90 -c
flang-new version 18.0.0git (https://github.com/llvm/llvm-project.git 0e07bf91f7e3d5a53f0a51309da12e91ea8accc9)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /path/to/install/bin
Found candidate GCC installation: /opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12
Selected GCC installation: /opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12
Candidate multilib: .;@m64
Selected multilib: .;@m64
 "/path/to/install/bin/flang-new" -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu generic -target-feature +neon -target-feature +v8a -mframe-pointer=non-leaf -o test.o -x f95-cpp-input test.f90
^C
real    6m0.521s
user    0m0.901s
sys     0m0.163s
$ time gfortran -v test.f90 -c
Using built-in specs.
COLLECT_GCC=gfortran
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/aarch64-redhat-linux/8/lto-wrapper
Target: aarch64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-gnu-indirect-function --build=aarch64-redhat-linux
Thread model: posix
gcc version 8.5.0 20210514 (Red Hat 8.5.0-18) (GCC)
 :

real    0m0.126s
user    0m0.066s
sys     0m0.006s

It seems that parsing takes a long time.

$ time flang-new -fc1 -E test.f90  -o /dev/null 

real    0m1.142s
user    0m0.886s
sys     0m0.151s
$ time flang-new -fc1 -fdebug-dump-parse-tree-no-sema test.f90
^C

real    6m30.762s
user    6m30.564s
sys     0m0.132s
llvmbot commented 10 months ago

@llvm/issue-subscribers-flang-frontend

Author: Yusuke MINATO (yus3710-fj)

This is an issue from Fujitsu testsuite. Flang-new needs a lot of time to compile the following code. (The compilation command is executed with `ulimit -t 300` in Fujitsu testsuite.) The following are the test program, the result of `time` command of flang-new and gfortran compilation. ```fortran ! test.f90 subroutine sub(a,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16,c17,n) real(8),dimension(1:n) :: a integer,dimension(1:n) :: c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16,c17 do i=1,n a(c1(c2(c3(c4(c5(c6(c7(c8(c9(c10(c11(c12(c13(c14(c15(c16(c17(i)))))))))))))))))) = 1.0 enddo end subroutine ``` ```console $ time flang-new -v test.f90 -c flang-new version 18.0.0git (https://github.com/llvm/llvm-project.git 0e07bf91f7e3d5a53f0a51309da12e91ea8accc9) Target: aarch64-unknown-linux-gnu Thread model: posix InstalledDir: /path/to/install/bin Found candidate GCC installation: /opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12 Selected GCC installation: /opt/rh/gcc-toolset-12/root/usr/lib/gcc/aarch64-redhat-linux/12 Candidate multilib: .;@m64 Selected multilib: .;@m64 "/path/to/install/bin/flang-new" -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu generic -target-feature +neon -target-feature +v8a -mframe-pointer=non-leaf -o test.o -x f95-cpp-input test.f90 ^C real 6m0.521s user 0m0.901s sys 0m0.163s ``` ```console $ time gfortran -v test.f90 -c Using built-in specs. COLLECT_GCC=gfortran COLLECT_LTO_WRAPPER=/usr/libexec/gcc/aarch64-redhat-linux/8/lto-wrapper Target: aarch64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --with-isl --disable-libmpx --enable-gnu-indirect-function --build=aarch64-redhat-linux Thread model: posix gcc version 8.5.0 20210514 (Red Hat 8.5.0-18) (GCC) : real 0m0.126s user 0m0.066s sys 0m0.006s ``` It seems that parsing takes a long time. ```console $ time flang-new -fc1 -E test.f90 -o /dev/null real 0m1.142s user 0m0.886s sys 0m0.151s $ time flang-new -fc1 -fdebug-dump-parse-tree-no-sema test.f90 ^C real 6m30.762s user 6m30.564s sys 0m0.132s ```
klausler commented 10 months ago

Fixed by https://github.com/llvm/llvm-project/pull/76533.

klausler commented 10 months ago

Patch has been merged into llvm-project/main.