public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug ipa/94693] New: IPA SRA should elide unused out parameters Date: Tue, 21 Apr 2020 14:28:10 +0000 [thread overview] Message-ID: <bug-94693-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94693 Bug ID: 94693 Summary: IPA SRA should elide unused out parameters Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ipa Assignee: unassigned at gcc dot gnu.org Reporter: rguenth at gcc dot gnu.org CC: marxin at gcc dot gnu.org Target Milestone: --- IPA SRA should elide 'out' in struct outs { int kind; int i; }; void foo (struct outs *out) { if (out->kind == 0) ; else out->i = out->kind; } int main() { struct outs out; out.kind = 3; foo (&out); // 'out' is unused [after the call] } IPA SRA transform should then produce void foo.isra (int kind) { struct outs out_; out_.kind = kind; struct outs *out = out_; if (out->kind == 0) ; else out->i = out->kind; } int main() { struct outs out; out.kind = 3; foo (3); } and DCE can then eliminate the dead code. Note the same can work for the case where out is not written to at all in main () and thus nothing needs to be passed to foo (that might be the most common case, like when passing an alternate output by reference that's not needed). The testcase above is a more general case. If analysis at the call site is flow-sensitive it can check whether any side-effects to 'out' might be observable to handle { struct outs out; if (test) { out.kind = 3; foo (&out); // out is dead after the call } else { bar (&out); printf ("%d", out.i); } } but probably IPA SRA local analysis isn't that powerful. Note the advantage is not eliding the out variable at the caller side but possible dead code removal in the callee which need to compute it (similar to the now handled unused return value handling).
next reply other threads:[~2020-04-21 14:28 UTC|newest] Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-04-21 14:28 rguenth at gcc dot gnu.org [this message] 2020-04-21 14:28 ` [Bug ipa/94693] " rguenth at gcc dot gnu.org 2020-04-21 14:29 ` rguenth at gcc dot gnu.org 2020-04-21 14:47 ` rguenth at gcc dot gnu.org 2020-04-21 14:54 ` rguenth at gcc dot gnu.org 2020-04-21 15:30 ` egallager 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-94693-4@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).