-
Notifications
You must be signed in to change notification settings - Fork 5.3k
[release/8.0-staging] Fix constant folding for arm64 MultiplyByScalar operations involving Vector2.One #98150
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
[release/8.0-staging] Fix constant folding for arm64 MultiplyByScalar operations involving Vector2.One #98150
Conversation
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue DetailsBackport of #94413 to release/8.0-staging Customer Impact
Expressions involving multiplications of Regression
TestingRegression test included. RiskLow. The fix has been in main for several months already.
|
|
Friendly reminder that Monday February 12th is the Code Complete deadline for the March Release. Please make sure to add the |
|
@jakobbotsch in the meantime, while this bug exists in release 8.0.x and likely will for at least a few weeks/months until this is merged and a new release is cut, can the problematic |
Not easily I think, @tannergooding do you know if we have any fine grained controls that would allow this? A possible workaround is to extract the multiplication to your own uninlined function, something like [MethodImpl(MethodImplOptions.NoInlining)]
static Vector2 MulByScalar(Vector2 v, float a) => v * a; |
jeffschwMSFT
left a comment
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.
approved. we will take for consideration in 8.0.x
We do not. You either get all intrinsics in an ISA, or none of them. There is no per method configuration (which would be a nightmare to maintain, given we have over 2000 Arm64 intrinsic APIs). We likewise have no support for emulating the behavior of Arm64 hardware intrinsics. If the hardware doesn't support them, you don't get access to them and they throw. |
@tannergooding understood. so disabling all arm64 hardware intrinsics is an option then in the meantime Is there any way to set that environment variable as default at application compile time? It seems like it needs to be set before the dotnet runtime even starts inorder for the jit to respect it, so setting it in the main Program.cs doesn't seem to work as that is too late. |
A lot of very core components in the BCL use hardware intrinsics for acceleration but very few of them rely on multiplication by a scalar and even fewer rely or expose any potential to hit multiplication of a scalar by a constant. As such, I expect you would see very significant performance regressions from globally disabling the feature and it would likely be significantly easier to just workaround the behavior in your own application instead. For example, if you're needing to construct a
Yes
Not that I'm aware of. These configuration knobs are primarily meant for testing purposes, so dev's can trivially test things like their software fallback on a platform with SIMD support. They aren't really meant to be actually disabled in production scenarios, so they only support environment variables and don't have a corresponding |
|
Approved by tactics over email. |
Sure, performance is poorer but the results are correct (which is what is important). Given the time/complexity/difficulty in working around the temporary problem (see below), I proposed the temporary solution. This issue existing at all even when a fix was in
Sure, easy to say in theory, not feasible in practice where vector math is used across many files in the application and its framework (just two examples here: https://github.com/FosterFramework/Foster/blob/main/Framework/Utility/Calc.cs https://github.com/ExOK/Celeste64/blob/main/Source/Helpers/Utils.cs). Looking at it further, I assume that any use of the following constants multiplied by a vector would cause the bug https://github.com/FosterFramework/Foster/blob/dc065e0bfe1ed73e7285701c7128f5c6d1443b4b/Framework/Utility/Calc.cs#L18-L49 but I have not checked every file for user of vectors multiplied by constants... it would be great ordeal to do so and fix each one. edit: or maybe not since those are floats... in any case, this just highlights the ordeal that it would be to go through the application and all recursive dependencies to check for vector times scalar operations. Its not my application either, I just was one of the ones that encountered the issue after building and testing the application on ARM64 linux and reported it to the application developer. Incase it wasn't clear, I am not a developer, just a hardware hacker/packager/porter/OS maintainer. edit: this comment does not necessitate a response. it is just something to think about for the future. |
|
@jakobbotsch I'd like to confirm that this PR will get merged into the upcoming v8.0.3 tag by @dotnet-bot It seems arbitrary to me what gets pulled from 8.0-staging into the release tag. Something like only commits that have an age >= 1 month seem to have gotten pulled in from 8.0-staging into the v8.0.2 release tag which is why this was missed last cycle. |
|
Yes, this will be in 8.0.3.
The servicing releases are finalized and validated several weeks before they are released. I've personally already manually validated that the reported issues around this bug are fixed with 8.0.3. It was never expected that this fix would make 8.0.2. |
Backport of #94413 to release/8.0-staging
Customer Impact
Expressions involving multiplications of
VectorX.Onewith a scalar are constant folded to incorrect values. For example,Vector2.One * a, which should be folded to<a, a>is folded to<a, 0>. Customer reported in #98137; this backports a .NET 9 fix #94413 that noticed and fixed the issue.Regression
Testing
Regression test included.
Risk
Low. The fix has been in main for several months already.