-
Notifications
You must be signed in to change notification settings - Fork 5.3k
arm64: Replace RSH/RSZ -> CAST nodes with clearing register #121007
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
jonathandavies-arm
wants to merge
9
commits into
dotnet:main
Choose a base branch
from
jonathandavies-arm:upstream/ce/right-shift-cast
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.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
974f180
arm64: Replace RSH/RSZ -> CAST nodes with clearing register
jonathandavies-arm 1e0e05e
Only optimise on unsigned casts
jonathandavies-arm 6e345eb
Pass int into tests and perform casts in functions
jonathandavies-arm 6aa1714
Merge branch 'main' into upstream/ce/right-shift-cast
jonathandavies-arm aed793e
Merge branch 'main' into upstream/ce/right-shift-cast
EgorBo 2f5e093
Move optimisation from lowering to morph
jonathandavies-arm 8f98e15
Merge branch 'main' into upstream/ce/right-shift-cast
jonathandavies-arm 578d286
Add comment
jonathandavies-arm 1927134
Merge branch 'main' into upstream/ce/right-shift-cast
jonathandavies-arm 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
349 changes: 349 additions & 0 deletions
349
src/tests/JIT/opt/InstructionCombining/CastRightShift.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,349 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System; | ||
| using System.Runtime.CompilerServices; | ||
| using Xunit; | ||
|
|
||
| namespace TestCastRightShift | ||
| { | ||
| public class Program | ||
| { | ||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| [Fact] | ||
| public static int CheckCastRightShift() | ||
| { | ||
| bool fail = false; | ||
|
|
||
| if (CastASR7_byte_int(255) == 0) | ||
| { | ||
| fail = true; | ||
| } | ||
|
|
||
| if (CastASR8_byte_int(255) != 0) | ||
| { | ||
| fail = true; | ||
| } | ||
|
|
||
| if (CastLSR7_byte_uint(255) != 1) | ||
| { | ||
| fail = true; | ||
| } | ||
|
|
||
| if (CastLSR8_byte_uint(255) != 0) | ||
| { | ||
| fail = true; | ||
| } | ||
|
|
||
| if (CastASR7_byte_long(255) == 0) | ||
| { | ||
| fail = true; | ||
| } | ||
|
|
||
| if (CastASR8_byte_long(255) != 0) | ||
| { | ||
| fail = true; | ||
| } | ||
|
|
||
| if (CastLSR7_byte_ulong(255) == 0) | ||
| { | ||
| fail = true; | ||
| } | ||
|
|
||
| if (CastLSR8_byte_ulong(255) != 0) | ||
| { | ||
| fail = true; | ||
| } | ||
|
|
||
| if (CastASR7_sbyte_int(-127) != -1) | ||
| { | ||
| fail = true; | ||
| } | ||
|
|
||
| if (CastASR8_sbyte_int(-127) != -1) | ||
| { | ||
| fail = true; | ||
| } | ||
|
|
||
| if (CastASR7_sbyte_long(-127) != -1) | ||
| { | ||
| fail = true; | ||
| } | ||
|
|
||
| if (CastASR8_sbyte_long(-127) != -1) | ||
| { | ||
| fail = true; | ||
| } | ||
|
|
||
| if (CastASR15_ushort_int(65535) == 0) | ||
| { | ||
| fail = true; | ||
| } | ||
|
|
||
| if (CastASR16_ushort_int(65535) != 0) | ||
| { | ||
| fail = true; | ||
| } | ||
|
|
||
| if (CastLSR15_ushort_uint(65535) == 0) | ||
| { | ||
| fail = true; | ||
| } | ||
|
|
||
| if (CastLSR16_ushort_uint(65535) != 0) | ||
| { | ||
| fail = true; | ||
| } | ||
|
|
||
| if (CastASR15_ushort_long(65535) == 0) | ||
| { | ||
| fail = true; | ||
| } | ||
|
|
||
| if (CastASR16_ushort_long(65535) != 0) | ||
| { | ||
| fail = true; | ||
| } | ||
|
|
||
| if (CastLSR15_ushort_ulong(65535) == 0) | ||
| { | ||
| fail = true; | ||
| } | ||
|
|
||
| if (CastLSR16_ushort_ulong(65535) != 0) | ||
| { | ||
| fail = true; | ||
| } | ||
|
|
||
| if (CastASR15_short_int(-1) != -1) | ||
| { | ||
| fail = true; | ||
| } | ||
|
|
||
| if (CastASR16_short_int(-1) != -1) | ||
| { | ||
| fail = true; | ||
| } | ||
|
|
||
| if (CastASR15_short_long(-1) != -1) | ||
| { | ||
| fail = true; | ||
| } | ||
|
|
||
| if (CastASR16_short_long(-1) != -1) | ||
| { | ||
| fail = true; | ||
| } | ||
|
|
||
| if (fail) | ||
| { | ||
| return 101; | ||
| } | ||
| return 100; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static int CastASR7_byte_int(int x) | ||
| { | ||
| //ARM64-FULL-LINE: uxtb {{w[0-9]+}}, {{w[0-9]+}} | ||
| //ARM64-FULL-LINE: asr {{w[0-9]+}}, {{w[0-9]+}}, #7 | ||
| return (byte)x >> 7; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static int CastASR8_byte_int(int x) | ||
| { | ||
| //ARM64-FULL-LINE: mov {{w[0-9]+}}, wzr | ||
| return (byte)x >> 8; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static uint CastLSR7_byte_uint(int x) | ||
| { | ||
| //ARM64-FULL-LINE: uxtb {{w[0-9]+}}, {{w[0-9]+}} | ||
| //ARM64-FULL-LINE: lsr {{w[0-9]+}}, {{w[0-9]+}}, #7 | ||
| return (uint)(byte)x >> 7; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static uint CastLSR8_byte_uint(int x) | ||
| { | ||
| //ARM64-FULL-LINE: mov {{w[0-9]+}}, wzr | ||
| return (uint)(byte)x >> 8; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static long CastASR7_byte_long(int x) | ||
| { | ||
| //ARM64-FULL-LINE: uxtb {{w[0-9]+}}, {{w[0-9]+}} | ||
| //ARM64-FULL-LINE: asr {{w[0-9]+}}, {{w[0-9]+}}, #7 | ||
| //ARM64-FULL-LINE: sxtw {{x[0-9]+}}, {{w[0-9]+}} | ||
| return (byte)x >> 7; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static long CastASR8_byte_long(int x) | ||
| { | ||
| //ARM64-FULL-LINE: mov {{x[0-9]+}}, xzr | ||
| return (byte)x >> 8; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static ulong CastLSR7_byte_ulong(int x) | ||
| { | ||
| //ARM64-FULL-LINE: uxtb {{w[0-9]+}}, {{w[0-9]+}} | ||
| //ARM64-FULL-LINE: mov {{w[0-9]+}}, {{w[0-9]+}} | ||
| //ARM64-FULL-LINE: lsr {{x[0-9]+}}, {{x[0-9]+}}, #7 | ||
| return (ulong)(byte)x >> 7; | ||
| } | ||
|
|
||
| // This produces the following tree section with 2 CASTs | ||
| // We should check all the CASTs and then check that the lsr value | ||
| // is greater than or equal to smallest src bits. In this case | ||
| // we could change to mov w0, wzr. | ||
| // * RSZ long | ||
| // +--* CAST long <- ulong | ||
| // | \--* CAST int <- ubyte <- int | ||
| // | \--* LCL_VAR int | ||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static ulong CastLSR8_byte_ulong(int x) | ||
| { | ||
| //ARM64-FULL-LINE: uxtb {{w[0-9]+}}, {{w[0-9]+}} | ||
| //ARM64-FULL-LINE: mov {{w[0-9]+}}, {{w[0-9]+}} | ||
| //ARM64-FULL-LINE: lsr {{x[0-9]+}}, {{x[0-9]+}}, #8 | ||
| return (ulong)(byte)x >> 8; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static int CastASR7_sbyte_int(int x) | ||
| { | ||
| //ARM64-FULL-LINE: sxtb {{w[0-9]+}}, {{w[0-9]+}} | ||
| //ARM64-FULL-LINE: asr {{w[0-9]+}}, {{w[0-9]+}}, #7 | ||
| return (sbyte)x >> 7; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static int CastASR8_sbyte_int(int x) | ||
| { | ||
| //ARM64-FULL-LINE: sxtb {{w[0-9]+}}, {{w[0-9]+}} | ||
| //ARM64-FULL-LINE: asr {{w[0-9]+}}, {{w[0-9]+}}, #8 | ||
| return (sbyte)x >> 8; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static long CastASR7_sbyte_long(int x) | ||
| { | ||
| //ARM64-FULL-LINE: sxtb {{w[0-9]+}}, {{w[0-9]+}} | ||
| //ARM64-FULL-LINE: asr {{w[0-9]+}}, {{w[0-9]+}}, #7 | ||
| //ARM64-FULL-LINE: sxtw {{x[0-9]+}}, {{w[0-9]+}} | ||
| return (sbyte)x >> 7; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static long CastASR8_sbyte_long(int x) | ||
| { | ||
| //ARM64-FULL-LINE: sxtb {{w[0-9]+}}, {{w[0-9]+}} | ||
| //ARM64-FULL-LINE: asr {{w[0-9]+}}, {{w[0-9]+}}, #8 | ||
| //ARM64-FULL-LINE: sxtw {{x[0-9]+}}, {{w[0-9]+}} | ||
| return (sbyte)x >> 8; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static int CastASR15_ushort_int(int x) | ||
| { | ||
| //ARM64-FULL-LINE: uxth {{w[0-9]+}}, {{w[0-9]+}} | ||
| //ARM64-FULL-LINE: asr {{w[0-9]+}}, {{w[0-9]+}}, #15 | ||
| return (ushort)x >> 15; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static int CastASR16_ushort_int(int x) | ||
| { | ||
| //ARM64-FULL-LINE: mov {{w[0-9]+}}, wzr | ||
| return (ushort)x >> 16; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static uint CastLSR15_ushort_uint(int x) | ||
| { | ||
| //ARM64-FULL-LINE: uxth {{w[0-9]+}}, {{w[0-9]+}} | ||
| //ARM64-FULL-LINE: lsr {{w[0-9]+}}, {{w[0-9]+}}, #15 | ||
| return (uint)(ushort)x >> 15; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static uint CastLSR16_ushort_uint(int x) | ||
| { | ||
| //ARM64-FULL-LINE: mov {{w[0-9]+}}, wzr | ||
| return (uint)(ushort)x >> 16; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static long CastASR15_ushort_long(int x) | ||
| { | ||
| //ARM64-FULL-LINE: uxth {{w[0-9]+}}, {{w[0-9]+}} | ||
| //ARM64-FULL-LINE: asr {{w[0-9]+}}, {{w[0-9]+}}, #15 | ||
| //ARM64-FULL-LINE: sxtw {{x[0-9]+}}, {{w[0-9]+}} | ||
| return (ushort)x >> 15; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static long CastASR16_ushort_long(int x) | ||
| { | ||
| //ARM64-FULL-LINE: mov {{x[0-9]+}}, xzr | ||
| return (ushort)x >> 16; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static ulong CastLSR15_ushort_ulong(int x) | ||
| { | ||
| //ARM64-FULL-LINE: uxth {{w[0-9]+}}, {{w[0-9]+}} | ||
| //ARM64-FULL-LINE: mov {{w[0-9]+}}, {{w[0-9]+}} | ||
| //ARM64-FULL-LINE: lsr {{x[0-9]+}}, {{x[0-9]+}}, #15 | ||
| return (ulong)(ushort)x >> 15; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static ulong CastLSR16_ushort_ulong(int x) | ||
| { | ||
| //ARM64-FULL-LINE: uxth {{w[0-9]+}}, {{w[0-9]+}} | ||
| //ARM64-FULL-LINE: mov {{w[0-9]+}}, {{w[0-9]+}} | ||
| //ARM64-FULL-LINE: lsr {{x[0-9]+}}, {{x[0-9]+}}, #16 | ||
| return (ulong)(ushort)x >> 16; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static int CastASR15_short_int(int x) | ||
| { | ||
| //ARM64-FULL-LINE: sxth {{w[0-9]+}}, {{w[0-9]+}} | ||
| //ARM64-FULL-LINE: asr {{w[0-9]+}}, {{w[0-9]+}}, #15 | ||
| return (short)x >> 15; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static int CastASR16_short_int(int x) | ||
| { | ||
| //ARM64-FULL-LINE: sxth {{w[0-9]+}}, {{w[0-9]+}} | ||
| //ARM64-FULL-LINE: asr {{w[0-9]+}}, {{w[0-9]+}}, #16 | ||
| return (short)x >> 16; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static long CastASR15_short_long(int x) | ||
| { | ||
| //ARM64-FULL-LINE: sxth {{w[0-9]+}}, {{w[0-9]+}} | ||
| //ARM64-FULL-LINE: asr {{w[0-9]+}}, {{w[0-9]+}}, #15 | ||
| //ARM64-FULL-LINE: sxtw {{x[0-9]+}}, {{w[0-9]+}} | ||
| return (short)x >> 15; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static long CastASR16_short_long(int x) | ||
| { | ||
| //ARM64-FULL-LINE: sxth {{w[0-9]+}}, {{w[0-9]+}} | ||
| //ARM64-FULL-LINE: asr {{w[0-9]+}}, {{w[0-9]+}}, #16 | ||
| //ARM64-FULL-LINE: sxtw {{x[0-9]+}}, {{w[0-9]+}} | ||
| return (short)x >> 16; | ||
| } | ||
| } | ||
| } |
17 changes: 17 additions & 0 deletions
17
src/tests/JIT/opt/InstructionCombining/CastRightShift.csproj
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,17 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <!-- Needed for CLRTestEnvironmentVariable --> | ||
| <RequiresProcessIsolation>true</RequiresProcessIsolation> | ||
| </PropertyGroup> | ||
| <PropertyGroup> | ||
| <DebugType>None</DebugType> | ||
| <Optimize>True</Optimize> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="CastRightShift.cs"> | ||
| <HasDisasmCheck>true</HasDisasmCheck> | ||
| </Compile> | ||
| <CLRTestEnvironmentVariable Include="DOTNET_TieredCompilation" Value="0" /> | ||
| <CLRTestEnvironmentVariable Include="DOTNET_JITMinOpts" Value="0" /> | ||
| </ItemGroup> | ||
| </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.
Can you add a small comment around here saying what the transform does? Just similar to the one on line 11279.
Change lgtm otherwise
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.
Added a comment.