Skip to content

Fix not-greater-than predicate when lowering SIMD selects - #133589

Merged
tannergooding merged 3 commits into
dotnet:mainfrom
tannergooding:tannergooding-simd-comparison-predicate-fixes
Sep 11, 2026
Merged

tannergooding merged 3 commits into
dotnet:mainfrom
tannergooding:tannergooding-simd-comparison-predicate-fixes

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Summary

Fix LowerHWIntrinsicTernaryLogic converting the X86Base and AVX CompareNotGreaterThan intrinsics to CompareGreaterThanMask when folding a comparison into an AVX-512 masked blend. Use CompareNotGreaterThanMask instead, preserving the predicate, including its true result for unordered inputs.

Add focused regression coverage for 128- and 256-bit float/double operands, less/equal/greater inputs, and NaN in either operand. Non-inlined helpers preserve runtime vector operands through lowering.

Fixes #133550.

Validation

  • Built checked CoreCLR with release libraries, then rebuilt the checked JIT with the fix.
  • All 10 regression cases failed before the fix on AVX-512 and passed afterward. AVX-512 instructions actually executed locally on Windows x64.
  • All 10 cases passed with AVX-512 disabled and with AVX2 disabled; the five applicable 128-bit cases passed with AVX disabled.
  • Existing packed and scalar AVX comparison tests passed with AVX-512 enabled and disabled.
  • Disassembly changes vcmpgtps to vcmpngtps without changing code size or instruction count: 34 bytes / 8 instructions for the 128-bit helper and 37 bytes / 9 instructions for the 256-bit helper. Double helpers emit vcmpngtpd.
  • Ran python3 src\coreclr\scripts\jitformat.py -r . -o windows -a x64 successfully.

Audited related predicate mappings and transforms across import, morph, VN, constant folding, rationalization, lowering, and intrinsic helpers. No additional uncovered predicate defect was found within that scope. This change does not duplicate the complement fixes in #133542.

Note

This PR description was generated by GitHub Copilot.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI lite review requested due to automatic review settings September 10, 2026 10:51
@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 10, 2026
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 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.

@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

The change is a small, localized correction to intrinsic ID selection with targeted regression coverage added in the JIT regression suite.

Review tier: Lite
Findings: None

What changed in this PR

This PR fixes an x86/x64 JIT lowering bug where CompareNotGreaterThan was incorrectly converted to CompareGreaterThanMask when folding comparisons into an AVX-512 masked blend, inverting the predicate (including unordered/NaN semantics). It also adds a focused JIT regression test covering the affected compare+select pattern for 128- and 256-bit float/double, including NaN cases.

Changes:

  • Fix LowerHWIntrinsicTernaryLogic to map NI_X86Base_CompareNotGreaterThan / NI_AVX_CompareNotGreaterThan to NI_AVX512_CompareNotGreaterThanMask (instead of CompareGreaterThanMask).
  • Add a new xUnit regression test exercising ConditionalSelect(CompareNotGreaterThan(...), ...) for 128/256 and float/double, including unordered (NaN) inputs.
  • Wire the new regression test into the Regression_ro_2.csproj compile list.
File Description
src/​coreclr/​jit/​lowerxarch.cpp Corrects the predicate mapping used when folding CompareNotGreaterThan into an AVX-512 per-element mask for masked blending.
src/​tests/​JIT/​Regression/​JitBlue/​Runtime_133550/​Runtime_133550.cs Adds regression coverage for CompareNotGreaterThan feeding ConditionalSelect across vector widths/types and NaN/unordered behavior.
src/​tests/​JIT/​Regression/​Regression_ro_2.csproj Includes the new regression test source file in the regression test project build.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 10, 2026 16:10

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

The change is a minimal, targeted correctness fix with appropriate regression coverage added in the same PR.

Review tier: Lite
Findings: None

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings September 11, 2026 02:35
@tannergooding

Copy link
Copy Markdown
Member Author

@EgorBo, resolved merge conflict now that the regression_ro_2.csproj has been fixed to avoid future conflicts. Need reapproval

@tannergooding
tannergooding enabled auto-merge (squash) September 11, 2026 02:38

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

The reviewed fix and regression coverage address the predicate-lowering defect.

Review tier: Lite
Findings: None

@tannergooding

Copy link
Copy Markdown
Member Author

/ba-g unrelated failures that are also on main

@tannergooding
tannergooding merged commit d0d1509 into dotnet:main Sep 11, 2026
141 of 143 checks passed
@tannergooding
tannergooding deleted the tannergooding-simd-comparison-predicate-fixes branch September 11, 2026 14:17
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 14, 2026
@tannergooding

Copy link
Copy Markdown
Member Author

/backport to release/11.0

Note

This backport request was posted by GitHub Copilot at the user's direction.

@github-actions

Copy link
Copy Markdown
Contributor

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

tannergooding added a commit that referenced this pull request Sep 20, 2026
…cts (#134214)

Backport of #133589 to release/11.0

/cc @tannergooding

## Customer Impact

- [ ] Customer reported
- [x] Found internally

This fixes #133550, where AVX-512 lowering changes
`CompareNotGreaterThan` to `CompareGreaterThan` when folding a
comparison into a masked SIMD select. Applications can silently receive
the opposite selected value for less-than, equal, greater-than, and
unordered inputs. The repro fails on .NET 11 RC2 but behaves correctly
on .NET 8, 9, and 10.

## Regression

- [x] Yes
- [ ] No

The incorrect predicate mapping was introduced during the .NET 11
development cycle; the exact introducing change was not identified.

## Testing

The source PR added focused 128- and 256-bit `float` and `double`
regressions covering less-than, equal, greater-than, and NaN inputs. All
10 cases failed before the fix on AVX-512 and passed afterward. They
also passed with AVX-512 and AVX2 disabled, with the applicable 128-bit
cases passing with AVX disabled. Existing packed and scalar AVX
comparison tests passed, and disassembly confirmed only the intended
predicate changed without increasing instruction count or code size.

## Risk

Low. The product change corrects a single intrinsic mapping from
`CompareGreaterThanMask` to `CompareNotGreaterThanMask`. Focused
coverage exercises all relevant predicates, element types, vector
widths, NaN handling, and non-AVX-512 fallbacks.

**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).

## 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.

> [!NOTE]
> This backport template was completed by GitHub Copilot at the user's
direction.

Co-authored-by: Tanner Gooding <tagoo@outlook.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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) CompareNotGreaterThan feeding a conditional select is evaluated as GreaterThan

3 participants