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

Fix #70849: Print LARGEJMP instruction on ARM64 #71094

Merged
merged 1 commit into from
Jun 22, 2022

Conversation

amanasifkhalid
Copy link
Member

@amanasifkhalid amanasifkhalid commented Jun 21, 2022

These changes address #70849 by implementing the special case of printing the LARGEJMP pseudo-instruction in emitter::emitDispIns on ARM64. To achieve functional and organizational parity between the ARM32 and ARM64 implementations, emitter::emitDispIns has been re-architected as so:

  • On ARM64, the method's logic has been moved to emitter::emitDispInsHelp (just like on ARM32). The method now checks for the special LARGEJMP case, and calls the appropriate method.
  • On both architectures, the logic for printing LARGEJMP instructions has been moved to its own method.

@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 Jun 21, 2022
@ghost ghost assigned amanasifkhalid Jun 21, 2022
@ghost
Copy link

ghost commented Jun 21, 2022

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

Issue Details

These changes address #70849 by implementing the special case of printing the LARGEJMP pseudo-instruction in emitter::emitDispIns on ARM64. To achieve functional and organizational parity between the ARM32 and ARM64 implementations, emitter::emitDispIns has been re-architected as so:

  • On ARM64, the method's logic has been moved to emitter::emitDispInsHelp (just like on ARM32). The method now checks for the special LARGEJMP case, and calls the appropriate method.
  • On both architectures, the LARGEJMP implementation has been moved to its own method.
Author: amanasifkhalid
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@amanasifkhalid
Copy link
Member Author

amanasifkhalid commented Jun 21, 2022

@BruceForstall PTAL. I thought I'd tackle this in my spare time between the ARM64 hot/cold splitting PR and getting started on crossgen2. Thanks!

pidJmp->idIns(INS_b);
pidJmp->idInsFmt(IF_T2_J2);
pidJmp->idInsSize(emitInsSize(IF_T2_J2));
pidJmp->idjShort = 0;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is set to 1 above and then 0 here. Are both needed? Does pidJmp point to a different piece of memory in these cases?

Copy link
Member Author

Choose a reason for hiding this comment

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

idjShort is initially set to 1 to satisfy an assert in emitDispInsHelp , as we emit a short conditional branch first for the pseudo-instruction. While the following unconditional branch is long (thus suggesting idjShort should be 0), I don't see any asserts in its control flow through emitDispInsHelp that require idjShort == 0, though that could change in the future.

This looks weird because pidJmp is used to emit both the short conditional and the long unconditional branches, but I think the logic is correct.

Copy link
Member

Choose a reason for hiding this comment

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

The memory pointed to gets zeroed between uses (so zeroing isn't required, perhaps, but in this case it's best to be clear and have it).

Copy link
Contributor

Choose a reason for hiding this comment

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

I agree, clarity is important. It might be worth a comment to explain that two different things are being done through the ptr but it's not a problem without.

Copy link
Member

@BruceForstall BruceForstall left a comment

Choose a reason for hiding this comment

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

This looks great, just one request.

Can you share a before/after example of the output?

src/coreclr/jit/emitarm64.cpp Show resolved Hide resolved
@ghost ghost added the needs-author-action An issue or pull request that requires more info or actions from the author. label Jun 21, 2022
emitter::emitDispIns supports printing LARGEJMP pseudo-instructions on
ARM32, but not on ARM64. This method has been re-architected on ARM64
to support printing LARGEJMP instructions on ARM64.
@ghost ghost removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Jun 22, 2022
@amanasifkhalid
Copy link
Member Author

Can you share a before/after example of the output?

Sure thing. Consider the following (large) conditional branch:
cbz x0, G_M55167_IG07

The JIT converts this instruction to a "jump stub" by inverting the condition and emitting a short branch, followed by an unconditional branch to the original target. Previously, emitDispIns did not support printing jump stubs, and thus printed this incorrectly as so:

cbz     (LARGEJMP)G_M55167_IG07

(note the missing register argument, and no hex encoding of the instruction)

This jump stub now prints correctly, as so:

B5000040          cbnz    x0, pc+1 instructions
1400001B          b       (LARGEJMP)G_M55167_IG07

The hex encodings are now present, and both instructions in the jump stub are printed correctly.
Note that this behavior largely won't be visible until hot/cold splitting is enabled on ARM64 via this PR.

Copy link
Member

@BruceForstall BruceForstall left a comment

Choose a reason for hiding this comment

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

Looks good.

@amanasifkhalid amanasifkhalid merged commit c1d4494 into dotnet:main Jun 22, 2022
@amanasifkhalid amanasifkhalid deleted the emit-disp-largejmp branch June 22, 2022 18:29
@ghost ghost locked as resolved and limited conversation to collaborators Jul 22, 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
Development

Successfully merging this pull request may close these issues.

3 participants