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