[Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003 Dominique d'Humieres dominiq at lps dot ens.fr changed: What|Removed |Added CC||dominiq at lps dot ens.fr --- Comment #12 from Dominique d'Humieres dominiq at lps dot ens.fr --- *** Bug 60006 has been marked as a duplicate of this bug. ***
[Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003 --- Comment #10 from Jakub Jelinek jakub at gcc dot gnu.org --- Author: jakub Date: Sat Feb 1 08:40:31 2014 New Revision: 207382 URL: http://gcc.gnu.org/viewcvs?rev=207382root=gccview=rev Log: PR tree-optimization/60003 * gimple-low.c (lower_builtin_setjmp): Set cfun-has_nonlocal_label. * profile.c (branch_prob): Use gimple_call_builtin_p to check for BUILT_IN_SETJMP_RECEIVER. * tree-inline.c (copy_bb): Call notice_special_calls. * gcc.c-torture/execute/pr60003.c: New test. Added: trunk/gcc/testsuite/gcc.c-torture/execute/pr60003.c Modified: trunk/gcc/ChangeLog trunk/gcc/gimple-low.c trunk/gcc/profile.c trunk/gcc/testsuite/ChangeLog trunk/gcc/tree-inline.c
[Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003 Jakub Jelinek jakub at gcc dot gnu.org changed: What|Removed |Added Status|ASSIGNED|RESOLVED Resolution|--- |FIXED --- Comment #11 from Jakub Jelinek jakub at gcc dot gnu.org --- Fixed.
[Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003 --- Comment #2 from Jakub Jelinek jakub at gcc dot gnu.org --- Ah, I see what's going on. eliminate_unnecessary_calls in dce calls clear_special_calls. Before my patch, __builtin_setjmp lowering would add a dummy non-local label to the function, so that while dce would clear cfun-calls_setjmp, cfun-has_nonlocal_label would be still set, but with my patch that is no longer happening, so stmt_can_make_abnormal_goto is always false during inlining and the corresponding edges aren't added. So, either e.g. tree-cfg.c could just set cfun-has_nonlocal_label when it sees a __builtin_setjmp_receiver (or say gimple-low.c when lowering __builtin_setjmp could set it) to restore status quo. Or I wonder, is there any special reason to avoid cfun-calls_setjmp when you actually call setjmp? Like say make __builtin_setjmp_receiver ECF_RETURNS_TWICE, or just special casing it in notice_special_calls and in the inliner (which just should call notice_special_calls)?
[Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003 --- Comment #3 from Jakub Jelinek jakub at gcc dot gnu.org --- Created attachment 31997 -- http://gcc.gnu.org/bugzilla/attachment.cgi?id=31997action=edit gcc49-pr60003-1.patch Untested quick hack to set cfun-has_nonlocal_label, seems to work on this testcase.
[Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003 --- Comment #4 from Eric Botcazou ebotcazou at gcc dot gnu.org --- Ah, I see what's going on. eliminate_unnecessary_calls in dce calls clear_special_calls. Before my patch, __builtin_setjmp lowering would add a dummy non-local label to the function, so that while dce would clear cfun-calls_setjmp, cfun-has_nonlocal_label would be still set, but with my patch that is no longer happening, so stmt_can_make_abnormal_goto is always false during inlining and the corresponding edges aren't added. OK, thanks for analysis. So, either e.g. tree-cfg.c could just set cfun-has_nonlocal_label when it sees a __builtin_setjmp_receiver (or say gimple-low.c when lowering __builtin_setjmp could set it) to restore status quo. At the RTL level, cfun-has_nonlocal_label is set when __builtin_setjmp_setup is expanded (in expand_builtin_setjmp_setup) so I think that we should do the same at the Tree level. My preference would be for gimple-low.c but no strong opinion. Or I wonder, is there any special reason to avoid cfun-calls_setjmp when you actually call setjmp? Like say make __builtin_setjmp_receiver ECF_RETURNS_TWICE, or just special casing it in notice_special_calls and in the inliner (which just should call notice_special_calls)? Historically cfun-calls_setjmp is a big hammer that disables optimization passes, which was unnecessary for __builtin_setjmp because everything is exposed in the IL. Nowadays the distinction with the regular setjmp is less clear, but I think that we should lean towards clearing cfun-calls_setjmp rather than setting it, or else reducing its impact on optimization passes.
[Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003 --- Comment #5 from Jakub Jelinek jakub at gcc dot gnu.org --- Created attachment 31998 -- http://gcc.gnu.org/bugzilla/attachment.cgi?id=31998action=edit gcc49-pr60003-2.patch Untested variant which makes __builtin_setjmp_receiver a returns twice function. For some strange reason this doesn't work, the test hangs.
[Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003 --- Comment #6 from Jakub Jelinek jakub at gcc dot gnu.org --- Created attachment 31999 -- http://gcc.gnu.org/bugzilla/attachment.cgi?id=31999action=edit gcc49-pr60003-3.patch Untested third variant, which just makes sure cfun-calls_setjmp is set even for __builtin_setjmp_receiver. This one seems to work for the testcase.
[Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003 --- Comment #7 from Jakub Jelinek jakub at gcc dot gnu.org --- (In reply to Eric Botcazou from comment #4) So, either e.g. tree-cfg.c could just set cfun-has_nonlocal_label when it sees a __builtin_setjmp_receiver (or say gimple-low.c when lowering __builtin_setjmp could set it) to restore status quo. At the RTL level, cfun-has_nonlocal_label is set when __builtin_setjmp_setup is expanded (in expand_builtin_setjmp_setup) so I think that we should do the same at the Tree level. My preference would be for gimple-low.c but no strong opinion. Ok, so you prefer the first patch? Now to write some comment explaining why... Or I wonder, is there any special reason to avoid cfun-calls_setjmp when you actually call setjmp? Like say make __builtin_setjmp_receiver ECF_RETURNS_TWICE, or just special casing it in notice_special_calls and in the inliner (which just should call notice_special_calls)? Historically cfun-calls_setjmp is a big hammer that disables optimization passes, which was unnecessary for __builtin_setjmp because everything is exposed in the IL. Nowadays the distinction with the regular setjmp is less clear, but I think that we should lean towards clearing cfun-calls_setjmp rather than setting it, or else reducing its impact on optimization passes. At GIMPLE level indeed, cfun-calls_setjmp is now purely about whether the abnormal edges are constructed or not, the tree-tailcall.c use probably could go. For normal setjmp calls (and fork etc.) we do nothing though at the RTL level though, so cfun-calls_setjmp is probably still needed there.
[Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003 --- Comment #8 from Eric Botcazou ebotcazou at gcc dot gnu.org --- Ok, so you prefer the first patch? Now to write some comment explaining why... Yes, I'm very fond of one-liners. :-) You can say that the label taken by __builtin_setjmp is treated as a non-local label by the middle-end.
[Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003 Jakub Jelinek jakub at gcc dot gnu.org changed: What|Removed |Added Status|NEW |ASSIGNED Assignee|unassigned at gcc dot gnu.org |jakub at gcc dot gnu.org --- Comment #9 from Jakub Jelinek jakub at gcc dot gnu.org --- Created attachment 32000 -- http://gcc.gnu.org/bugzilla/attachment.cgi?id=32000action=edit gcc49-pr60003.patch Ok, so this is what I'm going to bootstrap/regtest.
[Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003 Richard Biener rguenth at gcc dot gnu.org changed: What|Removed |Added Priority|P3 |P1
[Bug tree-optimization/60003] [4.9 regression] wrong code with __builtin_setjmp/__builtin_longjmp and inlining
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60003 Jakub Jelinek jakub at gcc dot gnu.org changed: What|Removed |Added Status|UNCONFIRMED |NEW Last reconfirmed||2014-01-30 Target Milestone|--- |4.9.0 Ever confirmed|0 |1 --- Comment #1 from Jakub Jelinek jakub at gcc dot gnu.org --- Thanks for the report, will have a look tomorrow.