[Transforms][GlobalSRA] huge array causes long compilation time and huge memory usage.
authorAlexey Lapshin <a.v.lapshin@mail.ru>
Tue, 24 Dec 2019 21:38:09 +0000 (00:38 +0300)
committerAlexey Lapshin <a.v.lapshin@mail.ru>
Sat, 4 Jan 2020 13:42:38 +0000 (16:42 +0300)
commit831bfcea47826a102ece03f0fad33ce39a73c672
treebb7b1888d2d50532cbe19602ff2e6354b58cc843
parenteb0e1978df7b9e7df3e645bb48fbf655f8aab69a
[Transforms][GlobalSRA] huge array causes long compilation time and huge memory usage.

Summary:
For artificial cases (huge array, few usages), Global SRA optimization creates
a lot of redundant data. It creates an instance of GlobalVariable for each array
element. For huge array, that means huge compilation time and huge memory usage.
Following example compiles for 10 minutes and requires 40GB of memory.

namespace {
  char LargeBuffer[64 * 1024 * 1024];
}

int main ( void ) {

    LargeBuffer[0] = 0;

    printf("\n ");

    return LargeBuffer[0] == 0;
}

The fix is to avoid Global SRA for large arrays.

Reviewers: craig.topper, rnk, efriedma, fhahn

Reviewed By: rnk

Subscribers: xbolva00, lebedev.ri, lkail, merge_guards_bot, hiraditya, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D71993
llvm/lib/Transforms/IPO/GlobalOpt.cpp
llvm/test/Transforms/GlobalOpt/long-compilation-global-sra.ll [new file with mode: 0644]