Skip to content

Commit 7a50b43

Browse files
JIT: Cast UInt64 to Single directly during const folding (#106419)
1 parent 7cd266e commit 7a50b43

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

src/coreclr/jit/gentree.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -15607,7 +15607,7 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree)
1560715607

1560815608
case TYP_FLOAT:
1560915609
{
15610-
#if defined(TARGET_64BIT)
15610+
#ifdef TARGET_64BIT
1561115611
if (tree->IsUnsigned() && (lval1 < 0))
1561215612
{
1561315613
f1 = FloatingPointUtils::convertUInt64ToFloat((uint64_t)lval1);

src/coreclr/jit/utils.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -2272,8 +2272,7 @@ double FloatingPointUtils::convertUInt64ToDouble(uint64_t uIntVal)
22722272

22732273
float FloatingPointUtils::convertUInt64ToFloat(uint64_t u64)
22742274
{
2275-
double d = convertUInt64ToDouble(u64);
2276-
return (float)d;
2275+
return (float)u64;
22772276
}
22782277

22792278
uint64_t FloatingPointUtils::convertDoubleToUInt64(double d)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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.2 on 2024-08-13 00:04:04
5+
// Run on Arm64 MacOS
6+
// Seed: 13207615092246842583-vectort,vector64,vector128,armadvsimd,armadvsimdarm64,armaes,armarmbase,armarmbasearm64,armcrc32,armcrc32arm64,armdp,armrdm,armrdmarm64,armsha1,armsha256
7+
// Reduced from 226.8 KiB to 0.4 KiB in 00:02:12
8+
// Debug: Outputs 1600094603
9+
// Release: Outputs 1600094604
10+
using System;
11+
using System.Runtime.InteropServices;
12+
using System.Runtime.Intrinsics.X86;
13+
using Xunit;
14+
15+
public class Runtime_106338
16+
{
17+
[Fact]
18+
[SkipOnMono("https://github.com/dotnet/runtime/issues/100368", TestPlatforms.Any)]
19+
public static void TestEntryPoint()
20+
{
21+
ulong vr10 = 16105307123914158031UL;
22+
float vr11 = 4294967295U | vr10;
23+
uint result = BitConverter.SingleToUInt32Bits(vr11);
24+
25+
if ((RuntimeInformation.ProcessArchitecture == Architecture.Arm64) || ((RuntimeInformation.ProcessArchitecture == Architecture.X64) && Avx512F.IsSupported))
26+
{
27+
// Expected to cast ulong -> float directly
28+
Assert.Equal(1600094603U, result);
29+
}
30+
else
31+
{
32+
// Expected to cast ulong -> double -> float
33+
Assert.Equal(1600094604U, result);
34+
}
35+
}
36+
}
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)