From 5fb42a458bc9c476978ec45092cc398f92371186 Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Tue, 6 Aug 2024 13:01:17 -0700 Subject: [PATCH] Ensure we aren't containing nodes that shouldn't be contained (#105993) * Ensure we aren't containing nodes that shouldn't be contained * Adding regression tests for the other resolved issues * Ensure the tests use the right `Isa.IsSupported` checks --- src/coreclr/jit/lowerxarch.cpp | 34 ++++++++++- .../JitBlue/Runtime_105967/Runtime_105967.cs | 58 +++++++++++++++++++ .../Runtime_105967/Runtime_105967.csproj | 8 +++ .../JitBlue/Runtime_105968/Runtime_105968.cs | 43 ++++++++++++++ .../Runtime_105968/Runtime_105968.csproj | 8 +++ .../JitBlue/Runtime_105970/Runtime_105970.cs | 42 ++++++++++++++ .../Runtime_105970/Runtime_105970.csproj | 8 +++ 7 files changed, 198 insertions(+), 3 deletions(-) create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_105967/Runtime_105967.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_105967/Runtime_105967.csproj create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_105968/Runtime_105968.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_105968/Runtime_105968.csproj create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_105970/Runtime_105970.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_105970/Runtime_105970.csproj diff --git a/src/coreclr/jit/lowerxarch.cpp b/src/coreclr/jit/lowerxarch.cpp index c1167bdb49362..76edb0dca7167 100644 --- a/src/coreclr/jit/lowerxarch.cpp +++ b/src/coreclr/jit/lowerxarch.cpp @@ -1899,6 +1899,33 @@ GenTree* Lowering::LowerHWIntrinsic(GenTreeHWIntrinsic* node) return LowerHWIntrinsicCmpOp(node, GT_NE); } + case NI_AVX512F_Fixup: + case NI_AVX512F_FixupScalar: + case NI_AVX512F_VL_Fixup: + case NI_AVX10v1_Fixup: + case NI_AVX10v1_FixupScalar: + { + if (!node->isRMWHWIntrinsic(comp)) + { + GenTree* op1 = node->Op(1); + + if (!op1->IsCnsVec()) + { + // op1 is never selected by the table so + // we replaced it with a containable constant + + var_types simdType = node->TypeGet(); + + op1->SetUnusedValue(); + op1 = comp->gtNewZeroConNode(simdType); + + BlockRange().InsertBefore(node, op1); + node->Op(1) = op1; + } + } + break; + } + case NI_EVEX_CompareEqualMask: case NI_EVEX_CompareNotEqualMask: { @@ -11434,10 +11461,11 @@ void Lowering::ContainCheckHWIntrinsic(GenTreeHWIntrinsic* node) if (!node->isRMWHWIntrinsic(comp)) { // op1 is never selected by the table so - // we can contain and ignore any register - // allocated to it resulting in better - // non-RMW based codegen. + // we should've replaced it with a containable + // constant, allowing us to get better non-RMW + // codegen + assert(op1->IsCnsVec()); MakeSrcContained(node, op1); } break; diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_105967/Runtime_105967.cs b/src/tests/JIT/Regression/JitBlue/Runtime_105967/Runtime_105967.cs new file mode 100644 index 0000000000000..2a1d9cca599a8 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_105967/Runtime_105967.cs @@ -0,0 +1,58 @@ +// 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 System.Numerics; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; +using Xunit; + +// Generated by Fuzzlyn v2.2 on 2024-08-04 16:04:50 +// Run on X64 Linux +// Seed: 2207552216055442248-vectort,vector128,vector256,vector512,x86aes,x86avx,x86avx2,x86avx512bw,x86avx512bwvl,x86avx512cd,x86avx512cdvl,x86avx512dq,x86avx512dqvl,x86avx512f,x86avx512fvl,x86avx512fx64,x86avx512vbmi,x86avx512vbmivl,x86bmi1,x86bmi1x64,x86bmi2,x86bmi2x64,x86fma,x86lzcnt,x86lzcntx64,x86pclmulqdq,x86popcnt,x86popcntx64,x86sse,x86ssex64,x86sse2,x86sse2x64,x86sse3,x86sse41,x86sse41x64,x86sse42,x86sse42x64,x86ssse3,x86x86base +// Reduced from 138.4 KiB to 0.8 KiB in 00:07:16 +// Hits JIT assert in Release: +// Assertion failed 'varDsc->GetRegNum() == REG_STK' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Generate code' (IL size 62; hash 0xade6b36b; FullOpts) +// +// File: /__w/1/s/src/coreclr/jit/codegenlinear.cpp Line: 1655 +// + +public class C0 +{ + public float F3; +} + +public class C2 +{ + public C0 F4; +} + +public class Runtime_105967 +{ + [Fact] + public static void TestEntryPoint() + { + if (Avx512F.IsSupported) + { + var vr26 = new C2(); + vr26.F4 = new C0(); + var vr29 = vr26.F4.F3; + var vr30 = Vector512.Create(vr29); + var vr31 = Vector512.CreateScalar(-193.44424f); + var vr32 = M17(); + var vr33 = Avx512F.Fixup(vr30, vr31, vr32, 0); + M16(vr33, new long[] { 1 }); + } + } + + private static void M16(Vector512 arg0, long[] arg2) + { + Assert.Equal(Vector512.Create(4286578687), arg0.AsUInt32()); + } + + private static Vector512 M17() + { + return Vector512.Create(-1); + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_105967/Runtime_105967.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_105967/Runtime_105967.csproj new file mode 100644 index 0000000000000..de6d5e08882e8 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_105967/Runtime_105967.csproj @@ -0,0 +1,8 @@ + + + True + + + + + diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_105968/Runtime_105968.cs b/src/tests/JIT/Regression/JitBlue/Runtime_105968/Runtime_105968.cs new file mode 100644 index 0000000000000..bfd10affe2d1b --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_105968/Runtime_105968.cs @@ -0,0 +1,43 @@ +// 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 System.Numerics; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; +using Xunit; + +// Generated by Fuzzlyn v2.2 on 2024-08-04 16:05:19 +// Run on X64 Linux +// Seed: 7664329391183577492-vectort,vector128,vector256,vector512,x86aes,x86avx,x86avx2,x86avx512bw,x86avx512bwvl,x86avx512cd,x86avx512cdvl,x86avx512dq,x86avx512dqvl,x86avx512f,x86avx512fvl,x86avx512fx64,x86avx512vbmi,x86avx512vbmivl,x86bmi1,x86bmi1x64,x86bmi2,x86bmi2x64,x86fma,x86lzcnt,x86lzcntx64,x86pclmulqdq,x86popcnt,x86popcntx64,x86sse,x86ssex64,x86sse2,x86sse2x64,x86sse3,x86sse41,x86sse41x64,x86sse42,x86sse42x64,x86ssse3,x86x86base +// Reduced from 35.1 KiB to 0.9 KiB in 00:00:35 +// Hits JIT assert in Release: +// Assertion failed 'childNode->canBeContained()' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Lowering nodeinfo' (IL size 134; hash 0xade6b36b; FullOpts) +// +// File: /__w/1/s/src/coreclr/jit/lower.cpp Line: 42 +// + +public class Runtime_105968 +{ + [Fact] + public static void TestEntryPoint() + { + if (Avx512F.IsSupported) + { + var vr11 = (double)0; + var vr12 = Vector128.CreateScalar(vr11); + var vr13 = Vector128.Create(0); + Vector128 vr23 = default(Vector128); + var vr15 = Vector128.CreateScalar(0d); + var vr16 = Avx512F.RoundScaleScalar(vr23, vr15, 0); + var vr17 = Sse2.DivideScalar(vr13, vr16); + var vr18 = (double)0; + var vr19 = Vector128.CreateScalar(vr18); + var vr20 = Vector128.CreateScalar(-1829879552908856156L); + var vr21 = Avx512F.FixupScalar(vr17, vr19, vr20, 0); + bool vr22 = Sse2.CompareScalarUnorderedLessThanOrEqual(vr12, vr21); + Assert.False(vr22); + } + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_105968/Runtime_105968.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_105968/Runtime_105968.csproj new file mode 100644 index 0000000000000..de6d5e08882e8 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_105968/Runtime_105968.csproj @@ -0,0 +1,8 @@ + + + True + + + + + diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_105970/Runtime_105970.cs b/src/tests/JIT/Regression/JitBlue/Runtime_105970/Runtime_105970.cs new file mode 100644 index 0000000000000..f10bf6c245249 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_105970/Runtime_105970.cs @@ -0,0 +1,42 @@ +// 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 System.Numerics; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; +using Xunit; + +// Generated by Fuzzlyn v2.2 on 2024-08-04 15:50:24 +// Run on X64 Windows +// Seed: 5477057901617732479-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 32.6 KiB to 0.8 KiB in 00:01:15 +// Hits JIT assert in Release: +// Assertion failed 'numArgs == 2' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Linear scan register alloc' (IL size 107; hash 0xade6b36b; FullOpts) +// +// File: D:\a\_work\1\s\src\coreclr\jit\lsrabuild.cpp Line: 3701 +// + +public class Runtime_105970 +{ + public static Vector256 s_1; + + [Fact] + public static void TestEntryPoint() + { + if (Avx512F.VL.IsSupported) + { + var vr9 = Vector256.CreateScalar(1.7976931348623157E+308d); + var vr10 = Vector256.CreateScalar(1.7976931348623157E+308d); + Vector256 vr18 = default(Vector256); + var vr12 = Avx512F.VL.Fixup(vr9, vr10, vr18, 0); + var vr13 = Vector256.CreateScalar(-1627.749979702826d); + var vr15 = Vector256.Create(-1); + var vr16 = Avx512F.VL.Fixup(vr12, vr13, vr15, 0); + Vector256 vr17 = Avx512F.VL.Shuffle2x128(vr16, s_1, 0); + Vector256 expected = Vector256.Create(18442240474082181119, 18442240474082181119, 0, 0); + Assert.Equal(expected, vr17.AsUInt64()); + } + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_105970/Runtime_105970.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_105970/Runtime_105970.csproj new file mode 100644 index 0000000000000..de6d5e08882e8 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_105970/Runtime_105970.csproj @@ -0,0 +1,8 @@ + + + True + + + + +