[Issue 22158] New: Optimize away empty loops
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Jul 30 09:02:07 UTC 2021
https://issues.dlang.org/show_bug.cgi?id=22158
Issue ID: 22158
Summary: Optimize away empty loops
Product: D
Version: D2
Hardware: x86_64
OS: All
Status: NEW
Keywords: performance
Severity: enhancement
Priority: P1
Component: dmd
Assignee: bugzilla at digitalmars.com
Reporter: dlang-bugzilla at thecybershadow.net
void fun(int a, int b)
{
for (int i = a; i < b; i++) {}
}
With -O -inline -release, DMD compiles the above function to:
push RBP
mov RBP,RSP
mov ECX,ESI
cmp ESI,EDI
jge $+7h
inc ECX
cmp ECX,EDI
jl $+FFFFFFFBh
pop RBP
ret
LDC and GDC (with their respective optimization flags on) both compile it to
just a "ret".
This optimization could help writing simpler code in performance-critical
areas, such as the GC:
https://github.com/dlang/druntime/pull/3523#discussion_r676094354
--
More information about the Digitalmars-d-bugs
mailing list