public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/37046]  New: Inlining produces calls which gimple_call_fndecl cannot handle correctly
@ 2008-08-07 10:11 jamborm at gcc dot gnu dot org
  2008-08-07 10:12 ` [Bug middle-end/37046] " jamborm at gcc dot gnu dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: jamborm at gcc dot gnu dot org @ 2008-08-07 10:11 UTC (permalink / raw)
  To: gcc-bugs

In the following example, the  fucntion hooray() does not get inlined,
even though it could.

#include <stdlib.h>
#include <stdio.h>


static __attribute__((always_inline)) void hooray ()
{
  printf ("hooray\n");
}

static __attribute__((always_inline)) void hiphip (void (*f)())
{
  printf ("hip hip\n");
  f ();    
}


int main (int argc, int *argv[])
{
  hiphip (hooray);
  return 0;
}

int d()
{
  hiphip (hooray);
  return 86;
}


The reasons  are I believe  a bit more  grave than the fact  that this
(mis)use of anlways_inline does not work.  When tree-inline.c produces
an inlined copy of hiphip() it remaps the destination of the call to f
in  remap_gimple_stmt()  to  call   hooray.   However,  the  new  call
statement has this form:

  call<addr_expr<function_decl>> 

which  is a  form  that gimple_call_fndecl()  cannot  cope with.   The
consequence  is  that  rebuild_cgraph_edges()  sees  a  call  with  an
unretrievable declaration and does not build a call graph edge for it.

Therefore, when early inlining  inlines hiphip into its callers, there
is no  call graph  edge for main->hooray  (or d->hooray) and  so these
call sites  are not even  considered when doing regular  inlining, let
alone always_inlining.


-- 
           Summary: Inlining produces calls which gimple_call_fndecl cannot
                    handle correctly
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: jamborm at gcc dot gnu dot org
        ReportedBy: jamborm at gcc dot gnu dot org


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


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

* [Bug middle-end/37046] Inlining produces calls which gimple_call_fndecl cannot handle correctly
  2008-08-07 10:11 [Bug middle-end/37046] New: Inlining produces calls which gimple_call_fndecl cannot handle correctly jamborm at gcc dot gnu dot org
@ 2008-08-07 10:12 ` jamborm at gcc dot gnu dot org
  2008-08-07 13:16 ` rguenth at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jamborm at gcc dot gnu dot org @ 2008-08-07 10:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from jamborm at gcc dot gnu dot org  2008-08-07 10:11 -------
I am testing the patch below which should fix the problem:

2008-08-07  Martin Jambor  <mjambor@suse.cz>

        * tree-inline.c (remap_gimple_stmt): Remove extraneous addr_expr
        from call statements.

Index: iinln/gcc/tree-inline.c
===================================================================
--- iinln.orig/gcc/tree-inline.c
+++ iinln/gcc/tree-inline.c
@@ -1209,6 +1209,14 @@ remap_gimple_stmt (gimple stmt, copy_bod
   wi.info = id;
   walk_gimple_op (copy, remap_gimple_op_r, &wi); 

+  /* When a parameter is propagated into a call destination, it is in the form
+     of call<addr_expr<fndecl>> which gimple_call_fndecl does not understand.
+     Therefore we need to take the extra addr_expr out here. */
+  if (is_gimple_call (copy)
+      && TREE_CODE (gimple_call_fn (copy)) == ADDR_EXPR
+      && TREE_CODE (TREE_OPERAND (gimple_call_fn (copy), 0)) == FUNCTION_DECL)
+    gimple_call_set_fn (copy, TREE_OPERAND (gimple_call_fn (copy), 0));
+
   /* We have to handle EH region remapping of GIMPLE_RESX specially because
      the region number is not an operand.  */
   if (gimple_code (stmt) == GIMPLE_RESX && id->eh_region_offset)


-- 

jamborm at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2008-08-07 10:11:37
               date|                            |


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


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

* [Bug middle-end/37046] Inlining produces calls which gimple_call_fndecl cannot handle correctly
  2008-08-07 10:11 [Bug middle-end/37046] New: Inlining produces calls which gimple_call_fndecl cannot handle correctly jamborm at gcc dot gnu dot org
  2008-08-07 10:12 ` [Bug middle-end/37046] " jamborm at gcc dot gnu dot org
@ 2008-08-07 13:16 ` rguenth at gcc dot gnu dot org
  2008-08-07 15:51 ` jamborm at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-08-07 13:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2008-08-07 13:14 -------
Looks good.  Similar things may happen with CCP propagation for like

void foo(void) {}

void bar(void)
{
  void (*fn)(void) = foo;
  fn();
}

can you verify this as well?  Thanks.


-- 


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


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

* [Bug middle-end/37046] Inlining produces calls which gimple_call_fndecl cannot handle correctly
  2008-08-07 10:11 [Bug middle-end/37046] New: Inlining produces calls which gimple_call_fndecl cannot handle correctly jamborm at gcc dot gnu dot org
  2008-08-07 10:12 ` [Bug middle-end/37046] " jamborm at gcc dot gnu dot org
  2008-08-07 13:16 ` rguenth at gcc dot gnu dot org
@ 2008-08-07 15:51 ` jamborm at gcc dot gnu dot org
  2008-08-07 16:01 ` rguenth at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jamborm at gcc dot gnu dot org @ 2008-08-07 15:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jamborm at gcc dot gnu dot org  2008-08-07 15:49 -------
Unfortunately, I got a fortran regression:

/abuild/mjambor/iinln/gcc/testsuite/gfortran.dg/char_cast_1.f90:24: internal
com
piler error: in expand_call_inline, at tree-inline.c:3117

The assert is gcc_assert (dest->needed); so I think I might have
uncovered some unrelated hidden problem.  We will see.

I will try to investigate but may not be able to go all the way
because I'm, leaving for vacation tomorrow.

Richi, that applies, to your question too.  I will try but I may not
make it.


-- 


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


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

* [Bug middle-end/37046] Inlining produces calls which gimple_call_fndecl cannot handle correctly
  2008-08-07 10:11 [Bug middle-end/37046] New: Inlining produces calls which gimple_call_fndecl cannot handle correctly jamborm at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2008-08-07 15:51 ` jamborm at gcc dot gnu dot org
@ 2008-08-07 16:01 ` rguenth at gcc dot gnu dot org
  2008-08-08  7:51 ` jamborm at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-08-07 16:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from rguenth at gcc dot gnu dot org  2008-08-07 16:00 -------
Interesting.  I may have a look into the CCP problem.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu dot
                   |                            |org


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


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

* [Bug middle-end/37046] Inlining produces calls which gimple_call_fndecl cannot handle correctly
  2008-08-07 10:11 [Bug middle-end/37046] New: Inlining produces calls which gimple_call_fndecl cannot handle correctly jamborm at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2008-08-07 16:01 ` rguenth at gcc dot gnu dot org
@ 2008-08-08  7:51 ` jamborm at gcc dot gnu dot org
  2008-08-10 20:28 ` [Bug middle-end/37046] [4.4 Regression] " pinskia at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jamborm at gcc dot gnu dot org @ 2008-08-08  7:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from jamborm at gcc dot gnu dot org  2008-08-08 07:50 -------
(In reply to comment #4)
> Interesting.  I may have a look into the CCP problem.
> 

Well, I think that we have pass_rebuild_cgraph_edges precisely because
passes like CCP are not trusted to update call graph correctly.  It is
not an elegant solution but might just work.

However, in order for it to work, gimple_call_fndecl() must be able to
find  the  declarations  (and  this  might also  be  problem  for  CCP
generated calls too).


-- 


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


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

* [Bug middle-end/37046] [4.4 Regression] Inlining produces calls which gimple_call_fndecl cannot handle correctly
  2008-08-07 10:11 [Bug middle-end/37046] New: Inlining produces calls which gimple_call_fndecl cannot handle correctly jamborm at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2008-08-08  7:51 ` jamborm at gcc dot gnu dot org
@ 2008-08-10 20:28 ` pinskia at gcc dot gnu dot org
  2008-08-10 20:45 ` rguenther at suse dot de
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-08-10 20:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from pinskia at gcc dot gnu dot org  2008-08-10 20:27 -------
Parts of it is fixed by:
http://gcc.gnu.org/ml/gcc-patches/2008-08/msg00549.html

Or is it a full fix, I can't tell anymore :).


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
            Summary|Inlining produces calls     |[4.4 Regression] Inlining
                   |which gimple_call_fndecl    |produces calls which
                   |cannot handle correctly     |gimple_call_fndecl cannot
                   |                            |handle correctly
   Target Milestone|---                         |4.4.0


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


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

* [Bug middle-end/37046] [4.4 Regression] Inlining produces calls which gimple_call_fndecl cannot handle correctly
  2008-08-07 10:11 [Bug middle-end/37046] New: Inlining produces calls which gimple_call_fndecl cannot handle correctly jamborm at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2008-08-10 20:28 ` [Bug middle-end/37046] [4.4 Regression] " pinskia at gcc dot gnu dot org
@ 2008-08-10 20:45 ` rguenther at suse dot de
  2008-08-22 15:06 ` rguenth at gcc dot gnu dot org
  2008-09-10 10:12 ` jamborm at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: rguenther at suse dot de @ 2008-08-10 20:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from rguenther at suse dot de  2008-08-10 20:44 -------
Subject: Re:  [4.4 Regression] Inlining produces calls
 which gimple_call_fndecl cannot handle correctly

On Sun, 10 Aug 2008, pinskia at gcc dot gnu dot org wrote:

> ------- Comment #6 from pinskia at gcc dot gnu dot org  2008-08-10 20:27 -------
> Parts of it is fixed by:
> http://gcc.gnu.org/ml/gcc-patches/2008-08/msg00549.html
> 
> Or is it a full fix, I can't tell anymore :).

It should fix it fully - but I'll leave it for Martin to check.

Richard.


-- 


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


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

* [Bug middle-end/37046] [4.4 Regression] Inlining produces calls which gimple_call_fndecl cannot handle correctly
  2008-08-07 10:11 [Bug middle-end/37046] New: Inlining produces calls which gimple_call_fndecl cannot handle correctly jamborm at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2008-08-10 20:45 ` rguenther at suse dot de
@ 2008-08-22 15:06 ` rguenth at gcc dot gnu dot org
  2008-09-10 10:12 ` jamborm at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-08-22 15:06 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from rguenth at gcc dot gnu dot org  2008-08-22 15:04 -------
Let's just close this.  Martin, please re-open if you figure that things are
still broken.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED


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


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

* [Bug middle-end/37046] [4.4 Regression] Inlining produces calls which gimple_call_fndecl cannot handle correctly
  2008-08-07 10:11 [Bug middle-end/37046] New: Inlining produces calls which gimple_call_fndecl cannot handle correctly jamborm at gcc dot gnu dot org
                   ` (7 preceding siblings ...)
  2008-08-22 15:06 ` rguenth at gcc dot gnu dot org
@ 2008-09-10 10:12 ` jamborm at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: jamborm at gcc dot gnu dot org @ 2008-09-10 10:12 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from jamborm at gcc dot gnu dot org  2008-09-10 10:11 -------
I've been away from computer for a rather long time so I could not check
earlier.  However, the problem is indeed gone.  Thanks Richi.


-- 


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


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

end of thread, other threads:[~2008-09-10 10:12 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-07 10:11 [Bug middle-end/37046] New: Inlining produces calls which gimple_call_fndecl cannot handle correctly jamborm at gcc dot gnu dot org
2008-08-07 10:12 ` [Bug middle-end/37046] " jamborm at gcc dot gnu dot org
2008-08-07 13:16 ` rguenth at gcc dot gnu dot org
2008-08-07 15:51 ` jamborm at gcc dot gnu dot org
2008-08-07 16:01 ` rguenth at gcc dot gnu dot org
2008-08-08  7:51 ` jamborm at gcc dot gnu dot org
2008-08-10 20:28 ` [Bug middle-end/37046] [4.4 Regression] " pinskia at gcc dot gnu dot org
2008-08-10 20:45 ` rguenther at suse dot de
2008-08-22 15:06 ` rguenth at gcc dot gnu dot org
2008-09-10 10:12 ` jamborm at gcc dot gnu dot 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).