Skip to content

Commit baa8df8

Browse files
Ensure that we add the broadcast and mask flags prior to computing the instruction size (#105757)
1 parent 40618ff commit baa8df8

File tree

3 files changed

+59
-6
lines changed

3 files changed

+59
-6
lines changed

src/coreclr/jit/emitxarch.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7464,6 +7464,9 @@ void emitter::emitIns_R_C(
74647464
else
74657465
#endif // TARGET_X86
74667466
{
7467+
SetEvexBroadcastIfNeeded(id, instOptions);
7468+
SetEvexEmbMaskIfNeeded(id, instOptions);
7469+
74677470
sz = emitInsSizeCV(id, insCodeRM(ins));
74687471
}
74697472

@@ -7478,9 +7481,6 @@ void emitter::emitIns_R_C(
74787481
}
74797482
}
74807483

7481-
SetEvexBroadcastIfNeeded(id, instOptions);
7482-
SetEvexEmbMaskIfNeeded(id, instOptions);
7483-
74847484
id->idCodeSize(sz);
74857485

74867486
id->idAddr()->iiaFieldHnd = fldHnd;
@@ -9295,8 +9295,7 @@ void emitter::emitIns_R_S(instruction ins, emitAttr attr, regNumber ireg, int va
92959295
return;
92969296
}
92979297

9298-
instrDesc* id = emitNewInstr(attr);
9299-
UNATIVE_OFFSET sz;
9298+
instrDesc* id = emitNewInstr(attr);
93009299
id->idIns(ins);
93019300
id->idInsFmt(fmt);
93029301
id->idReg1(ireg);
@@ -9305,7 +9304,7 @@ void emitter::emitIns_R_S(instruction ins, emitAttr attr, regNumber ireg, int va
93059304
SetEvexBroadcastIfNeeded(id, instOptions);
93069305
SetEvexEmbMaskIfNeeded(id, instOptions);
93079306

9308-
sz = emitInsSizeSV(id, insCodeRM(ins), varx, offs);
9307+
UNATIVE_OFFSET sz = emitInsSizeSV(id, insCodeRM(ins), varx, offs);
93099308
id->idCodeSize(sz);
93109309
#ifdef DEBUG
93119310
id->idDebugOnlyInfo()->idVarRefOffs = emitVarRefOffs;
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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;
5+
using System.Runtime.CompilerServices;
6+
using System.Numerics;
7+
using System.Runtime.Intrinsics;
8+
using System.Runtime.Intrinsics.X86;
9+
using Xunit;
10+
11+
// Generated by Fuzzlyn v2.2 on 2024-07-29 22:32:33
12+
// Run on X64 Linux
13+
// Seed: 1257362736509498015-vectort,vector128,vector256,x86aes,x86avx,x86avx2,x86avx512bw,x86avx512bwvl,x86avx512cd,x86avx512cdvl,x86avx512dq,x86avx512dqvl,x86avx512f,x86avx512fvl,x86avx512fx64,x86bmi1,x86bmi1x64,x86bmi2,x86bmi2x64,x86fma,x86lzcnt,x86lzcntx64,x86pclmulqdq,x86popcnt,x86popcntx64,x86sse,x86ssex64,x86sse2,x86sse2x64,x86sse3,x86sse41,x86sse41x64,x86sse42,x86sse42x64,x86ssse3,x86x86base
14+
// Reduced from 29.1 KiB to 0.6 KiB in 00:00:26
15+
// Hits JIT assert in Release:
16+
// Assertion failed 'estimatedSize >= actualSize' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Emit code' (IL size 59; hash 0xade6b36b; FullOpts)
17+
//
18+
// File: /__w/1/s/src/coreclr/jit/emit.cpp Line: 4361
19+
//
20+
21+
public class Runtime_105693
22+
{
23+
public static int s_2;
24+
25+
[Fact]
26+
public static void TestEntryPoint()
27+
{
28+
if (Avx2.IsSupported)
29+
{
30+
var vr5 = Vector128.Create<int>(1);
31+
var vr6 = Avx2.BroadcastScalarToVector256(vr5);
32+
var vr7 = Avx2.Abs(vr6);
33+
var vr8 = Vector256.CreateScalar(1U);
34+
if (Avx.TestZ(vr7, vr8))
35+
{
36+
var vr9 = Vector128.CreateScalar(1f);
37+
s_2 = Sse.ConvertToInt32(vr9);
38+
}
39+
else
40+
{
41+
s_2 = 1;
42+
}
43+
Assert.Equal(1, s_2);
44+
}
45+
}
46+
}
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)