Skip to content

[release/9.0-staging] JIT: fix local assertion prop error for partial local comparisons #112539

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

Merged
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
16 changes: 16 additions & 0 deletions src/coreclr/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2211,6 +2211,22 @@ AssertionInfo Compiler::optAssertionGenJtrue(GenTree* tree)
// If op1 is lcl and op2 is const or lcl, create assertion.
if ((op1->gtOper == GT_LCL_VAR) && (op2->OperIsConst() || (op2->gtOper == GT_LCL_VAR))) // Fix for Dev10 851483
{
// Watch out for cases where long local(s) are implicitly truncated.
//
LclVarDsc* const lcl1Dsc = lvaGetDesc(op1->AsLclVarCommon());
if ((lcl1Dsc->TypeGet() == TYP_LONG) && (op1->TypeGet() != TYP_LONG))
{
return NO_ASSERTION_INDEX;
}
if (op2->OperIs(GT_LCL_VAR))
{
LclVarDsc* const lcl2Dsc = lvaGetDesc(op2->AsLclVarCommon());
if ((lcl2Dsc->TypeGet() == TYP_LONG) && (op2->TypeGet() != TYP_LONG))
{
return NO_ASSERTION_INDEX;
}
}

return optCreateJtrueAssertions(op1, op2, assertionKind);
}
else if (!optLocalAssertionProp)
Expand Down
42 changes: 42 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_111352/Runtime_111352.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.CompilerServices;
using Xunit;

public class Runtime_111352
{
[Fact]
public static int Test1() => Problem1(0x1_0000_0001L, 0x2_0000_0001L);

[MethodImpl(MethodImplOptions.NoInlining)]
public static int Problem1(long x, long y)
{
if ((uint)x == (uint)y)
{
if (x == y)
{
return -1;
}
}

return 100;
}

[Fact]
public static int Test2() => Problem2(0x1_0000_0000L);

[MethodImpl(MethodImplOptions.NoInlining)]
public static int Problem2(long x)
{
if ((uint)x == 0)
{
if (x == 0)
{
return -1;
}
}

return 100;
}
}
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