未验证 提交 7a70d5a0 编写于 作者: W Will Smith 提交者: GitHub

[JIT] ARM64 - Fixed regressions for `GT_NEG` containment (#85230)

* Fixed regressions for 'GT_NEG' containment on ARM64

* Containing NEG is only valid for EQ and NE.

* Update codegenarm64.cpp

* Formatting
上级 2677eb26
......@@ -4569,29 +4569,33 @@ void CodeGen::genCodeForCompare(GenTreeOp* tree)
ins = INS_cmn;
oper = op2->gtGetOp1()->OperGet();
switch (oper)
if (op2->gtGetOp1()->isContained())
{
case GT_LSH:
case GT_RSH:
case GT_RSZ:
switch (oper)
{
GenTree* shiftOp1 = op2->gtGetOp1()->gtGetOp1();
GenTree* shiftOp2 = op2->gtGetOp1()->gtGetOp2();
assert(op2->gtGetOp1()->isContained());
assert(shiftOp2->IsCnsIntOrI());
assert(shiftOp2->isContained());
case GT_LSH:
case GT_RSH:
case GT_RSZ:
{
GenTree* shiftOp1 = op2->gtGetOp1()->gtGetOp1();
GenTree* shiftOp2 = op2->gtGetOp1()->gtGetOp2();
assert(shiftOp2->IsCnsIntOrI());
assert(shiftOp2->isContained());
emit->emitIns_R_R_I(ins, cmpSize, op1->GetRegNum(), shiftOp1->GetRegNum(),
shiftOp2->AsIntConCommon()->IntegralValue(),
ShiftOpToInsOpts(oper));
}
break;
emit->emitIns_R_R_I(ins, cmpSize, op1->GetRegNum(), shiftOp1->GetRegNum(),
shiftOp2->AsIntConCommon()->IntegralValue(), ShiftOpToInsOpts(oper));
default:
unreached();
}
break;
default:
assert(!op2->gtGetOp1()->isContained());
emit->emitIns_R_R(ins, cmpSize, op1->GetRegNum(), op2->gtGetOp1()->GetRegNum());
break;
}
else
{
emit->emitIns_R_R(ins, cmpSize, op1->GetRegNum(), op2->gtGetOp1()->GetRegNum());
}
break;
......
......@@ -294,7 +294,7 @@ bool Lowering::IsContainableUnaryOrBinaryOp(GenTree* parentNode, GenTree* childN
if (childNode->OperIs(GT_NEG))
{
// If we have a contained LSH, RSH or RSZ, we can still contain NEG if the parent is a CMP or comparison op.
// If we have a contained LSH, RSH or RSZ, we can still contain NEG if the parent is a EQ or NE.
if (childNode->gtGetOp1()->isContained() && !childNode->gtGetOp1()->OperIs(GT_LSH, GT_RSH, GT_RSZ))
{
// Cannot contain if the childs op1 is already contained
......@@ -307,7 +307,8 @@ bool Lowering::IsContainableUnaryOrBinaryOp(GenTree* parentNode, GenTree* childN
return false;
}
if (parentNode->OperIs(GT_CMP) || parentNode->OperIsCompare())
// EQ and NE are the only valid comparison ops that can contain NEG.
if (parentNode->OperIs(GT_EQ, GT_NE))
{
if (IsInvariantInRange(childNode, parentNode))
{
......
// 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.Collections;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Xunit;
public class Test
{
// Verify that containment on NEG is correctly handled for ARM64.
public class Program
{
[MethodImpl(MethodImplOptions.NoInlining)]
static void Consume(int x) { }
[MethodImpl(MethodImplOptions.NoInlining)]
static void Consume(bool x) { }
//---------------------------------
public static uint s_2;
[MethodImpl(MethodImplOptions.NoInlining)]
public static int Test1()
{
int vr0 = default(int);
if (56058 < (uint)(-s_2))
{
Consume(vr0);
return 0;
}
return 100;
}
//---------------------------------
public class C0
{
public bool F8;
}
public static C0 s_11;
public static byte s_35;
public static sbyte s_44;
[MethodImpl(MethodImplOptions.NoInlining)]
public static int Test2()
{
try
{
s_11.F8 |= s_35 < (-(1 << s_44));
return 0;
}
catch (NullReferenceException)
{
return 100;
}
}
//---------------------------------
public static uint s_4;
[MethodImpl(MethodImplOptions.NoInlining)]
public static int Test3()
{
return M17(0);
}
public static int M17(long arg0)
{
short var0 = default(short);
if ((ulong)((-s_4) & arg0) >= 1)
{
Consume(var0);
return 0;
}
return 100;
}
//---------------------------------
public static long s_7;
public static int[] s_12 = new int[] { 0 };
[MethodImpl(MethodImplOptions.NoInlining)]
public static int Test4()
{
s_12[0] = -2147483648;
var vr9 = (int)s_7 < (-s_12[0]);
Consume(vr9);
return vr9 ? 0 : 100;
}
}
[Fact]
public static int TestEntryPoint()
{
if (Program.Test1() != 100)
return 0;
if (Program.Test2() != 100)
return 0;
if (Program.Test3() != 100)
return 0;
if (Program.Test4() != 100)
return 0;
return 100;
}
}
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册