llvm / llvm/llvm-project

[Flang] Extremely slow compilation of partially initialized large arrays in COMMON blocks

Open
#209,393 4 comments 0 reactions 0 assignees View on GitHub
flang slow-compile
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

Flang takes tens of seconds to compile a source that partially initializes a large array in a named COMMON block (only a few leading elements have a DATA value, the rest default to zero). Compile time grows quadratically with the array size. Intel compiler and Gfortran handle the same input in ~1s.

Expected behavior: A partially initialized large array in a COMMON block compiles in roughly linear time, comparable to a fully initialized or uninitialized array of the same size.

Actual behavior: Compilation time blows up super-linearly (O(N^2)) with the array length. For a 55,000-element array the front end spends ~40s just generating LLVM IR; larger arrays get dramatically worse. There is no diagnostic, it simply hangs for a long time and then succeeds.

Reproducer:

```Fortran
Block Data
Integer i(55000)
Common /b/ i
Data (i(j), j = 1, 2) / 7, 77 /
End Block Data
```

Contributor guide

Open the contributing guide

Research direction

Start with the provided Block Data reproducer and compare compilation time as the COMMON-block array size changes. Investigate the Flang front end's LLVM IR generation for partially initialized arrays, comparing it with fully initialized and uninitialized cases. Done means the partial-initialization case scales roughly linearly and approaches the comparable cases.

Written by the indexing model from the issue text.

Assessment

Tech stack
fortran
Domain
compilers, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.