Skip to content

Commit

Permalink
JIT: Avoid removing CSE candidates in fgMorphExpandCast (dotnet#106691)
Browse files Browse the repository at this point in the history
  • Loading branch information
jakobbotsch authored Aug 21, 2024
1 parent 2831f11 commit 67993d0
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,8 @@ GenTree* Compiler::fgMorphExpandCast(GenTreeCast* tree)
// Because there is no IL instruction conv.r4.un, uint/ulong -> float
// casts are always imported as CAST(float <- CAST(double <- uint/ulong)).
// We can eliminate the redundant intermediate cast as an optimization.
else if ((dstType == TYP_FLOAT) && (srcType == TYP_DOUBLE) && oper->OperIs(GT_CAST)
else if ((dstType == TYP_FLOAT) && (srcType == TYP_DOUBLE) && oper->OperIs(GT_CAST) &&
!gtIsActiveCSE_Candidate(tree)
#ifdef TARGET_ARM
&& !varTypeIsLong(oper->AsCast()->CastOp())
#endif
Expand Down
45 changes: 45 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_106609/Runtime_106609.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// Generated by Fuzzlyn v2.2 on 2024-08-17 17:16:59
// Run on Arm64 Windows
// Seed: 18124298882625099135-vectort,vector64,vector128,armadvsimd,armadvsimdarm64,armaes,armarmbase,armarmbasearm64,armcrc32,armcrc32arm64,armdp,armsha1,armsha256
// Reduced from 129.5 KiB to 0.4 KiB in 00:04:55
// Hits JIT assert in Release:
// Assertion failed 'link' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Optimize Valnum CSEs' (IL size 39; hash 0xade6b36b; FullOpts)
//
// File: D:\a\_work\1\s\src\coreclr\jit\optcse.cpp Line: 5295
//
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.Arm;
using Xunit;

public class Runtime_106609
{
[Fact]
public static void TestEntrypoint()
{
if (AdvSimd.IsSupported)
{
try
{
Test();
}
catch
{
}
}
}

public static float[] s_2;
[MethodImpl(MethodImplOptions.NoInlining)]
private static void Test()
{
for (int vr8 = 0; vr8 < 2; vr8++)
{
var vr9 = Vector64.Create<uint>(0);
s_2[0] = (float)(-(-(double)AdvSimd.Extract(vr9, 0)));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>

0 comments on commit 67993d0

Please sign in to comment.