From ac56904d831061beb229004592619e6bd80b3565 Mon Sep 17 00:00:00 2001 From: Clinton Ingram Date: Mon, 24 Mar 2025 09:22:47 -0700 Subject: [PATCH 1/6] fix cast asserts --- src/coreclr/jit/lowerxarch.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/coreclr/jit/lowerxarch.cpp b/src/coreclr/jit/lowerxarch.cpp index 743218ecede33b..4d997adb465384 100644 --- a/src/coreclr/jit/lowerxarch.cpp +++ b/src/coreclr/jit/lowerxarch.cpp @@ -4076,14 +4076,13 @@ GenTree* Lowering::LowerHWIntrinsicCreate(GenTreeHWIntrinsic* node) var_types unsignedType = varTypeToUnsigned(simdBaseType); - if (op1->OperIs(GT_CAST) && !op1->gtOverflow()) + if (op1->OperIs(GT_CAST) && !op1->gtOverflow() && + (genTypeSize(op1->CastToType()) == genTypeSize(simdBaseType))) { - assert(op1->TypeIs(TYP_INT) && (genTypeSize(op1->CastToType()) == genTypeSize(simdBaseType))); op1->AsCast()->gtCastType = unsignedType; } - else if (op1->OperIs(GT_IND, GT_LCL_FLD)) + else if (op1->OperIs(GT_IND, GT_LCL_FLD) && (genTypeSize(op1) == genTypeSize(simdBaseType))) { - assert(genTypeSize(op1) == genTypeSize(simdBaseType)); op1->gtType = unsignedType; } else if (!op1->OperIs(GT_CAST) || (op1->AsCast()->CastToType() != unsignedType)) From b683d602b14116b22e312f99867d5c9eac4ac8ca Mon Sep 17 00:00:00 2001 From: Clinton Ingram Date: Mon, 24 Mar 2025 09:23:40 -0700 Subject: [PATCH 2/6] fix containment of CreateScalar --- src/coreclr/jit/lowerxarch.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/coreclr/jit/lowerxarch.cpp b/src/coreclr/jit/lowerxarch.cpp index 4d997adb465384..ba2fbc6d814560 100644 --- a/src/coreclr/jit/lowerxarch.cpp +++ b/src/coreclr/jit/lowerxarch.cpp @@ -9664,6 +9664,12 @@ void Lowering::ContainCheckHWIntrinsic(GenTreeHWIntrinsic* node) { GenTreeHWIntrinsic* childNode = op1->AsHWIntrinsic(); + if (childNode->Op(1)->OperIsLong()) + { + // Decomposed longs require special codegen + return; + } + if (HWIntrinsicInfo::IsVectorCreateScalarUnsafe(childNode->GetHWIntrinsicId())) { // We have a very special case of BroadcastScalarToVector(CreateScalarUnsafe(op1)) @@ -9676,12 +9682,6 @@ void Lowering::ContainCheckHWIntrinsic(GenTreeHWIntrinsic* node) // op1 directly, we'll then special case the codegen to materialize the value into a // SIMD register in the case it is marked optional and doesn't get spilled. - if (childNode->Op(1)->OperIsLong()) - { - // Decomposed longs require special codegen - return; - } - node->Op(1) = childNode->Op(1); BlockRange().Remove(op1); From b2416dafb1099694b5b34795f27396b8cc32a7b2 Mon Sep 17 00:00:00 2001 From: Clinton Ingram Date: Mon, 24 Mar 2025 14:16:44 -0700 Subject: [PATCH 3/6] fix containment of CreateScalar, add tests --- src/coreclr/jit/lowerxarch.cpp | 22 ++++++----- .../JitBlue/Runtime_113829/Runtime_113829.cs | 38 +++++++++++++++++++ .../Runtime_113829/Runtime_113829.csproj | 8 ++++ .../JitBlue/Runtime_113832/Runtime_113832.cs | 28 ++++++++++++++ .../Runtime_113832/Runtime_113832.csproj | 8 ++++ 5 files changed, 94 insertions(+), 10 deletions(-) create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_113829/Runtime_113829.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_113829/Runtime_113829.csproj create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_113832/Runtime_113832.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_113832/Runtime_113832.csproj diff --git a/src/coreclr/jit/lowerxarch.cpp b/src/coreclr/jit/lowerxarch.cpp index ba2fbc6d814560..0055b8693a32ad 100644 --- a/src/coreclr/jit/lowerxarch.cpp +++ b/src/coreclr/jit/lowerxarch.cpp @@ -9662,26 +9662,28 @@ void Lowering::ContainCheckHWIntrinsic(GenTreeHWIntrinsic* node) if (varTypeIsIntegral(simdBaseType) && op1->OperIsHWIntrinsic()) { - GenTreeHWIntrinsic* childNode = op1->AsHWIntrinsic(); + GenTreeHWIntrinsic* childNode = op1->AsHWIntrinsic(); + NamedIntrinsic childIntrinsic = childNode->GetHWIntrinsicId(); - if (childNode->Op(1)->OperIsLong()) + if (HWIntrinsicInfo::IsVectorCreateScalar(childIntrinsic) || + HWIntrinsicInfo::IsVectorCreateScalarUnsafe(childIntrinsic)) { - // Decomposed longs require special codegen - return; - } - - if (HWIntrinsicInfo::IsVectorCreateScalarUnsafe(childNode->GetHWIntrinsicId())) - { - // We have a very special case of BroadcastScalarToVector(CreateScalarUnsafe(op1)) + // We have a very special case of BroadcastScalarToVector(CreateScalar/Unsafe(op1)) // // This is one of the only instructions where it supports taking integer types from // a SIMD register or directly as a scalar from memory. Most other instructions, in // comparison, take such values from general-purpose registers instead. // - // Because of this, we're going to remove the CreateScalarUnsafe and try to contain + // Because of this, we're going to remove the CreateScalar/Unsafe and try to contain // op1 directly, we'll then special case the codegen to materialize the value into a // SIMD register in the case it is marked optional and doesn't get spilled. + if (childNode->Op(1)->OperIsLong()) + { + // Decomposed longs require special codegen + return; + } + node->Op(1) = childNode->Op(1); BlockRange().Remove(op1); diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_113829/Runtime_113829.cs b/src/tests/JIT/Regression/JitBlue/Runtime_113829/Runtime_113829.cs new file mode 100644 index 00000000000000..7a86295ae94bfa --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_113829/Runtime_113829.cs @@ -0,0 +1,38 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +// Generated by Fuzzlyn v2.5 on 2025-03-23 15:10:25 +// Run on X64 Windows +// Seed: 14181260275910254012-vectort,vector128,vector256,x86aes,x86avx,x86avx2,x86avx512bw,x86avx512bwvl,x86avx512cd,x86avx512cdvl,x86avx512dq,x86avx512dqvl,x86avx512f,x86avx512fvl,x86avx512fx64,x86bmi1,x86bmi1x64,x86bmi2,x86bmi2x64,x86fma,x86lzcnt,x86lzcntx64,x86pclmulqdq,x86popcnt,x86popcntx64,x86sse,x86ssex64,x86sse2,x86sse2x64,x86sse3,x86sse41,x86sse41x64,x86sse42,x86sse42x64,x86ssse3,x86x86base +// Reduced from 68.9 KiB to 0.3 KiB in 00:01:38 +// Problem() Hits JIT assert in Debug: +// Assertion failed 'genTypeSize(op1) == genTypeSize(simdBaseType)' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Lowering nodeinfo' (IL size 20; hash 0xade6b36b; MinOpts) + +// Generated by Fuzzlyn v2.5 on 2025-03-23 15:09:24 +// Run on X64 Windows +// Seed: 3022985173499088836-vectort,vector128,vector256,x86aes,x86avx,x86avx2,x86avx512bw,x86avx512bwvl,x86avx512cd,x86avx512cdvl,x86avx512dq,x86avx512dqvl,x86avx512f,x86avx512fvl,x86avx512fx64,x86bmi1,x86bmi1x64,x86bmi2,x86bmi2x64,x86fma,x86lzcnt,x86lzcntx64,x86pclmulqdq,x86popcnt,x86popcntx64,x86sse,x86ssex64,x86sse2,x86sse2x64,x86sse3,x86sse41,x86sse41x64,x86sse42,x86sse42x64,x86ssse3,x86x86base +// Reduced from 26.2 KiB to 0.3 KiB in 00:01:05 +// Problem2() Hits JIT assert in Debug: +// Assertion failed 'op1->TypeIs(TYP_INT) && (genTypeSize(op1->CastToType()) == genTypeSize(simdBaseType))' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Lowering nodeinfo' (IL size 31; hash 0xade6b36b; MinOpts) + +public class C0 +{ + public sbyte F4; +} + +public class Runtime_113829 // minopts +{ + [Fact] + public static void Problem() + { + var vr4 = new C0(); + Vector128.CreateScalar((short)vr4.F4); + } + + [Fact] + public static Vector256 Problem2() + { + var vr7 = Vector128.CreateScalar(2263564149047927034UL); + return Vector256.CreateScalar((short)(sbyte)Sse41.X64.Extract(vr7, 0)); + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_113829/Runtime_113829.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_113829/Runtime_113829.csproj new file mode 100644 index 00000000000000..6f727749d6c30c --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_113829/Runtime_113829.csproj @@ -0,0 +1,8 @@ + + + False + + + + + diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_113832/Runtime_113832.cs b/src/tests/JIT/Regression/JitBlue/Runtime_113832/Runtime_113832.cs new file mode 100644 index 00000000000000..3b700ffbacb8a1 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_113832/Runtime_113832.cs @@ -0,0 +1,28 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +// Generated by Fuzzlyn v2.5 on 2025-03-23 15:25:27 +// Run on X86 Windows +// Seed: 916448399438567841-vectort,vector128,vector256,x86aes,x86avx,x86avx2,x86avx512bw,x86avx512bwvl,x86avx512cd,x86avx512cdvl,x86avx512dq,x86avx512dqvl,x86avx512f,x86avx512fvl,x86bmi1,x86bmi2,x86fma,x86lzcnt,x86pclmulqdq,x86popcnt,x86sse,x86sse2,x86sse3,x86sse41,x86sse42,x86ssse3,x86x86base +// Reduced from 63.4 KiB to 0.7 KiB in 00:02:21 +// Hits JIT assert in Release: +// Assertion failed '(consume == 0) || (ComputeAvailableSrcCount(tree) == consume)' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Linear scan register alloc' (IL size 68; hash 0xade6b36b; FullOpts) +public class Runtime_113832 +{ + public static byte s_4; + + [Fact] + public static void Problem() + { + var vr9 = Vector128.Create(0); + var vr10 = (ulong)s_4; + var vr11 = Vector128.CreateScalar(vr10); + var vr12 = Avx2.BroadcastScalarToVector128(vr11); + var vr13 = (byte)0; + var vr14 = Vector256.CreateScalar(vr13); + var vr15 = (ulong)Avx2.MoveMask(vr14); + var vr16 = Vector128.Create(vr15); + var vr17 = Avx512F.VL.TernaryLogic(vr9, vr12, vr16, 1); + Console.WriteLine(vr17); + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_113832/Runtime_113832.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_113832/Runtime_113832.csproj new file mode 100644 index 00000000000000..de6d5e08882e86 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_113832/Runtime_113832.csproj @@ -0,0 +1,8 @@ + + + True + + + + + From d462ba8567ca5aedfdd6f331fb0fb8367843cad5 Mon Sep 17 00:00:00 2001 From: Clinton Ingram Date: Mon, 24 Mar 2025 15:41:30 -0700 Subject: [PATCH 4/6] fix test --- .../JIT/Regression/JitBlue/Runtime_113829/Runtime_113829.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_113829/Runtime_113829.cs b/src/tests/JIT/Regression/JitBlue/Runtime_113829/Runtime_113829.cs index 7a86295ae94bfa..b5a87a291a86a8 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_113829/Runtime_113829.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_113829/Runtime_113829.cs @@ -30,9 +30,9 @@ public static void Problem() } [Fact] - public static Vector256 Problem2() + public static void Problem2() { var vr7 = Vector128.CreateScalar(2263564149047927034UL); - return Vector256.CreateScalar((short)(sbyte)Sse41.X64.Extract(vr7, 0)); + Vector256.CreateScalar((short)(sbyte)Sse41.X64.Extract(vr7, 0)); } } From d935b645ddd8df1da2e494861b5f4a6f959b049e Mon Sep 17 00:00:00 2001 From: Clinton Ingram Date: Mon, 24 Mar 2025 17:10:10 -0700 Subject: [PATCH 5/6] fix tests, for real --- .../JIT/Regression/JitBlue/Runtime_113829/Runtime_113829.cs | 5 ++++- .../JIT/Regression/JitBlue/Runtime_113832/Runtime_113832.cs | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_113829/Runtime_113829.cs b/src/tests/JIT/Regression/JitBlue/Runtime_113829/Runtime_113829.cs index b5a87a291a86a8..0c5c356a745ae3 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_113829/Runtime_113829.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_113829/Runtime_113829.cs @@ -14,13 +14,16 @@ // Reduced from 26.2 KiB to 0.3 KiB in 00:01:05 // Problem2() Hits JIT assert in Debug: // Assertion failed 'op1->TypeIs(TYP_INT) && (genTypeSize(op1->CastToType()) == genTypeSize(simdBaseType))' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Lowering nodeinfo' (IL size 31; hash 0xade6b36b; MinOpts) +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; +using Xunit; public class C0 { public sbyte F4; } -public class Runtime_113829 // minopts +public class Runtime_113829 { [Fact] public static void Problem() diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_113832/Runtime_113832.cs b/src/tests/JIT/Regression/JitBlue/Runtime_113832/Runtime_113832.cs index 3b700ffbacb8a1..6e2ff297b8d083 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_113832/Runtime_113832.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_113832/Runtime_113832.cs @@ -7,6 +7,11 @@ // Reduced from 63.4 KiB to 0.7 KiB in 00:02:21 // Hits JIT assert in Release: // Assertion failed '(consume == 0) || (ComputeAvailableSrcCount(tree) == consume)' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Linear scan register alloc' (IL size 68; hash 0xade6b36b; FullOpts) +using System; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; +using Xunit; + public class Runtime_113832 { public static byte s_4; From 07ef21ca52498fdfe4346d10980095043c583a49 Mon Sep 17 00:00:00 2001 From: Clinton Ingram Date: Mon, 24 Mar 2025 18:39:10 -0700 Subject: [PATCH 6/6] check IsSupported for intrinsics in tests --- .../JitBlue/Runtime_113829/Runtime_113829.cs | 7 ++++-- .../JitBlue/Runtime_113832/Runtime_113832.cs | 23 +++++++++++-------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_113829/Runtime_113829.cs b/src/tests/JIT/Regression/JitBlue/Runtime_113829/Runtime_113829.cs index 0c5c356a745ae3..3e7d204c6f92ef 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_113829/Runtime_113829.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_113829/Runtime_113829.cs @@ -35,7 +35,10 @@ public static void Problem() [Fact] public static void Problem2() { - var vr7 = Vector128.CreateScalar(2263564149047927034UL); - Vector256.CreateScalar((short)(sbyte)Sse41.X64.Extract(vr7, 0)); + if (Sse41.X64.IsSupported) + { + var vr7 = Vector128.CreateScalar(2263564149047927034UL); + Vector256.CreateScalar((short)(sbyte)Sse41.X64.Extract(vr7, 0)); + } } } diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_113832/Runtime_113832.cs b/src/tests/JIT/Regression/JitBlue/Runtime_113832/Runtime_113832.cs index 6e2ff297b8d083..092f9cdcf1075f 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_113832/Runtime_113832.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_113832/Runtime_113832.cs @@ -19,15 +19,18 @@ public class Runtime_113832 [Fact] public static void Problem() { - var vr9 = Vector128.Create(0); - var vr10 = (ulong)s_4; - var vr11 = Vector128.CreateScalar(vr10); - var vr12 = Avx2.BroadcastScalarToVector128(vr11); - var vr13 = (byte)0; - var vr14 = Vector256.CreateScalar(vr13); - var vr15 = (ulong)Avx2.MoveMask(vr14); - var vr16 = Vector128.Create(vr15); - var vr17 = Avx512F.VL.TernaryLogic(vr9, vr12, vr16, 1); - Console.WriteLine(vr17); + if (Avx512F.VL.IsSupported) + { + var vr9 = Vector128.Create(0); + var vr10 = (ulong)s_4; + var vr11 = Vector128.CreateScalar(vr10); + var vr12 = Avx2.BroadcastScalarToVector128(vr11); + var vr13 = (byte)0; + var vr14 = Vector256.CreateScalar(vr13); + var vr15 = (ulong)Avx2.MoveMask(vr14); + var vr16 = Vector128.Create(vr15); + var vr17 = Avx512F.VL.TernaryLogic(vr9, vr12, vr16, 1); + Console.WriteLine(vr17); + } } }