digitalmars.D - dmd: if still there
- Chris (93/93) Sep 19 2014 Out of curiosity. dmd still produces the if statement, although
- Daniel Murphy (3/17) Sep 19 2014 See, no branches or comparisons.
- Chris (10/28) Sep 19 2014 All right, that escaped me. I'm not exactly asm-literate. Mea
- Rainer Schuetze (4/28) Sep 21 2014 dmd didn't do any inlining at all. It is very restrained with inlining,
- Vladimir Panteleev (4/6) Sep 21 2014 I believe the function *was* inlined, however the function was
- Daniel Murphy (5/8) Sep 22 2014 Check again, it inlined doIt into main. It still writes out doIt even
- Rainer Schuetze (4/12) Sep 22 2014 Yeah, my bad. I must have been confused by your quote of the
Out of curiosity. dmd still produces the if statement, although it ain't gonna happen. Same is true of "DoIt.yes". I know, it's an unlikely and marginal example. [code] import std.stdio; enum DoIt { yes, no } void main() { doit(DoIt.no); } void doit(DoIt flag) { if (flag == DoIt.yes) { writeln("I'm doing it!"); } else { writeln("No, I won't"); } } [asm] _Dmain: push RBP mov RBP,RSP mov EDI,1 call _D7dump_if4doitFE7dump_if4DoItZv PC32 xor EAX,EAX pop RBP ret 0f1f add [RAX],R8B .text._Dmain ends .text._D7dump_if4doitFE7dump_if4DoItZv segment assume CS:.text._D7dump_if4doitFE7dump_if4DoItZv _D7dump_if4doitFE7dump_if4DoItZv: push RBP mov RBP,RSP sub RSP,010h mov -8[RBP],EDI cmp dword ptr -8[RBP],0 jne L29 mov RDX,FLAT:.rodata[00h][RIP] mov RDI,FLAT:.rodata[00h][RIP] mov RSI,RDX call _D3std5stdio16__T7writelnTAyaZ7writelnFAyaZv PC32 jmp short L3F L29: mov RDX,FLAT:.rodata[00h][RIP] mov RDI,FLAT:.rodata[00h][RIP] mov RSI,RDX call _D3std5stdio16__T7writelnTAyaZ7writelnFAyaZv PC32 L3F: leave ret 0f1f add byte ptr [RAX],0 add [RAX],AL .text._D7dump_if4doitFE7dump_if4DoItZv ends [asm dmd (2.066) -release -boundscheck=off -O -inline] _Dmain: push RBP mov RBP,RSP mov RDX,FLAT:.rodata[00h][RIP] mov RDI,FLAT:.rodata[00h][RIP] mov RSI,RDX call _D3std5stdio16__T7writelnTAyaZ7writelnFAyaZv PC32 xor EAX,EAX pop RBP ret nop .text._Dmain ends .text._D7dump_if4doitFE7dump_if4DoItZv segment assume CS:.text._D7dump_if4doitFE7dump_if4DoItZv _D7dump_if4doitFE7dump_if4DoItZv: push RBP mov RBP,RSP sub RSP,010h mov -8[RBP],EDI cmp dword ptr -8[RBP],0 jne L29 mov RDX,FLAT:.rodata[00h][RIP] mov RDI,FLAT:.rodata[00h][RIP] mov RSI,RDX call _D3std5stdio16__T7writelnTAyaZ7writelnFAyaZv PC32 jmp short L3F L29: mov RDX,FLAT:.rodata[00h][RIP] mov RDI,FLAT:.rodata[00h][RIP] mov RSI,RDX call _D3std5stdio16__T7writelnTAyaZ7writelnFAyaZv PC32 L3F: mov RSP,RBP pop RBP ret 0f1f add 0[RCX],SPL .text._D7dump_if4doitFE7dump_if4DoItZv ends
Sep 19 2014
"Chris" wrote in message news:kcsnboocxeykhknjljfl forum.dlang.org...Out of curiosity. dmd still produces the if statement, although it ain't gonna happen. Same is true of "DoIt.yes". I know, it's an unlikely and marginal example.No it doesn't, here's main:_Dmain: push RBP mov RBP,RSP mov EDI,1 call _D7dump_if4doitFE7dump_if4DoItZv PC32 xor EAX,EAX pop RBP ret 0f1f add [RAX],R8B .text._Dmain endsSee, no branches or comparisons.
Sep 19 2014
On Friday, 19 September 2014 at 15:30:25 UTC, Daniel Murphy wrote:"Chris" wrote in message news:kcsnboocxeykhknjljfl forum.dlang.org...All right, that escaped me. I'm not exactly asm-literate. Mea maxima culpa! But good to know that you can rely on the compiler. It's not that unusual actually. Often I have things like that in my programs. I make the program flexible for extensions in the future but until that happens it lives happily with something like DoIt.no (usually in the signature flag = DoIt.no), i.e. DoIt.yes is never used throughout the program. The if statement should be kept alive in a library though, cos there's no way you can foresee what users gonna do.Out of curiosity. dmd still produces the if statement, although it ain't gonna happen. Same is true of "DoIt.yes". I know, it's an unlikely and marginal example.No it doesn't, here's main:_Dmain: push RBP mov RBP,RSP mov EDI,1 call _D7dump_if4doitFE7dump_if4DoItZv PC32 xor EAX,EAX pop RBP ret 0f1f add [RAX],R8B .text._Dmain endsSee, no branches or comparisons.
Sep 19 2014
On 19.09.2014 17:30, Daniel Murphy wrote:"Chris" wrote in message news:kcsnboocxeykhknjljfl forum.dlang.org...The branch is still in the doIt function:Out of curiosity. dmd still produces the if statement, although it ain't gonna happen. Same is true of "DoIt.yes". I know, it's an unlikely and marginal example.No it doesn't, here's main:_Dmain: push RBP mov RBP,RSP mov EDI,1 call _D7dump_if4doitFE7dump_if4DoItZv PC32 xor EAX,EAX pop RBP ret 0f1f add [RAX],R8B .text._Dmain endsSee, no branches or comparisons._D7dump_if4doitFE7dump_if4DoItZv: push RBP mov RBP,RSP sub RSP,010h mov -8[RBP],EDI cmp dword ptr -8[RBP],0 jne L29dmd didn't do any inlining at all. It is very restrained with inlining, you'll get much better results with GDC or LDC.
Sep 21 2014
On Sunday, 21 September 2014 at 13:28:59 UTC, Rainer Schuetze wrote:dmd didn't do any inlining at all. It is very restrained with inlining, you'll get much better results with GDC or LDC.I believe the function *was* inlined, however the function was still compiled separately and included in the object file.
Sep 21 2014
"Rainer Schuetze" wrote in message news:lvmjqr$h13$1 digitalmars.com...The branch is still in the doIt function:Yes.dmd didn't do any inlining at all. It is very restrained with inlining, you'll get much better results with GDC or LDC.Check again, it inlined doIt into main. It still writes out doIt even though it's now unreferenced, but that doesn't have much to do with the inliner.
Sep 22 2014
On 22.09.2014 15:24, Daniel Murphy wrote:"Rainer Schuetze" wrote in message news:lvmjqr$h13$1 digitalmars.com...Yeah, my bad. I must have been confused by your quote of the non-inlining main. Sorry to dmd for blaming it's inliner, again ;-)The branch is still in the doIt function:Yes.dmd didn't do any inlining at all. It is very restrained with inlining, you'll get much better results with GDC or LDC.Check again, it inlined doIt into main. It still writes out doIt even though it's now unreferenced, but that doesn't have much to do with the inliner.
Sep 22 2014