Skip to content

Commit 54a25d6

Browse files
authored
JIT: Fix illegal operand swapping in VectorXYZ.AndNot transformation (#91882)
The new logic introduced in #81993 would swap the LHS and RHS of the operands without any additional checks for side effects. Fix #91855
1 parent 6504cdb commit 54a25d6

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

src/coreclr/jit/morph.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11028,7 +11028,16 @@ GenTree* Compiler::fgOptimizeHWIntrinsic(GenTreeHWIntrinsic* node)
1102811028
}
1102911029
}
1103011030

11031-
if (lhs == nullptr || rhs == nullptr)
11031+
if ((lhs == nullptr) || (rhs == nullptr))
11032+
{
11033+
break;
11034+
}
11035+
11036+
// Filter out side effecting cases for several reasons:
11037+
// 1. gtNewSimdBinOpNode may swap operand order.
11038+
// 2. The code above will swap operand order.
11039+
// 3. The code above does not handle GTF_REVERSE_OPS.
11040+
if (((lhs->gtFlags | rhs->gtFlags) & GTF_ALL_EFFECT) != 0)
1103211041
{
1103311042
break;
1103411043
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.aa
3+
4+
using System;
5+
using System.Runtime.CompilerServices;
6+
using System.Runtime.Intrinsics;
7+
using Xunit;
8+
9+
public class Runitme_91855
10+
{
11+
[Fact]
12+
public static void TestEntryPoint()
13+
{
14+
Assert.Throws<DivideByZeroException>(() => Foo(null, 0));
15+
}
16+
17+
[MethodImpl(MethodImplOptions.NoInlining)]
18+
private static Vector128<uint> Foo(C c, uint val)
19+
{
20+
return Vector128.Create<uint>(100u / val) & (c.V ^ Vector128<uint>.AllBitsSet);
21+
}
22+
23+
private class C
24+
{
25+
public Vector128<uint> V;
26+
}
27+
}
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)