-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Optimization for full range checks (#70145) #70222
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 all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8f2935d
Optimization for full range checks (#70145)
SkiFoD 81523b6
Fix the x86 long value error (#70145)
SkiFoD 05022dd
Fix arm building errors (#70145)
SkiFoD ebbaa3e
Moved code according to the comments (#70145)
SkiFoD 5548ead
Moved code to fgOptimizeRelationalComparisonWithConst (#70145)
SkiFoD 4d7aaec
Moved logic to separate functions (#70145)
SkiFoD 2da383c
Simplified determining Lower/Upper bounds (#70145)
SkiFoD 01d7d48
Generalized both sides to intervals (#70145)
SkiFoD 8acf1cc
Refactoring of conditions (#70145)
SkiFoD 9a85185
Cut out unsigned types (#70145)
SkiFoD d11970c
Refactoring according to the comments (#70145)
SkiFoD 7c2cbd5
Fix parentheses (#70145)
SkiFoD 4faafae
Fix summary (#70145)
SkiFoD 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
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,204 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| // unit test for the full range comparison optimization | ||
|
|
||
| using System; | ||
| using System.Runtime.CompilerServices; | ||
|
|
||
| public class FullRangeComparisonTest | ||
| { | ||
| // Class for testing side effects promotion | ||
| public class SideEffects | ||
| { | ||
| public byte B; | ||
| } | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static bool EqualsOrGreaterThan_MinValue_RHSConst_Byte(byte b) => b >= 0; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static bool EqualsOrGreaterThan_MinValue_RHSConst_Short(short s) => s >= short.MinValue; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static bool EqualsOrGreaterThan_MinValue_RHSConst_Int(int i) => i >= int.MinValue; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static bool EqualsOrGreaterThan_MinValue_RHSConst_Long(long l) => l >= long.MinValue; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static bool EqualsOrLessThan_MaxValue_RHSConst_Byte(byte b) => b <= byte.MaxValue; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static bool EqualsOrLessThan_MaxValue_RHSConst_Short(short s) => s <= short.MaxValue; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static bool EqualsOrLessThan_MaxValue_RHSConst_Int(int i) => i <= int.MaxValue; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static bool EqualsOrLessThan_MaxValue_RHSConst_Long(long l) => l <= long.MaxValue; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static bool EqualsOrLessThan_MaxValue_RHSConst_UShort(ushort us) => us <= ushort.MaxValue; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static bool EqualsOrLessThan_MaxValue_RHSConst_UInt(uint ui) => ui <= uint.MaxValue; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static bool EqualsOrLessThan_MaxValue_RHSConst_ULong(ulong ul) => ul <= uint.MaxValue; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static bool EqualsOrLessThan_MinValue_LHSConst_Byte(byte b) => 0 <= b; | ||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static bool EqualsOrGreaterThan_MinValue_LHSConst_Short(short i) => short.MinValue <= i; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static bool EqualsOrLessThan_MinValue_LHSConst_Int(int i) => int.MinValue <= i; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static bool EqualsOrLessThan_MinValue_LHSConst_Long(long l) => long.MinValue <= l; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static bool EqualsOrGreaterThan_MaxValue_LHSConst_Byte(byte b) => byte.MaxValue >= b; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static bool EqualsOrGreaterThan_MaxValue_LHSConst_Short(short s) => short.MaxValue >= s; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static bool EqualsOrGreaterThan_MaxValue_LHSConst_Int(int i) => int.MaxValue >= i; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static bool EqualsOrGreaterThan_MaxValue_LHSConst_Long(long l) => long.MaxValue >= l; | ||
|
|
||
| [MethodImpl(MethodImplOptions.NoInlining)] | ||
| public static bool EqualsOrGreaterThan_MaxValue_LHSConst_SideEffects(SideEffects c) => c.B <= 255; | ||
| public static int Main() | ||
| { | ||
| // Optimize comparison with full range values | ||
| // RHS Const Optimization | ||
| if (!EqualsOrGreaterThan_MinValue_RHSConst_Byte(10)) | ||
| { | ||
| Console.WriteLine("FullRangeComparisonTest:EqualsOrGreaterThan_MinValue_RHSConst_Byte(10) failed"); | ||
| return 101; | ||
| } | ||
|
|
||
| if (!EqualsOrGreaterThan_MinValue_RHSConst_Short(-10)) | ||
| { | ||
| Console.WriteLine("FullRangeComparisonTest:EqualsOrGreaterThan_MinValue_RHSConst_Short(10) failed"); | ||
| return 101; | ||
| } | ||
|
|
||
| if (!EqualsOrGreaterThan_MinValue_RHSConst_Int(-10)) | ||
| { | ||
| Console.WriteLine("FullRangeComparisonTest:EqualsOrGreaterThan_MinValue_RHSConst_Int(10) failed"); | ||
| return 101; | ||
| } | ||
|
|
||
| if (!EqualsOrGreaterThan_MinValue_RHSConst_Long(-10)) | ||
| { | ||
| Console.WriteLine("FullRangeComparisonTest:EqualsOrGreaterThan_MinValue_RHSConst_Long(10) failed"); | ||
| return 101; | ||
| } | ||
|
|
||
| if (!EqualsOrLessThan_MaxValue_RHSConst_Byte(10)) | ||
| { | ||
| Console.WriteLine("FullRangeComparisonTest:EqualsOrLessThan_MaxValue_RHSConst_Byte(10) failed"); | ||
| return 101; | ||
| } | ||
|
|
||
| if (!EqualsOrLessThan_MaxValue_RHSConst_Short(10)) | ||
| { | ||
| Console.WriteLine("FullRangeComparisonTest:EqualsOrLessThan_MaxValue_RHSConst_Short(10) failed"); | ||
| return 101; | ||
| } | ||
|
|
||
| if (!EqualsOrLessThan_MaxValue_RHSConst_Int(10)) | ||
| { | ||
| Console.WriteLine("FullRangeComparisonTest:EqualsOrLessThan_MaxValue_RHSConst_Int(10) failed"); | ||
| return 101; | ||
| } | ||
|
|
||
| if (!EqualsOrLessThan_MaxValue_RHSConst_Long(10)) | ||
| { | ||
| Console.WriteLine("FullRangeComparisonTest:EqualsOrLessThan_MaxValue_RHSConst_Long(10) failed"); | ||
| return 101; | ||
| } | ||
|
|
||
| // LHS Const Optimization | ||
| if (!EqualsOrLessThan_MinValue_LHSConst_Byte(10)) | ||
| { | ||
| Console.WriteLine("FullRangeComparisonTest:EqualsOrLessThan_MinValue_LHSConst_Byte(10) failed"); | ||
| return 101; | ||
| } | ||
|
|
||
| if (!EqualsOrLessThan_MinValue_LHSConst_Int(-10)) | ||
| { | ||
| Console.WriteLine("FullRangeComparisonTest:EqualsOrLessThan_MinValue_LHSConst_Int(10) failed"); | ||
| return 101; | ||
| } | ||
|
|
||
| if (!EqualsOrLessThan_MinValue_LHSConst_Long(-10)) | ||
| { | ||
| Console.WriteLine("FullRangeComparisonTest:EqualsOrLessThan_MinValue_LHSConst_Long(10) failed"); | ||
| return 101; | ||
| } | ||
|
|
||
| if (!EqualsOrGreaterThan_MaxValue_LHSConst_Byte(10)) | ||
| { | ||
| Console.WriteLine("FullRangeComparisonTest:EqualsOrGreaterThan_MaxValue_LHSConst_Byte(10) failed"); | ||
| return 101; | ||
| } | ||
|
|
||
| if (!EqualsOrGreaterThan_MaxValue_LHSConst_Int(10)) | ||
| { | ||
| Console.WriteLine("FullRangeComparisonTest:EqualsOrGreaterThan_MaxValue_LHSConst_Int(10) failed"); | ||
| return 101; | ||
| } | ||
|
|
||
| if (!EqualsOrGreaterThan_MaxValue_LHSConst_Long(10)) | ||
| { | ||
| Console.WriteLine("FullRangeComparisonTest:EqualsOrGreaterThan_MaxValue_LHSConst_Long(10) failed"); | ||
| return 101; | ||
| } | ||
|
|
||
|
|
||
| // Unsigned values | ||
| if (!EqualsOrLessThan_MaxValue_RHSConst_UShort(10)) | ||
| { | ||
| Console.WriteLine("FullRangeComparisonTest:EqualsOrLessThan_MaxValue_RHSConst_UShort(10) failed"); | ||
| return 101; | ||
| } | ||
|
|
||
| if (!EqualsOrLessThan_MaxValue_RHSConst_UInt(10)) | ||
| { | ||
| Console.WriteLine("FullRangeComparisonTest:EqualsOrLessThan_MaxValue_RHSConst_UInt(10) failed"); | ||
| return 101; | ||
| } | ||
|
|
||
| if (!EqualsOrLessThan_MaxValue_RHSConst_ULong(10)) | ||
| { | ||
| Console.WriteLine("FullRangeComparisonTest:EqualsOrLessThan_MaxValue_RHSConst_ULong(10) failed"); | ||
| return 101; | ||
| } | ||
|
|
||
| // Side effects persist | ||
| try | ||
| { | ||
| EqualsOrGreaterThan_MaxValue_LHSConst_SideEffects(null); | ||
| Console.WriteLine("FullRangeComparisonTest:EqualsOrGreaterThan_MaxValue_LHSConst_SideEffects(null) failed"); | ||
| return 101; | ||
| } | ||
| catch (NullReferenceException ex) | ||
| { | ||
|
|
||
| } | ||
| catch (Exception ex) | ||
| { | ||
| Console.WriteLine("FullRangeComparisonTest:EqualsOrGreaterThan_MaxValue_LHSConst_SideEffects(null) failed"); | ||
| return 101; | ||
| } | ||
|
|
||
| Console.WriteLine("PASSED"); | ||
| return 100; | ||
| } | ||
| } |
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,12 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <OutputType>Exe</OutputType> | ||
| </PropertyGroup> | ||
| <PropertyGroup> | ||
| <DebugType>PdbOnly</DebugType> | ||
| <Optimize>True</Optimize> | ||
| </PropertyGroup> | ||
| <ItemGroup> | ||
| <Compile Include="$(MSBuildProjectName).cs" /> | ||
| </ItemGroup> | ||
| </Project> |
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.