public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "anlauf at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/55978] class_optional_2.f90 -Os fails Date: Sat, 22 Jun 2024 17:35:06 +0000 [thread overview] Message-ID: <bug-55978-4-sgtJEKj6uv@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-55978-4@http.gcc.gnu.org/bugzilla/> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=55978 --- Comment #33 from anlauf at gcc dot gnu.org --- I've been repeatedly struggling with the testcase in comment#19. Since the dump-tree did not reveal anything, I ran a reduced version under gdb to see why the code crashes at -O0 and -Og but not at higher optimization. I got them impression that the dump-tree does not tell the full truth: subroutine one has { struct array01_integer(kind=4) * D.4292; D.4292 = x != 0B ? (struct array01_integer(kind=4) *) _gfortran_internal_pack (x) : 0B; two (D.4292); if (x != 0B && (integer(kind=4)[0:] *) x->data != (integer(kind=4)[0:] *) D.4292) { _gfortran_internal_unpack (x, D.4292); __builtin_free ((void *) D.4292); } } but to my untrained eye it looked like the test x->data != D.4292 was executed before x != 0B. This lead me to the following tentative patch: diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc index 19d69aec9c0..06bfea1f461 100644 --- a/gcc/fortran/trans-array.cc +++ b/gcc/fortran/trans-array.cc @@ -9025,7 +9100,7 @@ gfc_conv_array_parameter (gfc_se * se, gfc_expr * expr, bool g77, fold_convert (TREE_TYPE (tmp), ptr), tmp); if (fsym && fsym->attr.optional && sym && sym->attr.optional) - tmp = fold_build2_loc (input_location, TRUTH_AND_EXPR, + tmp = fold_build2_loc (input_location, TRUTH_ANDIF_EXPR, logical_type_node, gfc_conv_expr_present (sym), tmp); Strangely enough, this gives exactly the same dump-tree! (If someone knows why, please enlighten me!) But it fixed the issue. The I looked at the optimized tree. The reference version has: <bb 4> [local count: 1073741824]: # _5 = PHI <_19(3), y_17(D)(2)> two (_5); _1 = y_17(D) != 0B; _2 = y_17(D)->data; _3 = _2 != _5; _4 = _1 & _3; if (_4 != 0) goto <bb 5>; [33.00%] else goto <bb 6>; [67.00%] <bb 5> [local count: 354334800]: __builtin_free (_5); This explains the "boom". The version with the ANDIF has: <bb 4> [local count: 1073741824]: # _2 = PHI <_16(3), y_14(D)(2)> two (_2); if (y_14(D) != 0B) goto <bb 5>; [70.00%] else goto <bb 7>; [30.00%] <bb 5> [local count: 751619280]: _1 = y_14(D)->data; if (_1 != _2) goto <bb 6>; [53.47%] else goto <bb 7>; [46.53%] <bb 6> [local count: 401890828]: __builtin_free (_2); This looks sane to me: the data component is not referenced if the dummy is seen to be absent. Regtesting...
next prev parent reply other threads:[~2024-06-22 17:35 UTC|newest] Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top 2013-01-14 20:56 [Bug fortran/55978] New: [4.8 Regression] " tkoenig at gcc dot gnu.org 2013-01-14 21:30 ` [Bug fortran/55978] " tkoenig at gcc dot gnu.org 2013-01-14 22:33 ` dominiq at lps dot ens.fr 2013-01-14 23:03 ` tkoenig at gcc dot gnu.org 2013-01-15 9:55 ` rguenth at gcc dot gnu.org 2013-01-15 11:27 ` burnus at gcc dot gnu.org 2013-01-15 11:27 ` burnus at gcc dot gnu.org 2013-01-15 11:36 ` burnus at gcc dot gnu.org 2013-01-15 14:48 ` burnus at gcc dot gnu.org 2013-01-19 7:40 ` hp at gcc dot gnu.org 2013-01-25 17:44 ` dominiq at lps dot ens.fr 2013-02-04 13:11 ` ro at gcc dot gnu.org 2013-02-04 13:45 ` jakub at gcc dot gnu.org 2013-02-05 21:26 ` janus at gcc dot gnu.org 2013-02-05 22:27 ` janus at gcc dot gnu.org 2013-02-05 22:31 ` janus at gcc dot gnu.org 2013-02-05 22:46 ` burnus at gcc dot gnu.org 2013-02-06 10:55 ` janus at gcc dot gnu.org 2013-02-06 11:17 ` burnus at gcc dot gnu.org 2013-02-06 11:45 ` janus at gcc dot gnu.org 2013-02-06 12:17 ` burnus at gcc dot gnu.org 2013-02-06 12:55 ` janus at gcc dot gnu.org 2013-02-06 13:01 ` janus at gcc dot gnu.org 2013-02-06 13:56 ` janus at gcc dot gnu.org 2013-02-06 19:41 ` janus at gcc dot gnu.org 2013-02-06 19:51 ` [Bug fortran/55978] " janus at gcc dot gnu.org 2013-03-22 14:45 ` jakub at gcc dot gnu.org 2013-05-31 10:59 ` jakub at gcc dot gnu.org 2013-10-16 9:49 ` jakub at gcc dot gnu.org 2015-06-22 14:25 ` rguenth at gcc dot gnu.org 2023-12-16 21:45 ` anlauf at gcc dot gnu.org 2023-12-16 21:47 ` anlauf at gcc dot gnu.org 2024-03-22 21:02 ` cvs-commit at gcc dot gnu.org 2024-03-23 20:13 ` cvs-commit at gcc dot gnu.org 2024-06-22 17:35 ` anlauf at gcc dot gnu.org [this message] 2024-06-24 17:25 ` cvs-commit at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-55978-4-sgtJEKj6uv@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).