Skip to content

JIT: Investigate fallthrough flow regression from empty block removal #129275

Open

Description

@BoyBaykiller

In the diffs from #129092 there are a few cases where we no longer have fallthrough flow.

Example 1. coreclr_tests System.Math:Max.
G_M48648_IG08 -> G_M48648_IG07

G_M48648_IG02:  ;; offset=0x0000
       vucomiss xmm0, xmm1
       jp       SHORT G_M48648_IG03
       je       SHORT G_M48648_IG08
						;; size=8 bbWeight=1 PerfScore 4.00
G_M48648_IG03:  ;; offset=0x0008
       vucomiss xmm0, xmm0
       jp       SHORT G_M48648_IG04
       vucomiss xmm0, xmm1
       jbe      SHORT G_M48648_IG07
						;; size=12 bbWeight=1 PerfScore 6.00
G_M48648_IG04:  ;; offset=0x0014
       vmovaps  xmm1, xmm0
						;; size=4 bbWeight=1 PerfScore 0.25
G_M48648_IG05:  ;; offset=0x0018
       vmovaps  xmm0, xmm1
						;; size=4 bbWeight=1 PerfScore 0.25
G_M48648_IG06:  ;; offset=0x001C
       ret      
						;; size=1 bbWeight=1 PerfScore 1.00
G_M48648_IG07:  ;; offset=0x001D
       jmp      SHORT G_M48648_IG05
						;; size=2 bbWeight=0 PerfScore 0.00
G_M48648_IG08:  ;; offset=0x001F
       vmovd    eax, xmm1
       test     eax, eax
       jl       SHORT G_M48648_IG04
       jmp      SHORT G_M48648_IG07
						;; size=10 bbWeight=0 PerfScore 0.00

Example 2. benchmarks.run_pgo.windows System.Text.RegularExpressions.RegexNode:get_IsBacktrackingConstruct
G_M48811_IG07 -> G_M48811_IG05

G_M48811_IG02:  ;; offset=0x0000
       movzx    rax, byte  ptr [rcx+0x2E]
       lea      edx, [rax-0x03]
       cmp      edx, 5
       jbe      SHORT G_M48811_IG07
       cmp      eax, 24
       je       SHORT G_M48811_IG05
       add      eax, -26
       cmp      eax, 1
       jbe      SHORT G_M48811_IG06
						;; size=25 bbWeight=1 PerfScore 6.50
G_M48811_IG03:  ;; offset=0x0019
       xor      eax, eax
						;; size=2 bbWeight=1 PerfScore 0.25
G_M48811_IG04:  ;; offset=0x001B
       ret      
						;; size=1 bbWeight=1 PerfScore 1.00
G_M48811_IG05:  ;; offset=0x001C
       mov      eax, 1
       jmp      SHORT G_M48811_IG04
						;; size=7 bbWeight=0 PerfScore 0.00
G_M48811_IG06:  ;; offset=0x0023
       mov      eax, dword ptr [rcx+0x20]
       cmp      eax, dword ptr [rcx+0x24]
       je       SHORT G_M48811_IG03
       jmp      SHORT G_M48811_IG05
						;; size=10 bbWeight=0 PerfScore 0.00
G_M48811_IG07:  ;; offset=0x002D
       mov      eax, dword ptr [rcx+0x20]
       cmp      eax, dword ptr [rcx+0x24]
       je       SHORT G_M48811_IG03
       jmp      SHORT G_M48811_IG05
						;; size=10 bbWeight=0 PerfScore 0.00

Note how these cases are evolving arround bbWeight=0.0.
The original PR just removed empty blocks. I don't see why the new codegen would be any worse.

Activity

  1. added
    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
    on Jun 11, 2026
  2. dotnet-policy-service commented on Jun 11, 2026

    @dotnet-policy-service
    Contributor

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

  3. MihuBot commented on Jun 11, 2026

    @MihuBot

    I'm a bot. Here is a possible related and/or duplicate issue (I may be wrong):

  4. changed the title [-]JIT: Investigate regressions from empty block removal[/-] [+]JIT: Investigate fallthrough flow regression from empty block removal[/+] on Jun 12, 2026
  5. BoyBaykiller commented on Jun 12, 2026

    @BoyBaykiller
    ContributorAuthor

    So the reason for the diffs is quite simple.
    Layout opts intentionally don't waste time on bbWeight=0.0 blocks:

    // When walking the RPO-based layout, compact the hot blocks, and remember the end of the hot section.
    // We don't want to waste time running 3-opt on cold blocks, or on handler sections.
    unsigned numHotBlocks = 0;
    auto addToSequence = [this, initialLayout, &numHotBlocks](BasicBlock* block) {
    // The first block really shouldn't be cold, but if it is, ensure it's still placed first.
    if (!block->hasHndIndex() && (!block->isBBWeightCold(this) || block->IsFirst()))
    {
    // Set the block's ordinal.
    block->bbPreorderNum = numHotBlocks;
    initialLayout[numHotBlocks++] = block;
    }
    };

    I wonder if we can at least do something to avoid spurious diffs. Such as ordering all bbWeight=0.0 blocks by bbNum.
    Also I'm gonna try lift that restriction just to see diffs/tp impact. (@AndyAyersMS)

  6. added this to the Future milestone on Jun 30, 2026
  7. added
    help wanted[up-for-grabs] Good issue for external contributors
    and removed
    untriagedNew issue has not been triaged by the area owner
    on Jun 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIhelp wanted[up-for-grabs] Good issue for external contributors

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions