-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Prefer "mov reg, wzr" over "mov reg, #0" #64740
Conversation
Tagging subscribers to this area: @JulieLeeMSFT Issue Detailsit's slightly more efficient. int Test() => 0; ; Assembly listing for method Runtime:Test():int:this
- mov w0, #0
+ mov w0, wzr
|
15d7abc
to
4c9b17d
Compare
@dotnet/jit-contrib simple change, no size diffs, quite a few text diffs |
GetEmitter()->emitIns_R_I(INS_mov, size, reg, 0 ARM_ARG(flags)); | ||
#elif defined(TARGET_ARM64) | ||
GetEmitter()->emitIns_Mov(INS_mov, size, reg, REG_ZR, /* canSkip */ true); |
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 seems like a more general optimization (there are many Arm64 instructions that support ZR
or Immediate
). Is there something we can/should be doing in emit
instead to automatically recognize I == 0
and convert it to REG_ZR
to ensure that this optimization always lights up and that devs don't need to remember to specially handle it in every scenario?
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.
@tannergooding I think we already do it (e.g. #52269), just not sure how this one was skipped.
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.
I'll take a look at r2r dump corelib to find #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.
That's just handling containment in lowering which isn't quite the same as something like this (which is the result of we need zero and can't contain)
I was referring to doing basically a peephole in emit that says "you're passing #0
but this instruction also supports REG_ZR
, so fix it up there.
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.
By that PR I meant that we already do it since a simple change that just enabled containing resulted in ZR everywhere and huge diffs
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.
I've just checked all functions in R2R'd corelib - we only use #0
for cmp
and movn
now.
There are some cases where cmp reg, #0
is followed by a branch which most likely can be folded to "branch if zero" instructions but it's not related
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.
movn reg, #0
is interesting though
it's slightly more efficient.