From 93e91df5a7c54dd4bf133f9535acd705f91b789a Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Tue, 28 Mar 2023 09:07:52 +0200 Subject: [PATCH] JIT: Allow forward substituting small-typed nodes (#83969) --- src/coreclr/jit/forwardsub.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/coreclr/jit/forwardsub.cpp b/src/coreclr/jit/forwardsub.cpp index 50998316832f2..bd1730b697e4e 100644 --- a/src/coreclr/jit/forwardsub.cpp +++ b/src/coreclr/jit/forwardsub.cpp @@ -675,10 +675,7 @@ bool Compiler::fgForwardSubStatement(Statement* stmt) // Next statement seems suitable. // See if we can forward sub without changing semantics. // - // Bail if types disagree. - // Might be able to tolerate these by retyping. - // - if (fsv.GetNode()->TypeGet() != fwdSubNode->TypeGet()) + if (genActualType(fsv.GetNode()) != genActualType(fwdSubNode)) { JITDUMP(" mismatched types (substitution)\n"); return false; @@ -845,12 +842,12 @@ bool Compiler::fgForwardSubStatement(Statement* stmt) } } - // If the initial has truncate on store semantics, we need to replicate - // that here with a cast. + // If the value is being roundtripped through a small-typed local then we + // may need to insert an explicit cast to emulate normalize-on-load/store. // - if (varDsc->lvNormalizeOnStore() && fgCastNeeded(fwdSubNode, varDsc->TypeGet())) + if (varTypeIsSmall(varDsc) && fgCastNeeded(fwdSubNode, varDsc->TypeGet())) { - JITDUMP(" [adding cast for normalize on store]"); + JITDUMP(" [adding cast for small-typed local]"); fwdSubNode = gtNewCastNode(TYP_INT, fwdSubNode, false, varDsc->TypeGet()); }