Skip to content

Fix assertions related to combining cmn (extended-register) (#113337) #113376

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 8 commits into from
Mar 26, 2025
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
21 changes: 19 additions & 2 deletions src/coreclr/jit/lowerarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,21 @@ bool Lowering::IsContainableUnaryOrBinaryOp(GenTree* parentNode, GenTree* childN

if (childNode->gtGetOp1()->OperIs(GT_CAST))
{
// Grab the cast as well, we can contain this with cmn.
GenTreeCast* cast = childNode->gtGetOp1()->AsCast();
// Grab the cast as well, we can contain this with cmn (extended-register).
GenTreeCast* cast = childNode->gtGetOp1()->AsCast();
GenTree* castOp = cast->CastOp();

// Cannot contain the cast from floating point.
if (!varTypeIsIntegral(castOp))
{
return false;
}

// Cannot contain the cast if it already contains it's CastOp.
if (castOp->isContained())
{
return false;
}

assert(!cast->gtOverflow());
assert(varTypeIsIntegral(cast) && varTypeIsIntegral(cast->CastToType()));
Expand Down Expand Up @@ -3187,11 +3200,15 @@ bool Lowering::TryLowerAndOrToCCMP(GenTreeOp* tree, GenTree** next)
//
GenCondition cond1;
if (op2->OperIsCmpCompare() && varTypeIsIntegralOrI(op2->gtGetOp1()) && IsInvariantInRange(op2, tree) &&
(op2->gtGetOp1()->IsIntegralConst() || !op2->gtGetOp1()->isContained()) &&
(op2->gtGetOp2() == nullptr || op2->gtGetOp2()->IsIntegralConst() || !op2->gtGetOp2()->isContained()) &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This nullptr check is unnecessary (we already checked for CmpCompare above, all of those are binops). But let's not wait for another round of CI here.

TryLowerConditionToFlagsNode(tree, op1, &cond1))
{
// Fall through, converting op2 to the CCMP
}
else if (op1->OperIsCmpCompare() && varTypeIsIntegralOrI(op1->gtGetOp1()) && IsInvariantInRange(op1, tree) &&
(op1->gtGetOp1()->IsIntegralConst() || !op1->gtGetOp1()->isContained()) &&
(op1->gtGetOp2() == nullptr || op1->gtGetOp2()->IsIntegralConst() || !op1->gtGetOp2()->isContained()) &&
TryLowerConditionToFlagsNode(tree, op2, &cond1))
{
std::swap(op1, op2);
Expand Down
78 changes: 78 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_113337/Runtime_113337.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// 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.Numerics;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.Arm;
using System.Runtime.CompilerServices;
using Xunit;

#pragma warning disable SYSLIB5003 // Allow experimental SVE

public class Runtime_113337
{
static sbyte[] s_7;

[MethodImpl(MethodImplOptions.NoInlining)]
static void issue1()
{
try
{
var vr9 = Vector64.Create<float>(0);
if ((2147483647 == (-(int)AdvSimd.Extract(vr9, 1))))
{
s_7 = s_7;
}
}
catch (PlatformNotSupportedException e)
{
}
}

static int[][] s_2;
static bool s_3;

[MethodImpl(MethodImplOptions.NoInlining)]
static void issue2()
{
try
{
s_3 ^= (2021486855 != (-(long)s_2[0][0]));
}
catch (NullReferenceException e)
{
}
}

static Vector<ulong>[] s_4;
[MethodImpl(MethodImplOptions.NoInlining)]
static void issue3()
{
try
{
var vr3 = Vector.Create<short>(1);
var vr4 = (short)0;
var vr5 = Vector128.CreateScalar(vr4).AsVector();
if ((Sve.TestFirstTrue(vr3, vr5) | (3268100580U != (-(uint)Sve.SaturatingDecrementBy16BitElementCount(0, 1)))))
{
s_4[0] = s_4[0];
}
}
catch (PlatformNotSupportedException e)
{
}
catch (NullReferenceException e)
{
}
}

[Fact]
public static void TestEntryPoint()
{
// Checking for successful compilation
issue1();
issue2();
issue3();
}
}
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