Skip to content

Commit

Permalink
JIT: Determine which ARM64 HWIntrinsics will throw ArgumentOufOfRange…
Browse files Browse the repository at this point in the history
…Exceptions (#105527)
  • Loading branch information
TIHan authored Jul 28, 2024
1 parent 8d54d66 commit f832e66
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 2 deletions.
13 changes: 12 additions & 1 deletion src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7201,6 +7201,8 @@ ExceptionSetFlags GenTree::OperExceptions(Compiler* comp)
#ifdef FEATURE_HW_INTRINSICS
case GT_HWINTRINSIC:
{
assert((gtFlags & GTF_HW_USER_CALL) == 0);

GenTreeHWIntrinsic* hwIntrinsicNode = this->AsHWIntrinsic();

if (hwIntrinsicNode->OperIsMemoryLoadOrStore())
Expand Down Expand Up @@ -7239,6 +7241,15 @@ bool GenTree::OperMayThrow(Compiler* comp)
helper = comp->eeGetHelperNum(this->AsCall()->gtCallMethHnd);
return ((helper == CORINFO_HELP_UNDEF) || !comp->s_helperCallProperties.NoThrow(helper));
}
#ifdef FEATURE_HW_INTRINSICS
else if (OperIsHWIntrinsic())
{
if ((gtFlags & GTF_HW_USER_CALL) != 0)
{
return true;
}
}
#endif // FEATURE_HW_INTRINSICS

return OperExceptions(comp) != ExceptionSetFlags::None;
}
Expand Down Expand Up @@ -20118,7 +20129,7 @@ void GenTreeJitIntrinsic::SetMethodHandle(Compiler* com
CORINFO_METHOD_HANDLE methodHandle R2RARG(CORINFO_CONST_LOOKUP entryPoint))
{
assert(OperIsHWIntrinsic() && !IsUserCall());
gtFlags |= GTF_HW_USER_CALL;
gtFlags |= (GTF_HW_USER_CALL | GTF_EXCEPT | GTF_CALL);

size_t operandCount = GetOperandCount();

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/rationalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ void Rationalizer::RewriteHWIntrinsicAsUserCall(GenTree** use, ArrayStack<GenTre
immUpperBound, hasFullRangeImm, &useFallback))
{
// We're already in the right shape, so just stop tracking ourselves as a user call
hwintrinsic->gtFlags &= ~GTF_HW_USER_CALL;
hwintrinsic->gtFlags &= ~(GTF_HW_USER_CALL | GTF_EXCEPT | GTF_CALL);
return;
}
}
Expand Down
44 changes: 44 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_105474/Runtime_105474.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// 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;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.Arm;
using System.Runtime.Intrinsics.X86;
using Xunit;

#nullable disable

public class Runtime_105474_A
{
private void Method0()
{
Vector128<ulong> vr0 = Vector128.CreateScalar(1698800584428641629UL);
AdvSimd.ShiftLeftLogicalSaturate(vr0, 229);
}

private void Method1()
{
Vector128<float> vr1 = default;
Avx.Compare(vr1, vr1, (FloatComparisonMode)255);
}

[Fact]
public static void TestEntryPointArm()
{
if (AdvSimd.IsSupported)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new Runtime_105474_A().Method0());
}
}

[Fact]
public static void TestEntryPoint()
{
if (Avx.IsSupported)
{
Assert.Throws<ArgumentOutOfRangeException>(() => new Runtime_105474_A().Method1());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>

0 comments on commit f832e66

Please sign in to comment.