-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Improve compare-and-branch sequences produced by Emitter #111797
base: main
Are you sure you want to change the base?
Improve compare-and-branch sequences produced by Emitter #111797
Conversation
Introduces an overload of `genJumpToThrowHlpBlk` that allows you to pass a function that generates the branch code, before it creates an inline throw block. This allows us to choose compare-and-branch sequences such as `cbz` on ARM64 for checks added in the emitter, such as divide-by-zero.
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Emit `cbz` instead of `cmp+b.ls` when checking bounds for an access to the 0 index of an array. It can only throw when `arrayLength == 0`. Fixes dotnet#42514
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added few comments.
src/coreclr/jit/codegencommon.cpp
Outdated
BasicBlock* CodeGen::genGetThrowHelper(SpecialCodeKind codeKind) | ||
{ | ||
bool useThrowHlpBlk = compiler->fgUseThrowHelperBlocks(); | ||
#if defined(UNIX_X86_ABI) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we remove this s because it is mainly used for arm64. Perhaps move this code from codegencommon.cpp
to codegenarm64.cpp
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I'll do that.
// For ARM64 we only expect equality comparisons. | ||
assert((cond == GenCondition::EQ) || (cond == GenCondition::NE)); | ||
|
||
if (compareImm == 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method is just called with compareImm == 0
. Are you planning to use it for other scenarios as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I would try and use this helper anywhere I have an immediate and want to compare-and-branch as it would handle the instruction selection generally.
Maybe if we used it here it might emit tbnz
sometimes for 2^n? Otherwise it just simplifies that block.
runtime/src/coreclr/jit/codegenarm64.cpp
Line 4177 in adf123c
if (comparand->IsIntegralConst(0)) |
Possibly another
cbz
case:runtime/src/coreclr/jit/codegenarm64.cpp
Line 4319 in adf123c
GetEmitter()->emitIns_R_I(INS_cmp, EA_4BYTE, data->GetRegNum(), 0); |
Introduces an overload of
genJumpToThrowHlpBlk
that allows you to pass a function that generates the branch code, before it creates an inline throw block. This allows us to choose compare-and-branch sequences such ascbz
on ARM64 for checks added in the emitter, such as divide-by-zero.Working towards #68028, I'll be looking into something similar for #42514 next using this helper I've added.