sched-deps.cc (find_modifiable_mems): Avoid exponential behavior [PR96388]
commit0c42d1782e48d8ad578ace2065cce9b3615f97c0
authorMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>
Sun, 19 Nov 2023 08:43:05 +0000 (19 08:43 +0000)
committerMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>
Wed, 17 Jan 2024 07:47:37 +0000 (17 07:47 +0000)
tree3dd2b3476a03aa17d296a73929640ec9f68a3570
parent25bb8a40abd91fccf9a59dd6518a7a283433dea3
sched-deps.cc (find_modifiable_mems): Avoid exponential behavior [PR96388]

This patch avoids sched-deps.cc:find_inc() creating exponential number
of dependencies, which become memory and compilation time hogs.
Consider example (simplified from PR96388) ...
===
sp=sp-4 // sp_insnA
mem_insnA1[sp+A1]
...
mem_insnAN[sp+AN]
sp=sp-4 // sp_insnB
mem_insnB1[sp+B1]
...
mem_insnBM[sp+BM]
===

[For simplicity, let's assume find_inc(backwards==true)].
In this example find_modifiable_mems() will arrange for mem_insnA*
to be able to pass sp_insnA, and, while doing this, will create
dependencies between all mem_insnA*s and sp_insnB -- because sp_insnB
is a consumer of sp_insnA.  After this sp_insnB will have N new
backward dependencies.
Then find_modifiable_mems() gets to mem_insnB*s and starts to create
N new dependencies for _every_ mem_insnB*.  This gets us N*M new
dependencies.

In PR96833's testcase N and M are 10k-15k, which causes RAM usage of
30GB and compilation time of 30 minutes, with sched2 accounting for
95% of both metrics.  After this patch the RAM usage is down to 1GB
and compilation time is down to 3-4 minutes, with sched2 no longer
standing out on -ftime-report or memory usage.

gcc/ChangeLog:

PR rtl-optimization/96388
PR rtl-optimization/111554
* sched-deps.cc (find_inc): Avoid exponential behavior.
gcc/sched-deps.cc