[Bug c/108500] New: -O -finline-small-functions results in "internal compiler error: Segmentation fault" on a very large program (700k function calls)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108500 Bug ID: 108500 Summary: -O -finline-small-functions results in "internal compiler error: Segmentation fault" on a very large program (700k function calls) Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: dhekir at gmail dot com Target Milestone: --- Created attachment 54328 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54328&action=edit compressed version of a simplified program causing the ICE In the attached preprocessed program (compressed with .tar.gz), running 'gcc -O -finline-small-functions' results in: gcc: internal compiler error: Segmentation fault signal terminated program cc1 The original program is more interesting than this simplified version. Still, it does have more than 700k function calls in the main function, which is causing the problem. The original command line was simply 'gcc -O2', then I narrowed the options down to -finline-small-functions. I tried several GCC Docker images (running 'gcc -O2' on the attached file), and I narrowed it down to: - with gcc:10.4 (or older), compilation works without any errors; - with gcc:11.1 (or newer; I tested up to 12.2.0), segmentation fault happens.
[Bug c/108500] -O -finline-small-functions results in "internal compiler error: Segmentation fault" on a very large program (700k function calls)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108500 dhekir at gmail dot com changed: What|Removed |Added Attachment #54328|0 |1 is obsolete|| --- Comment #1 from dhekir at gmail dot com --- Created attachment 54329 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54329&action=edit .tar.gz compressed version of program causing crash
[Bug tree-optimization/108500] [11/12 Regression] -O -finline-small-functions results in "internal compiler error: Segmentation fault" on a very large program (700k function calls)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108500 --- Comment #12 from dhekir at gmail dot com --- Created attachment 54386 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54386&action=edit another test case, this time with 1M calls and structs as arguments A more complex test case, which still works (no segmentation fault), but takes too long to compile.
[Bug tree-optimization/108500] [11/12 Regression] -O -finline-small-functions results in "internal compiler error: Segmentation fault" on a very large program (700k function calls)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108500 --- Comment #13 from dhekir at gmail dot com --- Thank you very much for the work. Running the attached file with `-O -finline-small-functions` does compile in under 30 seconds on my computer. However, when trying to compile the original program (which is about 1 million lines, and each call passes 2 structures as arguments, instead of just calling a function without any arguments), it's taking several dozen minutes. I tried preprocessing it (5s to obtain the .i) file, and then running it with `-O -finline-small-functions`, or `-O2`, or `-O3`, and without any options at all, and in all cases, I ended up terminating the program before it finished (after more than 10 minutes; in some cases I waited up to 30 minutes). I tried re-simplifying the program. After preprocessing, I tried the following variants, with options `-O -finline-small-functions`: - 1M calls, no arguments, function returning a (global) struct: compiles in 30s; - 1M calls, each with a single argument of type `struct s`, function returns that same argument (that is, `struct s f(struct s s1) {return s1;}`): compiles in <2 minutes; - 1M calls, each with 2 arguments of types `struct s1` and `struct s2`, returning the second argument (that is, `struct s2 f(struct s1 arg1, struct s2 arg2) {return arg2;}`): >50 minutes (I had to terminate it). The last version, with -O2, I left it compiling for almost 3h before having to stop it. In any case, this bug seems definitely solved for me, and I no longer have the original stack overflow. However, I am still unable to compile my original code, so I'll have to try something else. It's possibly not a regression, however. I'm attaching it in case you may want to try it, but feel free to ignore it.
[Bug tree-optimization/108500] [11/12 Regression] -O -finline-small-functions results in "internal compiler error: Segmentation fault" on a very large program (700k function calls)
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108500 --- Comment #17 from dhekir at gmail dot com --- To be honest, the "real" test case is very similar to the last one I sent: it's a semi-generated code, with some initialization of the data in the beginning, and then a lot of statements which perform not necessarily useful operations, and in the end a few assertions are checked (e.g. that the initialized data was not tampered with). So, in reality, I expected GCC to discard most of the program after optimization and execute it almost instantly. When I encountered the segmentation fault during compilation, I thought it might also be relevant for other users, so I submitted the bug. Now, however, that the issue is mostly a "performance" issue, it's less likely that other users will encounter such a huge program with "useful" purposes, so I understand completely if you decide this is just not interesting/useful enough. To be honest, I tried compiling the code with other open source C compilers (Clang, and another not-so-mature one), and one failed with a stack overflow, and the other didn't complete until 1h30m, so I terminated it. So, the simple fact that you were able to succesfully compile it with those options is already very interesting to me and sufficient for my "real" test case.