dotnet / dotnet/runtime

Simpler nullcheck can be emitted

Open
#123,302 3 comments 0 reactions 0 assignees View on GitHub
area-CodeGen-coreclr
Dominant language
C#
Stars
18.3k
Forks
5.6k
PR merge metrics
PR metrics pending

Description

Another finding from https://github.com/dotnet/runtime/pull/123290 diffs

```cs
private readonly char _oldValue;
private readonly char _newValue;

public void Test()
{
ReadOnlySpan.Empty.Replace(Span.Empty, _oldValue, _newValue);
}
```
Actual codegen:
```asm
; Method Runtime_122254:Test():this (FullOpts)
movsx rax, word ptr [rcx+0x08]
ret
; Total bytes of code: 6
```
Expected codegen:
```asm
; Method Runtime_122254:Test():this (FullOpts)
cmp byte ptr [rcx+0x08], cl
ret
```
unused `IND(ADD(X, CNS))` should be converted into `NULLCHECK`

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.