Skip to content
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

JIT: fix bad arm64 move peephole #68631

Merged
merged 1 commit into from
Apr 28, 2022
Merged

Conversation

AndyAyersMS
Copy link
Member

IF_DR_2G (mov sp/reg, reg/sp) has an implicit reg2, so an unwary peephole opt
might mistakenly think it is mov reg, x0. If the opt is unlucky and the next
instruction is a real mov reg, x0 the peephole opt might suppress the second
instruction, leaving the wrong value in reg.

Fix is to just disallow IF_DR_2G in the peephole.

Fixes #68527.

`IF_DR_2G` `(mov sp/reg, reg/sp)` has an implicit reg2, so an unwary peephole opt
might mistakenly think it is `mov reg, x0`. If the opt is unlucky and the next
instruction is a real `mov reg, x0` the peephole opt might suppress the second
instruction, leaving the wrong value in `reg`.

Fix is to just disallow `IF_DR_2G` in the peephole.

Fixes dotnet#68527.
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Apr 28, 2022
@ghost ghost assigned AndyAyersMS Apr 28, 2022
@ghost
Copy link

ghost commented Apr 28, 2022

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

Issue Details

IF_DR_2G (mov sp/reg, reg/sp) has an implicit reg2, so an unwary peephole opt
might mistakenly think it is mov reg, x0. If the opt is unlucky and the next
instruction is a real mov reg, x0 the peephole opt might suppress the second
instruction, leaving the wrong value in reg.

Fix is to just disallow IF_DR_2G in the peephole.

Fixes #68527.

Author: AndyAyersMS
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@AndyAyersMS
Copy link
Member Author

@kunalspathak PTAL
cc @dotnet/jit-contrib

If we see any diffs here we might think about backporting this. But seems unlikely we'll see any.

Copy link
Member

@kunalspathak kunalspathak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a nasty one and I continue to have similar thoughts that I had in #57016 (review). "I can imagine the pain to get to the bottom of this!" LGTM.

@BruceForstall BruceForstall merged commit e3eab0b into dotnet:main Apr 28, 2022
@AndyAyersMS
Copy link
Member Author

I can imagine the pain to get to the bottom of this!" LGTM.

It wasn't that bad. Once I got an updated windbg I used JitHashHalt and was able to single step through the method until it failed, then search back through all that to see where the value of x21 came from.

If you look at the diffs from #57016 the bug is there waiting for someone to spot it. Unfortunately, I assumed the previous assert for the various instr forms was sensible...

@ghost ghost locked as resolved and limited conversation to collaborators May 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
3 participants