Skip to content

Commit

Permalink
Ensure we aren't containing nodes that shouldn't be contained (#105993)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tannergooding authored Aug 6, 2024
1 parent 7dd55a0 commit 5fb42a4
Show file tree
Hide file tree
Showing 7 changed files with 198 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/coreclr/jit/lowerxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
{
Expand Down Expand Up @@ -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;
Expand Down
58 changes: 58 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_105967/Runtime_105967.cs
Original file line number Diff line number Diff line change
@@ -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<float>(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<float> arg0, long[] arg2)
{
Assert.Equal(Vector512.Create(4286578687), arg0.AsUInt32());
}

private static Vector512<int> M17()
{
return Vector512.Create<int>(-1);
}
}
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>
43 changes: 43 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_105968/Runtime_105968.cs
Original file line number Diff line number Diff line change
@@ -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<double>(0);
Vector128<double> vr23 = default(Vector128<double>);
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);
}
}
}
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>
42 changes: 42 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_105970/Runtime_105970.cs
Original file line number Diff line number Diff line change
@@ -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<double> 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<long> vr18 = default(Vector256<long>);
var vr12 = Avx512F.VL.Fixup(vr9, vr10, vr18, 0);
var vr13 = Vector256.CreateScalar(-1627.749979702826d);
var vr15 = Vector256.Create<long>(-1);
var vr16 = Avx512F.VL.Fixup(vr12, vr13, vr15, 0);
Vector256<double> vr17 = Avx512F.VL.Shuffle2x128(vr16, s_1, 0);
Vector256<ulong> expected = Vector256.Create(18442240474082181119, 18442240474082181119, 0, 0);
Assert.Equal(expected, vr17.AsUInt64());
}
}
}
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>

0 comments on commit 5fb42a4

Please sign in to comment.