Skip to content
Closed
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
16 changes: 13 additions & 3 deletions src/coreclr/jit/redundantbranchopts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1961,16 +1961,26 @@ bool Compiler::optRedundantRelop(BasicBlock* const block)
continue;
}

// If the lcl defined here is live out, forward sub is problematic.
// We'll either create a redundant tree (as the original won't be dead)
// or lose the def (if we actually move the RHS tree).
// If the lcl defined here is live out we'll create a redundant tree
// (as the original won't be dead).
//
if (VarSetOps::IsMember(this, block->bbLiveOut, prevTreeLclDsc->lvVarIndex))
{
JITDUMP(" -- prev tree lcl V%02u is live-out\n", prevTreeLcl);
continue;
}

// The local may have uses between the def and the JTRUE. Duplicating
// reads is not allowed and in any case duplicating it in this case is
// probably not be worth it from a profitability perspective.
//
LclSsaVarDsc* ssaDefDsc = prevTreeLclDsc->GetPerSsaData(prevTreeLHS->AsLclVarCommon()->GetSsaNum());
if (ssaDefDsc->GetNumUses() >= 2)
Copy link
Contributor

Choose a reason for hiding this comment

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

Notably, this it is not a 100% fix, since we do not count composite uses.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, well that's unfortunate as I was trying to simplify the substitution that happens below.
Do we see the composite case here?

Copy link
Contributor

@SingleAccretion SingleAccretion Nov 22, 2022

Choose a reason for hiding this comment

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

It is theoretically possible, though I suspect quite hard to encounter in practice.

(A reproduction would go along the lines of complex field reinterpretations s.t. we end up with LCL_FLD<parent> as the "unaccounted" use)

{
JITDUMP(" -- prev tree lcl V%02u has up to %d uses\n", prevTreeLcl, ssaDefDsc->GetNumUses());
continue;
}

JITDUMP(" -- prev tree is viable candidate for relop fwd sub!\n");
candidateTree = prevTreeRHS;
candidateStmt = prevStmt;
Expand Down