Skip to content

Commit

Permalink
Update the assert for BlendVariable (dotnet#92183)
Browse files Browse the repository at this point in the history
* Update the assert for BlendVariable

* Add test cases

* Add Sse41.IsSupported check
kunalspathak authored Sep 20, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent e235aef commit b4be77b
Showing 3 changed files with 59 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/coreclr/jit/emitxarch.cpp
Original file line number Diff line number Diff line change
@@ -8609,9 +8609,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);
43 changes: 43 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_91798/Runtime_91798.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.
//
// 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<uint> v128_uint_75 = Vector128.Create((uint)2, 1, 0, 1);

[MethodImpl(MethodImplOptions.NoInlining)]
public Vector128<uint> Method0()
{
return Sse41.BlendVariable(v128_uint_75, Vector128<uint>.One, v128_uint_75);
}

[Fact]
public static void TestEntryPoint()
{
if (Sse41.IsSupported)
{
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
*/

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
<CLRTestEnvironmentVariable Include="DOTNET_EnableSSE42" Value="0" />
</ItemGroup>
</Project>

0 comments on commit b4be77b

Please sign in to comment.