<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/76477>76477</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            [Flang] Compilation of a chain of indirect accesses of arrays needs a lot of time
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            flang:frontend
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          yus3710-fj
      </td>
    </tr>
</table>

<pre>
    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
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJy8V92O4yoSfhpyg4gwjh1ykYueZHx2pZHO0Wyv9rKFcdmhB4OXn_45T78Cx0l3Kz2js9KuFBG7qOKrKhdfgfBeDQZgj6ovqDquRAwn6_av0ZfbgpL-cdXa7nV_f1IeK4-Fwcr7CLh3dsRNfFTBRxzABx9VgDWiR0Tv5rHRwgzEwDM2AJ3HAmsbsO1xUCPgYLG046Q04HAC3Fut7bMyA5a2u6zD-P0JznoiKGvS8yhMl3yBF5AxQIefVThhVNOo1agCJgGXlKKaYmVuuch2b728fwcu3OxOUseTs4MTI2KHLHPgo84BoJqmGBLE4o_tcX-JNwmG3rrghHnr_bv0oJrOv7PiEnKRwdf9js4SH1tnY1AGsI8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