Skip to content

Remove dead/unreachable code in several JIT phases - #130801

Merged
tannergooding merged 4 commits into
dotnet:mainfrom
tannergooding:tannergooding-jit-phase-review
Jul 20, 2026
Merged

tannergooding merged 4 commits into
dotnet:mainfrom
tannergooding:tannergooding-jit-phase-review

Conversation

@tannergooding

Copy link
Copy Markdown
Member

This removes four pieces of dead or unreachable code found while auditing the major JIT phases. Each is an isolated, no-diff-expected cleanup and is a separate commit.


Remove dead reference-equality fast path in span half-const Equals

impUtf16SpanComparison wrapped the unrolled compare with GT_EQ(spanReferenceFld, cnsStr). spanReferenceFld is the span's _reference (TYP_BYREF, pointing at the character data) where-as cnsStr is the string object handle (TYP_REF), so the comparison is always false and the fast path never fires. This was copy-pasted from the string variant in impUtf16StringComparison, where comparing two object references is correct.

Note the intent here was real (added by #117431); making it actually fire for spans requires comparing span._reference against the address of the frozen string literal's character data, which is a larger change. Removing the always-false path for now.


Remove unfinished isSpanLength block in MorphStructFieldAddress

The block computed exactSize/exactFieldSize and then did nothing with them -- it was an unfinished attempt to preserve the "never negative" Span.Length property (from #81055) across struct promotion. The IsSpanLength() flag itself remains live and used; only the no-op block is removed.


Remove unused optCSE_MaskHelper

Superseded leftover -- the mask-data collection it was meant to do is handled by the MaskDataWalker class in optCSE_GetMaskData. The helper was a no-op with no callers.


Remove unreachable XnorMask handling in rationalization

NI_AVX512_XnorMask is only produced during lowering (lowerxarch.cpp), which runs after rationalization, so the XnorMask cases in RewriteHWIntrinsicToNonMask and ShouldRewriteToNonMaskHWIntrinsic were never reached. The rewrite was also malformed: it built a TYP_SIMD XOR from the still-TYP_MASK operands, which would trip unreached() if it ever ran.


No behavioral change is expected from any of these; jit-format is clean.

Note

This PR description and the underlying audit were drafted with the help of GitHub Copilot.

tannergooding and others added 4 commits July 15, 2026 09:41
The span variant of the vectorized Equals compared the span's `_reference`
byref against the string-literal object handle (a `TYP_REF`). Those pointers
are never equal, so the `?:` fast path never fired and only emitted a dead
always-false compare plus a QMARK. The string variant is a genuine ref==ref
compare and is left intact.

Co-authored-by: Copilot App <[email protected]>
The `isSpanLength` block computed `exactSize`/`exactFieldSize` from the
never-negative Span.Length case and did nothing with them -- an optimization
that was never finished. Drop the dead block along with the now-unused
`isSpanLength` and `fieldVarDsc`/`fieldSize` bookkeeping.

Co-authored-by: Copilot App <[email protected]>
`optCSE_MaskHelper` is a no-op that returns `WALK_CONTINUE` without touching
its arguments, and it has no callers -- the mask data is gathered by the
`MaskDataWalker` in `optCSE_GetMaskData`. Remove the definition and its
declaration.

Co-authored-by: Copilot App <[email protected]>
`NI_AVX512_XnorMask` is only produced during lowering, which runs after
rationalization, so the `XnorMask` cases in `RewriteHWIntrinsicToNonMask` and
`ShouldRewriteToNonMaskHWIntrinsic` were never reached. The rewrite was also
malformed: it built a `TYP_SIMD` XOR from the still-`TYP_MASK` operands and
then recursed into it, which would trip `unreached()` if it ever ran.

Co-authored-by: Copilot App <[email protected]>
Copilot AI review requested due to automatic review settings July 15, 2026 16:56
@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 15, 2026
@azure-pipelines

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

Pull request overview

This PR removes several dead or unreachable code paths across CoreCLR JIT phases, reducing maintenance burden without changing intended behavior.

Changes:

  • Removes the unreachable NI_AVX512_XnorMask rewrite logic from rationalization.
  • Deletes the unused optCSE_MaskHelper declaration/definition (mask collection is handled by the MaskDataWalker visitor).
  • Removes a non-functional reference-equality fast path in span half-const Equals, and deletes a no-op IsSpanLength block in local morphing.
Show a summary per file
File Description
src/coreclr/jit/rationalize.cpp Drops unreachable XnorMask rewrite handling from mask-to-nonmask rationalization logic.
src/coreclr/jit/optcse.cpp Removes the unused optCSE_MaskHelper walker callback stub.
src/coreclr/jit/lclmorph.cpp Deletes an unused/no-op IsSpanLength-related block in MorphStructFieldAddress.
src/coreclr/jit/importervectorization.cpp Removes a reference-equality check that could not usefully fire for span _reference vs string object handle.
src/coreclr/jit/compiler.h Removes the optCSE_MaskHelper declaration and updates adjacent comments for optCSE_MaskData.

Copilot's findings

  • Files reviewed: 5/5 changed files
  • Comments generated: 0

@tannergooding

Copy link
Copy Markdown
Member Author

CC. @dotnet/jit-contrib, @EgorBo

Some more dead code removal.

@github-actions

github-actions Bot commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow state for the Holistic Review Orchestrator.

{
  "version": 5,
  "last_dispatched_commit": "03914c8030b573a1c891b42db2b58d084c27c743",
  "last_dispatched_base_ref": "main",
  "last_dispatched_base_sha": "883277ee4090d28d5e1d996cab7be81bf4f96c50",
  "last_reviewed_commit": "03914c8030b573a1c891b42db2b58d084c27c743",
  "last_reviewed_base_ref": "main",
  "last_reviewed_base_sha": "883277ee4090d28d5e1d996cab7be81bf4f96c50",
  "last_recorded_worker_run_id": "29688129543",
  "review_attempt_commit": "",
  "review_attempt_base_ref": "",
  "review_attempt_count": 0,
  "max_review_attempts": 5,
  "review_history_format": "holistic-review-disclosure-v1",
  "review_history": [
    {
      "commit": "03914c8030b573a1c891b42db2b58d084c27c743",
      "review_id": 4730810027
    }
  ]
}

@github-actions github-actions Bot 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.

Holistic Review

Motivation: The PR removes four pieces of dead or unreachable JIT code discovered while auditing major phases: an always-false span reference-equality fast path in impUtf16SpanComparison, an unfinished no-op isSpanLength block in MorphStructFieldAddress, the unused optCSE_MaskHelper treewalk callback, and an unreachable NI_AVX512_XnorMask case in rationalization.

Approach: Each concern is an isolated deletion in its own commit, with no expected behavioral change. I independently verified each claim against the surrounding code before reading the PR narrative.

  • span fast path: spanReferenceFld is a TYP_BYREF _reference field while cnsStr is a TYP_REF string handle, so GT_EQ(spanReferenceFld, cnsStr) is always false and the QMARK fast path never fires. spanReferenceFld remains used at the impExpandHalfConstEquals call, so no orphaned locals result. The analogous ref==ref path in the string variant (impUtf16StringComparison) is correctly left intact.
  • isSpanLength block: The removed block computed exactSize/exactFieldSize and did nothing with them. fieldVarDsc/fieldSize were only consumed by that dead block, so removing them is safe; IsSpanLength() itself is untouched.
  • optCSE_MaskHelper: I confirmed there are no remaining callers anywhere in src/coreclr/jit/. The body only returned WALK_CONTINUE; the real mask collection is done by MaskDataWalker in optCSE_GetMaskData. The declaration in compiler.h and definition in optcse.cpp are both removed consistently, and the retained optCSE_MaskData comment was updated.
  • XnorMask: NI_AVX512_XnorMask is produced only in lowerxarch.cpp, and PHASE_RATIONALIZE runs before PHASE_LOWERING, so the case in RewriteHWIntrinsicToNonMask and ShouldRewriteToNonMaskHWIntrinsic was never reachable. The rewrite was also malformed (building a TYP_SIMD XOR from still-TYP_MASK operands). Codegen support in hwintrinsiccodegenxarch.cpp for the intrinsic remains, as expected.

Summary: ✅ LGTM. These are correct, well-scoped, verifiable removals of genuinely dead or unreachable code with no expected diff. I found no orphaned variables, no remaining references to the removed symbols, and no behavioral risk. Nothing blocking.

Note

This review was generated by this repository's Holistic Review agentic workflow to complement the built-in Copilot review.

Generated by Holistic Review · 54.2 AIC · ⌖ 10.6 AIC · ⊞ 10K

@EgorBo

EgorBo commented Jul 20, 2026

Copy link
Copy Markdown
Member

@EgorBo EgorBo 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.

Up to you regarding fixing the issue with Span, we can handle that separately

@tannergooding
tannergooding merged commit 73a9e0a into dotnet:main Jul 20, 2026
139 of 141 checks passed
@tannergooding
tannergooding deleted the tannergooding-jit-phase-review branch July 20, 2026 20:17
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 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.

3 participants