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: Extraneous jumps around alignment in some cases after BBJ_NONE removal #96998

Closed
jakobbotsch opened this issue Jan 15, 2024 · 1 comment · Fixed by #97011
Closed

JIT: Extraneous jumps around alignment in some cases after BBJ_NONE removal #96998

jakobbotsch opened this issue Jan 15, 2024 · 1 comment · Fixed by #97011
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone

Comments

@jakobbotsch
Copy link
Member

jakobbotsch commented Jan 15, 2024

Simple case from @EgorBo:

public static void Foo()
{
    Foo();
}

Before #94239:

G_M24659_IG01:  ;; offset=0x0000
                                                ;; size=0 bbWeight=1 PerfScore 0.00
G_M24659_IG02:  ;; offset=0x0000
       align    [0 bytes for IG03]
                                                ;; size=0 bbWeight=1 PerfScore 0.00
G_M24659_IG03:  ;; offset=0x0000
       jmp      SHORT G_M24659_IG03
                                                ;; size=2 bbWeight=8 PerfScore 16.00

; Total bytes of code 2, prolog size 0, PerfScore 16.20, instruction count 2, allocated bytes for code 2 (MethodHash=999a9fac) for method Program:Foo() (FullOpts)

After #94239:

G_M24659_IG01:  ;; offset=0x0000
                                                ;; size=0 bbWeight=1 PerfScore 0.00
G_M24659_IG02:  ;; offset=0x0000
       jmp      SHORT G_M24659_IG03
       align    [0 bytes for IG03]
                                                ;; size=2 bbWeight=1 PerfScore 2.00
G_M24659_IG03:  ;; offset=0x0002
       jmp      SHORT G_M24659_IG03
                                                ;; size=2 bbWeight=8 PerfScore 16.00

; Total bytes of code 4, prolog size 0, PerfScore 18.40, instruction count 3, allocated bytes for code 4 (MethodHash=999a9fac) for method Program:Foo() (FullOpts)

cc @dotnet/jit-contrib @amanasifkhalid

@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 Jan 15, 2024
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jan 15, 2024
@ghost
Copy link

ghost commented Jan 15, 2024

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

Issue Details

Simple case from @EgorBo:

public static void Foo()
{
    Foo();
}

Before #94239:

G_M24659_IG01:  ;; offset=0x0000
                                                ;; size=0 bbWeight=1 PerfScore 0.00
G_M24659_IG02:  ;; offset=0x0000
       align    [0 bytes for IG03]
                                                ;; size=0 bbWeight=1 PerfScore 0.00
G_M24659_IG03:  ;; offset=0x0000
       jmp      SHORT G_M24659_IG03
                                                ;; size=2 bbWeight=8 PerfScore 16.00

; Total bytes of code 2, prolog size 0, PerfScore 16.20, instruction count 2, allocated bytes for code 2 (MethodHash=999a9fac) for method Program:Foo() (FullOpts)

(IG03 correctly aligned)

After #94239:

G_M24659_IG01:  ;; offset=0x0000
                                                ;; size=0 bbWeight=1 PerfScore 0.00
G_M24659_IG02:  ;; offset=0x0000
       jmp      SHORT G_M24659_IG03
       align    [0 bytes for IG03]
                                                ;; size=2 bbWeight=1 PerfScore 2.00
G_M24659_IG03:  ;; offset=0x0002
       jmp      SHORT G_M24659_IG03
                                                ;; size=2 bbWeight=8 PerfScore 16.00

; Total bytes of code 4, prolog size 0, PerfScore 18.40, instruction count 3, allocated bytes for code 4 (MethodHash=999a9fac) for method Program:Foo() (FullOpts)

(IG03 not correctly aligned)

cc @dotnet/jit-contrib @amanasifkhalid

Author: jakobbotsch
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@amanasifkhalid amanasifkhalid self-assigned this Jan 15, 2024
@amanasifkhalid amanasifkhalid added this to the 9.0.0 milestone Jan 15, 2024
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jan 15, 2024
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jan 15, 2024
@jakobbotsch jakobbotsch changed the title JIT: Loop alignment is computed incorrectly in some cases after BBJ_NONE removal JIT: Extraneous jumps around alignment in some cases after BBJ_NONE removal Jan 16, 2024
amanasifkhalid added a commit that referenced this issue Feb 2, 2024
Fixes #96998. The jump-to-next-block removal optimization currently passes on jumps with alignment padding behind them (see BasicBlock::CanRemoveJumpToNext). While our alignment placement strategy does not consider blocks with jumps that will be removed, it is possible for such a block to be chosen if it precedes the start of the loop being aligned. This alignment decision blocks the jump from being removed. Under normal circumstances, it should be fine to remove such jumps, and just fall through the alignment padding into the next block, but JitStress might decide to place breakpoint instructions in these alignment areas if behind a jump. So in debug builds, we now tell emitter::emitLoopAlignment if the jump was removed so JitStress does not consider placing breakpoints in the alignment padding.
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Feb 2, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 4, 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 a pull request may close this issue.

2 participants