Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[JIT] Fix - Do not remove CAST nodes on store if the LCL_VAR is address exposed #85734

Merged
merged 8 commits into from
Jul 20, 2023
Prev Previous commit
Next Next commit
Update src/coreclr/jit/morph.cpp
Co-authored-by: Jakob Botsch Nielsen <Jakob.botsch.nielsen@gmail.com>
  • Loading branch information
TIHan and jakobbotsch committed Jul 18, 2023
commit d6417d50bfda2bf0d983c80094dd5abb2e738ebe
7 changes: 5 additions & 2 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10119,8 +10119,11 @@ GenTree* Compiler::fgOptimizeCastOnStore(GenTree* store)
{
LclVarDsc* varDsc = lvaGetDesc(store->AsLclVarCommon()->GetLclNum());

// It is not safe to remove the cast for non-NormalizeOnLoad variables, parameters or struct fields.
if (!varDsc->lvNormalizeOnLoad() || varDsc->lvIsParam || varDsc->lvIsStructField)
// We can make this transformation only under the assumption that NOL locals are always normalized before they are used,
// however this is not always the case: the JIT will utilize subrange assertions for NOL locals to make normalization
// assumptions -- see fgMorphLeafLocal. Thus we can only do this for cases where we know for sure that subsequent uses
// will normalize, which we can only guarantee when the local is address exposed.
if (!varDsc->lvNormalizeOnLoad() || !varDsc->IsAddressExposed())
return store;
}

Expand Down
Loading