Skip to content

Conversation

@EgorBo
Copy link
Member

@EgorBo EgorBo commented Nov 25, 2023

Should help with cases like:

void Test(int x) { if (x > 100) if (x > 10) // always true Console.WriteLine(); }
; Method Program:Test(int):this (FullOpts) sub rsp, 40 cmp edx, 100 jle SHORT G_M52364_IG04 - cmp edx, 10 - jle SHORT G_M52364_IG04 call [System.Console:WriteLine()] G_M52364_IG04: nop add rsp, 40 ret -; Total bytes of code: 26 +; Total bytes of code: 21

Ideally, it should be done in "redundant branch opt" phase, but it seems to be way more complicated so at least let's have it in assertprop for now: EgorBo@cdbaac0

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

ghost commented Nov 25, 2023

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

Issue Details

Should help with cases like:

void Test(int x) { if (x > 100) if (x > 10) // always true Console.WriteLine(); }

Ideally, it should be done in "redundant branch opt" phase, but it seems to be way more complicated so at least let's have it in assertprop for now.

Author: EgorBo
Assignees: EgorBo
Labels:

area-CodeGen-coreclr

Milestone: -
@EgorBo EgorBo force-pushed the implied-relop-assertprop branch from ffa7d1a to 3f82e12 Compare November 26, 2023 11:21
@EgorBo EgorBo changed the title Optimize "implied relops" in assertprop Improve branch optimizer around implied relops Nov 30, 2023
@EgorBo EgorBo marked this pull request as ready for review November 30, 2023 18:48
@EgorBo
Copy link
Member Author

EgorBo commented Nov 30, 2023

/azp run runtime-coreclr outerloop, runtime-coreclr jitstress, Fuzzlyn

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).
@EgorBo
Copy link
Member Author

EgorBo commented Nov 30, 2023

PTAL @AndyAyersMS @dotnet/jit-contrib

Diffs (not too big but I have some follow-up ideas how to extend them)

@EgorBo EgorBo requested a review from AndyAyersMS November 30, 2023 23:09
// BB4:
// return;

// Check whether the dominating compare being "false" implies the dominated compare is known
Copy link
Member

Choose a reason for hiding this comment

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

The reversal/negation here is a bit tricky, but I think I follow it.

Seems like there's a complementary case where you don't negate the upper relop and then may instead have canInferFromTrue abilities?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, basically there are two cases:

canInferFromFalse:

if (x > 100) { if (x > 10) { ... } }

canInferFromTrue:

if (x > 100) { ... } if (x > 10) { ... }

I'll check separately the 2nd case (last I tried it added very little diffs)

@danmoseley
Copy link
Member

(not too big but I have some follow-up ideas how to extend them

How many of those diffs represent places code itself should be cleaned up? Like your example.

@EgorBo
Copy link
Member Author

EgorBo commented Dec 1, 2023

(not too big but I have some follow-up ideas how to extend them

How many of those diffs represent places code itself should be cleaned up? Like your example.

I inspected a few diffs and they were inlining-related so I wasn't able to find an obvious case that can be cleaned up in C#

@EgorBo
Copy link
Member Author

EgorBo commented Dec 1, 2023

Hm.. arm failures look related and they're floating point related... soft floats?

@EgorBo
Copy link
Member Author

EgorBo commented Dec 28, 2023

Since the last review I found a small bug - I replaced ssize_t with target_ssize_t (Linux arm failed on CI and it was the only target where we generate R2R'd code for corelib using 64bit jit for it via crosscompilation).

@EgorBo EgorBo merged commit 7c8b2c8 into dotnet:main Jan 2, 2024
@EgorBo EgorBo deleted the implied-relop-assertprop branch January 2, 2024 21:13
@github-actions github-actions bot locked and limited conversation to collaborators Feb 2, 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

4 participants