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
Remove morph optimization for NormalizeOnLoad in fgMorphLocalVar. Upd…
…ate test.
  • Loading branch information
TIHan committed May 5, 2023
commit e68875b110f4461b31391adad1a7f716980b92bc
17 changes: 0 additions & 17 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4898,23 +4898,6 @@ GenTree* Compiler::fgMorphLocalVar(GenTree* tree)
var_types lclVarType = varDsc->TypeGet();
bool isBoolQuirk = lclVarType == TYP_BOOL;

// Assertion prop can tell us to omit adding a cast here. This is
// useful when the local is a small-typed parameter that is passed in a
// register: in that case, the ABI specifies that the upper bits might
// be invalid, but the assertion guarantees us that we have normalized
// when we wrote it.
if (optLocalAssertionProp && !isBoolQuirk &&
optAssertionIsSubrange(tree, IntegralRange::ForType(lclVarType), apFull) != NO_ASSERTION_INDEX)
{
// The previous assertion can guarantee us that if this node gets
// assigned a register, it will be normalized already. It is still
// possible that this node ends up being in memory, in which case
// normalization will still be needed, so we better have the right
// type.
assert(tree->TypeGet() == varDsc->TypeGet());
return tree;
}

// Small-typed arguments and aliased locals are normalized on load.
// Other small-typed locals are normalized on store.
// Also, under the debugger as the debugger could write to the variable.
Expand Down
49 changes: 48 additions & 1 deletion src/tests/JIT/Regression/JitBlue/Runtime_85382/Runtime_85382.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,55 @@ public static int M40(ushort arg0)
}
}

public class Program2
{
public static long s_15;
public static sbyte s_17;
public static ushort s_21 = 36659;
public static int Test()
{
s_15 = ~1;
return M40();
}

[MethodImpl(MethodImplOptions.NoInlining)]
public static void Consume(ushort x) { }

[MethodImpl(MethodImplOptions.NoInlining)]
public static int M40()
{
S s = default;
for (int var0 = 0; var0 < 2; var0++)
{
s.U = 65535;
s.U &= (ushort)(s_15++ >> s_17);
s.U %= s_21;
}

Consume(s.U);

if (s.U != 28876)
{
return 0;
}
return 100;
}

public struct S { public ushort U; }
}

[Fact]
public static int TestEntryPoint() {
return Test.Program.Test();
if (Test.Program.Test() != 100)
{
return 0;
}

if (Test.Program2.Test() != 100)
{
return 0;
}

return 100;
}
}