From 347847265d0832def96a2ff4057029999ffc70b1 Mon Sep 17 00:00:00 2001 From: Bruce Forstall Date: Sat, 13 Aug 2022 14:49:23 -0700 Subject: [PATCH] Fix arm64 scalar intrinsic use with small arguments (#73876) The code already uses `emitActualTypeSize` in the scalar case; this also uses `genActualType` to get the "actual" type of small types when deciding the intrinsic base type, used in codegen. Fixes #73804 --- src/coreclr/jit/compiler.h | 4 +++ src/coreclr/jit/hwintrinsic.h | 5 ++++ .../JitBlue/Runtime_73804/Runtime_73804.cs | 29 +++++++++++++++++++ .../Runtime_73804/Runtime_73804.csproj | 10 +++++++ 4 files changed, 48 insertions(+) create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_73804/Runtime_73804.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_73804/Runtime_73804.csproj diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 806205aded63b..3291aca767c38 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -58,6 +58,10 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX #include "emit.h" +// Forward declaration +template +inline var_types genActualType(T value); + #include "hwintrinsic.h" #include "simd.h" #include "simdashwintrinsic.h" diff --git a/src/coreclr/jit/hwintrinsic.h b/src/coreclr/jit/hwintrinsic.h index 8a82605991e16..88e5b4ae57505 100644 --- a/src/coreclr/jit/hwintrinsic.h +++ b/src/coreclr/jit/hwintrinsic.h @@ -878,6 +878,11 @@ struct HWIntrinsic final { baseType = node->TypeGet(); } + + if (category == HW_Category_Scalar) + { + baseType = genActualType(baseType); + } } } }; diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_73804/Runtime_73804.cs b/src/tests/JIT/Regression/JitBlue/Runtime_73804/Runtime_73804.cs new file mode 100644 index 0000000000000..02dfe5918d732 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_73804/Runtime_73804.cs @@ -0,0 +1,29 @@ +// 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.CompilerServices; + +public unsafe class Runtime_73804 +{ + public static int Main() + { + short value = 0x1000; + int r = Problem(&value); + + return 100 + r - System.Numerics.BitOperations.LeadingZeroCount((uint)value); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static int Problem(short* s) + { + if (System.Runtime.Intrinsics.Arm.ArmBase.IsSupported) + { + return System.Runtime.Intrinsics.Arm.ArmBase.LeadingZeroCount(*s); + } + else + { + return System.Numerics.BitOperations.LeadingZeroCount((uint)*s); + } + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_73804/Runtime_73804.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_73804/Runtime_73804.csproj new file mode 100644 index 0000000000000..cf94135633b19 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_73804/Runtime_73804.csproj @@ -0,0 +1,10 @@ + + + Exe + True + true + + + + + \ No newline at end of file