Bug 22158 – Optimize away empty loops that have no side effect

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
All
Creation time
2021-07-30T09:02:07Z
Last change time
2024-12-13T19:17:44Z
Keywords
backend, performance
Assigned to
Walter Bright
Creator
Vladimir Panteleev
Moved to GitHub: dmd#19964 →

Comments

Comment #0 by dlang-bugzilla — 2021-07-30T09:02:07Z
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
Comment #1 by b2.temp — 2021-07-30T10:06:37Z
I suggest to edit the tittle: Optimize away empty loops -> Optimize away empty loops that have no side effect because the Test and the Increment can do things even if the loop body is empty
Comment #2 by robert.schadek — 2024-12-13T19:17:44Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19964 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB