Skip to content

Commit b4be77b

Browse files
authored
Update the assert for BlendVariable (dotnet#92183)
* Update the assert for BlendVariable * Add test cases * Add Sse41.IsSupported check
1 parent e235aef commit b4be77b

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

src/coreclr/jit/emitxarch.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -8609,9 +8609,14 @@ void emitter::emitIns_SIMD_R_R_R_R(
86098609
// SSE4.1 blendv* hardcode the mask vector (op3) in XMM0
86108610
emitIns_Mov(INS_movaps, attr, REG_XMM0, op3Reg, /* canSkip */ true);
86118611

8612-
// Ensure we aren't overwriting op2 or oop3 (which should be REG_XMM0)
8612+
// Ensure we aren't overwriting op2 or op3 (which should be REG_XMM0)
86138613
assert((op2Reg != targetReg) || (op1Reg == targetReg));
8614-
assert(targetReg != REG_XMM0);
8614+
8615+
// If targetReg == REG_XMM0, it means that op3 was last use and we decided to
8616+
// reuse REG_XMM0 for destination i.e. targetReg. In such case, make sure
8617+
// that XMM0 value after the (op3Reg -> XMM0) move done above is not
8618+
// overwritten by op1Reg.
8619+
assert((targetReg != REG_XMM0) || (op1Reg == op3Reg));
86158620

86168621
emitIns_Mov(INS_movaps, attr, targetReg, op1Reg, /* canSkip */ true);
86178622
emitIns_R_R(ins, attr, targetReg, op2Reg);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
//
4+
// There was an issue with Sse41.BlendVariable where we might reuse XMM0
5+
// for targetReg.
6+
7+
using System;
8+
using System.Runtime.CompilerServices;
9+
using System.Runtime.Intrinsics;
10+
using System.Runtime.Intrinsics.X86;
11+
using Xunit;
12+
13+
public class TestClass_91798
14+
{
15+
Vector128<uint> v128_uint_75 = Vector128.Create((uint)2, 1, 0, 1);
16+
17+
[MethodImpl(MethodImplOptions.NoInlining)]
18+
public Vector128<uint> Method0()
19+
{
20+
return Sse41.BlendVariable(v128_uint_75, Vector128<uint>.One, v128_uint_75);
21+
}
22+
23+
[Fact]
24+
public static void TestEntryPoint()
25+
{
26+
if (Sse41.IsSupported)
27+
{
28+
TestClass_91798 obj = new TestClass_91798();
29+
obj.Method0();
30+
}
31+
}
32+
}
33+
/*
34+
Environment:
35+
36+
set DOTNET_EnableSSE42=0
37+
38+
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)
39+
40+
File: D:\git\runtime2\src\coreclr\jit\emitxarch.cpp Line: 8612
41+
Image: d:\git\runtime2\artifacts\tests\coreclr\windows.x64.Checked\tests\Core_Root\corerun.exe
42+
*/
43+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<Optimize>True</Optimize>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<Compile Include="$(MSBuildProjectName).cs" />
7+
<CLRTestEnvironmentVariable Include="DOTNET_EnableSSE42" Value="0" />
8+
</ItemGroup>
9+
</Project>

0 commit comments

Comments
 (0)