Skip to content

Commit

Permalink
Track that kmov instructions may write to GPR register (dotnet#107428)
Browse files Browse the repository at this point in the history
* kmov*_gpr writes to gpr

* add test

* Add using
  • Loading branch information
kunalspathak authored and sirntar committed Sep 30, 2024
1 parent e0c6d70 commit 4aec78b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/coreclr/jit/emitxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2789,7 +2789,14 @@ bool emitter::emitInsCanOnlyWriteSSE2OrAVXReg(instrDesc* id)
// These SSE instructions write to a general purpose integer register.
return false;
}

case INS_kmovb_gpr:
case INS_kmovw_gpr:
case INS_kmovd_gpr:
case INS_kmovq_gpr:
{
// These kmov writes to a general purpose integer register
return !isGeneralRegister(id->idReg1());
}
default:
{
return true;
Expand Down
35 changes: 35 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_106545/Runtime_106545.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

/*
Found by Fuzzlyn
Assertion failed '(emitThisGCrefRegs & regMask) == 0' in 'TestClass:Method4(short,System.Runtime.Intrinsics.Vector512`1[long],byref,short,byref,byref,TestClass+S1,byref):byte:this' during 'Emit code' (IL size 47; hash 0x0a275b75; FullOpts)
File: D:\a\_work\1\s\src\coreclr\jit\emitxarch.cpp Line: 1498
*/
using System;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
using Xunit;

public class Runtime_106545
{
Vector512<byte> v512_byte_97 = Vector512.CreateScalar((byte)1);

public ulong Method0()
{
v512_byte_97 = Vector512<byte>.AllBitsSet;
return (0 - Vector512.ExtractMostSignificantBits(v512_byte_97));
}

[Fact]
public static void TestEntryPoint()
{
if (Avx2.IsSupported)
{
new Runtime_106545().Method0();
}
}
}
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 4aec78b

Please sign in to comment.