From 3e8d33dcde5aac0f36956130b650546eb284e0ab Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Sat, 16 Sep 2023 12:30:43 -0700 Subject: [PATCH 1/3] Update the assert for BlendVariable --- src/coreclr/jit/emitxarch.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/emitxarch.cpp b/src/coreclr/jit/emitxarch.cpp index ba599c9e465ad..0941e46767684 100644 --- a/src/coreclr/jit/emitxarch.cpp +++ b/src/coreclr/jit/emitxarch.cpp @@ -8602,9 +8602,14 @@ void emitter::emitIns_SIMD_R_R_R_R( // SSE4.1 blendv* hardcode the mask vector (op3) in XMM0 emitIns_Mov(INS_movaps, attr, REG_XMM0, op3Reg, /* canSkip */ true); - // Ensure we aren't overwriting op2 or oop3 (which should be REG_XMM0) + // Ensure we aren't overwriting op2 or op3 (which should be REG_XMM0) assert((op2Reg != targetReg) || (op1Reg == targetReg)); - assert(targetReg != REG_XMM0); + + // If targetReg == REG_XMM0, it means that op3 was last use and we decided to + // reuse REG_XMM0 for destination i.e. targetReg. In such case, make sure + // that XMM0 value after the (op3Reg -> XMM0) move done above is not + // overwritten by op1Reg. + assert((targetReg != REG_XMM0) || (op1Reg == op3Reg)); emitIns_Mov(INS_movaps, attr, targetReg, op1Reg, /* canSkip */ true); emitIns_R_R(ins, attr, targetReg, op2Reg); From 600fef542aa83bdbe8405247b94d0d9474af3b7d Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Sat, 16 Sep 2023 12:42:33 -0700 Subject: [PATCH 2/3] Add test cases --- .../JitBlue/Runtime_91798/Runtime_91798.cs | 40 +++++++++++++++++++ .../Runtime_91798/Runtime_91798.csproj | 9 +++++ 2 files changed, 49 insertions(+) create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_91798/Runtime_91798.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_91798/Runtime_91798.csproj diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_91798/Runtime_91798.cs b/src/tests/JIT/Regression/JitBlue/Runtime_91798/Runtime_91798.cs new file mode 100644 index 0000000000000..1c37db59426ac --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_91798/Runtime_91798.cs @@ -0,0 +1,40 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// +// There was an issue with Sse41.BlendVariable where we might reuse XMM0 +// for targetReg. + +using System; +using System.Runtime.CompilerServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; +using Xunit; + +public class TestClass_91798 +{ + Vector128 v128_uint_75 = Vector128.Create((uint)2, 1, 0, 1); + + [MethodImpl(MethodImplOptions.NoInlining)] + public Vector128 Method0() + { + return Sse41.BlendVariable(v128_uint_75, Vector128.One, v128_uint_75); + } + + [Fact] + public static void TestEntryPoint() + { + TestClass_91798 obj = new TestClass_91798(); + obj.Method0(); + } +} +/* +Environment: + +set DOTNET_EnableSSE42=0 + +Assert failure(PID 8884 [0x000022b4], Thread: 14588 [0x38fc]): Assertion failed '(targetReg != REG_XMM0)' in 'TestClass_91798:Method0():System.Runtime.Intrinsics.Vector128`1[uint]:this' during 'Generate code' (IL size 23; hash 0x557a6266; FullOpts) + + File: D:\git\runtime2\src\coreclr\jit\emitxarch.cpp Line: 8612 + Image: d:\git\runtime2\artifacts\tests\coreclr\windows.x64.Checked\tests\Core_Root\corerun.exe +*/ + diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_91798/Runtime_91798.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_91798/Runtime_91798.csproj new file mode 100644 index 0000000000000..9f6a0b76d8caf --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_91798/Runtime_91798.csproj @@ -0,0 +1,9 @@ + + + True + + + + + + From 8d49f3ca2f2746f5e11bf89f4240646d198240ba Mon Sep 17 00:00:00 2001 From: Kunal Pathak Date: Sun, 17 Sep 2023 01:59:09 -0700 Subject: [PATCH 3/3] Add Sse41.IsSupported check --- .../JIT/Regression/JitBlue/Runtime_91798/Runtime_91798.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_91798/Runtime_91798.cs b/src/tests/JIT/Regression/JitBlue/Runtime_91798/Runtime_91798.cs index 1c37db59426ac..3e23f98734229 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_91798/Runtime_91798.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_91798/Runtime_91798.cs @@ -23,8 +23,11 @@ public Vector128 Method0() [Fact] public static void TestEntryPoint() { - TestClass_91798 obj = new TestClass_91798(); - obj.Method0(); + if (Sse41.IsSupported) + { + TestClass_91798 obj = new TestClass_91798(); + obj.Method0(); + } } } /*