Skip to content

Fix unsigned vector division correction lane width - #134362

Merged
tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-unsigned-vector-division
Sep 22, 2026
Merged

tannergooding merged 1 commit into
dotnet:mainfrom
tannergooding:tannergooding-unsigned-vector-division

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Use blendvps instead of blendvpd for the final unsigned quotient correction in both the AVX and SSE4.1 division paths.

The fallback computes quotients as doubles, then converts them to packed 32-bit integers with cvttpd2dq. Quotients at or above 2^31 produce the signed conversion's overflow sentinel. For nonzero uint divisors, those quotients require a divisor of 1, so the correction selects the original dividend. That selection must operate independently on each 32-bit lane; the previous 64-bit blend could miss an overflowing lane or incorrectly replace its neighbor. The earlier unsigned-input-to-double correction still correctly uses blendvpd.

Add focused Vector128<uint> and Vector256<uint> regressions covering the reported inputs, the signed-conversion boundary, and differing correction masks in neighboring lanes.

Validation

  • Built Checked and Release JITs on Windows x64. Both regression tests fail without the fix under AVX2, AVX-only, and SSE4.1, and pass with it. AVX-512 and software-fallback controls pass before and after.
  • Compared generated code: the corrected paths differ only in the blend opcode, with unchanged instruction counts and code size. Local BenchmarkDotNet comparisons had overlapping timing intervals; no throughput improvement is claimed.
  • Ran an additional 16,314 vector comparisons across five ISA configurations for nearby integer division, conversion boundaries, and mixed-mask selection paths.
  • Ran the Windows x64 JIT formatting check. x86 execution was not tested.

Resolves #133752

Note

This pull request description was drafted with GitHub Copilot.

Copilot AI lite review requested due to automatic review settings September 21, 2026 18:46
@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Sep 21, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 6 pipeline(s).
10 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot review overview

🟢 Approval recommended

No unresolved blocking issues were identified.

Review effort: Lite
Findings: None

What changed in this PR

Fixes incorrect unsigned SIMD vector division correction by selecting quotient corrections independently per 32-bit lane.

Changes:

  • Replaces blendvpd with blendvps in AVX and SSE4.1 paths.
  • Updates blend-mask register documentation.
  • Adds Vector128<uint> and Vector256<uint> regression tests.
File Description
src/​tests/​JIT/​Regression_ro_2/​Runtime_133752.cs Adds focused unsigned division regressions.
src/​coreclr/​jit/​lsraxarch.cpp Updates blend instruction allocation commentary.
src/​coreclr/​jit/​hwintrinsiccodegenxarch.cpp Corrects quotient correction to use 32-bit lanes.

@tannergooding
tannergooding merged commit b08d5fd into dotnet:main Sep 22, 2026
148 of 151 checks passed
@tannergooding
tannergooding deleted the tannergooding-unsigned-vector-division branch September 22, 2026 14:05
@tannergooding

Copy link
Copy Markdown
Member Author

/backport to release/11.0

Note

Backport requested through GitHub Copilot at the maintainer's direction.

@github-actions

Copy link
Copy Markdown
Contributor

Started backporting to release/11.0 (link to workflow run)

@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 23, 2026
JulieLeeMSFT pushed a commit that referenced this pull request Oct 12, 2026
…34421)

Backport of #134362 to `release/11.0`.

## Customer Impact

- [ ] Customer reported
- [x] Found internally

Reported in #133752 with a focused JIT repro; no
production customer incident is documented in that report. On x86/x64
unsigned-vector division paths without AVX-512, `Vector128<uint>` and
`Vector256<uint>` can silently return incorrect results when a quotient
reaches `2^31`. The correction can also overwrite an adjacent lane whose
quotient was already correct.

For example, `<uint.MaxValue, 9, 1, 1> / <1, 3, 1, 1>` should produce
`<4294967295, 3, 1, 1>`, but produces `<2147483648, 3, 1, 1>`. This
affects the AVX/AVX2 and legacy SSE4.1 fallback paths; AVX-512 and
software-fallback controls are unaffected.

The fix replaces the two final quotient-correction `blendvpd`
instructions with `blendvps`, so selection operates on the packed 32-bit
quotient lanes rather than pairs of lanes. The earlier double-precision
input correction remains unchanged.

## Regression

- [x] Yes
- [ ] No

Introduced during .NET 11 development by #117996, commit
`be7db811e5d11f176ecad493bb623e22985e7a85`, merged September 15, 2025.
That change extended SIMD integer division to unsigned and smaller
integer types and introduced both incorrect correction blends.

The .NET 10.0.0 source only imports this integer-division path for
signed `int`, not `uint`; the introducing commit is not in the .NET
10.0.0 release ancestry. This version assessment is based on
source/history inspection, not execution on .NET 10.

## Testing

On the main-branch implementation, built Checked and Release JITs on
Windows x64. Both added regression tests fail without the fix under
AVX2, AVX-only, and SSE4.1, and pass with the fix. AVX-512 and
software-fallback controls pass before and after. Verified that both
tests actually executed using the test-result XML.

The focused regressions cover the reported 128-bit and 256-bit inputs,
quotients below/at/above the signed-conversion boundary, and neighboring
lanes requiring different corrections. Ordinary small quotients do not
expose the error, and the AVX-512 path bypasses the faulty correction;
the new cases explicitly exercise those missing conditions.

An additional scratch audit passed 16,314 vector comparisons across five
ISA configurations, covering related integer division, conversion
boundaries, and mixed-mask selection. Disassembly comparisons showed
only the intended blend-opcode changes, with unchanged instruction
counts and code size. Local BenchmarkDotNet timing intervals overlapped;
no throughput improvement is claimed. The Windows x64 JIT formatting
check passed.

The bot-created backport was inspected and contains the same two opcode
fixes, explanatory comments, and focused regression tests. The
release/11.0 backport has not been built or executed locally; the
execution results above are from main. x86 and non-Windows execution
were not tested locally.

## Risk

Low. The executable change is limited to two blend opcodes in the
non-AVX-512 unsigned quotient correction. It corrects selection
granularity without changing register allocation, instruction count,
code size, public APIs, or the double-precision input conversion.
Focused before/after regressions cover both affected emission paths, and
AVX-512/software controls confirm unaffected paths retain their results.
The backport introduces no additional implementation changes.

**IMPORTANT**: If this backport is for a servicing release, please
verify that:

- For .NET 8 and .NET 9: The PR target branch is `release/X.0-staging`,
not `release/X.0`.
- For .NET 10+: The PR target branch is `release/X.0` (no `-staging`
suffix).

Verified: this PR targets `dotnet/runtime:release/11.0`.

## Package authoring no longer needed in .NET 9

**IMPORTANT**: Starting with .NET 9, you no longer need to edit a NuGet
package's csproj to enable building and bump the version.
Keep in mind that we still need package authoring in .NET 8 and older
versions.

No package-authoring changes are needed for this .NET 11 JIT fix.

Resolves #133752

> [!NOTE]
> This servicing assessment was drafted with GitHub Copilot.

Co-authored-by: Tanner Gooding <[email protected]>
Co-authored-by: Copilot App <[email protected]>
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JIT: (bug) Vector128/256<uint> division produces wrong lanes without AVX-512 (blendvpd used for 32-bit correction)

3 participants