-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
JIT: Fix over-shifting logic when constant-folding AdvSimd.ShiftRight*
and AdvSimd.ShiftLeft*
#105847
Merged
Merged
JIT: Fix over-shifting logic when constant-folding AdvSimd.ShiftRight*
and AdvSimd.ShiftLeft*
#105847
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7f6fc8f
Fix overshifting for RSZ folding
amanasifkhalid 227197c
Add tests
amanasifkhalid 1c58151
Fix for RSH folding too
amanasifkhalid 1e257b8
Fix imms
amanasifkhalid a83832e
Add fallbacks for ShiftRight APIs; use them when imm is non-const/OOB
amanasifkhalid 9c808d5
Test coverage
amanasifkhalid a2cbdd3
Add ShiftLeft fallback + tests
amanasifkhalid 87b5533
Merge from main
amanasifkhalid 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 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
60 changes: 60 additions & 0 deletions
60
src/tests/JIT/Regression/JitBlue/Runtime_105817/Runtime_105817.cs
This file contains 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,60 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
// Generated by Fuzzlyn v2.2 on 2024-08-01 14:37:47 | ||
// Run on Arm64 MacOS | ||
// Seed: 14773448547728333023-vectort,vector64,vector128,armadvsimd,armadvsimdarm64,armaes,armarmbase,armarmbasearm64,armcrc32,armcrc32arm64,armdp,armrdm,armrdmarm64,armsha1,armsha256 | ||
// Reduced from 270.2 KiB to 0.4 KiB in 00:01:48 | ||
// Debug: Outputs 0 | ||
// Release: Outputs 1 | ||
using System; | ||
using System.Runtime.Intrinsics; | ||
using System.Runtime.Intrinsics.Arm; | ||
using Xunit; | ||
|
||
public class Runtime_105817 | ||
{ | ||
[Fact] | ||
public static void TestOverShiftRightLogical() | ||
{ | ||
if (AdvSimd.IsSupported) | ||
{ | ||
var vr6 = Vector128.Create<short>(1); | ||
var vr7 = AdvSimd.ShiftRightLogical(vr6, 16); | ||
Assert.Equal(vr7, Vector128<short>.Zero); | ||
} | ||
} | ||
|
||
[Fact] | ||
public static void TestOverShiftRightLogicalScalar() | ||
{ | ||
if (AdvSimd.IsSupported) | ||
{ | ||
var vr6 = Vector64.Create<long>(1); | ||
var vr7 = AdvSimd.ShiftRightLogicalScalar(vr6, 64); | ||
Assert.Equal(vr7, Vector64<long>.Zero); | ||
} | ||
} | ||
|
||
[Fact] | ||
public static void TestOverShiftRightArithmetic() | ||
{ | ||
if (AdvSimd.IsSupported) | ||
{ | ||
var vr6 = Vector128.Create<short>(1); | ||
var vr7 = AdvSimd.ShiftRightArithmetic(vr6, 16); | ||
Assert.Equal(vr7, Vector128<short>.Zero); | ||
} | ||
} | ||
|
||
[Fact] | ||
public static void TestOverShiftRightArithmeticScalar() | ||
{ | ||
if (AdvSimd.IsSupported) | ||
{ | ||
var vr6 = Vector64.Create<long>(1); | ||
var vr7 = AdvSimd.ShiftRightArithmeticScalar(vr6, 64); | ||
Assert.Equal(vr7, Vector64<long>.Zero); | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/tests/JIT/Regression/JitBlue/Runtime_105817/Runtime_105817.csproj
This file contains 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,8 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="$(MSBuildProjectName).cs" /> | ||
</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 we also check an out of range value like
65
? With the other change it should now be executing theShiftLogical
path rather than throwing, so we want to ensure its computing the right result between the unoptimized vs optimized as well.It may be interesting to check it for a non-constant or a value that only becomes constant after importation as well.
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.
Sure thing. #105777 only added the fallback implementation for
ShiftRightLogical
, soShiftRightLogicalScalar
,ShiftRightArithmetic
, andShiftRightArithmeticScalar
still throw in Debug. Are you ok with me adding their fallback implementations in this PR, or would you prefer that work in a separate one?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.
We weren't using the fallback APIs for non-const immediates either, so I added the
HW_Flag_NoJmpTableIMM
flag to theShiftRight*
APIs so we always use the fallback instead of a jump table.