Skip to content

Commit

Permalink
Account for HWI stores in LIR side effects code (#65079)
Browse files Browse the repository at this point in the history
* Add a test

* Account for HWI stores in LIR side effect code

Otherwise we risk missing stores to addressable locations.

* Add MEMORYBARRIER to fix the assert

Won't ever matter as memory barriers split statements.
  • Loading branch information
SingleAccretion authored Feb 9, 2022
1 parent 30abc7b commit 99452b2
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/coreclr/jit/sideeffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,18 @@ AliasSet::NodeInfo::NodeInfo(Compiler* compiler, GenTree* node)
isWrite = true;
node = node->gtGetOp1();
}
else if (node->OperIsStore())
else if (node->OperIsStore() || node->OperIs(GT_MEMORYBARRIER))
{
isWrite = true;
}
#ifdef FEATURE_HW_INTRINSICS
else if (node->OperIsHWIntrinsic() && node->AsHWIntrinsic()->OperIsMemoryStore())
{
isWrite = true;
}
#endif // FEATURE_HW_INTRINSICS

assert(isWrite || !node->OperRequiresAsgFlag());

// `node` is the location being accessed. Determine whether or not it is a memory or local variable access, and if
// it is the latter, get the number of the lclVar.
Expand Down
37 changes: 37 additions & 0 deletions src/tests/JIT/HardwareIntrinsics/General/HwiOp/HwiSideEffects.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// 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.Intrinsics.X86;
using System.Runtime.CompilerServices;

// Tests that side effects induced by the HWI nodes are correctly accounted for.

unsafe class HwiSideEffects
{
public static int Main()
{
if (ProblemWithInterferenceChecks(2) != 2)
{
return 101;
}

return 100;
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static uint ProblemWithInterferenceChecks(uint a)
{
uint x;
if (Bmi2.IsSupported)
{
// Make sure we don't try to contain "a" under the "add" here.
x = a + Bmi2.MultiplyNoFlags(a, a, &a);
}
else
{
x = a;
}

return x;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>

0 comments on commit 99452b2

Please sign in to comment.