Skip to content

JIT: Consistently use TypeIs/OperIs for type/oper checks #116141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 3, 2025

Conversation

jakobbotsch
Copy link
Member

@jakobbotsch jakobbotsch commented May 30, 2025

  • Add LclVarDsc::TypeIs
  • Switch type and oper checks to TypeIs and OperIs everywhere (replacements done with a series of regex)

@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 May 30, 2025
Copy link
Contributor

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

@EgorBo
Copy link
Member

EgorBo commented May 30, 2025

I would be more interested in replacing .gtType == instead

@jakobbotsch
Copy link
Member Author

I would be more interested in replacing .gtType == instead

I can try adding that to this PR. There's also gtOper == and OperGet() == . But the main thing here is that it had been annoying me for a while that LclVarDsc::TypeIs was not available.

@jakobbotsch jakobbotsch changed the title JIT: Add LclVarDsc::TypeIs; switch instances of 'TypeGet() == TYP_X' JIT: Consistently use TypeIs/OperIs for type/oper checks May 31, 2025
@jakobbotsch jakobbotsch marked this pull request as ready for review June 2, 2025 12:32
@Copilot Copilot AI review requested due to automatic review settings June 2, 2025 12:32
@jakobbotsch
Copy link
Member Author

PTAL @dotnet/jit-contrib

@jakobbotsch jakobbotsch requested a review from a team June 2, 2025 12:32
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 standardizes type and operator checks across the JIT by introducing and using TypeIs and OperIs in place of direct TypeGet/gtType and OperGet/gtOper comparisons.

  • Adds LclVarDsc::TypeIs (and variadic overload) for succinct multi‐type checks
  • Replaces OperGet() == ... with OperIs(...) everywhere
  • Replaces gtType/TypeGet() checks with TypeIs(...)

Reviewed Changes

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

Show a summary per file
File Description
emitriscv64.cpp OperGet/gtTypeOperIs/TypeIs in emitter logic
emitarm64.cpp, emitarm.cpp Same replacements in ARM emitters
emit.cpp, earlyprop.cpp Replaced legacy checks in codegen and early propagation
decomposelongs.cpp Assertions on GT_LONG use OperIs
compiler.hpp, compiler.h, compiler.cpp Added TypeIs and replaced type/operator checks
codegen*.cpp (xarch, risc-V, LoongArch, ARM) Wide spread substitutions in code generators
block.cpp, async.cpp, assertionprop.cpp Updated IR checks in flow/block and assertion props
codegencommon.cpp Address mode and register mask logic updated

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.

Surprised to see up to +0.12 TP regression - is it because of inlining?

@jakobbotsch
Copy link
Member Author

Surprised to see up to +0.12 TP regression - is it because of inlining?

Hmm, good question. In fact it does not repro for me locally... I get these results:

Overall (-0.04% to +0.00%)
Collection PDIFF
coreclr_tests.run.windows.arm64.checked.mch -0.04%
libraries.crossgen2.windows.arm64.checked.mch -0.03%
libraries.pmi.windows.arm64.checked.mch -0.01%
libraries_tests.run.windows.arm64.Release.mch -0.01%
libraries_tests_no_tiered_compilation.run.windows.arm64.Release.mch -0.02%
MinOpts (-0.15% to -0.07%)
Collection PDIFF
benchmarks.run.windows.arm64.checked.mch -0.09%
benchmarks.run_pgo.windows.arm64.checked.mch -0.08%
benchmarks.run_pgo_optrepeat.windows.arm64.checked.mch -0.09%
coreclr_tests.run.windows.arm64.checked.mch -0.08%
libraries.crossgen2.windows.arm64.checked.mch -0.08%
libraries.pmi.windows.arm64.checked.mch -0.08%
libraries_tests.run.windows.arm64.Release.mch -0.09%
libraries_tests_no_tiered_compilation.run.windows.arm64.Release.mch -0.07%
realworld.run.windows.arm64.checked.mch -0.15%
smoke_tests.nativeaot.windows.arm64.checked.mch -0.09%
FullOpts (-0.03% to +0.02%)
Collection PDIFF
benchmarks.run_pgo.windows.arm64.checked.mch +0.02%
coreclr_tests.run.windows.arm64.checked.mch -0.02%
libraries.crossgen2.windows.arm64.checked.mch -0.03%
libraries.pmi.windows.arm64.checked.mch -0.01%
libraries_tests.run.windows.arm64.Release.mch +0.01%
libraries_tests_no_tiered_compilation.run.windows.arm64.Release.mch -0.01%
Details

All contexts:

Collection Base # instructions Diff # instructions PDIFF
benchmarks.run.windows.arm64.checked.mch 42,792,977,269 42,792,221,072 -0.00%
benchmarks.run_pgo.windows.arm64.checked.mch 119,748,719,098 119,752,110,147 +0.00%
benchmarks.run_pgo_optrepeat.windows.arm64.checked.mch 42,828,529,180 42,827,744,300 -0.00%
coreclr_tests.run.windows.arm64.checked.mch 995,409,748,267 994,992,621,089 -0.04%
libraries.crossgen2.windows.arm64.checked.mch 151,857,837,650 151,817,820,219 -0.03%
libraries.pmi.windows.arm64.checked.mch 263,660,394,101 263,640,638,442 -0.01%
libraries_tests.run.windows.arm64.Release.mch 932,290,922,260 932,159,962,716 -0.01%
libraries_tests_no_tiered_compilation.run.windows.arm64.Release.mch 647,638,576,348 647,541,209,213 -0.02%
realworld.run.windows.arm64.checked.mch 54,340,454,293 54,338,321,544 -0.00%
smoke_tests.nativeaot.windows.arm64.checked.mch 15,373,973,969 15,373,237,134 -0.00%

MinOpts contexts:

Collection Base # instructions Diff # instructions PDIFF
benchmarks.run.windows.arm64.checked.mch 681,689 681,069 -0.09%
benchmarks.run_pgo.windows.arm64.checked.mch 16,050,213,750 16,036,824,267 -0.08%
benchmarks.run_pgo_optrepeat.windows.arm64.checked.mch 681,637 681,017 -0.09%
coreclr_tests.run.windows.arm64.checked.mch 392,316,889,269 392,001,312,512 -0.08%
libraries.crossgen2.windows.arm64.checked.mch 2,331,600 2,329,793 -0.08%
libraries.pmi.windows.arm64.checked.mch 146,028,223 145,906,441 -0.08%
libraries_tests.run.windows.arm64.Release.mch 220,660,525,305 220,456,644,188 -0.09%
libraries_tests_no_tiered_compilation.run.windows.arm64.Release.mch 13,799,334,658 13,789,288,251 -0.07%
realworld.run.windows.arm64.checked.mch 240,636,719 240,278,427 -0.15%
smoke_tests.nativeaot.windows.arm64.checked.mch 1,463,562 1,462,243 -0.09%

FullOpts contexts:

Collection Base # instructions Diff # instructions PDIFF
benchmarks.run.windows.arm64.checked.mch 42,792,295,580 42,791,540,003 -0.00%
benchmarks.run_pgo.windows.arm64.checked.mch 103,698,505,348 103,715,285,880 +0.02%
benchmarks.run_pgo_optrepeat.windows.arm64.checked.mch 42,827,847,543 42,827,063,283 -0.00%
coreclr_tests.run.windows.arm64.checked.mch 603,092,858,998 602,991,308,577 -0.02%
libraries.crossgen2.windows.arm64.checked.mch 151,855,506,050 151,815,490,426 -0.03%
libraries.pmi.windows.arm64.checked.mch 263,514,365,878 263,494,732,001 -0.01%
libraries_tests.run.windows.arm64.Release.mch 711,630,396,955 711,703,318,528 +0.01%
libraries_tests_no_tiered_compilation.run.windows.arm64.Release.mch 633,839,241,690 633,751,920,962 -0.01%
realworld.run.windows.arm64.checked.mch 54,099,817,574 54,098,043,117 -0.00%
smoke_tests.nativeaot.windows.arm64.checked.mch 15,372,510,407 15,371,774,891 -0.00%

I would expect that yes, it has to do with different inlining decisions, and it's probably quite sensitive to MSVC version. If that's the case it will change entirely with native PGO enabled. It also looks like there are no TP diffs with clang, so I will merge as-is.

@jakobbotsch jakobbotsch merged commit 43edad5 into dotnet:main Jun 3, 2025
114 checks passed
@jakobbotsch jakobbotsch deleted the vardsc-typeis branch June 3, 2025 10:11
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.

2 participants