Fix not-greater-than predicate when lowering SIMD selects - #133589
tannergooding merged 3 commits into
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
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. |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
There was a problem hiding this comment.
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
LowerHWIntrinsicTernaryLogicto mapNI_X86Base_CompareNotGreaterThan/NI_AVX_CompareNotGreaterThantoNI_AVX512_CompareNotGreaterThanMask(instead ofCompareGreaterThanMask). - 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.csprojcompile 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>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
@EgorBo, resolved merge conflict now that the regression_ro_2.csproj has been fixed to avoid future conflicts. Need reapproval |
|
/ba-g unrelated failures that are also on main |
|
/backport to release/11.0 Note This backport request was posted by GitHub Copilot at the user's direction. |
|
Started backporting to |
…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>
Summary
Fix
LowerHWIntrinsicTernaryLogicconverting the X86Base and AVXCompareNotGreaterThanintrinsics toCompareGreaterThanMaskwhen folding a comparison into an AVX-512 masked blend. UseCompareNotGreaterThanMaskinstead, preserving the predicate, including its true result for unordered inputs.Add focused regression coverage for 128- and 256-bit
float/doubleoperands, less/equal/greater inputs, and NaN in either operand. Non-inlined helpers preserve runtime vector operands through lowering.Fixes #133550.
Validation
vcmpgtpstovcmpngtpswithout 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 emitvcmpngtpd.python3 src\coreclr\scripts\jitformat.py -r . -o windows -a x64successfully.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.