Skip to content
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
20 changes: 18 additions & 2 deletions src/coreclr/jit/optimizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2479,8 +2479,24 @@ PhaseStatus Compiler::optOptimizePostLayout()
{
GenTree* const test = block->lastNode();
assert(test->OperIsConditionalJump());
GenTree* const cond = gtReverseCond(test);
assert(cond == test); // Ensure `gtReverseCond` did not create a new node

if (test->OperIs(GT_JTRUE))
{
// Flip GT_JTRUE node's conditional operand, and handle any new nodes this may introduce
GenTree* const cond = test->gtGetOp1();
GenTree* const newCond = gtReverseCond(cond);
if (cond != newCond)
{
LIR::AsRange(block).InsertAfter(cond, newCond);
test->AsUnOp()->gtOp1 = newCond;
}
}
else
{
// gtReverseCond can handle other conditional jumps without introducing a new node
GenTree* const cond = gtReverseCond(test);
assert(cond == test);
}

FlowEdge* const oldTrueEdge = block->GetTrueEdge();
FlowEdge* const oldFalseEdge = block->GetFalseEdge();
Expand Down