Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update the assert for BlendVariable #92183

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/coreclr/jit/emitxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
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>
Loading