Skip to content

JIT: Treat store in JTRUE block as the ElseOperation in if-conversion#124738

Open
BoyBaykiller wants to merge 1 commit intodotnet:mainfrom
BoyBaykiller:if-conv-unconditional-store-to-else-124713
Open

JIT: Treat store in JTRUE block as the ElseOperation in if-conversion#124738
BoyBaykiller wants to merge 1 commit intodotnet:mainfrom
BoyBaykiller:if-conv-unconditional-store-to-else-124713

Conversation

@BoyBaykiller
Copy link
Copy Markdown
Contributor

@BoyBaykiller BoyBaykiller commented Feb 23, 2026

If-conversion phase now produces the same IR for these two cases:

bool First(int tMinLeft, int tMinRight)
{
    bool leftCloser = false;
    if (tMinLeft < tMinRight)
    {
        leftCloser = true;
    }
    return leftCloser;
}

bool Second(int tMinLeft, int tMinRight)
{
    bool leftCloser;
    if (tMinLeft < tMinRight)
    {
        leftCloser = true;
    }
    else
    {
        leftCloser = false;
    }
    return leftCloser;
}

The last unconditional store (leftCloser = false) is substituted into the SELECT which enables further optimization. Specifically it fixes #124713.

@github-actions github-actions bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Feb 23, 2026
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Feb 23, 2026
@dotnet-policy-service
Copy link
Copy Markdown
Contributor

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

@BoyBaykiller
Copy link
Copy Markdown
Contributor Author

@dotnet-policy-service agree

@BoyBaykiller BoyBaykiller marked this pull request as ready for review February 24, 2026 19:40
@BoyBaykiller BoyBaykiller marked this pull request as draft February 24, 2026 20:01
@BoyBaykiller BoyBaykiller changed the title JIT: Treat unconditional store as the else case in if-conversion JIT: Treat store in JTRUE block as the ElseOperation in if-conversion Mar 10, 2026
@BoyBaykiller BoyBaykiller force-pushed the if-conv-unconditional-store-to-else-124713 branch from 208cc34 to cba3e37 Compare March 19, 2026 00:48
@BoyBaykiller BoyBaykiller force-pushed the if-conv-unconditional-store-to-else-124713 branch from 8997012 to 2ae217c Compare April 15, 2026 18:29
@BoyBaykiller BoyBaykiller reopened this Apr 16, 2026
@BoyBaykiller BoyBaykiller marked this pull request as ready for review April 16, 2026 04:07
@BoyBaykiller
Copy link
Copy Markdown
Contributor Author

@a74nh @jakobbotsch PTAL

GenTreeLclVar* prevStore = tree->AsLclVar();
if (prevStore->GetLclNum() == targetLclNum)
{
if (prevStore->Data()->IsInvariant())
Copy link
Copy Markdown
Contributor Author

@BoyBaykiller BoyBaykiller Apr 16, 2026

Choose a reason for hiding this comment

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

This logic could for sure be made smarter to catch more cases but it's the best I can do for now. If we ever get a HIR version of IsInvariantInRange then we could use it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI community-contribution Indicates that the PR has been added by a community member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JIT: Turn conditional move arround bool into setl to save registers

1 participant