Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17402,10 +17402,20 @@ GenTree* Compiler::gtTryRemoveBoxUpstreamEffects(GenTree* op, BoxRemovalOptions
}
}

// The copy store implicitly normalizes small-typed values, and morph may
// have already removed an explicit cast from its source.
GenTree* boxedValue = copySrc;
if (varTypeIsSmall(copy) && fgCastNeeded(copySrc, copy->TypeGet()) &&
!(copySrc->IsIntegralConst() &&
IntegralRange::ForType(copy->TypeGet()).Contains(copySrc->AsIntConCommon()->IntegralValue())))
{
boxedValue = gtNewCastNode(TYP_INT, copySrc, false, copy->TypeGet());
}

// If this was a trial removal, we're done.
if (options == BR_DONT_REMOVE)
{
return copySrc;
return boxedValue;
}

if (options == BR_DONT_REMOVE_WANT_TYPE_HANDLE)
Expand Down Expand Up @@ -17472,7 +17482,7 @@ GenTree* Compiler::gtTryRemoveBoxUpstreamEffects(GenTree* op, BoxRemovalOptions
}
else
{
return copySrc;
return boxedValue;
}
}

Expand Down
26 changes: 26 additions & 0 deletions src/tests/JIT/Regression_ro_2/Runtime_138344.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Runtime.CompilerServices;
using Xunit;

public class Runtime_138344
{
private enum E : byte
{
A = 1
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Enum Box(int x) => (E)x;

[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
private static bool Test(int x) => E.A.HasFlag(Box(x));

[Fact]
public static void TestEntryPoint()
{
Assert.True(Test(0x101));
}
}
Loading