www.digitalmars.com         C & C++   DMDScript  

D.gnu - Inexplicable LDC vs GDC speed difference

reply Joseph Rushton Wakeling <joseph.wakeling webdrake.net> writes:
Following some code posted in d.learn, I've observed a bizarre and (to me) 
inexplicable difference in code speed depending on whether LDC or GDC is used
as 
the compiler:
http://forum.dlang.org/post/mailman.1239.1360764028.22503.digitalmars-d-learn puremagic.com

I'm using latest-from-GitHub versions of both compilers, compiled as release 
versions.

Anyone have any idea what could be the source of the speed difference?
Feb 13 2013
next sibling parent "jerro" <a a.com> writes:
On Wednesday, 13 February 2013 at 15:07:04 UTC, Joseph Rushton 
Wakeling wrote:
 Following some code posted in d.learn, I've observed a bizarre 
 and (to me) inexplicable difference in code speed depending on 
 whether LDC or GDC is used as the compiler:
 http://forum.dlang.org/post/mailman.1239.1360764028.22503.digitalmars-d-learn puremagic.com

 I'm using latest-from-GitHub versions of both compilers, 
 compiled as release versions.

 Anyone have any idea what could be the source of the speed 
 difference?

The speed difference is partly caused by the fact that GDC doesn't inline juliaFunction and squarePlusMag. I have a build of GDC with always_inline attribute enabled (I just copied a few lines of code from some old version of GDC to d-builtins.c of a recent version), so I tried adding pragma(attribute, always_inline) to those functions. It seems that GDC is unable to inline them for some reason. When I added always_inline to juliaFunction, I got this error: error: inlining failed in call to always_inline ?main.Julia!(float).juliaFunction?: function body can be overwritten at link time Here's reduced code that gives the same error when always_inline is added to bar: int bar()(int x) { if (x) return 0; return 1; } int foo(int a) { return bar( a); } bar can be inlined if I remove the first pair of parentheses (so that it isn't a template). When I add always_inline to squarePlusMag I get: error: inlining failed in call to always_inline ?main.Julia!(float).ComplexStruct.squarePlusMag?: mismatched arguments Reduced code that gives the same error when always_inline is added to bar: struct S { int bar(const S s) { return 0; } } int foo() { S s; return s.bar(s); } bar can be inlined if I remove const. I have compiled all the samples with -c -O3 -finline-functions -frelease.
Feb 13 2013
prev sibling next sibling parent Johannes Pfau <nospam example.com> writes:
Am Thu, 14 Feb 2013 01:18:21 +0100
schrieb "jerro" <a a.com>:

 
 When I added always_inline to juliaFunction, I got this error:
 
 error: inlining failed in call to always_inline 
 ?main.Julia!(float).juliaFunction?: function body can be 
 overwritten at link time
 
 Here's reduced code that gives the same error when always_inline 
 is added to bar:
 
 int bar()(int x)
 {
      if (x)
          return 0;
 
      return 1;
 }
 
 int foo(int a)
 {
      return bar( a);
 }
 
 bar can be inlined if I remove the first pair of parentheses (so 
 that it isn't a template).
 

I'll have a look at this soon. I already have an idea what could be wrong.
 
 When I add always_inline to squarePlusMag I get:
 
 error: inlining failed in call to always_inline 
 ?main.Julia!(float).ComplexStruct.squarePlusMag?: mismatched 
 arguments
 
 Reduced code that gives the same error when always_inline is 
 added to bar:
 
 struct S
 {
      int bar(const S s)
      {
          return 0;
      }
 }
 
 int foo()
 {
      S s;
      return s.bar(s);
 }
 
 bar can be inlined if I remove const.
 
 I have compiled all the samples with -c -O3 -finline-functions 
 -frelease.

Feb 14 2013
prev sibling next sibling parent Johannes Pfau <nospam example.com> writes:
Am Thu, 14 Feb 2013 01:18:21 +0100
schrieb "jerro" <a a.com>:

 On Wednesday, 13 February 2013 at 15:07:04 UTC, Joseph Rushton 
 Wakeling wrote:	
 
 Here's reduced code that gives the same error when always_inline 
 is added to bar:
 
 int bar()(int x)
 {
      if (x)
          return 0;
 
      return 1;
 }
 
 int foo(int a)
 {
      return bar( a);
 }
 
 bar can be inlined if I remove the first pair of parentheses (so 
 that it isn't a template).

https://github.com/D-Programming-GDC/GDC/pull/50
 
 struct S
 {
      int bar(const S s)
      {
          return 0;
      }
 }
 
 int foo()
 {
      S s;
      return s.bar(s);
 }
 
 bar can be inlined if I remove const.
 
 I have compiled all the samples with -c -O3 -finline-functions 
 -frelease.

I posted this to our bugzilla, I'm not sure if I'll have the time to look at this one. http://gdcproject.org/bugzilla/show_bug.cgi?id=37
Feb 19 2013
prev sibling next sibling parent Joseph Rushton Wakeling <joseph.wakeling webdrake.net> writes:
On 02/19/2013 09:34 AM, Johannes Pfau wrote:
 I posted this to our bugzilla, I'm not sure if I'll have the time to
 look at this one.

 http://gdcproject.org/bugzilla/show_bug.cgi?id=37

Just to note -- with your pull request #50 now included in GDC, things speed up very slightly. Removing the const from the Julia value code, results become comparable to g++ and the C++ implementation (i.e. about 4.3 s for the 'double' case). LDC still produces a faster executable for this particular code, but then, clang++ also produces a faster executable than g++.
Feb 22 2013
prev sibling parent Iain Buclaw <ibuclaw ubuntu.com> writes:
--20cf302ef79e7c390704d654d768
Content-Type: text/plain; charset=ISO-8859-1

On 22 February 2013 18:59, Joseph Rushton Wakeling <
joseph.wakeling webdrake.net> wrote:

 On 02/19/2013 09:34 AM, Johannes Pfau wrote:

 I posted this to our bugzilla, I'm not sure if I'll have the time to
 look at this one.

 http://gdcproject.org/**bugzilla/show_bug.cgi?id=37<http://gdcproject.org/bugzilla/show_bug.cgi?id=37>

Just to note -- with your pull request #50 now included in GDC, things speed up very slightly. Removing the const from the Julia value code, results become comparable to g++ and the C++ implementation (i.e. about 4.3 s for the 'double' case). LDC still produces a faster executable for this particular code, but then, clang++ also produces a faster executable than g++.

Cool, cheers for checking. -- Iain Buclaw *(p < e ? p++ : p) = (c & 0x0f) + '0'; --20cf302ef79e7c390704d654d768 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_extra"><div class=3D"gmail_quote">On 2= 2 February 2013 18:59, Joseph Rushton Wakeling <span dir=3D"ltr">&lt;<a hre= f=3D"mailto:joseph.wakeling webdrake.net" target=3D"_blank">joseph.wakeling= webdrake.net</a>&gt;</span> wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"><div class=3D"im">On 02/19/2013 09:34 AM, Jo= hannes Pfau wrote:<br> <blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p= x #ccc solid;padding-left:1ex"> I posted this to our bugzilla, I&#39;m not sure if I&#39;ll have the time t= o<br> look at this one.<br> <br> <a href=3D"http://gdcproject.org/bugzilla/show_bug.cgi?id=3D37" target=3D"_= blank">http://gdcproject.org/<u></u>bugzilla/show_bug.cgi?id=3D37</a><br> </blockquote> <br></div> Just to note -- with your pull request #50 now included in GDC, things spee= d up very slightly. =A0Removing the const from the Julia value code, result= s become comparable to g++ and the C++ implementation (i.e. about 4.3 s for= the &#39;double&#39; case).<br> <br> LDC still produces a faster executable for this particular code, but then, = clang++ also produces a faster executable than g++.<br> </blockquote></div><br><br></div><div class=3D"gmail_extra">Cool, cheers fo= r checking.<br clear=3D"all"></div><div class=3D"gmail_extra"><br><br>-- <b= r>Iain Buclaw<br><br>*(p &lt; e ? p++ : p) =3D (c &amp; 0x0f) + &#39;0&#39;= ; </div></div> --20cf302ef79e7c390704d654d768--
Feb 22 2013