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

Extend the copy propagation type check to local field cases #101256

Merged
merged 2 commits into from
Apr 19, 2024
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
18 changes: 8 additions & 10 deletions src/coreclr/jit/copyprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,18 +230,16 @@ bool Compiler::optCopyProp(
continue;
}

if (tree->OperIs(GT_LCL_VAR))
var_types newLclType = newLclVarDsc->TypeGet();
if (!newLclVarDsc->lvNormalizeOnLoad())
{
var_types newLclType = newLclVarDsc->TypeGet();
if (!newLclVarDsc->lvNormalizeOnLoad())
{
newLclType = genActualType(newLclType);
}
newLclType = genActualType(newLclType);
}

if (newLclType != tree->TypeGet())
{
continue;
}
var_types oldLclType = tree->OperIs(GT_LCL_VAR) ? tree->TypeGet() : varDsc->TypeGet();
if (newLclType != oldLclType)
{
continue;
}

#ifdef DEBUG
Expand Down
1 change: 1 addition & 0 deletions src/tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
<GenerateRuntimeConfigurationFiles>false</GenerateRuntimeConfigurationFiles>
<CopyLocalLockFileAssemblies>false</CopyLocalLockFileAssemblies>
<UseAppHost>false</UseAppHost>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>

<!-- Set arch specific properties -->
Expand Down
58 changes: 58 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_101034/Runtime_101034.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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 static unsafe class Runtime_101034
{
[Fact]
public static void Test()
{
StructWithTwoShorts x = new() { ShortOne = -1, ShortTwo = -1 };
StructWithThreeBytes y = default;
Problem(&x, &y);
Assert.True(y.ByteThree == 0);
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static StructWithTwoShorts Problem(StructWithTwoShorts* s, StructWithThreeBytes* p)
{
StructWithTwoShorts y = *s;

int z = 255;
ForceILLocal(&z);
if (z == 255)
{
y.ShortOne = 255;
}
else
{
y.ShortOne = 1;
}

if (p != null)
{
int x = 255;
*p = Unsafe.As<int, StructWithThreeBytes>(ref x);
}

return y;
}

private static void ForceILLocal(void* x) { }

struct StructWithTwoShorts
{
public short ShortOne;
public short ShortTwo;
}

struct StructWithThreeBytes
{
public byte ByteOne;
public byte ByteTwo;
public byte ByteThree;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>
Loading