diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 64635e15cb2960..6353797cb3c238 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -9267,6 +9267,7 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX STRESS_MODE(SWITCH_CMP_BR_EXPANSION) \ STRESS_MODE(GENERIC_VARN) \ STRESS_MODE(PROFILER_CALLBACKS) /* Will generate profiler hooks for ELT callbacks */ \ + STRESS_MODE(BYREF_PROMOTION) /* Change undoPromotion decisions for byrefs */ \ \ /* After COUNT_VARN, stress level 2 does all of these all the time */ \ \ diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index c2ee204766075e..762171b4a6cee6 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -18513,6 +18513,18 @@ void Compiler::fgRetypeImplicitByRefArgs() bool undoPromotion = ((lvaGetPromotionType(newVarDsc) == PROMOTION_TYPE_DEPENDENT) || (nonCallAppearances <= varDsc->lvFieldCnt)); +#ifdef DEBUG + // Above is a profitability heurisic; either value of + // undoPromotion should lead to correct code. So, + // under stress, make different decisions at times. + if (compStressCompile(STRESS_BYREF_PROMOTION, 25)) + { + undoPromotion = !undoPromotion; + JITDUMP("Stress -- changing byref undo promotion for V%02u to %s undo\n", lclNum, + undoPromotion ? "" : "NOT"); + } +#endif // DEBUG + JITDUMP("%s promotion of implicit by-ref V%02u: %s total: %u non-call: %u fields: %u\n", undoPromotion ? "Undoing" : "Keeping", lclNum, (lvaGetPromotionType(newVarDsc) == PROMOTION_TYPE_DEPENDENT) ? "dependent;" : "",