Repository navigation
Remove dead/unreachable code in several JIT phases - #130801
Conversation
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]>
|
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. |
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
There was a problem hiding this comment.
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_XnorMaskrewrite logic from rationalization. - Deletes the unused
optCSE_MaskHelperdeclaration/definition (mask collection is handled by theMaskDataWalkervisitor). - Removes a non-functional reference-equality fast path in span half-const
Equals, and deletes a no-opIsSpanLengthblock 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
|
CC. @dotnet/jit-contrib, @EgorBo Some more dead code removal. |
|
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
}
]
} |
There was a problem hiding this comment.
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:
spanReferenceFldis aTYP_BYREF_referencefield whilecnsStris aTYP_REFstring handle, soGT_EQ(spanReferenceFld, cnsStr)is always false and the QMARK fast path never fires.spanReferenceFldremains used at theimpExpandHalfConstEqualscall, 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/exactFieldSizeand did nothing with them.fieldVarDsc/fieldSizewere 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 returnedWALK_CONTINUE; the real mask collection is done byMaskDataWalkerinoptCSE_GetMaskData. The declaration incompiler.hand definition inoptcse.cppare both removed consistently, and the retainedoptCSE_MaskDatacomment was updated. - XnorMask:
NI_AVX512_XnorMaskis produced only inlowerxarch.cpp, andPHASE_RATIONALIZEruns beforePHASE_LOWERING, so the case inRewriteHWIntrinsicToNonMaskandShouldRewriteToNonMaskHWIntrinsicwas never reachable. The rewrite was also malformed (building aTYP_SIMDXOR from still-TYP_MASKoperands). Codegen support inhwintrinsiccodegenxarch.cppfor 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
|
Um.. why does unreachable code deletion lead to SPMI diffs (with perfscore regressions)? https://dev.azure.com/dnceng-public/public/_build/results?buildId=1510864&view=ms.vss-build-web.run-extensions-tab |
EgorBo
left a comment
There was a problem hiding this comment.
Up to you regarding fixing the issue with Span, we can handle that separately
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
EqualsimpUtf16SpanComparisonwrapped the unrolled compare withGT_EQ(spanReferenceFld, cnsStr).spanReferenceFldis the span's_reference(TYP_BYREF, pointing at the character data) where-ascnsStris the string object handle (TYP_REF), so the comparison is alwaysfalseand the fast path never fires. This was copy-pasted from the string variant inimpUtf16StringComparison, 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._referenceagainst the address of the frozen string literal's character data, which is a larger change. Removing the always-false path for now.Remove unfinished
isSpanLengthblock inMorphStructFieldAddressThe block computed
exactSize/exactFieldSizeand then did nothing with them -- it was an unfinished attempt to preserve the "never negative"Span.Lengthproperty (from #81055) across struct promotion. TheIsSpanLength()flag itself remains live and used; only the no-op block is removed.Remove unused
optCSE_MaskHelperSuperseded leftover -- the mask-data collection it was meant to do is handled by the
MaskDataWalkerclass inoptCSE_GetMaskData. The helper was a no-op with no callers.Remove unreachable
XnorMaskhandling in rationalizationNI_AVX512_XnorMaskis only produced during lowering (lowerxarch.cpp), which runs after rationalization, so theXnorMaskcases inRewriteHWIntrinsicToNonMaskandShouldRewriteToNonMaskHWIntrinsicwere never reached. The rewrite was also malformed: it built aTYP_SIMDXOR from the still-TYP_MASKoperands, which would tripunreached()if it ever ran.No behavioral change is expected from any of these;
jit-formatis clean.Note
This PR description and the underlying audit were drafted with the help of GitHub Copilot.