Repository navigation
[release/11.0] [mono] Cast the float and double vector comparisons of Vector to their integer mask type - #137615
Open
kenconnet666 wants to merge 2 commits into
Open
kenconnet666 wants to merge 2 commits into
kenconnet666 wants to merge 2 commits into
Conversation
…r integer mask type Vector.Equals, GreaterThan, GreaterThanOrEqual, LessThan and LessThanOrEqual for Vector<float> and Vector<double> return Vector<int> and Vector<long> masks, but the SIMD intrinsic typed the comparison with the class of its operands. With LLVM, the masks were then added as floats (a wrong result), and comparing such a sum tripped the `LLVMTypeOf (lhs) == LLVMTypeOf (rhs)` assertion in mini-llvm.c, which aborts the AOT compiler (for instance on BepuPhysics for browser-wasm with SIMD). The comparison is now cast to the type of the result, as IsNegative and IsPositive already do. Fixes dotnet#136319 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kenconnet666
requested review from
ilonatommy,
maraf,
steveisok and
vitek-karas
as code owners
November 16, 2026 06:07
|
Azure Pipelines: Successfully started running 4 pipeline(s). 11 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Author
|
@dotnet-policy-service agree |
lewing
reviewed
Nov 16, 2026
lewing
left a comment
Member
There was a problem hiding this comment.
Thanks, the change looks good overall but please add a test for the Vector.Equals(Vector<float>, Vector<float>) case that is summed or compared afterwards to validate the changed path.
Vector.Equals has its own path in emit_sri_vector, which the test did not reach: it only summed the masks of GreaterThan and LessThan. The program now also sums three Vector.Equals masks of Vector<float> and of Vector<double>, and compares a sum with zero. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Author
|
Added in 175b903: the test program now sums three Checked with an AOT publish of that part of the program, run in Node:
So on the The failures of the previous run look unrelated: the known |
This was referenced Nov 19, 2026
This branch has not been deployed
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #136319
This targets release/11.0 directly: Mono's product build left main in #137518, so the fix has no main PR to back
port.
Description
Vector.Equals,GreaterThan,GreaterThanOrEqual,LessThanandLessThanOrEqualforVector<float>andVector<double>return integer masks (Vector<int>,Vector<long>). Inemit_sri_vector,klassis the class ofthe first argument, and the comparison was emitted with it: the mask got the type of a float vector. With LLVM,
OP_XCOMPARE_FPthen bitcasts the mask to the type of its operands, so adding masks became a float addition (a wrongresult), and comparing such a sum reaches
OP_XCOMPAREwith operands of two types and tripsg_assert (LLVMTypeOf (lhs) == LLVMTypeOf (rhs))in mini-llvm.c, which aborts the AOT compiler.The fix casts the comparison to the type of the result with
OP_XCASTwhen the two differ, asIsNegativeandIsPositivealready do in the same file. Comparisons whose result has the type of their operands (all ofVector64/128/256/512, andVector<T>for integerT) are unchanged.Customer Impact
Reported in #136319, and hit by others there ("a blocker for web builds"). With
RunAOTCompilation=trueand thedefault WebAssembly SIMD, any assembly that adds or compares the masks of float vector comparisons either computes
wrong values silently, or stops the AOT compiler. BepuPhysics 2.5.0-beta.33 is in the second case
(
TriangleCylinderTester.TryAddInteriorPoint): a browser app that uses it cannot be AOT-compiled with SIMD. The onlyworkaround is
WasmEnableSIMD=false, which turns SIMD off for the whole app.Regression
The same code is in v10.0.0, so .NET 10 is affected too; earlier releases were not tried.
Testing
WasmSIMDTestsgets the case of the issue: its program adds three masks ofVector<float>and ofVector<double>comparisons, and compares a sum with zero, and the tests check the values in all their AOT, interpreter and SIMD
combinations.
Validated on Linux x64, in the
azurelinux-3.0-net11.0-webassembly-amd64image of this branch's CI:Then, with the official .NET SDK 11.0.100 and its
wasm-toolsworkload, two apps were published withRunAOTCompilation=true, first with the AOT cross compiler of the workload, then with the one of this build in itsplace:
LLVMTypeOf (lhs) == LLVMTypeOf (rhs)assertionsum <-2, -2, -2, -2>,none <0, 0, 0, 0>The added
WasmSIMDTestscases were not run locally: run without a workload (-p:InstallWorkloadForTesting=false -p:TestUsingWorkloads=false), the class discovers none of its tests, and installing the workload from this build needs the CoreCLR browser runtime pack, which it does not build. CI runs them.Risk
Low. The change only adds a cast after the comparisons of
Vectorwhose return type differs from the type of theiroperands, the float and double overloads that return integer masks;
OP_XCASTis a bitcast in LLVM and a registermove elsewhere. Every other comparison emits the same instructions as before.
🤖 Generated with Claude Code