-
Notifications
You must be signed in to change notification settings - Fork 5.5k
[arm64] Avoid sign-extending TYP_INT register moves #129864
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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
78 changes: 78 additions & 0 deletions
78
src/tests/JIT/opt/InstructionCombining/IntMoveNoSignExtend.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,78 @@ | ||
| // 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 TestIntMoveNoSignExtend | ||
| { | ||
| public class Program | ||
| { | ||
| static int s_value = 7; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static int GetInt() => s_value; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static void Sink(int x) => s_value ^= x; | ||
|
|
||
| // A reg-to-reg move of a TYP_INT value (here the call result kept in a callee-saved register | ||
| // across the following call) must not be sign extended to 64 bits: the upper bits are never | ||
| // observed for an int, so a plain 'mov Wd, Wn' suffices instead of 'sxtw Wd, Wn'. | ||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static int IntMove() | ||
| { | ||
| //ARM64-NOT: sxtw {{w[0-9]+}}, {{w[0-9]+}} | ||
|
AndyAyersMS marked this conversation as resolved.
Outdated
|
||
| int a = GetInt(); | ||
| Sink(0); | ||
| return a + GetInt(); | ||
| } | ||
|
|
||
| // A genuine int -> long widening must still sign extend with 'sxtw Xd, Wn'. | ||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| static long Widen(int x) | ||
| { | ||
| //ARM64-FULL-LINE: sxtw {{x[0-9]+}}, {{w[0-9]+}} | ||
| return x; | ||
| } | ||
|
|
||
| [Fact] | ||
| public static int TestEntryPoint() | ||
| { | ||
| int result = 100; | ||
|
|
||
| s_value = 7; | ||
| if (IntMove() != 14) | ||
| { | ||
| result = -1; | ||
| } | ||
|
|
||
| // Negative values must round-trip correctly through the move. | ||
| s_value = -123456; | ||
| if (IntMove() != -246912) | ||
| { | ||
| result = -1; | ||
| } | ||
|
|
||
| s_value = int.MinValue; | ||
| // int.MinValue + int.MinValue overflows to 0 in unchecked int arithmetic. | ||
| if (IntMove() != 0) | ||
| { | ||
| result = -1; | ||
| } | ||
|
|
||
| // Genuine widening must preserve the sign. | ||
| if (Widen(-7) != -7L) | ||
| { | ||
| result = -1; | ||
| } | ||
| if (Widen(int.MinValue) != int.MinValue) | ||
| { | ||
| result = -1; | ||
| } | ||
|
|
||
| return result; | ||
| } | ||
| } | ||
| } | ||
17 changes: 17 additions & 0 deletions
17
src/tests/JIT/opt/InstructionCombining/IntMoveNoSignExtend.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="IntMoveNoSignExtend.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.
Uh oh!
There was an error while loading. Please reload this page.