-
Notifications
You must be signed in to change notification settings - Fork 5.2k
Update a few code paths to ensure the trimmer can do its job #106777
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
| // The .NET Foundation licenses this file to you under the MIT license. | ||
|
|
||
| using System.Diagnostics; | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Runtime.CompilerServices; | ||
| #if NET | ||
| using System.Runtime.Intrinsics; | ||
|
|
@@ -181,6 +182,16 @@ internal static Vector128<byte> ShuffleUnsafe(Vector128<byte> vector, Vector128< | |
| } | ||
| #endif | ||
|
|
||
| [DoesNotReturn] | ||
| internal static void ThrowUnreachableException() | ||
| { | ||
| #if NET | ||
| throw new UnreachableException(); | ||
|
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. TIL that this exception type exists. Does it have any special meaning from the perspective of the trimmer?
Member
Author
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. No, its just the exception type we added explicitly to represent paths that should be "unreachable", so its the most appropriate one to use here. |
||
| #else | ||
| throw new Exception("Unreachable"); | ||
| #endif | ||
| } | ||
|
|
||
| internal interface IBase64Encoder<T> where T : unmanaged | ||
| { | ||
| ReadOnlySpan<byte> EncodingMap { get; } | ||
|
|
||
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.
Could you explain why this added branch is necessary? My expectation is that the entire method should have been trimmed altogether if its preconditions are not met.
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.
Some of the checks are "dynamic" and not statically
true/false.For example,
if (Sse2.IsSupported)is statically true forx86/x64andif (AdvSimd.Arm64.IsSupported)is staticallyfalse, butif (Ssse3.IsSupported)is dynamic because it depends on the underlying hardware.This means that on an
x86/x64system, theTryDecodeFromUtf16will always be preserved in IL. Prior to this PR, theelsepath was therefore being kept for the case that we were on hardware whereSsse3.IsSupportedwasfalseand that rootedAdvSimd.Arm64on xarch unnecessarily.With this change, we instead now allow the
AdvSimdpath to be trimmed out as dead code and the IL will instead keep theThrowUnreachableExceptionwhich allows things like R2R, the JIT, or AOT compilers to trim it out as dead code (because they will know the target hardware and treatSsse3.IsSupportedas constant, then allowing the method to be removed).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.
Thanks