Skip to content

Conversation

tannergooding
Copy link
Member

@tannergooding tannergooding commented Jul 29, 2025

This resolves #118143

This was exposed in, but not actually introduced by, #116983. The actual bug was introduced a bit over 10 months ago (still unique to .NET 10), as part of enabling the mask conversion optimization pass for xarch.

The general issue was that the transform was introducing invalid IR as it was creating a ConditionalSelect(mask, simd, simd) node when in actuality IR requires this to be: ConditionalSelect(simd, simd, simd). Cases like Sve.ConditionalSelect(mask, simd, simd) and BlendVariableMask(simd, simd, mask) do exist. But they will already be in the right shape as the mask operand will either directly be taking a mask (no conversion necessary) or they will have something like CvtSimdToMask(simd) for that argument position (which is handled by a different logical path in the mask conversion optimization phase).

The side effect of this invalid IR is that we would end up with an incorrect mask, which was logically being treated as zero when it should have been treated as a bitwise operation instead. This resulted in one path being dropped as dead code and us always returning op2 of ConditionalSelect(mask, op1, op2).

The intent of the handling was rather to look for cases that were logically ConditionalSelect(MaskToSimd(mask), simd, simd) and say "this could instead be BlendVariableMask(simd, simd, mask), but that is a bit more involved and is largely irrelevant with #116983 as we're preferring importing things to be handled as masks natively where possible already, which would allow the normal CvtSimdToMask(lcl) and CvtMaskToSimd(lcl) handling to kick-in.

@Copilot Copilot AI review requested due to automatic review settings July 29, 2025 06:24
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a bug in the mask conversion optimization pass that was creating invalid IR by incorrectly handling conditional select nodes. The optimization was transforming ConditionalSelect(mask, simd, simd) when IR requires ConditionalSelect(simd, simd, simd) format.

Key changes:

  • Removes invalid conditional select handling from mask conversion optimization
  • Eliminates the OperIsVectorConditionalSelect method that enabled the faulty transform
  • Cleans up whitespace in the optimization visitor code

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/coreclr/jit/optimizemaskconversions.cpp Removes conditional select handling logic and cleans up whitespace
src/coreclr/jit/gentree.h Removes OperIsVectorConditionalSelect method declaration
src/coreclr/jit/gentree.cpp Removes OperIsVectorConditionalSelect method implementation

@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 Jul 29, 2025
Copy link
Contributor

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

Copy link
Member

@EgorBo EgorBo left a comment

Choose a reason for hiding this comment

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

LGTM, do we need to backport this to any 10.0 preview branch?

@EgorBo
Copy link
Member

EgorBo commented Jul 29, 2025

Also, worth adding the original repro as a test case maybe?

@EgorBo
Copy link
Member

EgorBo commented Jul 29, 2025

/backport to release/10.0-preview7

Copy link
Contributor

Started backporting to release/10.0-preview7: https://github.com/dotnet/runtime/actions/runs/16599485416

@EgorBo EgorBo enabled auto-merge (squash) July 29, 2025 14:50
@EgorBo EgorBo merged commit 55805ee into dotnet:main Jul 29, 2025
114 of 116 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Aug 29, 2025
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.

Data Corruption in System.Buffers.Text.Base64.EncodeToUtf8
2 participants