Thread overview |
---|
March 25, 2006 [Bug 73] New: Functions used to initialize variables are not inlined. | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/bugzilla/show_bug.cgi?id=73 Summary: Functions used to initialize variables are not inlined. Product: D Version: 0.150 Platform: All OS/Version: All Status: NEW Severity: major Priority: P3 Component: DMD AssignedTo: bugzilla@digitalmars.com ReportedBy: godaves@yahoo.com /* Compile with -O -inline -release This program compares performance of 2 loops, one initializing a scope local variable w/ a function and the other not. The function used as an initializer is not inlined. There is about a 11x difference on my system. */ import std.stdio, std.date, std.math; // local copy of std.math.abs() // (imported functions are not inlined - see DMD bug #67) int abs(int x) { return x >= 0 ? x : -x; } void main() { int sum = 0; d_time s = getUTCtime(); for(int i = 0; i < 100_000_000; i++) { int val = abs(i); sum += val - val; } d_time e = getUTCtime(); writefln("std.math.abs(): sum= ",sum,", secs = ",(e - s)/cast(double)TicksPerSecond); d_time tmp = e - s; sum = 0; s = getUTCtime(); for(int i = 0; i < 100_000_000; i++) { int val; val = abs(i); sum += val - val; } e = getUTCtime(); writefln("local abs(): sum= ",sum,", secs = ",(e - s)/cast(double)TicksPerSecond); writefln("ratio = ", tmp / cast(double)(e - s)); } -- |
March 25, 2006 [Bug 73] Functions used to initialize variables are not inlined. | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/bugzilla/show_bug.cgi?id=73 unknown@simplemachines.org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |unknown@simplemachines.org ------- Comment #1 from unknown@simplemachines.org 2006-03-25 02:36 ------- There's a comment in inline.c for DeclarationExp's saying: // Should scan variable initializers But it isn't happening right now. Adding a basic scan of the ExpInitializer (if present) the same way DeclarationExp::inlineCost works seems to resolve this, but considering how trivial that is... I can't help but expect that there's more to it than just that. -[Unknown] -- |
March 25, 2006 [Bug 73] Functions used to initialize variables are not inlined. | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/bugzilla/show_bug.cgi?id=73 ------- Comment #2 from godaves@yahoo.com 2006-03-25 12:01 ------- (In reply to comment #1) > There's a comment in inline.c for DeclarationExp's saying: > > // Should scan variable initializers > > But it isn't happening right now. Adding a basic scan of the ExpInitializer (if present) the same way DeclarationExp::inlineCost works seems to resolve this, but considering how trivial that is... I can't help but expect that there's more to it than just that. > I've noticed that too and agree there must be more to it for some cases. But couldn't that just be re-written by the compiler as two expressions and then inlined? int i = foo(); => int i; i = foo(); => doInline(); Are there cases where that wouldn't be semantically identical? Thanks, - Dave > -[Unknown] -- |
March 25, 2006 [Bug 73] Functions used to initialize variables are not inlined. | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/bugzilla/show_bug.cgi?id=73 ------- Comment #3 from unknown@simplemachines.org 2006-03-25 12:34 ------- Created an attachment (id=8) --> (http://d.puremagic.com/bugzilla/attachment.cgi?id=8&action=view) Add a basic scan to DeclarationExp. AFAICT, that's exactly what adding a scan in there does. I'm just compiling DMD without backend hooks, but I can see with my changes that it now wants to inline things (by turning on CANINLINE_LOG.) It's just calling the inline stuff on ExpInitializer's exp, which is probably an AssignExp or something, which is a BinExp, which then has the CallExp checked, which then finally gets inlined. I'm just worried it wasn't added because it might cause fallout. I don't really know the code base, so I'm not privy to what fallout might be caused. Anyway, here's a patch that shows what I changed to enable inlining in these cases. If I had the time on my hands, I might try running DStress with this patch on gdc, to see if it causes any regressions. -[Unknown] -- |
March 25, 2006 Re: [Bug 73] Functions used to initialize variables are not inlined. | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | I've got this one solved, too. No need to expend any more effort on it. |
April 03, 2006 [Bug 73] Functions used to initialize variables are not inlined. | ||||
---|---|---|---|---|
| ||||
Posted in reply to d-bugmail | http://d.puremagic.com/bugzilla/show_bug.cgi?id=73 deewiant@gmail.com changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED ------- Comment #4 from deewiant@gmail.com 2006-04-03 06:09 ------- Fixed in DMD 0.151. -- |
Copyright © 1999-2021 by the D Language Foundation