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: enhance RBO inference for similar compares to constants #111766

Merged
merged 2 commits into from
Jan 25, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions src/coreclr/jit/redundantbranchopts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,19 +681,21 @@ bool Compiler::optRelopTryInferWithOneEqualOperand(const VNFuncApp& domApp,
// BB4:
// return;

// Check whether the dominating compare being "false" implies the dominated compare is known
// Check whether the dominating compare being "true" or false" implies the dominated compare is known
// to be either "true" or "false".
RelopResult treeOperStatus = IsCmp2ImpliedByCmp1(GenTree::ReverseRelop(domOper), domCns, treeOper, treeCns);
if (treeOperStatus == RelopResult::Unknown)
RelopResult ifTrueStatus = IsCmp2ImpliedByCmp1(domOper, domCns, treeOper, treeCns);
RelopResult ifFalseStatus = IsCmp2ImpliedByCmp1(GenTree::ReverseRelop(domOper), domCns, treeOper, treeCns);

if ((ifTrueStatus == RelopResult::Unknown) && (ifFalseStatus == RelopResult::Unknown))
{
return false;
}

rii->canInfer = true;
rii->vnRelation = ValueNumStore::VN_RELATION_KIND::VRK_Inferred;
rii->canInferFromTrue = false;
rii->canInferFromFalse = true;
rii->reverseSense = treeOperStatus == RelopResult::AlwaysTrue;
rii->canInferFromTrue = (ifTrueStatus != RelopResult::Unknown);
rii->canInferFromFalse = (ifFalseStatus != RelopResult::Unknown);
rii->reverseSense = (ifFalseStatus == RelopResult::AlwaysTrue) || (ifTrueStatus == RelopResult::AlwaysFalse);
return true;
}

Expand Down Expand Up @@ -832,10 +834,12 @@ bool Compiler::optRedundantBranch(BasicBlock* const block)
//
if (domIsInferredRelop)
{
// This inference should be one-sided
// We used to assert rii.canInferFromTrue ^ rii.canInferFromFalse here.
//
// But now we can find fully redundant compares with different relops,
// eg LT x, 47 dominating LE x, 46. The second relop's value is equal to the first.
//
assert(rii.canInferFromTrue ^ rii.canInferFromFalse);
JITDUMP("\nDominator " FMT_BB " of " FMT_BB " has same VN operands but different relop\n",
JITDUMP("\nDominator " FMT_BB " of " FMT_BB " can infer value of dominated relop\n",
domBlock->bbNum, block->bbNum);
}
else
Expand Down
Loading