Skip to content

JIT: Fix zero-flag reuse for BSF/BSR - #133801

Merged
EgorBo merged 2 commits into
dotnet:mainfrom
EgorBo:fix-jit-bsf-bsr-zero-flags
Sep 21, 2026
Merged

EgorBo merged 2 commits into
dotnet:mainfrom
EgorBo:fix-jit-bsf-bsr-zero-flags

Conversation

@EgorBo

@EgorBo EgorBo commented Sep 12, 2026

Copy link
Copy Markdown
Member

Fixes #133783

Don't reuse BSF/BSR zero flags for result comparisons.

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

🟡 Changes recommended

The regression test needs explicit configuration to reliably exercise the BSF/BSR paths.

Get a fresh assessment by requesting another Copilot review.

Pull request overview

Fixes incorrect JIT zero-flag reuse for BSF/BSR result comparisons.

Changes:

  • Excludes BSF/BSR from result-based zero-flag reuse.
  • Updates related JIT flag-analysis helpers.
  • Adds regression coverage for 32-bit and 64-bit operations.
File summaries
File Reviewed changes
src/tests/JIT/Regression_ro_2/Runtime_133783.cs Adds regression coverage, but does not deterministically exercise BSF/BSR.
src/coreclr/jit/gentree.cpp Uses result-aware zero-flag detection.
src/coreclr/jit/emitxarch.h Updates the helper declaration.
src/coreclr/jit/emitxarch.cpp Excludes BSF/BSR from zero-flag reuse.
Review details
  • Files reviewed: 4/4 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment thread src/tests/JIT/Regression_ro_2/Runtime_133783.cs
@EgorBo

EgorBo commented Sep 14, 2026

Copy link
Copy Markdown
Member Author

PTAL @tannergooding

Comment thread src/coreclr/jit/emitxarch.cpp Outdated
Merge dotnet/runtime main at db48eab and rename the result-aware zero-flag helper to DoesWriteZeroFlagForResult as requested by Tanner.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 3e398eb-e934-46bc-bd49-79f54948c6be
Copilot AI review requested due to automatic review settings September 20, 2026 15:14

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

No unresolved blocking issues were identified.

Review effort: Lite
Findings: None

Resolved since last review (1)

@EgorBo
EgorBo merged commit df402ef into dotnet:main Sep 21, 2026
140 of 143 checks passed
@dotnet-milestone-bot dotnet-milestone-bot Bot added this to the 12.0-preview1 milestone Sep 22, 2026
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) x64: BitOperations.Log2/TrailingZeroCount compared against 0 produces wrong results when the BSR/BSF fallback is used

3 participants