Dead Code Elimination
Walter Bright
newshound2 at digitalmars.com
Wed Oct 21 19:30:32 UTC 2026
On 10/18/2026 11:45 PM, Richard (Rikki) Andrew Cattermole wrote:
> On 19/10/2026 7:36 PM, Walter Bright wrote:
>> On 10/18/2026 8:33 AM, libxmoc wrote:
>>> I noticed that dmd doesn't do DCE
>>
>> Yes, it does. Use the -O switch.
>
> dmd -O
>
> ```d
> void main() {
>
> }
>
> void foo() {
> }
> ```
>
> ```asm.text._Dmain segment
> assume CS:.text._Dmain
> _Dmain:
> push RBP
> mov RBP,RSP
> xor EAX,EAX
> pop RBP
> ret
> .text._Dmain ends
> .text.void onlineapp.foo() segment
> assume CS:.text.void onlineapp.foo()
> void onlineapp.foo():
> push RBP
> mov RBP,RSP
> pop RBP
> ret
> add [RAX],AL
> .text.void onlineapp.foo() ends
> ```
Current version of dmd:
_Dmain:
0000: 31 C0 xor EAX,EAX
0002: C3 ret
_D4dead3fooFZv:
0000: C3 ret
More information about the Digitalmars-d
mailing list