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 tree-optimization/42970] Missed unused function return value elimination Date: Mon, 11 Nov 2013 09:12:00 -0000 [thread overview] Message-ID: <bug-42970-4-tXRv77SQMh@http.gcc.gnu.org/bugzilla/> (raw) In-Reply-To: <bug-42970-4@http.gcc.gnu.org/bugzilla/> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42970 --- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> --- Consider LTO. Note that the issue is that while we remove assignments to unused variables from calls at the caller side we never remove a never used return value from a return statement. This keeps the computation of 'counter' and 'counter' itself life and thus weakens IPA reference analysis. For the following testcase we should be able to remove the call to quantum_gate_counter _without using the trick of inlining it_. Basically some IPA optimization should figure out that 'return counter' is dead and it and all producing stmts can be elimiated. You cannot elimiate the return stmt if you don't change the functions signature, but if you don't want to do that you can for example just return 0. It get's tricky with the requirements in the description but the idea was that the early IPA-SRA pass would clone the function for "unused return value", local passes then would eliminate all stmts in the clone making it const and thus we win. The tricky part here is that early opts don't see the whole program so that quantum_gate_counter is exported (and we share the 'counter' variable with the original function which cannot be eliminated). static int __attribute__((noinline,noclone)) quantum_gate_counter(int inc) { static int counter = 0; if(inc > 0) counter += inc; else if(inc < 0) counter = 0; return counter; } int main() { quantum_gate_counter (1); return 0; }
prev parent reply other threads:[~2013-11-11 9:12 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top [not found] <bug-42970-4@http.gcc.gnu.org/bugzilla/> 2010-11-10 17:24 ` hubicka at gcc dot gnu.org 2013-11-10 19:33 ` pinskia at gcc dot gnu.org 2013-11-10 19:42 ` ktietz at gcc dot gnu.org 2013-11-11 9:12 ` rguenth at gcc dot gnu.org [this message]
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-42970-4-tXRv77SQMh@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).