diff --git a/src/coreclr/jit/optimizer.cpp b/src/coreclr/jit/optimizer.cpp index 4c174f1aaa0a68..79b32874f58fd7 100644 --- a/src/coreclr/jit/optimizer.cpp +++ b/src/coreclr/jit/optimizer.cpp @@ -4484,7 +4484,7 @@ PhaseStatus Compiler::optInvertLoops() } } - const bool madeChanges = fgModified; + bool madeChanges = fgModified; if (madeChanges) { @@ -4493,6 +4493,15 @@ PhaseStatus Compiler::optInvertLoops() fgModified = false; } + // optInvertWhileLoop can cause IR changes even if it does not modify + // the flow graph. It calls gtPrepareCost which can cause operand swapping. + // Work around this for now. + // + // Note phase status only impacts dumping and checking done post-phase, + // it has no impact on a release build. + // + madeChanges = true; + return madeChanges ? PhaseStatus::MODIFIED_EVERYTHING : PhaseStatus::MODIFIED_NOTHING; } @@ -4514,6 +4523,15 @@ PhaseStatus Compiler::optOptimizeLayout() madeChanges |= fgReorderBlocks(); madeChanges |= fgUpdateFlowGraph(); + // fgReorderBlocks can cause IR changes even if it does not modify + // the flow graph. It calls gtPrepareCost which can cause operand swapping. + // Work around this for now. + // + // Note phase status only impacts dumping and checking done post-phase, + // it has no impact on a release build. + // + madeChanges = true; + return madeChanges ? PhaseStatus::MODIFIED_EVERYTHING : PhaseStatus::MODIFIED_NOTHING; }