-
Notifications
You must be signed in to change notification settings - Fork 5.5k
JIT: fold CAST<small>(COMMA(se, IND<small-same-size>))
#129387
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
Open
AndyAyersMS
wants to merge
1
commit into
dotnet:main
Choose a base branch
from
AndyAyersMS:fix-69472-fold-cast-ind-through-comma
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+125
−3
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
src/tests/JIT/Regression/JitBlue/Runtime_69472/Runtime_69472.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| namespace Runtime_69472; | ||
|
|
||
| using System; | ||
| using System.Runtime.CompilerServices; | ||
| using Xunit; | ||
|
|
||
| // Validates the fgOptimizeCast extension that looks through GT_COMMA wrappers | ||
| // to fold `CAST<small>(COMMA(side-effects, IND<small-same-size>))` into | ||
| // `COMMA(side-effects, IND<castToType>)`. The common shape is | ||
| // `(sbyte)span[i]` which previously emitted a zero-extending load followed by | ||
| // a sign-extending cast and should now collapse to a single `movsx` (or | ||
| // equivalently `movzx`) load. | ||
|
Comment on lines
+13
to
+15
|
||
| // | ||
| // Correctness must hold across signed/unsigned source-and-target combinations | ||
| // and across all relevant integer values for the small type. | ||
|
|
||
| public class Runtime_69472 | ||
| { | ||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static int SbyteFromByteArr(byte[] a, int i) => (sbyte)a[i]; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static int ByteFromSbyteArr(sbyte[] a, int i) => (byte)a[i]; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static int ShortFromUshortArr(ushort[] a, int i) => (short)a[i]; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static int UshortFromShortArr(short[] a, int i) => (ushort)a[i]; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static int SbyteFromReadOnlySpan(ReadOnlySpan<byte> s, int i) => (sbyte)s[i]; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static unsafe int SbyteFromPointer(byte* p) => (sbyte)*p; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| private static int SbyteFromByteField(Boxed b) => (sbyte)b._value; | ||
|
|
||
| private sealed class Boxed | ||
| { | ||
| public byte _value; | ||
| } | ||
|
|
||
| [Fact] | ||
| public static int TestEntryPoint() | ||
| { | ||
| bool ok = true; | ||
|
|
||
| for (int v = 0; v < 256; v++) | ||
| { | ||
| byte b = (byte)v; | ||
| sbyte sb = unchecked((sbyte)v); | ||
|
|
||
| byte[] ba = new[] { b }; | ||
| sbyte[] sba = new[] { sb }; | ||
|
|
||
| int expSbyteFromByte = unchecked((sbyte)b); | ||
| int expByteFromSbyte = (byte)sb; | ||
|
|
||
| if (SbyteFromByteArr(ba, 0) != expSbyteFromByte) | ||
| { | ||
| ok = false; | ||
| } | ||
| if (ByteFromSbyteArr(sba, 0) != expByteFromSbyte) | ||
| { | ||
| ok = false; | ||
| } | ||
| if (SbyteFromReadOnlySpan(ba, 0) != expSbyteFromByte) | ||
| { | ||
| ok = false; | ||
| } | ||
| if (SbyteFromByteField(new Boxed { _value = b }) != expSbyteFromByte) | ||
| { | ||
| ok = false; | ||
| } | ||
| unsafe | ||
| { | ||
| byte bb = b; | ||
| if (SbyteFromPointer(&bb) != expSbyteFromByte) | ||
| { | ||
| ok = false; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| for (int v = 0; v <= 0xFFFF; v++) | ||
| { | ||
| ushort uw = (ushort)v; | ||
| short sw = unchecked((short)v); | ||
| ushort[] ua = new[] { uw }; | ||
| short[] sa = new[] { sw }; | ||
|
|
||
|
Comment on lines
+90
to
+96
|
||
| if (ShortFromUshortArr(ua, 0) != unchecked((short)uw)) | ||
| { | ||
| ok = false; | ||
| } | ||
| if (UshortFromShortArr(sa, 0) != (ushort)sw) | ||
| { | ||
| ok = false; | ||
| } | ||
| } | ||
|
|
||
| return ok ? 100 : 1; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,6 +102,7 @@ | |
| <Compile Include="JitBlue\Runtime_128801\Runtime_128801.cs" /> | ||
| <Compile Include="JitBlue\Runtime_129076\Runtime_129076.cs" /> | ||
| <Compile Include="JitBlue\Runtime_129176\Runtime_129176.cs" /> | ||
| <Compile Include="JitBlue\Runtime_69472\Runtime_69472.cs" /> | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should this be a regression test? |
||
| </ItemGroup> | ||
| <Import Project="$(TestSourceDir)MergedTestRunner.targets" /> | ||
| </Project> | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't ChangeType do this already if called on the right node?