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
13 changes: 13 additions & 0 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8640,6 +8640,19 @@ GenTree* Compiler::fgOptimizeCast(GenTreeCast* cast)

var_types castToType = cast->CastToType();

// For small-int casts fed by a widening int->long, remove the widening so we truncate directly
// from the original int value.
if (varTypeIsSmall(castToType) && src->OperIs(GT_CAST) && !src->gtOverflow())
{
GenTreeCast* widening = src->AsCast();
if (varTypeIsLong(widening->CastToType()) && (genActualType(widening->CastFromType()) == TYP_INT))
{
cast->CastOp() = widening->CastOp();
DEBUG_DESTROY_NODE(widening);
src = cast->CastOp();
}
}

// For indir-like nodes, we may be able to change their type to satisfy (and discard) the cast.
if (varTypeIsSmall(castToType) && (genTypeSize(castToType) == genTypeSize(src)) &&
src->OperIs(GT_IND, GT_LCL_FLD))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
</PropertyGroup>
<ItemGroup>
<Compile Include="AssertExtensions.cs" />
<Compile Include="Expect.cs" />
<Compile Include="Generator.cs" />
<Compile Include="Logging.cs" />
<Compile Include="TestFramework.cs" />
Expand Down
41 changes: 41 additions & 0 deletions src/tests/Common/CoreCLRTestLibrary/Expect.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// 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.Linq.Expressions;
using Xunit;

namespace TestLibrary;

public static class Expect
{
public static void ExpectEqual<T>(Expression<Func<T>> expr, T expected, ref bool fail)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need these if we can use xunit's Assert.Equal and friends?

{
var compiled = expr.Compile();
T actual = compiled();

// Get just the expression body text
string exprText = expr.Body.ToString();

if (!Equals(actual, expected))
{
Console.WriteLine($"{exprText} = {actual}, expected {expected}");
fail = true;
}
}

public static void ExpectTrue(Expression<Func<bool>> expr, ref bool fail)
{
var compiled = expr.Compile();
bool actual = compiled();

// Get just the expression body text
string exprText = expr.Body.ToString();

if (!actual)
{
Console.WriteLine($"{exprText} = {actual}, expected True");
fail = true;
}
}
}
Loading
Loading