Skip to content

Commit d564cb3

Browse files
tannergoodinghez2010
authored andcommitted
Ensure that we don't try and optimize masks for promoted fields (dotnet#110485)
* Ensure that we don't try and optimize masks for promoted fields * Add using for Xunit * Fix test name * Make the xunit analyzer happy
1 parent 8708c3d commit d564cb3

File tree

3 files changed

+113
-1
lines changed

3 files changed

+113
-1
lines changed

src/coreclr/jit/optimizemaskconversions.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,22 @@ class MaskConversionsCheckVisitor final : public GenTreeVisitor<MaskConversionsC
227227
weight->InvalidateWeight();
228228
return fgWalkResult::WALK_CONTINUE;
229229
}
230+
231+
// Cannot convert any locals that r promoted struct fields
232+
if (varDsc->lvIsStructField)
233+
{
234+
JITDUMP("is struct field. ");
235+
weight->InvalidateWeight();
236+
return fgWalkResult::WALK_CONTINUE;
237+
}
238+
230239
// TODO: Converting to a mask loses data - as each field is only a single bit.
231240
// For parameters, OSR locals, and locals which are used as vectors, then they
232241
// cannot be stored as a mask as data will be lost.
233242
// For all of these, conversions could be done by creating a new store of type mask.
234243
// Then uses as mask could be converted to type mask and pointed to use the new
235244
// definition. The weighting would need updating to take this into account.
236-
else if (isLocalUse && !hasConversion)
245+
if (isLocalUse && !hasConversion)
237246
{
238247
JITDUMP("is used as vector. ");
239248
weight->InvalidateWeight();
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
using System.Numerics;
5+
using System.Runtime.CompilerServices;
6+
using System.Runtime.Intrinsics;
7+
using Xunit;
8+
9+
public class Runtime_110326A
10+
{
11+
public struct S1
12+
{
13+
public bool bool_2;
14+
public Vector512<short> v512_short_3;
15+
public Vector512<float> v512_float_4;
16+
}
17+
18+
[Fact]
19+
public static void TestEntryPoint()
20+
{
21+
Runtime_110326A.Method1();
22+
}
23+
24+
[MethodImpl(MethodImplOptions.NoInlining)]
25+
private static ulong Method1()
26+
{
27+
S1 s1_s1_d1_f3_160 = new S1();
28+
return Vector512.ExtractMostSignificantBits(s1_s1_d1_f3_160.v512_short_3);
29+
}
30+
}
31+
32+
public class Runtime_110326B
33+
{
34+
public struct S2_D1_F2
35+
{
36+
public struct S2_D2_F2
37+
{
38+
public Vector<double> v_double_0;
39+
}
40+
41+
public struct S2_D2_F3
42+
{
43+
public Vector3 v3_10;
44+
}
45+
}
46+
47+
public struct S2_D1_F3
48+
{
49+
public struct S2_D2_F3
50+
{
51+
public Vector256<int> v256_int_14;
52+
}
53+
54+
public Vector128<long> v128_long_13;
55+
public Vector512<uint> v512_uint_16;
56+
}
57+
58+
[Fact]
59+
public static void TestEntryPoint()
60+
{
61+
Runtime_110326B.Method0();
62+
}
63+
64+
[MethodImpl(MethodImplOptions.NoInlining)]
65+
private static void Method0()
66+
{
67+
S2_D1_F2.S2_D2_F2 s2_s2_d1_f2_s2_d2_f2_262 = new S2_D1_F2.S2_D2_F2();
68+
S2_D1_F2.S2_D2_F2 s2_s2_d1_f2_s2_d2_f2_263 = s2_s2_d1_f2_s2_d2_f2_262;
69+
S2_D1_F2.S2_D2_F3 s2_s2_d1_f2_s2_d2_f3_264 = new S2_D1_F2.S2_D2_F3();
70+
S2_D1_F2.S2_D2_F3 s2_s2_d1_f2_s2_d2_f3_265 = s2_s2_d1_f2_s2_d2_f3_264;
71+
S2_D1_F2 s2_s2_d1_f2_266 = new S2_D1_F2();
72+
S2_D1_F3.S2_D2_F3 s2_s2_d1_f3_s2_d2_f3_268 = new S2_D1_F3.S2_D2_F3();
73+
S2_D1_F3 s2_s2_d1_f3_269 = new S2_D1_F3();
74+
S2_D1_F3 s2_s2_d1_f3_270 = s2_s2_d1_f3_269;
75+
s2_s2_d1_f3_270.v512_uint_16 = Vector512.IsZero(Vector512<uint>.AllBitsSet);
76+
77+
Log("s2_s2_d1_f", s2_s2_d1_f2_s2_d2_f2_262.v_double_0);
78+
Log("s2_s2_d1_f", s2_s2_d1_f2_s2_d2_f2_263.v_double_0);
79+
Log("s2_s2_d1_f", s2_s2_d1_f2_s2_d2_f3_264);
80+
Log("s2_s2_d1_f", s2_s2_d1_f2_s2_d2_f3_265.v3_10);
81+
Log("s2_s2_d1_f", s2_s2_d1_f2_266);
82+
Log("s2_s2_d1_f", s2_s2_d1_f3_s2_d2_f3_268.v256_int_14);
83+
Log("s2_s2_d1_f", s2_s2_d1_f3_269.v128_long_13);
84+
Log("s2_s2_d1_f", s2_s2_d1_f3_270.v128_long_13);
85+
}
86+
87+
[MethodImpl(MethodImplOptions.NoInlining)]
88+
private static void Log(string varName, object varValue)
89+
{
90+
}
91+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<Optimize>True</Optimize>
4+
</PropertyGroup>
5+
<ItemGroup>
6+
<Compile Include="$(MSBuildProjectName).cs" />
7+
</ItemGroup>
8+
<ItemGroup>
9+
<CLRTestEnvironmentVariable Include="DOTNET_TieredCompilation" Value="0" />
10+
<CLRTestEnvironmentVariable Include="DOTNET_JitStress" Value="2" />
11+
</ItemGroup>
12+
</Project>

0 commit comments

Comments
 (0)