Skip to content

Commit a3b617e

Browse files
JIT: Don't assume unsigned arithmetic always produces non-negative result in value numbering (#109384)
Fixes #109337.
1 parent 9e3f557 commit a3b617e

File tree

3 files changed

+67
-5
lines changed

3 files changed

+67
-5
lines changed

src/coreclr/jit/valuenum.cpp

+10-5
Original file line numberDiff line numberDiff line change
@@ -6553,6 +6553,16 @@ bool ValueNumStore::IsVNInt32Constant(ValueNum vn)
65536553
return TypeOfVN(vn) == TYP_INT;
65546554
}
65556555

6556+
//------------------------------------------------------------------------
6557+
// IsVNNeverNegative: Determines if the given value number can never take on a negative value
6558+
// in a signed context (i.e. when the most-significant bit represents signedness).
6559+
//
6560+
// Parameters:
6561+
// vn - Value number to query
6562+
//
6563+
// Returns:
6564+
// True if the most-significant bit is never set, false otherwise.
6565+
//
65566566
bool ValueNumStore::IsVNNeverNegative(ValueNum vn)
65576567
{
65586568
auto vnVisitor = [this](ValueNum vn) -> VNVisit {
@@ -6595,15 +6605,10 @@ bool ValueNumStore::IsVNNeverNegative(ValueNum vn)
65956605
case VNF_LE:
65966606
case VNF_EQ:
65976607
case VNF_NE:
6598-
case VNF_UMOD:
6599-
case VNF_UDIV:
66006608
case VNF_GE_UN:
66016609
case VNF_GT_UN:
66026610
case VNF_LE_UN:
66036611
case VNF_LT_UN:
6604-
case VNF_ADD_UN_OVF:
6605-
case VNF_SUB_UN_OVF:
6606-
case VNF_MUL_UN_OVF:
66076612
case VNF_MDArrLowerBound:
66086613
#ifdef FEATURE_HW_INTRINSICS
66096614
#ifdef TARGET_XARCH
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
// Generated by Fuzzlyn v2.4 on 2024-10-27 16:58:11
5+
// Run on X86 Windows
6+
// Seed: 13886187988830061152-vectort,vector128,vector256,x86aes,x86avx,x86avx2,x86avx512bw,x86avx512bwvl,x86avx512cd,x86avx512cdvl,x86avx512dq,x86avx512dqvl,x86avx512f,x86avx512fvl,x86bmi1,x86bmi2,x86fma,x86lzcnt,x86pclmulqdq,x86popcnt,x86sse,x86sse2,x86sse3,x86sse41,x86sse42,x86ssse3,x86x86base
7+
// Reduced from 241.5 KiB to 0.6 KiB in 00:05:21
8+
// Debug: Prints 0 line(s)
9+
// Release: Prints 1 line(s)
10+
using Xunit;
11+
12+
public class Runtime_109337
13+
{
14+
private struct S0
15+
{
16+
public uint F1;
17+
public ushort F2;
18+
}
19+
20+
[Fact]
21+
public static void TestEntryPoint()
22+
{
23+
var vr4 = new S0();
24+
Assert.Equal(0, TestDiv(vr4));
25+
26+
vr4.F1 = 2147483649u;
27+
Assert.Equal(0, TestMod(vr4));
28+
}
29+
30+
private static int TestDiv(S0 argThis)
31+
{
32+
if (((long)(17731708739983220386UL / (ushort)(argThis.F2 | 1))) >= 0)
33+
{
34+
return 1;
35+
}
36+
37+
return 0;
38+
}
39+
40+
private static int TestMod(S0 argThis)
41+
{
42+
if (((int)(2147483648u % argThis.F1)) >= 0)
43+
{
44+
return 1;
45+
}
46+
47+
return 0;
48+
}
49+
}
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)