Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Ensure that embedded broadcast checks the base type of the parent node
  • Loading branch information
tannergooding authored and github-actions committed Sep 22, 2023
commit 51d50285bb560ab0dec541382bdadfb047207303
20 changes: 16 additions & 4 deletions src/coreclr/jit/lowerxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8202,18 +8202,20 @@ bool Lowering::IsContainableHWIntrinsicOp(GenTreeHWIntrinsic* parentNode, GenTre
case NI_AVX2_BroadcastScalarToVector256:
case NI_AVX512F_BroadcastScalarToVector512:
{
var_types baseType = hwintrinsic->GetSimdBaseType();
if (varTypeIsSmall(baseType))
var_types parentBaseType = parentNode->GetSimdBaseType();
var_types childBaseType = hwintrinsic->GetSimdBaseType();

if (varTypeIsSmall(parentBaseType) || varTypeIsSmall(childBaseType))
{
// early return if the base type is not embedded broadcast compatible.
// early return if either base type is not embedded broadcast compatible.
return false;
}

// make the broadcast node containable when embedded broadcast can be enabled.
if (intrinsicId == NI_SSE3_MoveAndDuplicate)
{
// NI_SSE3_MoveAndDuplicate is for Vector128<double> only.
assert(baseType == TYP_DOUBLE);
assert(childBaseType == TYP_DOUBLE);
}

if (comp->compOpportunisticallyDependsOn(InstructionSet_AVX512F_VL) &&
Expand Down Expand Up @@ -8246,6 +8248,16 @@ bool Lowering::IsContainableHWIntrinsicOp(GenTreeHWIntrinsic* parentNode, GenTre
case NI_AVX_BroadcastScalarToVector128:
case NI_AVX_BroadcastScalarToVector256:
{
var_types parentBaseType = parentNode->GetSimdBaseType();
var_types childBaseType = hwintrinsic->GetSimdBaseType();

if (varTypeIsSmall(parentBaseType))
{
// early return if either base type is not embedded broadcast compatible.
return false;
}
assert(!varTypeIsSmall(childBaseType));

return parentNode->OperIsEmbBroadcastCompatible();
}

Expand Down
29 changes: 29 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_92357/Runtime_92357.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;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
using Xunit;

public static class Runtime_92357
{
[Fact]
[MethodImpl(MethodImplOptions.AggressiveOptimization)]
public static void Problem()
{
int y = 5;

Vector256<short> actual = Test(Vector256.Create((short)1), ref y);
Vector256<short> expected = Vector256.Create(10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0, 10, 0);

Assert.Equal(expected, actual);
}

[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)]
public static Vector256<short> Test(Vector256<short> x, ref int y)
{
return Avx2.MultiplyLow(x + x, Vector256.Create(y).AsInt16());
}
}
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>