[Issue 20834] New: pragma(inline, true) fails to inline simple functions. fails with -inline
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri May 15 15:59:32 UTC 2020
https://issues.dlang.org/show_bug.cgi?id=20834
Issue ID: 20834
Summary: pragma(inline, true) fails to inline simple functions.
fails with -inline
Product: D
Version: D2
Hardware: x86_64
OS: Linux
Status: NEW
Severity: major
Priority: P1
Component: dmd
Assignee: nobody at puremagic.com
Reporter: witold.baryluk+d at gmail.com
https://godbolt.org/z/keEyMi
```
private final struct PTest {
ulong j;
pragma(inline, true)
final bool f() {
return !(j & 0xfffffffuL); // Works.
}
pragma(inline, true)
final bool g() {
// Doesn't work in DMD.
if (!(j & 0xfffffffuL)) {
j++;
return true;
} else {
return false;
}
}
}
void test1() {
scope p = PTest();
p.f();
p.g();
}
```
this fail to compile when using `dmd -O -inline`.
:(
1) DMD should be a bit smarter and consider more function types for inlining.
It looks like right now it only consider `return (expr);`-style functions only.
2) There should be a switch to dmd compiler, or different pragma, to not make
it an error, but just a warning. `pragma(hint_inline, true)` maybe?
I noticed this problem, when I tried to move some of the code into struct on
stack and call to its methods, but saw 20% performance drop. assembly revealed
missing inlining to one of the function. trying to inline it with pragma failed
as above.
--
More information about the Digitalmars-d-bugs
mailing list