Bug 7625 – inlining only works with explicit else branch

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P5
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-03-01T16:10:26Z
Last change time
2022-02-18T17:14:23Z
Keywords
performance, pull
Assigned to
No Owner
Creator
Martin Nowak

Comments

Comment #0 by code — 2012-03-01T16:10:26Z
int foo(int v) { return bar(2 * v); } int bar(int a) { if (a > 0) return 1; // else return baz(a); } int baz(int a) { if (a > 0) throw new Exception("a > 0"); return a - 1; } -------- bar is only inlined by foo when 'else' is present.
Comment #1 by code — 2014-09-29T02:27:28Z
Workaround for a performance regression in std.utf caused by this. https://github.com/D-Programming-Language/phobos/pull/2566
Comment #2 by github-bugzilla — 2014-09-29T08:29:03Z
Commits pushed to master at https://github.com/D-Programming-Language/phobos https://github.com/D-Programming-Language/phobos/commit/fea9bad209272b032fc8e38d358f06035676b14f workaround inline Issue 7625 - add explicit else branches so that dmd can inline those functions https://github.com/D-Programming-Language/phobos/commit/335228cb079ccc2060790a2b23bca5db645fa7f0 Merge pull request #2566 from MartinNowak/workaround7625 workaround inline Issue 7625
Comment #3 by github-bugzilla — 2015-02-18T03:39:21Z
Comment #4 by bugzilla — 2015-08-22T20:27:53Z
Comment #5 by github-bugzilla — 2015-09-21T12:10:49Z
Commits pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/f5261a2a978831e10a2ff36d3e342770f846dd1b fix Issue 7625 - inlining only works with explicit else branch https://github.com/D-Programming-Language/dmd/commit/26bd7451bf69051d7662f807978441cf1eefeb2f Merge pull request #4919 from WalterBright/fix7625 fix Issue 7625 - inlining only works with explicit else branch
Comment #6 by hsteoh — 2016-03-30T16:53:48Z
The fix was incomplete. Here's a test case for which dmd fails to inline a function that's basically identical to another inlined function, the only difference being the omission of `else`: ------ int tembo(int x, int y) { if (y == 0) return 0; x++; return x / y; } int pembo(int x, int y) { if (y == 0) return 0; else { x++; return x / y; } } int twiga(int x, int y, int z) { auto w = tembo(x, y); return w * z; } int simba(int x, int y, int z) { auto w = pembo(x, y); return w * z; } ------ Compiling with `dmd -O -inline` and disassembling, I found that twiga still contains a function call to tembo, whereas simba inlines pembo. Commenting out the x++ from tembo and pembo causes successful inlining of both functions in twiga and simba. So it seems that the inliner is still unable to deal with the case where the else block (with omitted `else`) contains anything more than just a simple return statement.
Comment #7 by k.hara.pg — 2016-04-03T15:57:24Z
https://github.com/D-Programming-Language/dmd/pull/5626(In reply to hsteoh from comment #6) > The fix was incomplete. Do further generalized fix. https://github.com/D-Programming-Language/dmd/pull/5626
Comment #8 by thomas.bockman — 2016-04-04T18:59:08Z
Comment #9 by k.hara.pg — 2016-04-05T13:07:21Z
*** Issue 15483 has been marked as a duplicate of this issue. ***
Comment #10 by dlang-bot — 2022-02-18T13:35:42Z
@ibuclaw updated dlang/dmd pull request #7690 "fix Issue 7625 - inlining only works with explicit else branch" fixing this issue: - fix Issue 7625 - inlining only works with explicit else branch https://github.com/dlang/dmd/pull/7690
Comment #11 by ibuclaw — 2022-02-18T14:17:42Z
Comment #12 by dlang-bot — 2022-02-18T17:14:23Z
dlang/dmd pull request #7690 "fix Issue 7625 - inlining only works with explicit else branch" was merged into master: - f0e3d93b715cda77b6b5cac7966243c5e7b0c232 by Iain Buclaw: fix Issue 7625 - inlining only works with explicit else branch https://github.com/dlang/dmd/pull/7690