From 2a522f87ced687db53ba4f815471f10cb9cf2075 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Tue, 26 Sep 2023 20:44:43 +0200 Subject: [PATCH 1/9] Fix containment --- src/coreclr/jit/lowerxarch.cpp | 3 +- .../JitBlue/Runtime_90508/Runtime_90508.cs | 39 +++++++++++++++++++ .../Runtime_90508/Runtime_90508.csproj | 8 ++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.csproj diff --git a/src/coreclr/jit/lowerxarch.cpp b/src/coreclr/jit/lowerxarch.cpp index 866cd170dd2356..0c332ca4dd0cc9 100644 --- a/src/coreclr/jit/lowerxarch.cpp +++ b/src/coreclr/jit/lowerxarch.cpp @@ -7656,7 +7656,8 @@ bool Lowering::IsContainableHWIntrinsicOp(GenTreeHWIntrinsic* parentNode, GenTre const unsigned expectedSize = genTypeSize(parentNode->TypeGet()) / 2; const unsigned operandSize = genTypeSize(childNode->TypeGet()); - supportsGeneralLoads = supportsUnalignedSIMDLoads && (operandSize >= expectedSize); + supportsGeneralLoads = (childNode->OperIsConst() || childNode->OperIs(GT_IND)) && + supportsUnalignedSIMDLoads && (operandSize >= expectedSize); break; } diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.cs b/src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.cs new file mode 100644 index 00000000000000..0cf4231ec09337 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.cs @@ -0,0 +1,39 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.CompilerServices; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; +using Xunit; + +public class Runtime_90508 +{ + [MethodImpl(MethodImplOptions.NoInlining)] + private static Vector128 Div1(Vector128 v, double b) => + v + Sse3.MoveAndDuplicate(Vector128.CreateScalarUnsafe(b)); + + [MethodImpl(MethodImplOptions.NoInlining)] + private static Vector128 Div2(Vector128 v, double b) => + v + Sse3.MoveAndDuplicate(Vector128.CreateScalarUnsafe(1.0)); + + [MethodImpl(MethodImplOptions.NoInlining)] + private static Vector128 Div3(Vector128 v, double b) => + v + Sse3.MoveAndDuplicate(Vector128.Create(1.0)); + + [Fact] + public static int TestEntryPoint() + { + if (!Ssse3.IsSupported) + { + return 100; + } + + if (Div1(Vector128.Create(42.0), 1).ToString().Equals("<43, 43>") && + Div2(Vector128.Create(42.0), 1).ToString().Equals("<43, 43>") && + Div3(Vector128.Create(42.0), 1).ToString().Equals("<43, 43>")) + { + return 100; + } + return 101; + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.csproj new file mode 100644 index 00000000000000..15edd99711a1a4 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.csproj @@ -0,0 +1,8 @@ + + + True + + + + + \ No newline at end of file From 64e5573ca589f7b3451e0d1747c221ab394ad188 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Tue, 26 Sep 2023 20:48:05 +0200 Subject: [PATCH 2/9] Fix naming --- .../JitBlue/Runtime_90508/Runtime_90508.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.cs b/src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.cs index 0cf4231ec09337..527ddd52801d7d 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.cs @@ -9,15 +9,15 @@ public class Runtime_90508 { [MethodImpl(MethodImplOptions.NoInlining)] - private static Vector128 Div1(Vector128 v, double b) => + private static Vector128 Test1(Vector128 v, double b) => v + Sse3.MoveAndDuplicate(Vector128.CreateScalarUnsafe(b)); [MethodImpl(MethodImplOptions.NoInlining)] - private static Vector128 Div2(Vector128 v, double b) => + private static Vector128 Test2(Vector128 v, double b) => v + Sse3.MoveAndDuplicate(Vector128.CreateScalarUnsafe(1.0)); [MethodImpl(MethodImplOptions.NoInlining)] - private static Vector128 Div3(Vector128 v, double b) => + private static Vector128 Test3(Vector128 v, double b) => v + Sse3.MoveAndDuplicate(Vector128.Create(1.0)); [Fact] @@ -28,9 +28,9 @@ public static int TestEntryPoint() return 100; } - if (Div1(Vector128.Create(42.0), 1).ToString().Equals("<43, 43>") && - Div2(Vector128.Create(42.0), 1).ToString().Equals("<43, 43>") && - Div3(Vector128.Create(42.0), 1).ToString().Equals("<43, 43>")) + if (Test1(Vector128.Create(42.0), 1).ToString().Equals("<43, 43>") && + Test2(Vector128.Create(42.0), 1).ToString().Equals("<43, 43>") && + Test3(Vector128.Create(42.0), 1).ToString().Equals("<43, 43>")) { return 100; } From c9a011c98ddb7591667d7fcb3a5e6382c8919ba8 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Tue, 26 Sep 2023 20:48:37 +0200 Subject: [PATCH 3/9] Update src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.cs Co-authored-by: Bruce Forstall --- src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.cs b/src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.cs index 527ddd52801d7d..56ba6f46285fbc 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.cs @@ -23,7 +23,7 @@ private static Vector128 Test3(Vector128 v, double b) => [Fact] public static int TestEntryPoint() { - if (!Ssse3.IsSupported) + if (!Sse3.IsSupported) { return 100; } From d479fdf488d4a7f76ed53b23e502b40f7b11d591 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 2 Oct 2023 17:42:04 +0200 Subject: [PATCH 4/9] better fix --- src/coreclr/jit/lowerxarch.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/coreclr/jit/lowerxarch.cpp b/src/coreclr/jit/lowerxarch.cpp index 0c332ca4dd0cc9..c188e531472eb0 100644 --- a/src/coreclr/jit/lowerxarch.cpp +++ b/src/coreclr/jit/lowerxarch.cpp @@ -7656,8 +7656,10 @@ bool Lowering::IsContainableHWIntrinsicOp(GenTreeHWIntrinsic* parentNode, GenTre const unsigned expectedSize = genTypeSize(parentNode->TypeGet()) / 2; const unsigned operandSize = genTypeSize(childNode->TypeGet()); - supportsGeneralLoads = (childNode->OperIsConst() || childNode->OperIs(GT_IND)) && - supportsUnalignedSIMDLoads && (operandSize >= expectedSize); + // We can only broadcast constants (we expand them in JIT) or memory loads + const bool canBeBroadcasted = childNode->OperIsConst() && childNode->OperIs(GT_IND, GT_LCL_FLD); + supportsGeneralLoads = + canBeBroadcasted && supportsUnalignedSIMDLoads && (operandSize >= expectedSize); break; } From 8c527ee6fe1831a8a7f53943d8a4d55c84c7525d Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 2 Oct 2023 17:45:45 +0200 Subject: [PATCH 5/9] oops, typo --- src/coreclr/jit/lowerxarch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/jit/lowerxarch.cpp b/src/coreclr/jit/lowerxarch.cpp index c188e531472eb0..cfd51f07f9d129 100644 --- a/src/coreclr/jit/lowerxarch.cpp +++ b/src/coreclr/jit/lowerxarch.cpp @@ -7657,7 +7657,7 @@ bool Lowering::IsContainableHWIntrinsicOp(GenTreeHWIntrinsic* parentNode, GenTre const unsigned operandSize = genTypeSize(childNode->TypeGet()); // We can only broadcast constants (we expand them in JIT) or memory loads - const bool canBeBroadcasted = childNode->OperIsConst() && childNode->OperIs(GT_IND, GT_LCL_FLD); + const bool canBeBroadcasted = childNode->OperIsConst() || childNode->OperIs(GT_IND, GT_LCL_FLD); supportsGeneralLoads = canBeBroadcasted && supportsUnalignedSIMDLoads && (operandSize >= expectedSize); break; From 9eb029cebe7056d461df6fe81b0266fc1e35a562 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 2 Oct 2023 17:59:26 +0200 Subject: [PATCH 6/9] clean up --- src/coreclr/jit/lowerxarch.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/coreclr/jit/lowerxarch.cpp b/src/coreclr/jit/lowerxarch.cpp index cfd51f07f9d129..c78406298c6689 100644 --- a/src/coreclr/jit/lowerxarch.cpp +++ b/src/coreclr/jit/lowerxarch.cpp @@ -7656,10 +7656,12 @@ bool Lowering::IsContainableHWIntrinsicOp(GenTreeHWIntrinsic* parentNode, GenTre const unsigned expectedSize = genTypeSize(parentNode->TypeGet()) / 2; const unsigned operandSize = genTypeSize(childNode->TypeGet()); - // We can only broadcast constants (we expand them in JIT) or memory loads - const bool canBeBroadcasted = childNode->OperIsConst() || childNode->OperIs(GT_IND, GT_LCL_FLD); + comp->gtDispTree(parentNode); + + // For broadcasts we can only optimize constants and memory operands + const bool broadcastIsContainable = childNode->OperIsConst() || childNode->isMemoryOp(); supportsGeneralLoads = - canBeBroadcasted && supportsUnalignedSIMDLoads && (operandSize >= expectedSize); + broadcastIsContainable && supportsUnalignedSIMDLoads && (operandSize >= expectedSize); break; } From 7a4a489f01e9e4287e4685f6e288b3e4a84f8c41 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Mon, 2 Oct 2023 21:48:20 +0200 Subject: [PATCH 7/9] Update lowerxarch.cpp --- src/coreclr/jit/lowerxarch.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/coreclr/jit/lowerxarch.cpp b/src/coreclr/jit/lowerxarch.cpp index c78406298c6689..8372fd0959be10 100644 --- a/src/coreclr/jit/lowerxarch.cpp +++ b/src/coreclr/jit/lowerxarch.cpp @@ -7656,8 +7656,6 @@ bool Lowering::IsContainableHWIntrinsicOp(GenTreeHWIntrinsic* parentNode, GenTre const unsigned expectedSize = genTypeSize(parentNode->TypeGet()) / 2; const unsigned operandSize = genTypeSize(childNode->TypeGet()); - comp->gtDispTree(parentNode); - // For broadcasts we can only optimize constants and memory operands const bool broadcastIsContainable = childNode->OperIsConst() || childNode->isMemoryOp(); supportsGeneralLoads = From 142e765afacdf88bc2d80983842923530b5f9fd2 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Wed, 4 Oct 2023 02:50:44 +0200 Subject: [PATCH 8/9] Update Runtime_90508.cs --- .../JitBlue/Runtime_90508/Runtime_90508.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.cs b/src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.cs index 56ba6f46285fbc..8caf9000d7715d 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.cs @@ -9,15 +9,15 @@ public class Runtime_90508 { [MethodImpl(MethodImplOptions.NoInlining)] - private static Vector128 Test1(Vector128 v, double b) => + private static Vector128 Test1(Vector128 v) => v + Sse3.MoveAndDuplicate(Vector128.CreateScalarUnsafe(b)); [MethodImpl(MethodImplOptions.NoInlining)] - private static Vector128 Test2(Vector128 v, double b) => + private static Vector128 Test2(Vector128 v) => v + Sse3.MoveAndDuplicate(Vector128.CreateScalarUnsafe(1.0)); [MethodImpl(MethodImplOptions.NoInlining)] - private static Vector128 Test3(Vector128 v, double b) => + private static Vector128 Test3(Vector128 v) => v + Sse3.MoveAndDuplicate(Vector128.Create(1.0)); [Fact] @@ -28,9 +28,9 @@ public static int TestEntryPoint() return 100; } - if (Test1(Vector128.Create(42.0), 1).ToString().Equals("<43, 43>") && - Test2(Vector128.Create(42.0), 1).ToString().Equals("<43, 43>") && - Test3(Vector128.Create(42.0), 1).ToString().Equals("<43, 43>")) + if (Test1(Vector128.Create(42.0)).ToString().Equals("<43, 43>") && + Test2(Vector128.Create(42.0)).ToString().Equals("<43, 43>") && + Test3(Vector128.Create(42.0)).ToString().Equals("<43, 43>")) { return 100; } From fa4c5d8daad2c74a51612a8c8ea39a26d95d8253 Mon Sep 17 00:00:00 2001 From: Egor Bogatov Date: Wed, 4 Oct 2023 03:47:13 +0200 Subject: [PATCH 9/9] Update Runtime_90508.cs --- .../JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.cs b/src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.cs index 8caf9000d7715d..ce2881a9d67185 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_90508/Runtime_90508.cs @@ -9,7 +9,7 @@ public class Runtime_90508 { [MethodImpl(MethodImplOptions.NoInlining)] - private static Vector128 Test1(Vector128 v) => + private static Vector128 Test1(Vector128 v, double b) => v + Sse3.MoveAndDuplicate(Vector128.CreateScalarUnsafe(b)); [MethodImpl(MethodImplOptions.NoInlining)] @@ -28,7 +28,7 @@ public static int TestEntryPoint() return 100; } - if (Test1(Vector128.Create(42.0)).ToString().Equals("<43, 43>") && + if (Test1(Vector128.Create(42.0), 1).ToString().Equals("<43, 43>") && Test2(Vector128.Create(42.0)).ToString().Equals("<43, 43>") && Test3(Vector128.Create(42.0)).ToString().Equals("<43, 43>")) {