Skip to content

Commit c446706

Browse files
authored
JIT: arrays are now not always TYP_REF (#115801)
Remove some asserts saying otherwise. Fixes #115495.
1 parent 1998b26 commit c446706

File tree

3 files changed

+101
-7
lines changed

3 files changed

+101
-7
lines changed

src/coreclr/jit/simd.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -627,14 +627,11 @@ bool Compiler::areArrayElementsContiguous(GenTree* op1, GenTree* op2)
627627

628628
GenTreeIndexAddr* op1IndexAddr = op1->AsIndir()->Addr()->AsIndexAddr();
629629
GenTreeIndexAddr* op2IndexAddr = op2->AsIndir()->Addr()->AsIndexAddr();
630+
GenTree* op1ArrayRef = op1IndexAddr->Arr();
631+
GenTree* op2ArrayRef = op2IndexAddr->Arr();
632+
GenTree* op1IndexNode = op1IndexAddr->Index();
633+
GenTree* op2IndexNode = op2IndexAddr->Index();
630634

631-
GenTree* op1ArrayRef = op1IndexAddr->Arr();
632-
GenTree* op2ArrayRef = op2IndexAddr->Arr();
633-
assert(op1ArrayRef->TypeGet() == TYP_REF);
634-
assert(op2ArrayRef->TypeGet() == TYP_REF);
635-
636-
GenTree* op1IndexNode = op1IndexAddr->Index();
637-
GenTree* op2IndexNode = op2IndexAddr->Index();
638635
if ((op1IndexNode->OperGet() == GT_CNS_INT && op2IndexNode->OperGet() == GT_CNS_INT) &&
639636
(op1IndexNode->AsIntCon()->gtIconVal + 1 == op2IndexNode->AsIntCon()->gtIconVal))
640637
{
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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.Collections.Generic;
6+
using System.Numerics;
7+
using System.Runtime.CompilerServices;
8+
using Xunit;
9+
10+
// LLM-Fuzz Mutation 5
11+
12+
public class Runtime_115495
13+
{
14+
private const int Pass = 100;
15+
private const int Fail = -1;
16+
17+
public class Assert
18+
{
19+
public static void Equal(float a, float b)
20+
{
21+
if (a != b)
22+
throw new Exception("Assert.Equal failed");
23+
}
24+
25+
public static void NotEqual(float a, float b)
26+
{
27+
if (a == b)
28+
throw new Exception("Assert.NotEqual failed");
29+
}
30+
}
31+
32+
public struct SimpleVector3
33+
{
34+
// Introduce lambda expressions to process array values.
35+
static Func<int, int> multiply = x => x * 2;
36+
37+
static void Vector3GetHashCodeTest(ref int checksum)
38+
{
39+
Vector3 one = new Vector3(2.0f, 3.0f, 3.3f);
40+
Vector3 two = new Vector3(2.0f, 3.0f, 3.3f);
41+
Vector3 three = new Vector3(3.0f, 2.0f, 3.3f);
42+
Assert.Equal(one.GetHashCode(), two.GetHashCode());
43+
Assert.NotEqual(one.GetHashCode(), three.GetHashCode());
44+
Vector3 zero = new Vector3(0.0f, 0.0f, 0.0f);
45+
Vector3 oneAxis = new Vector3(1.0f, 0.0f, 0.0f);
46+
Assert.NotEqual(zero.GetHashCode(), oneAxis.GetHashCode());
47+
48+
// Create an array and then use a for-loop with invariant bounds.
49+
float[] items = new float[] { one.X, one.Y, one.Z, three.X, three.Y };
50+
for (int i = 0, cnt = items.Length; i < cnt; i++)
51+
{
52+
checksum += (int)(items[i] * 1.0f);
53+
}
54+
// Use a for-each loop conditionally.
55+
if (checksum % 4 == 0)
56+
{
57+
foreach (float f in items)
58+
{
59+
checksum += multiply((int)f);
60+
}
61+
}
62+
Console.WriteLine("Intermediate Checksum (Mutation 5): " + checksum);
63+
}
64+
65+
[Fact]
66+
public static int Problem()
67+
{
68+
int checksum = 19;
69+
int returnVal = Pass;
70+
try
71+
{
72+
Vector3GetHashCodeTest(ref checksum);
73+
}
74+
catch (Exception ex)
75+
{
76+
Console.WriteLine("FAILED: " + ex.Message);
77+
returnVal = Fail;
78+
}
79+
// Additional clonable loop using same array in a different context.
80+
int[] reusedArray = { 2, 4, 6, 8, 10 };
81+
for (int i = 0, length = reusedArray.Length; i < length; i++)
82+
{
83+
checksum += (i % 2 == 0) ? reusedArray[i] : -reusedArray[i];
84+
}
85+
Console.WriteLine("Final Checksum (Mutation 5): " + checksum);
86+
return returnVal;
87+
}
88+
}
89+
}
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)