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: one-sided inference from unrelated predicates #72979

Merged
merged 9 commits into from
Aug 19, 2022

Conversation

AndyAyersMS
Copy link
Member

Simplistic version where we just look for identical operands.

@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 Jul 28, 2022
@ghost ghost assigned AndyAyersMS Jul 28, 2022
@ghost
Copy link

ghost commented Jul 28, 2022

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

Issue Details

Simplistic version where we just look for identical operands.

Author: AndyAyersMS
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@AndyAyersMS
Copy link
Member Author

/azp run fuzzlyn

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@AndyAyersMS
Copy link
Member Author

Looking at regressions I realized that we sometimes stop looking too early. In earlier versions of optRedundantBranch the only partial inferencing we could do was path based, but now it can also be predicate based, so we should keep looking up the tree if we see there's a path. Running new diffs now.

@AndyAyersMS
Copy link
Member Author

Also, a fair number of the larger improvements are from removing what appear to be cloned loops.

@kunalspathak
Copy link
Member

Also, a fair number of the larger improvements are from removing what appear to be cloned loops.

That's a big win. Just pasting the diff here where we were cloning the loop for redundant condition.

image

@@ -178,15 +178,123 @@ void Compiler::optRelopImpliesRelop(RelopImplicationInfo* rii)

genTreeOps const oper = genTreeOps(funcApp.m_func);

// Exclude floating point relops.
Copy link
Member

Choose a reason for hiding this comment

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

// Note we could also infer the tree relop's value from other
// dominating relops, for example, (x >= 0) dominating (x > 0).
// That is left as a future enhancement.

This comment at the top of function can be deleted now?

rii->reverseSense = ((treeOper == GT_GT) || (treeOper == GT_LT));
rii->canInferFromTrue = true;
rii->canInferFromFalse = false;
rii->vnRelation = ValueNumStore::VN_RELATION_KIND::VRK_Unrelated;
Copy link
Member

Choose a reason for hiding this comment

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

I am trying to understand the meaning of VRK_Unrelated here. What we are saying is although we can infer R* from R, they are not related meaning they cannot be simply swapped or reversed, but they have slightly different operators. Can we have something meaningful enum value for such cases like VRK_DomInferred or similar?

Copy link
Member Author

Choose a reason for hiding this comment

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

Happy to rename it if you think it makes things clearer.

@AndyAyersMS AndyAyersMS marked this pull request as ready for review August 16, 2022 21:00
@AndyAyersMS
Copy link
Member Author

@dotnet/jit-contrib PTAL

@@ -370,11 +481,26 @@ bool Compiler::optRedundantBranch(BasicBlock* const block)
return false;
}

// Was this an inference from an unrelated relop (GE => GT, say)?
//
const bool domIsUnrelatedRelop = (rii.vnRelation == ValueNumStore::VN_RELATION_KIND::VRK_Unrelated);
Copy link
Member

Choose a reason for hiding this comment

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

likewise here...if you can rename from domIsUnrelatedRelop to domIsInferredRelop, that would be great.

@kunalspathak
Copy link
Member

LGTM with few suggestions.

rii->canInferFromFalse = false;
rii->canInferFromTrue = true;
rii->vnRelation = ValueNumStore::VN_RELATION_KIND::VRK_Unrelated;
break;
Copy link
Member

Choose a reason for hiding this comment

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

@AndyAyersMS nit: in my attempt to do something very similar I ended up with a sort of a table, like this:
image

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, there's probably some refactoring like this that makes sense.

@@ -178,15 +178,123 @@ void Compiler::optRelopImpliesRelop(RelopImplicationInfo* rii)

genTreeOps const oper = genTreeOps(funcApp.m_func);
Copy link
Member

Choose a reason for hiding this comment

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

I assume it doesn't currently handle unsigned comparisons? (e.g. VNF_GT_UN)

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct, it does not handle them.

@JulieLeeMSFT JulieLeeMSFT added this to the 8.0.0 milestone Aug 16, 2022
@AndyAyersMS
Copy link
Member Author

Ok, revised per feedback. Same diffs as before (locally).

Copy link
Member

@kunalspathak kunalspathak left a comment

Choose a reason for hiding this comment

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

Refactoring looks much better now. Thanks!

@AndyAyersMS
Copy link
Member Author

Superpmi failure is a timeout.

@AndyAyersMS AndyAyersMS merged commit 68fe6b8 into dotnet:main Aug 19, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Sep 18, 2022
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.

4 participants