Skip to content

Commit 953ccfb

Browse files
authored
Make sure to remove operand of TernaryLogic node (#116876)
* Make sure to replace the operand * add test cases
1 parent 2e24b81 commit 953ccfb

File tree

3 files changed

+86
-2
lines changed

3 files changed

+86
-2
lines changed

src/coreclr/jit/lowerxarch.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3646,8 +3646,16 @@ GenTree* Lowering::LowerHWIntrinsicTernaryLogic(GenTreeHWIntrinsic* node)
36463646
if (condition->OperIsConvertMaskToVector())
36473647
{
36483648
GenTree* tmp = condition->AsHWIntrinsic()->Op(1);
3649-
BlockRange().Remove(condition);
3650-
condition = tmp;
3649+
if (tmp->OperIsHWIntrinsic())
3650+
{
3651+
BlockRange().Remove(condition);
3652+
condition = tmp;
3653+
}
3654+
else
3655+
{
3656+
// We can't change to a BlendVariable intrinsic
3657+
break;
3658+
}
36513659
}
36523660
else if (!varTypeIsMask(condition))
36533661
{
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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+
// Assert failure(PID 7200 [0x00001c20], Thread: 19780 [0x4d44]): Assertion failed 'false && "found use of a node that is not in the LIR sequence"' in 'Runtime_114572:Main()' during 'Lowering nodeinfo' (IL size 138; hash 0x86f53552; FullOpts)
5+
6+
// File: C:\repos\runtime1\src\coreclr\jit\lir.cpp:1687
7+
// Image: c:\repos\runtime1\artifacts\tests\coreclr\windows.x64.Checked\tests\core_root\corerun.exe
8+
9+
using System;
10+
using System.Numerics;
11+
using System.Runtime.CompilerServices;
12+
using System.Runtime.Intrinsics;
13+
using System.Runtime.Intrinsics.X86;
14+
using Xunit;
15+
16+
public class Runtime_116568
17+
{
18+
public static Vector256<ushort> s_2;
19+
public static ushort s_4;
20+
public static byte s_ub = 1;
21+
public static ushort s_us = 1;
22+
private struct LocalStruct
23+
{
24+
public int Value;
25+
}
26+
27+
private static int CalculateChecksum(int initialChecksum)
28+
{
29+
// Simple checksum calculation
30+
int checksum = initialChecksum;
31+
for (int i = 0; i < 5; i++)
32+
{
33+
checksum += i * (i + 1);
34+
}
35+
return checksum;
36+
}
37+
38+
[Fact]
39+
public static void TestEntryPoint()
40+
{
41+
CalculateChecksum(0);
42+
43+
if (Avx512F.VL.IsSupported)
44+
{
45+
var vr11 = Vector256.Create<ushort>(0);
46+
var vr12 = Vector256.Create<ushort>(1);
47+
var vr13 = (ushort)0;
48+
var vr14 = Vector256.CreateScalar(vr13);
49+
var vr15 = (ushort)1;
50+
var vr16 = Vector256.CreateScalar(vr15);
51+
var vr17 = Vector256.Create<ushort>(s_4);
52+
var vr18 = Avx2.Max(vr16, vr17);
53+
54+
for (int i = 0; i < 3; i++)
55+
{
56+
s_2 = Avx512F.VL.TernaryLogic(vr11, vr12, Avx512BW.VL.CompareGreaterThanOrEqual(vr14, vr18), 216);
57+
Console.WriteLine(s_2);
58+
59+
if (i == 1)
60+
{
61+
Console.WriteLine("Redundant branch: i == 1");
62+
}
63+
64+
CalculateChecksum(123);
65+
}
66+
}
67+
}
68+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<Optimize>True</Optimize>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<Compile Include="$(MSBuildProjectName).cs" />
7+
</ItemGroup>
8+
</Project>

0 commit comments

Comments
 (0)