From aebe4f84c3fdff44bec3415029e7489a68583ead Mon Sep 17 00:00:00 2001 From: "Aman Khalid (from Dev Box)" Date: Wed, 14 Aug 2024 16:19:34 -0400 Subject: [PATCH 01/13] Fix cast folding on ARM64 --- src/coreclr/jit/gentree.cpp | 12 ++++++------ src/coreclr/jit/utils.cpp | 5 +++++ 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index f687f9139f5981..5f07233e86f28c 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -15607,7 +15607,7 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree) case TYP_FLOAT: { -#if defined(TARGET_64BIT) +#ifdef TARGET_64BIT if (tree->IsUnsigned() && (lval1 < 0)) { f1 = FloatingPointUtils::convertUInt64ToFloat((uint64_t)lval1); @@ -15616,10 +15616,10 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree) { f1 = (float)lval1; } -#else - // 32-bit currently does a 2-step conversion, which is incorrect - // but which we are going to take a breaking change around early - // in a release cycle. +#else // !TARGET_64BIT + // 32-bit currently does a 2-step conversion, which is incorrect + // but which we are going to take a breaking change around early + // in a release cycle. if (tree->IsUnsigned() && (lval1 < 0)) { @@ -15629,7 +15629,7 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree) { f1 = forceCastToFloat((double)lval1); } -#endif +#endif // !TARGET_64BIT d1 = f1; goto CNS_DOUBLE; diff --git a/src/coreclr/jit/utils.cpp b/src/coreclr/jit/utils.cpp index 209b23ac6f46a0..06fec7951e1b44 100644 --- a/src/coreclr/jit/utils.cpp +++ b/src/coreclr/jit/utils.cpp @@ -2272,8 +2272,13 @@ double FloatingPointUtils::convertUInt64ToDouble(uint64_t uIntVal) float FloatingPointUtils::convertUInt64ToFloat(uint64_t u64) { +#ifdef TARGET_ARM64 + // ARM64 supports casting directly to float + return (float)u64; +#else // !TARGET_ARM64 double d = convertUInt64ToDouble(u64); return (float)d; +#endif // !TARGET_ARM64 } uint64_t FloatingPointUtils::convertDoubleToUInt64(double d) From afbd84051957678f176985fbdc5ede2bd36a1603 Mon Sep 17 00:00:00 2001 From: "Aman Khalid (from Dev Box)" Date: Wed, 14 Aug 2024 16:24:15 -0400 Subject: [PATCH 02/13] Add test --- .../JitBlue/Runtime_106338/Runtime_106338.cs | 21 +++++++++++++++++++ .../Runtime_106338/Runtime_106338.csproj | 9 ++++++++ 2 files changed, 30 insertions(+) create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.csproj diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs new file mode 100644 index 00000000000000..51219374e2c1e5 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs @@ -0,0 +1,21 @@ +// 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-13 00:04:04 +// Run on Arm64 MacOS +// Seed: 13207615092246842583-vectort,vector64,vector128,armadvsimd,armadvsimdarm64,armaes,armarmbase,armarmbasearm64,armcrc32,armcrc32arm64,armdp,armrdm,armrdmarm64,armsha1,armsha256 +// Reduced from 226.8 KiB to 0.4 KiB in 00:02:12 +// Debug: Outputs 1600094603 +// Release: Outputs 1600094604 +using System; + +public class Runtime_106338 +{ + [Fact] + public static void TestEntryPoint() + { + ulong vr10 = 16105307123914158031UL; + float vr11 = 4294967295U | vr10; + Assert.Equal(BitConverter.SingleToUInt32Bits(vr11), 1600094603); + } +} \ No newline at end of file diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.csproj new file mode 100644 index 00000000000000..0393f77dbcc14d --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.csproj @@ -0,0 +1,9 @@ + + + True + true + + + + + From 3b2aab7045e7e58c496f30f33d29e61d109e7a7a Mon Sep 17 00:00:00 2001 From: "Aman Khalid (from Dev Box)" Date: Wed, 14 Aug 2024 16:29:35 -0400 Subject: [PATCH 03/13] Fix weird comment spacing --- src/coreclr/jit/gentree.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index 5f07233e86f28c..50adf99687d371 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -15616,10 +15616,10 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree) { f1 = (float)lval1; } -#else // !TARGET_64BIT - // 32-bit currently does a 2-step conversion, which is incorrect - // but which we are going to take a breaking change around early - // in a release cycle. +#else + // 32-bit currently does a 2-step conversion, which is incorrect + // but which we are going to take a breaking change around early + // in a release cycle. if (tree->IsUnsigned() && (lval1 < 0)) { @@ -15629,7 +15629,7 @@ GenTree* Compiler::gtFoldExprConst(GenTree* tree) { f1 = forceCastToFloat((double)lval1); } -#endif // !TARGET_64BIT +#endif d1 = f1; goto CNS_DOUBLE; From d4d0299c21d168d2cdae478804d88aa4398f93db Mon Sep 17 00:00:00 2001 From: "Aman Khalid (from Dev Box)" Date: Wed, 14 Aug 2024 16:33:42 -0400 Subject: [PATCH 04/13] Fix test --- .../JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs index 51219374e2c1e5..700ff10e2d3df8 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs @@ -8,6 +8,7 @@ // Debug: Outputs 1600094603 // Release: Outputs 1600094604 using System; +using Xunit; public class Runtime_106338 { From 22d413f03a0cc9aea263c2a614ca41e81cddfacd Mon Sep 17 00:00:00 2001 From: "Aman Khalid (from Dev Box)" Date: Wed, 14 Aug 2024 16:35:35 -0400 Subject: [PATCH 05/13] Fix test --- .../JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs index 700ff10e2d3df8..743edc319ba80e 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs @@ -17,6 +17,6 @@ public static void TestEntryPoint() { ulong vr10 = 16105307123914158031UL; float vr11 = 4294967295U | vr10; - Assert.Equal(BitConverter.SingleToUInt32Bits(vr11), 1600094603); + Assert.Equal(BitConverter.SingleToUInt32Bits(vr11), 1600094603U); } } \ No newline at end of file From 7e42985515dbd2738057a5aba60dc1e7fee0667c Mon Sep 17 00:00:00 2001 From: "Aman Khalid (from Dev Box)" Date: Wed, 14 Aug 2024 16:54:40 -0400 Subject: [PATCH 06/13] Flip params --- .../JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs index 743edc319ba80e..d767dcd690b556 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs @@ -17,6 +17,6 @@ public static void TestEntryPoint() { ulong vr10 = 16105307123914158031UL; float vr11 = 4294967295U | vr10; - Assert.Equal(BitConverter.SingleToUInt32Bits(vr11), 1600094603U); + Assert.Equal(1600094603U, BitConverter.SingleToUInt32Bits(vr11)); } } \ No newline at end of file From b630fd2b88b3ec4f9b1f3d3c2b613d1716a98da9 Mon Sep 17 00:00:00 2001 From: "Aman Khalid (from Dev Box)" Date: Wed, 14 Aug 2024 18:18:05 -0400 Subject: [PATCH 07/13] Run test on CoreCLR only --- .../JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.csproj index 0393f77dbcc14d..806e0dd00c5d8d 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.csproj +++ b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.csproj @@ -1,7 +1,7 @@ True - true + true From e8a8246ea0e1a22c4ff44b8d913f87460ff5af6e Mon Sep 17 00:00:00 2001 From: "Aman Khalid (from Dev Box)" Date: Wed, 14 Aug 2024 18:45:09 -0400 Subject: [PATCH 08/13] Add RequiresProcessIsolation --- .../JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.csproj | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.csproj index 806e0dd00c5d8d..0d10a9e0fd681c 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.csproj +++ b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.csproj @@ -1,6 +1,8 @@ True + + true true From ad3fb3bdb4f27579438773a0d85cd6cca8bab315 Mon Sep 17 00:00:00 2001 From: "Aman Khalid (from Dev Box)" Date: Thu, 15 Aug 2024 15:13:15 -0400 Subject: [PATCH 09/13] Do single-step conversion on all platforms --- src/coreclr/jit/utils.cpp | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/coreclr/jit/utils.cpp b/src/coreclr/jit/utils.cpp index 06fec7951e1b44..cbee0be0158183 100644 --- a/src/coreclr/jit/utils.cpp +++ b/src/coreclr/jit/utils.cpp @@ -2272,13 +2272,7 @@ double FloatingPointUtils::convertUInt64ToDouble(uint64_t uIntVal) float FloatingPointUtils::convertUInt64ToFloat(uint64_t u64) { -#ifdef TARGET_ARM64 - // ARM64 supports casting directly to float return (float)u64; -#else // !TARGET_ARM64 - double d = convertUInt64ToDouble(u64); - return (float)d; -#endif // !TARGET_ARM64 } uint64_t FloatingPointUtils::convertDoubleToUInt64(double d) From b49d75ab4319561bacd5e6a37b177d65b8e8b0d1 Mon Sep 17 00:00:00 2001 From: "Aman Khalid (from Dev Box)" Date: Mon, 19 Aug 2024 15:27:44 -0400 Subject: [PATCH 10/13] Expand test coverage --- .../JitBlue/Runtime_106338/Runtime_106338.cs | 13 ++++++++++--- .../JitBlue/Runtime_106338/Runtime_106338.csproj | 3 ++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs index d767dcd690b556..e7139c462ed84f 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs @@ -8,6 +8,8 @@ // Debug: Outputs 1600094603 // Release: Outputs 1600094604 using System; +using System.Runtime.InteropServices; +using System.Runtime.Intrinsics.X86; using Xunit; public class Runtime_106338 @@ -15,8 +17,13 @@ public class Runtime_106338 [Fact] public static void TestEntryPoint() { - ulong vr10 = 16105307123914158031UL; - float vr11 = 4294967295U | vr10; - Assert.Equal(1600094603U, BitConverter.SingleToUInt32Bits(vr11)); + bool runTest = (RuntimeInformation.ProcessArchitecture == Architecture.Arm64) || Avx512F.IsSupported; + + if (runTest) + { + ulong vr10 = 16105307123914158031UL; + float vr11 = 4294967295U | vr10; + Assert.Equal(1600094603U, BitConverter.SingleToUInt32Bits(vr11)); + } } } \ No newline at end of file diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.csproj index 0d10a9e0fd681c..e03a0fcd667efd 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.csproj +++ b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.csproj @@ -3,7 +3,8 @@ True true - true + true + true From 92d96498b2d327cc5cd01007bfc087e8940d3da1 Mon Sep 17 00:00:00 2001 From: "Aman Khalid (from Dev Box)" Date: Mon, 19 Aug 2024 15:52:32 -0400 Subject: [PATCH 11/13] Update test --- .../JitBlue/Runtime_106338/Runtime_106338.cs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs index e7139c462ed84f..e6a8f150c8305a 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs @@ -17,13 +17,19 @@ public class Runtime_106338 [Fact] public static void TestEntryPoint() { - bool runTest = (RuntimeInformation.ProcessArchitecture == Architecture.Arm64) || Avx512F.IsSupported; + ulong vr10 = 16105307123914158031UL; + float vr11 = 4294967295U | vr10; + uint result = BitConverter.SingleToUInt32Bits(vr11); - if (runTest) + if ((RuntimeInformation.ProcessArchitecture == Architecture.Arm64) || Avx512F.IsSupported) { - ulong vr10 = 16105307123914158031UL; - float vr11 = 4294967295U | vr10; - Assert.Equal(1600094603U, BitConverter.SingleToUInt32Bits(vr11)); + // Expected to cast ulong -> float directly + Assert.Equal(1600094603U, result); + } + else + { + // Expected to cast ulong -> double -> float + Assert.Equal(1600094604U, result); } } } \ No newline at end of file From 8460d2f6ada311b29852f4894b9777fa6070e797 Mon Sep 17 00:00:00 2001 From: "Aman Khalid (from Dev Box)" Date: Tue, 20 Aug 2024 11:07:53 -0400 Subject: [PATCH 12/13] Try running test on all CoreCLR platforms --- .../JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs | 1 + .../Regression/JitBlue/Runtime_106338/Runtime_106338.csproj | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs index e6a8f150c8305a..93fd00b8124176 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs @@ -15,6 +15,7 @@ public class Runtime_106338 { [Fact] + [SkipOnMono("https://github.com/dotnet/runtime/issues/100368", TestPlatforms.Any)] public static void TestEntryPoint() { ulong vr10 = 16105307123914158031UL; diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.csproj index e03a0fcd667efd..de6d5e08882e86 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.csproj +++ b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.csproj @@ -1,10 +1,6 @@ True - - true - true - true From a5b3894074851329807b577603b8c8b61f342622 Mon Sep 17 00:00:00 2001 From: "Aman Khalid (from Dev Box)" Date: Tue, 20 Aug 2024 12:57:09 -0400 Subject: [PATCH 13/13] Fix condition --- .../JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs index 93fd00b8124176..5cc1b75d42fda1 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_106338/Runtime_106338.cs @@ -22,7 +22,7 @@ public static void TestEntryPoint() float vr11 = 4294967295U | vr10; uint result = BitConverter.SingleToUInt32Bits(vr11); - if ((RuntimeInformation.ProcessArchitecture == Architecture.Arm64) || Avx512F.IsSupported) + if ((RuntimeInformation.ProcessArchitecture == Architecture.Arm64) || ((RuntimeInformation.ProcessArchitecture == Architecture.X64) && Avx512F.IsSupported)) { // Expected to cast ulong -> float directly Assert.Equal(1600094603U, result);