Closed Zhentar closed 4 years ago
@Zhentar Have you tried to check IL ?
I have, but I don't know what I'm looking for so it didn't help much. The struct copy looks like this:
IL_0023: stloc.s line
IL_0025: ldloc.0 // result
IL_0026: ldloca.s line
Issue 1 is dotnet/runtime#8186 and 2 is dotnet/runtime#4308
For the third, in ref int colStarts = ref MemoryMarshal.GetReference(_colStarts);
, the span _colStarts
is being promoted; mov ecx,dword ptr [rcx+8]
is loading the _length
field of span even though it's not ever used. My searches haven't turned up any issues for that, but I could just be using the wrong terms.
IIRC when we promote a struct we load all its fields like this, and yeah, it seems unnecessary. We should investigate.
The unnecessary load is not there anymore.
; Assembly listing for method TestCase:TestCaseCode():int:this
G_M15559_IG15:
cmp dword ptr [rbp-50H], 1
jbe G_M15559_IG24
lea rcx, bword ptr [rbp-58H]
mov rcx, bword ptr [rcx]
mov edx, dword ptr [rcx]
mov ecx, dword ptr [rcx+4]
dec ecx
Not sure when the codegen changed, perhaps from better quality ref counts...(#19345) ??
Think we can close this as the other CQ issues here are tracked.
@Zhentar feel free to take a fresh look.
@Zhentar I'm going to go ahead and close this one. Feel free to re-open when/if you've had a chance to take a look.
It also looks to me like it has been resolved 👍
tl;dr: tried to go plaid, got polka dots C# code:
Selected ASM:
I see a few issues here...
readonly
struct so it shouldn't need a defensive copy, but even if it did, it's not referenced after the call so it wouldn't be necessary, and even if it were, the call is inlined so the lack of modification should be detectable.mov ecx,dword ptr [rcx+8]
is completely pointless since it's immediately overwritten.