Skip to content

Conversation

@kunalspathak
Copy link
Contributor

We track the jmp instructions in IG as potential candidate for removal, regardless of if the IG jumps to the next IG or if the IG contains alignment. In emitRemoveJumpToNextInst(), we first iterate over these candidate jmp instructions and expect the IG shouldn't have align instruction, which is false. Only if the IG was marked as IGF_HAS_REMOVABLE_JMP, we should assert that it shouldn't end up with align instruction. Moved the assert at right place.

Fix the problem reported in #95729 (comment)

@ghost ghost assigned kunalspathak Dec 11, 2023
@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Dec 11, 2023
@ghost
Copy link

ghost commented Dec 11, 2023

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

Issue Details

We track the jmp instructions in IG as potential candidate for removal, regardless of if the IG jumps to the next IG or if the IG contains alignment. In emitRemoveJumpToNextInst(), we first iterate over these candidate jmp instructions and expect the IG shouldn't have align instruction, which is false. Only if the IG was marked as IGF_HAS_REMOVABLE_JMP, we should assert that it shouldn't end up with align instruction. Moved the assert at right place.

Fix the problem reported in #95729 (comment)

Author: kunalspathak
Assignees: kunalspathak
Labels:

area-CodeGen-coreclr

Milestone: -

@kunalspathak kunalspathak marked this pull request as ready for review December 11, 2023 15:03
@kunalspathak kunalspathak changed the title Force new IG for align, if current IG could have a removable jmp Update the place where we assert about align presence while removing jump to next instr Dec 11, 2023
@kunalspathak
Copy link
Contributor Author

@dotnet/jit-contrib

Copy link
Member

@jakobbotsch jakobbotsch left a comment

Choose a reason for hiding this comment

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

LGTM.

Does it mean this check for hasAlign() is unnecessary?

// If a block was selected to place an alignment instruction because it ended
// with a jump, do not remove jumps from such blocks.
// Do not remove a jump between hot and cold regions.
bool isRemovableJmpCandidate =
!block->hasAlign() && !compiler->fgInDifferentRegions(block, block->GetTarget());

When I was looking at the issue I kind of got the feeling that this check is what normally filters out the case, but in this particular scenario didn't because we had two basic blocks mapped to the same IG.

@kunalspathak
Copy link
Contributor Author

Does it mean this check for hasAlign() is unnecessary?

ideally yes, that seems unnecessary. We will only attempt to remove the jmp if the block has the flag on it, regardless of what instruction flag idjIsRemovableJmpCandidate says. I will remove it in this PR.

@kunalspathak kunalspathak merged commit acc3f0c into dotnet:main Dec 13, 2023
@kunalspathak kunalspathak deleted the loop-align-bug branch December 13, 2023 19:54
@github-actions github-actions bot locked and limited conversation to collaborators Jan 13, 2024
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.

2 participants