Skip to content

Commit

Permalink
Fix arm64 scalar intrinsic use with small arguments (#73876)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
BruceForstall authored Aug 13, 2022
1 parent a037f0c commit 3478472
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

#include "emit.h"

// Forward declaration
template <class T>
inline var_types genActualType(T value);

#include "hwintrinsic.h"
#include "simd.h"
#include "simdashwintrinsic.h"
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/jit/hwintrinsic.h
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,11 @@ struct HWIntrinsic final
{
baseType = node->TypeGet();
}

if (category == HW_Category_Scalar)
{
baseType = genActualType(baseType);
}
}
}
};
Expand Down
29 changes: 29 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_73804/Runtime_73804.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Optimize>True</Optimize>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>

0 comments on commit 3478472

Please sign in to comment.