From 8cffe244c015564a90393862dfba1a8063a5d7f5 Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Mon, 29 Jul 2024 14:48:42 -0700 Subject: [PATCH 1/2] Ensure that embedded broadcast is correctly checking for EVEX support before use --- src/coreclr/jit/lowerxarch.cpp | 2 +- .../JitBlue/Runtime_96156/Runtime_96156.cs | 31 +++++++++++++++++++ .../Runtime_96156/Runtime_96156.csproj | 13 ++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_96156/Runtime_96156.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_96156/Runtime_96156.csproj diff --git a/src/coreclr/jit/lowerxarch.cpp b/src/coreclr/jit/lowerxarch.cpp index dad1df9ffcfb76..8f3150e7e7b18e 100644 --- a/src/coreclr/jit/lowerxarch.cpp +++ b/src/coreclr/jit/lowerxarch.cpp @@ -8292,7 +8292,7 @@ bool Lowering::IsContainableHWIntrinsicOp(GenTreeHWIntrinsic* parentNode, GenTre return false; } - return parentNode->OperIsEmbBroadcastCompatible(); + return parentNode->OperIsEmbBroadcastCompatible() && comp->canUseEvexEncoding(); } default: diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_96156/Runtime_96156.cs b/src/tests/JIT/Regression/JitBlue/Runtime_96156/Runtime_96156.cs new file mode 100644 index 00000000000000..0ece5b261a171c --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_96156/Runtime_96156.cs @@ -0,0 +1,31 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using System.Runtime.Intrinsics; +using System.Runtime.Intrinsics.X86; +using System.Runtime.CompilerServices; +using Xunit; + +public class Runtime_96156 +{ + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private unsafe static Vector128 BroadcastScalarToVector128(float value) + { + return Avx.BroadcastScalarToVector128(&value); + } + + [Fact] + public static void TestEntryPoint() + { + Vector128 c = Vector128.Create(1.0f); + Vector128 r = Problem(2.0f, 0.5f, c); + Assert.Equal(Vector128.Create(4.0f), r); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static Vector128 Problem(float a, float b, Vector128 c) + { + return Avx.Multiply(c, BroadcastScalarToVector128(a / b)); + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_96156/Runtime_96156.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_96156/Runtime_96156.csproj new file mode 100644 index 00000000000000..37d1a42b02dbe1 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_96156/Runtime_96156.csproj @@ -0,0 +1,13 @@ + + + True + True + + + + + + + + + From c0ce03f8b3d0a0b1e92c6817b98654fe6cee0b56 Mon Sep 17 00:00:00 2001 From: Tanner Gooding Date: Mon, 29 Jul 2024 16:51:47 -0700 Subject: [PATCH 2/2] Only run the test if Avx is supported --- .../Regression/JitBlue/Runtime_96156/Runtime_96156.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_96156/Runtime_96156.cs b/src/tests/JIT/Regression/JitBlue/Runtime_96156/Runtime_96156.cs index 0ece5b261a171c..15fe1b0f93842b 100644 --- a/src/tests/JIT/Regression/JitBlue/Runtime_96156/Runtime_96156.cs +++ b/src/tests/JIT/Regression/JitBlue/Runtime_96156/Runtime_96156.cs @@ -18,9 +18,12 @@ private unsafe static Vector128 BroadcastScalarToVector128(float value) [Fact] public static void TestEntryPoint() { - Vector128 c = Vector128.Create(1.0f); - Vector128 r = Problem(2.0f, 0.5f, c); - Assert.Equal(Vector128.Create(4.0f), r); + if (Avx.IsSupported) + { + Vector128 c = Vector128.Create(1.0f); + Vector128 r = Problem(2.0f, 0.5f, c); + Assert.Equal(Vector128.Create(4.0f), r); + } } [MethodImpl(MethodImplOptions.NoInlining)]