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

Normalize returns after optimizing returned indirs #64881

Merged
merged 1 commit into from
Feb 7, 2022
Merged
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
35 changes: 18 additions & 17 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11421,23 +11421,6 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac)
return fgMorphIntoHelperCall(tree, helper, gtNewCallArgs(op1, op2));

case GT_RETURN:
// normalize small integer return values
if (fgGlobalMorph && varTypeIsSmall(info.compRetType) && (op1 != nullptr) && !op1->TypeIs(TYP_VOID) &&
fgCastNeeded(op1, info.compRetType))
{
// Small-typed return values are normalized by the callee
op1 = gtNewCastNode(TYP_INT, op1, false, info.compRetType);

// Propagate GTF_COLON_COND
op1->gtFlags |= (tree->gtFlags & GTF_COLON_COND);

tree->AsOp()->gtOp1 = fgMorphTree(op1);

// Propagate side effect flags
tree->SetAllEffectsFlags(tree->AsOp()->gtGetOp1());

return tree;
}
if (!tree->TypeIs(TYP_VOID))
{
if (op1->OperIs(GT_OBJ, GT_BLK, GT_IND))
Expand Down Expand Up @@ -11471,6 +11454,24 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac)
}
}
}

// normalize small integer return values
if (fgGlobalMorph && varTypeIsSmall(info.compRetType) && (op1 != nullptr) && !op1->TypeIs(TYP_VOID) &&
fgCastNeeded(op1, info.compRetType))
{
// Small-typed return values are normalized by the callee
op1 = gtNewCastNode(TYP_INT, op1, false, info.compRetType);

// Propagate GTF_COLON_COND
op1->gtFlags |= (tree->gtFlags & GTF_COLON_COND);

tree->AsOp()->gtOp1 = fgMorphTree(op1);

// Propagate side effect flags
tree->SetAllEffectsFlags(tree->AsOp()->gtGetOp1());

return tree;
}
break;

case GT_EQ:
Expand Down
19 changes: 19 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_61359/Runtime_61359.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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;

public unsafe class Runtime_61359
{
public static int Main()
{
return HalfToInt16Bits((Half)(-1)) == -17408 ? 100 : -1;
}

[MethodImpl(MethodImplOptions.NoInlining)]
static short HalfToInt16Bits(Half h)
{
return *(short*)&h;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
</PropertyGroup>
<PropertyGroup>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>