public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/42970] Missed unused function return value elimination
       [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
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 4+ messages in thread
From: hubicka at gcc dot gnu.org @ 2010-11-10 17:24 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42970

Jan Hubicka <hubicka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2010.11.10 17:24:29
                 CC|                            |hubicka at gcc dot gnu.org
     Ever Confirmed|0                           |1


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tree-optimization/42970] Missed unused function return value elimination
       [not found] <bug-42970-4@http.gcc.gnu.org/bugzilla/>
  2010-11-10 17:24 ` [Bug tree-optimization/42970] Missed unused function return value elimination 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
  3 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-11-10 19:33 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42970

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|WAITING                     |NEW


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tree-optimization/42970] Missed unused function return value elimination
       [not found] <bug-42970-4@http.gcc.gnu.org/bugzilla/>
  2010-11-10 17:24 ` [Bug tree-optimization/42970] Missed unused function return value elimination 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
  3 siblings, 0 replies; 4+ messages in thread
From: ktietz at gcc dot gnu.org @ 2013-11-10 19:42 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42970

Kai Tietz <ktietz at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ktietz at gcc dot gnu.org

--- Comment #1 from Kai Tietz <ktietz at gcc dot gnu.org> ---
This testcase seems to be invalid ...
The function quantum_gate_counter is visible out-side of the current TU.  So
nobody can predict that return-type isn't used by external users.  So
optimization can be done.

By adding static to the prototype of quantum_gate_counter for making it visible
only to local TU, things getting optimized as desired.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug tree-optimization/42970] Missed unused function return value elimination
       [not found] <bug-42970-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2013-11-10 19:42 ` ktietz at gcc dot gnu.org
@ 2013-11-11  9:12 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-11-11  9:12 UTC (permalink / raw)
  To: gcc-bugs

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;
}


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-11-11  9:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-42970-4@http.gcc.gnu.org/bugzilla/>
2010-11-10 17:24 ` [Bug tree-optimization/42970] Missed unused function return value elimination 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 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).