Skip to content
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: 8 additions & 8 deletions src/coreclr/jit/valuenum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2069,15 +2069,15 @@ ValueNum ValueNumStore::VNForCastOper(var_types castToType, bool srcIsUnsigned)

//------------------------------------------------------------------------
// VNIgnoreIntToLongCast: Looks through a sign-extending int-to-long cast
// or convert long-typed integral constants to int.
// or converts non-handle long-typed integral constants to int.
//
// Arguments:
// vn - The value number to inspect.
//
// Return Value:
// The value number of the original TYP_INT operand if 'vn' is a VNF_Cast
// that sign-extends a TYP_INT to TYP_LONG; or the value number of a TYP_INT
// constant if 'vn' is a TYP_LONG constant that fits in an int; otherwise, 'vn' itself.
// constant if 'vn' is a non-handle TYP_LONG constant that fits in an int; otherwise, 'vn' itself.
//
ValueNum ValueNumStore::VNIgnoreIntToLongCast(ValueNum vn)
{
Expand All @@ -2099,9 +2099,9 @@ ValueNum ValueNumStore::VNIgnoreIntToLongCast(ValueNum vn)
}
}

// Also look through any long-typed integral constant that fits in an int.
// Also look through any non-handle long-typed integral constant that fits in an int.
int intCns;
if (IsVNIntegralConstant(vn, &intCns))
if (!IsVNHandle(vn) && IsVNIntegralConstant(vn, &intCns))
Comment thread
EgorBo marked this conversation as resolved.
Resolved
{
return VNForIntCon(intCns);
}
Expand Down Expand Up @@ -4936,6 +4936,10 @@ bool ValueNumStore::VNEvalCanFoldBinaryFunc(var_types type, VNFunc func, ValueNu
case GT_RSZ:
case GT_ROL:
case GT_ROR:
case GT_GT:
case GT_GE:
case GT_LT:
case GT_LE:
if (m_compiler->opts.compReloc && (IsVNHandle(arg0VN) || IsVNHandle(arg1VN)))
{
return false;
Expand All @@ -4944,10 +4948,6 @@ bool ValueNumStore::VNEvalCanFoldBinaryFunc(var_types type, VNFunc func, ValueNu

case GT_EQ:
case GT_NE:
case GT_GT:
case GT_GE:
case GT_LT:
case GT_LE:
break;

default:
Expand Down
60 changes: 60 additions & 0 deletions src/tests/JIT/Regression_ro_2/Runtime_134891.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// 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_134891
{
private const int Bound = 0x1000000;

[Fact]
public static void TestEntryPoint()
{
nint handle = GetHandle();
Assert.Equal(handle > Bound, Greater());
Assert.Equal(handle >= Bound, GreaterOrEqual());
Assert.Equal(handle < Bound, Less());
Assert.Equal(handle <= Bound, LessOrEqual());
Assert.Equal(Bound > handle, GreaterReversed());
Assert.Equal(Bound >= handle, GreaterOrEqualReversed());
Assert.Equal(Bound < handle, LessReversed());
Assert.Equal(Bound <= handle, LessOrEqualReversed());
Assert.Equal((nuint)handle > Bound, GreaterUnsigned());
Assert.Equal((nuint)handle < Bound, LessUnsigned());
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static nint GetHandle() => typeof(Runtime_134891).TypeHandle.Value;

[MethodImpl(MethodImplOptions.NoInlining)]
private static bool Greater() => typeof(Runtime_134891).TypeHandle.Value > Bound;

[MethodImpl(MethodImplOptions.NoInlining)]
private static bool GreaterOrEqual() => typeof(Runtime_134891).TypeHandle.Value >= Bound;

[MethodImpl(MethodImplOptions.NoInlining)]
private static bool Less() => typeof(Runtime_134891).TypeHandle.Value < Bound;

[MethodImpl(MethodImplOptions.NoInlining)]
private static bool LessOrEqual() => typeof(Runtime_134891).TypeHandle.Value <= Bound;

[MethodImpl(MethodImplOptions.NoInlining)]
private static bool GreaterReversed() => Bound > typeof(Runtime_134891).TypeHandle.Value;

[MethodImpl(MethodImplOptions.NoInlining)]
private static bool GreaterOrEqualReversed() => Bound >= typeof(Runtime_134891).TypeHandle.Value;

[MethodImpl(MethodImplOptions.NoInlining)]
private static bool LessReversed() => Bound < typeof(Runtime_134891).TypeHandle.Value;

[MethodImpl(MethodImplOptions.NoInlining)]
private static bool LessOrEqualReversed() => Bound <= typeof(Runtime_134891).TypeHandle.Value;

[MethodImpl(MethodImplOptions.NoInlining)]
private static bool GreaterUnsigned() => (nuint)typeof(Runtime_134891).TypeHandle.Value > Bound;

[MethodImpl(MethodImplOptions.NoInlining)]
private static bool LessUnsigned() => (nuint)typeof(Runtime_134891).TypeHandle.Value < Bound;
}
Loading