diff --git a/src/coreclr/jit/lowerarmarch.cpp b/src/coreclr/jit/lowerarmarch.cpp index 8c2528de2c2e65..fdfef546fde5a4 100644 --- a/src/coreclr/jit/lowerarmarch.cpp +++ b/src/coreclr/jit/lowerarmarch.cpp @@ -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())); @@ -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()) && 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); diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_113337/Runtime_113337.cs b/src/tests/JIT/Regression/JitBlue/Runtime_113337/Runtime_113337.cs new file mode 100644 index 00000000000000..bb0d2c8aa4529b --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_113337/Runtime_113337.cs @@ -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(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[] s_4; + [MethodImpl(MethodImplOptions.NoInlining)] + static void issue3() + { + try + { + var vr3 = Vector.Create(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(); + } +} \ No newline at end of file diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_113337/Runtime_113337.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_113337/Runtime_113337.csproj new file mode 100644 index 00000000000000..15edd99711a1a4 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_113337/Runtime_113337.csproj @@ -0,0 +1,8 @@ + + + True + + + + + \ No newline at end of file