Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DisassemblyDiagnoser producing invalid disassembly #2074

Closed
adamsitnik opened this issue Aug 18, 2022 · 0 comments · Fixed by #2075
Closed

DisassemblyDiagnoser producing invalid disassembly #2074

adamsitnik opened this issue Aug 18, 2022 · 0 comments · Fixed by #2075
Assignees
Milestone

Comments

@adamsitnik
Copy link
Member

Reported offline by @stephentoub

For following C# code:

public void Compute()
{
    for (int thousands = 0; thousands < 10; thousands++)
    {
        for (int hundreds = 0; hundreds < 10; hundreds++)
        {
            for (int tens = 0; tens < 10; tens++)
            {
                for (int ones = 0; ones < 10; ones++)
                {
                    int n = (thousands * 1000) +
                            (hundreds * 100) +
                            (tens * 10) +
                            ones;
                    Process(n);
                }
            }
        }
    }
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void Process(int n) { }

We get:

.NET 6.0.8 (6.0.822.36306), X64 RyuJIT AVX2

; BenchmarkDotNet.Samples.Repro.Compute()
       push      r14
       push      rdi
       push      rsi
       push      rbp
       push      rbx
       sub       rsp,20
       xor       esi,esi
M00_L00:
       xor       edi,edi
M00_L01:
       xor       ebx,ebx
M00_L02:
       xor       ebp,ebp
       imul      ecx,esi,3E8
       imul      eax,edi,64
       add       ecx,eax
       lea       eax,[rbx+rbx*4]
       lea       r14d,[rcx+rax*2]
M00_L03:
       lea       ecx,[r14+rbp]
       call      BenchmarkDotNet.Samples.Repro.Process(Int32)
       inc       ebp
       cmp       ebp,0A
       jl        short M00_L03
       inc       ebx
       cmp       ebx,0A
       jl        short M00_L02
       inc       edi
       cmp       edi,0A
       jl        short M00_L01
       inc       esi
       cmp       esi,0A
       jl        short M00_L00
       add       rsp,20
       pop       rbx
       pop       rbp
       pop       rsi
       pop       rdi
       pop       r14
       ret
       sbb       [rdx],ecx
       (bad)
       or        dh,[rdx]
       (bad)
       add       eax,3600450
       jo        short M00_L04
       loopne    M00_L04
M00_L04:
       add       [rax],al
       (bad)
; Total bytes of code 105
; BenchmarkDotNet.Samples.Repro.Process(Int32)
       push      rbp
       mov       rbp,rsp
       mov       [rbp+10],ecx
       pop       rbp
       ret
       add       [rax],al
       add       [rcx],bl
       add       [rcx],eax
       add       [rcx],al
       push      rax
       add       [rax],al
       add       [rax],al
       add       [rax],al
       clc
       test      [rcx],r11d
       std
       jg        short M01_L00
M01_L00:
       add       [rbp+48],dl
       sub       esp,50
       (bad)
; Total bytes of code 39

While in the past we used to get:

.NET 6.0.8 (6.0.822.36306), X64 RyuJIT AVX2

; BenchmarkDotNet.Samples.Repro.Compute()
       push      r14
       push      rdi
       push      rsi
       push      rbp
       push      rbx
       sub       rsp,20
       xor       esi,esi
       xor       edi,edi
       xor       ebx,ebx
       xor       ebp,ebp
       imul      ecx,esi,3E8
       imul      eax,edi,64
       add       ecx,eax
       lea       eax,[rbx+rbx*4]
       lea       r14d,[rcx+rax*2]
       lea       ecx,[r14+rbp]
       call      0000000000001D90
       inc       ebp
       cmp       ebp,0A
       jl        short 0000000000009244
       inc       ebx
       cmp       ebx,0A
       jl        short 0000000000009230
       inc       edi
       cmp       edi,0A
       jl        short 000000000000922E
       inc       esi
       cmp       esi,0A
       jl        short 000000000000922C
       add       rsp,20
       pop       rbx
       pop       rbp
       pop       rsi
       pop       rdi
       pop       r14
       ret
; Total bytes of code 84
; BenchmarkDotNet.Samples.Repro.Process(Int32)
       push      rbp
       mov       rbp,rsp
       mov       [rbp+10],ecx
       pop       rbp
       ret
; Total bytes of code 9

@AndreyAkinshin it's a release blocker to me, I am going to try to solve it now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant