Skip to content

[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
dotnet:release/11.0from
kenconnet666:mono-vector-compare-mask-class
Open

kenconnet666 wants to merge 2 commits into
dotnet:release/11.0from
kenconnet666:mono-vector-compare-mask-class

Conversation

@kenconnet666

Copy link
Copy Markdown

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, LessThan and LessThanOrEqual for Vector<float> and
Vector<double> return integer masks (Vector<int>, Vector<long>). In emit_sri_vector, klass is the class of
the first argument, and the comparison was emitted with it: the mask got the type of a float vector. With LLVM,
OP_XCOMPARE_FP then bitcasts the mask to the type of its operands, so adding masks became a float addition (a wrong
result), and comparing such a sum reaches OP_XCOMPARE with operands of two types and trips
g_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_XCAST when the two differ, as IsNegative and
IsPositive already do in the same file. Comparisons whose result has the type of their operands (all of
Vector64/128/256/512, and Vector<T> for integer T) are unchanged.

Customer Impact

  • Customer reported
  • Found internally

Reported in #136319, and hit by others there ("a blocker for web builds"). With RunAOTCompilation=true and the
default 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 only
workaround is WasmEnableSIMD=false, which turns SIMD off for the whole app.

Regression

  • Yes
  • No

The same code is in v10.0.0, so .NET 10 is affected too; earlier releases were not tried.

Testing

WasmSIMDTests gets the case of the issue: its program adds three masks of Vector<float> and of Vector<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-amd64 image of this branch's CI:

./build.sh -s mono+libs+packs -os browser -c Release

Then, with the official .NET SDK 11.0.100 and its wasm-tools workload, two apps were published with
RunAOTCompilation=true, first with the AOT cross compiler of the workload, then with the one of this build in its
place:

App 11.0.0 compiler Patched compiler
The repro of #136319 LLVMTypeOf (lhs) == LLVMTypeOf (rhs) assertion Publishes; in Node: sum <-2, -2, -2, -2>, none <0, 0, 0, 0>
An app that roots BepuPhysics 2.5.0-beta.33 Same assertion Publishes

The added WasmSIMDTests cases 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 Vector whose return type differs from the type of their
operands, the float and double overloads that return integer masks; OP_XCAST is a bitcast in LLVM and a register
move elsewhere. Every other comparison emits the same instructions as before.

🤖 Generated with Claude Code

…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 <[email protected]>
@dotnet-policy-service dotnet-policy-service Bot added the community-contribution Indicates that the PR has been added by a community member label Nov 16, 2026
@azure-pipelines

Copy link
Copy Markdown
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.

@kenconnet666

Copy link
Copy Markdown
Author

@dotnet-policy-service agree

@lewing lewing left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 <[email protected]>
@kenconnet666

Copy link
Copy Markdown
Author

Added in 175b903: the test program now sums three Vector.Equals masks of Vector<float> and of
Vector<double>, and compares the float sum with zero.

Checked with an AOT publish of that part of the program, run in Node:

Compiler Output
11.0.0 float equals <-1, -1, -1, -1>, double equals <-1, -1>
This PR float equals <-2, -2, -2, -2>, double equals <-2, -2>

So on the Equals path the unpatched compiler does not assert, it adds the masks as floats.

The failures of the previous run look unrelated: the known MutexTests failures of release/11.0, and a crash
of JIT.opt in OffsetLimit:DecGtArrayLengthPlusMaxValue.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-Build-mono community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants