diff --git a/src/coreclr/jit/optimizer.cpp b/src/coreclr/jit/optimizer.cpp index 1b028eca78b846..ee576b1bc35964 100644 --- a/src/coreclr/jit/optimizer.cpp +++ b/src/coreclr/jit/optimizer.cpp @@ -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();