Bug 16743 – Intrinsic recognition sometimes fails if a software implementation is available
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-11-23T19:55:02Z
Last change time
2019-05-09T02:30:52Z
Keywords
pull
Assigned to
No Owner
Creator
thomas.bockman
Comments
Comment #0 by thomas.bockman — 2016-11-23T19:55:02Z
core.bitop.bsr() is supposed to be an intrinsic, but often DMD (master) uses the function body instead. GDC and LDC do not appear to be affected.
This *sometimes* works on -m64, but not on -m32:
module app;
import core.bitop;
int main(string[] args) {
return bsf(~cast(size_t) args.length);
}
But, if I remove the cast it fails on -m64, too:
module app;
import core.bitop;
int main(string[] args) {
return bsf(~args.length);
}
The uint overload never works for me on -m64, even though all it does (according to the druntime source code) is forward to the ulong one:
module app;
import core.bitop;
int main(string[] args) {
return bsf(~cast(uint) args.length);
}
Omitting the bitwise complement also breaks the bsf() intrinsic:
module app;
import core.bitop;
int main(string[] args) {
return bsf(cast(size_t) args.length);
}
The bsr() intrinsic is similarly fragile.
My wild guess is that DMD's inliner is sometimes running before the intrinsic detection? The intrinsic works consistently if druntime is recompiled with the function body removed.