public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/32817]  New: inline (pure) accessor functions
@ 2007-07-19  8:38 dfranke at gcc dot gnu dot org
  2007-07-19  9:00 ` [Bug fortran/32817] " pinskia at gcc dot gnu dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 12+ messages in thread
From: dfranke at gcc dot gnu dot org @ 2007-07-19  8:38 UTC (permalink / raw)
  To: gcc-bugs

I don't know whether this is possible to achieve, but simple PURE functions
should sometimes be inlined. Please consider:

$> cat inline.f90
MODULE foomod
TYPE foo
  PRIVATE          ! change to PUBLIC to run the "inlined" loop
  INTEGER :: value
END TYPE

INTERFACE OPERATOR(==)
  MODULE PROCEDURE foo_equal
END INTERFACE

CONTAINS
  PURE FUNCTION foo_new(value) RESULT (this)
    INTEGER, INTENT(in)          :: value
    TYPE(foo) :: this
    this = foo(value)
  END FUNCTION

  PURE FUNCTION foo_equal(this, other)
    TYPE(foo), INTENT(in) :: this, other
    LOGICAL  :: foo_equal

    foo_equal = (this%value == other%value)
  END FUNCTION
END MODULE

USE foomod
INTEGER :: i, j

TYPE(foo) :: x(50000)
DO i = 1, SIZE(x)
  x(i) = foo_new(i)
END DO

DO i = 1, SIZE(x)
  DO j = i + 1, SIZE(x)
    IF (x(i) == x(j)) EXIT    ! call foo_equal
  END DO
END DO

!DO i = 1, SIZE(x)
!  DO j = i + 1, SIZE(x)
!    IF (x(i)%value == x(j)%value) EXIT  ! inlined
!  END DO
!END DO
END


Using comparison function foo_equal
$> gfortran-svn -O3 inline.f90 && time ./a.out
real    0m6.818s
user    0m6.772s
sys     0m0.036s

Inlined access:
$> gfortran-svn -O3 inline.f90 && time ./a.out

real    0m1.242s
user    0m1.236s
sys     0m0.008s


The example above was taken from a real-world application that (currently)
spends about 10% of its 3 hour runtime in accessor/comparison functions like
the one shown. In general, I'd prefer the OO'ish approach over PUBLIC access to
the components.


-- 
           Summary: inline (pure) accessor functions
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dfranke at gcc dot gnu dot org


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


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

* [Bug fortran/32817] inline (pure) accessor functions
  2007-07-19  8:38 [Bug fortran/32817] New: inline (pure) accessor functions dfranke at gcc dot gnu dot org
@ 2007-07-19  9:00 ` pinskia at gcc dot gnu dot org
  2007-07-19  9:18 ` dfranke at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-07-19  9:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2007-07-19 09:00 -------
I think this is just the normal inline function problem with gfortran.  Where
we have two decls for the same function which causes no inlining to happen.


-- 


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


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

* [Bug fortran/32817] inline (pure) accessor functions
  2007-07-19  8:38 [Bug fortran/32817] New: inline (pure) accessor functions dfranke at gcc dot gnu dot org
  2007-07-19  9:00 ` [Bug fortran/32817] " pinskia at gcc dot gnu dot org
@ 2007-07-19  9:18 ` dfranke at gcc dot gnu dot org
  2007-07-24 16:03 ` jb at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: dfranke at gcc dot gnu dot org @ 2007-07-19  9:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from dfranke at gcc dot gnu dot org  2007-07-19 09:17 -------
Andrew, you mentioned the two-decl per function elsewhere as well. Where can
one learn more about this? why do we have two decls at all? where do they come
from, where do they go? How are they dealt with? I'm sort of lost there ...


-- 


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


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

* [Bug fortran/32817] inline (pure) accessor functions
  2007-07-19  8:38 [Bug fortran/32817] New: inline (pure) accessor functions dfranke at gcc dot gnu dot org
  2007-07-19  9:00 ` [Bug fortran/32817] " pinskia at gcc dot gnu dot org
  2007-07-19  9:18 ` dfranke at gcc dot gnu dot org
@ 2007-07-24 16:03 ` jb at gcc dot gnu dot org
  2008-01-29 17:26 ` fxcoudert at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: jb at gcc dot gnu dot org @ 2007-07-24 16:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from jb at gcc dot gnu dot org  2007-07-24 16:03 -------
Confirmed.

Gfortran should IMHO not do any inlining itself, rather somehow tell the
middle-end when inlining is allowed, and let the middle-end optimizer decide
when to actually inline.


-- 

jb at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2007-07-24 16:03:03
               date|                            |


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


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

* [Bug fortran/32817] inline (pure) accessor functions
  2007-07-19  8:38 [Bug fortran/32817] New: inline (pure) accessor functions dfranke at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2007-07-24 16:03 ` jb at gcc dot gnu dot org
@ 2008-01-29 17:26 ` fxcoudert at gcc dot gnu dot org
  2009-05-02 16:26 ` [Bug fortran/32817] MODULE functions are not inlined fxcoudert at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2008-01-29 17:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from fxcoudert at gcc dot gnu dot org  2008-01-29 16:15 -------
(In reply to comment #2)
> Andrew, you mentioned the two-decl per function elsewhere as well. Where can
> one learn more about this? why do we have two decls at all? where do they come
> from, where do they go? How are they dealt with? I'm sort of lost there ...

You can start reading this thread:
http://gcc.gnu.org/ml/fortran/2007-08/msg00323.html, especially the message
from Michael Matz and especially the paragraphs starting from "That's because
the fortran frontend generates a 
new FUNCTION_DECL for each get_extern_function_decl call..."


-- 

fxcoudert at gcc dot gnu dot org changed:

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


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


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

* [Bug fortran/32817] MODULE functions are not inlined
  2007-07-19  8:38 [Bug fortran/32817] New: inline (pure) accessor functions dfranke at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2008-01-29 17:26 ` fxcoudert at gcc dot gnu dot org
@ 2009-05-02 16:26 ` fxcoudert at gcc dot gnu dot org
  2009-05-02 16:43 ` fxcoudert at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2009-05-02 16:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from fxcoudert at gcc dot gnu dot org  2009-05-02 16:26 -------
Now, inlining of non-CONTAINED procedures works when -fwhole-file is used (it
will be the default when the remaining bugs are fixed).

However, functions from used modules are still not inlined; a reduced testcase
is:

  module foomod
  contains
    integer function bar()
      bar = 1
    end function
  end module

  subroutine gee
    use foomod
    if (bar() == 0) call abort
  end subroutine

In this, the call to bar() should be inlined, but it is not (compile with "-O2
-fdump-tree-optimized -fwhole-file" and check the .optimized tree dump). The
same code, with a non-module global function, has the call inlined:

  integer function bar()
    bar = 1
  end function

  subroutine gee
    integer, external :: bar
    if (bar() == 0) call abort
  end subroutine


-- 

fxcoudert at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |fxcoudert at gcc dot gnu dot
                   |                            |org
   Last reconfirmed|2007-07-24 16:03:03         |2009-05-02 16:26:23
               date|                            |
            Summary|inline (pure) accessor      |MODULE functions are not
                   |functions                   |inlined


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


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

* [Bug fortran/32817] MODULE functions are not inlined
  2007-07-19  8:38 [Bug fortran/32817] New: inline (pure) accessor functions dfranke at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2009-05-02 16:26 ` [Bug fortran/32817] MODULE functions are not inlined fxcoudert at gcc dot gnu dot org
@ 2009-05-02 16:43 ` fxcoudert at gcc dot gnu dot org
  2010-05-09 10:03 ` dfranke at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: fxcoudert at gcc dot gnu dot org @ 2009-05-02 16:43 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from fxcoudert at gcc dot gnu dot org  2009-05-02 16:42 -------
The cause of that is that module procedure are never entered into the global
symbol list (gfc_gsym_root). I think they should be there, under their mangled
name.


-- 


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


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

* [Bug fortran/32817] MODULE functions are not inlined
  2007-07-19  8:38 [Bug fortran/32817] New: inline (pure) accessor functions dfranke at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2009-05-02 16:43 ` fxcoudert at gcc dot gnu dot org
@ 2010-05-09 10:03 ` dfranke at gcc dot gnu dot org
  2010-05-10 17:16 ` mikael at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 12+ messages in thread
From: dfranke at gcc dot gnu dot org @ 2010-05-09 10:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from dfranke at gcc dot gnu dot org  2010-05-09 10:02 -------
With -fwhole-file I now get the same timings either way. I call that fixed.


-- 

dfranke at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
OtherBugsDependingO|                            |40011
              nThis|                            |
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED


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


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

* [Bug fortran/32817] MODULE functions are not inlined
  2007-07-19  8:38 [Bug fortran/32817] New: inline (pure) accessor functions dfranke at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2010-05-09 10:03 ` dfranke at gcc dot gnu dot org
@ 2010-05-10 17:16 ` mikael at gcc dot gnu dot org
  2010-05-10 18:43 ` mikael at gcc dot gnu dot org
  2010-07-24 17:58 ` jv244 at cam dot ac dot uk
  9 siblings, 0 replies; 12+ messages in thread
From: mikael at gcc dot gnu dot org @ 2010-05-10 17:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from mikael at gcc dot gnu dot org  2010-05-10 17:16 -------
(In reply to comment #7)
> With -fwhole-file I now get the same timings either way. I call that fixed.
> 
Unless there is one other bug tracking inlining of use-associated functions,
one cannot close this yet. 
The comment #5 case is still not inlined


-- 

mikael at gcc dot gnu dot org changed:

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


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


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

* [Bug fortran/32817] MODULE functions are not inlined
  2007-07-19  8:38 [Bug fortran/32817] New: inline (pure) accessor functions dfranke at gcc dot gnu dot org
                   ` (7 preceding siblings ...)
  2010-05-10 17:16 ` mikael at gcc dot gnu dot org
@ 2010-05-10 18:43 ` mikael at gcc dot gnu dot org
  2010-07-24 17:58 ` jv244 at cam dot ac dot uk
  9 siblings, 0 replies; 12+ messages in thread
From: mikael at gcc dot gnu dot org @ 2010-05-10 18:43 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from mikael at gcc dot gnu dot org  2010-05-10 18:42 -------
This depends on the double decl problem, which is : 
if a module is both defined and used in the same file, we create new symbols
when we load the module, instead of reusing/sharing them.  

(In reply to comment #8)
> one cannot close this yet. 
> 
I'll mark as waiting for pr25708


-- 

mikael at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  BugsThisDependsOn|                            |25708
             Status|REOPENED                    |SUSPENDED


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


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

* [Bug fortran/32817] MODULE functions are not inlined
  2007-07-19  8:38 [Bug fortran/32817] New: inline (pure) accessor functions dfranke at gcc dot gnu dot org
                   ` (8 preceding siblings ...)
  2010-05-10 18:43 ` mikael at gcc dot gnu dot org
@ 2010-07-24 17:58 ` jv244 at cam dot ac dot uk
  9 siblings, 0 replies; 12+ messages in thread
From: jv244 at cam dot ac dot uk @ 2010-07-24 17:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from jv244 at cam dot ac dot uk  2010-07-24 17:58 -------
with -fwhole-file being the default this testcase

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32817#c5 

gets properly inlined at -O2. Yeah!

I think this can be closed, but probably one would like to add a testcase to
the testsuite


-- 

jv244 at cam dot ac dot uk changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |burnus at gcc dot gnu dot
                   |                            |org
             Status|SUSPENDED                   |RESOLVED
         Resolution|                            |FIXED


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


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

* [Bug fortran/32817] MODULE functions are not inlined
       [not found] <bug-32817-4@http.gcc.gnu.org/bugzilla/>
@ 2015-10-10  9:12 ` dominiq at lps dot ens.fr
  0 siblings, 0 replies; 12+ messages in thread
From: dominiq at lps dot ens.fr @ 2015-10-10  9:12 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=32817
Bug 32817 depends on bug 25708, which changed state.

Bug 25708 Summary: [F95] Module loading is not good at all
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25708

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


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

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

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-19  8:38 [Bug fortran/32817] New: inline (pure) accessor functions dfranke at gcc dot gnu dot org
2007-07-19  9:00 ` [Bug fortran/32817] " pinskia at gcc dot gnu dot org
2007-07-19  9:18 ` dfranke at gcc dot gnu dot org
2007-07-24 16:03 ` jb at gcc dot gnu dot org
2008-01-29 17:26 ` fxcoudert at gcc dot gnu dot org
2009-05-02 16:26 ` [Bug fortran/32817] MODULE functions are not inlined fxcoudert at gcc dot gnu dot org
2009-05-02 16:43 ` fxcoudert at gcc dot gnu dot org
2010-05-09 10:03 ` dfranke at gcc dot gnu dot org
2010-05-10 17:16 ` mikael at gcc dot gnu dot org
2010-05-10 18:43 ` mikael at gcc dot gnu dot org
2010-07-24 17:58 ` jv244 at cam dot ac dot uk
     [not found] <bug-32817-4@http.gcc.gnu.org/bugzilla/>
2015-10-10  9:12 ` dominiq at lps dot ens.fr

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).