Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
35 changes: 22 additions & 13 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11434,6 +11434,28 @@ void Lowering::LowerStoreCoalescing(GenTree* node)

assert(newType != TYP_UNDEF);

// Validate the constants before removing the previous store or widening the current one.
uint64_t lowerCns = 0;
uint64_t upperCns = 0;
#if defined(TARGET_AMD64) && defined(FEATURE_HW_INTRINSICS)

@dhartglassMSFT dhartglassMSFT Sep 18, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably want that "// Only on x64 since..." comment here too, since a TARGET ifdef in the middle of lowering without a comment looks unusual. Change LGTM otherwise

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, will need a new sign-off

// Only on x64 since ARM64 has no options above SIMD16.
if (varTypeIsSIMD(oldType))
{
if (!prevData.value->OperIs(GT_CNS_VEC) || !currData.value->OperIs(GT_CNS_VEC))
{
return;
}
}
else
#endif // TARGET_AMD64 && FEATURE_HW_INTRINSICS
{
if (!TryGetStoreCoalescingConstantBits(prevData.value, &lowerCns) ||
!TryGetStoreCoalescingConstantBits(currData.value, &upperCns))
{
return;
}
}

if (node->OperIs(GT_STOREIND, GT_STORE_BLK))
{
auto* ind = node->AsStoreInd();
Expand Down Expand Up @@ -11487,11 +11509,6 @@ void Lowering::LowerStoreCoalescing(GenTree* node)
// Only on x64 since ARM64 has no options above SIMD16.
if (varTypeIsSIMD(oldType))
{
if (!prevData.value->OperIs(GT_CNS_VEC) || !currData.value->OperIs(GT_CNS_VEC))
{
return;
}

int8_t* lowerCns = prevData.value->AsVecCon()->gtSimdVal.i8;
int8_t* upperCns = currData.value->AsVecCon()->gtSimdVal.i8;

Expand All @@ -11512,14 +11529,6 @@ void Lowering::LowerStoreCoalescing(GenTree* node)

// The integer path below places each constant according to its byte offset, so it doesn't need to swap the
// values first. Only the SIMD packing paths above need to normalize lower/upper order explicitly.
uint64_t lowerCns = 0;
uint64_t upperCns = 0;
if (!TryGetStoreCoalescingConstantBits(prevData.value, &lowerCns) ||
!TryGetStoreCoalescingConstantBits(currData.value, &upperCns))
{
return;
}

#if defined(TARGET_64BIT) && defined(FEATURE_HW_INTRINSICS)
if (varTypeIsSIMD(newType))
{
Expand Down
49 changes: 49 additions & 0 deletions src/tests/JIT/Regression_2/Runtime_133746/Runtime_133746.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.Intrinsics;
using Xunit;

public class Runtime_133746
{
[Fact]
[SkipLocalsInit]
public static void TestEntryPoint()
{
Vector2 pair = new Vector2(1.0f, -2.0f);
Unsafe.As<Vector2, sbyte>(ref pair) = -1;
ValidatePair(in pair);

Validate(Vector64.CreateScalar((sbyte)-1), (sbyte)-1);
Validate(Vector64.CreateScalar(sbyte.MinValue), sbyte.MinValue);
Validate(Vector64.CreateScalar(sbyte.MaxValue), sbyte.MaxValue);
Validate(Vector64.CreateScalar((short)-1), (short)-1);
Validate(Vector64.CreateScalar(short.MinValue), short.MinValue);
Validate(Vector64.CreateScalar(short.MaxValue), short.MaxValue);
Validate(Vector64.CreateScalar(-1), -1);
Validate(Vector64.CreateScalar(int.MinValue), int.MinValue);
Validate(Vector64.CreateScalar(int.MaxValue), int.MaxValue);
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void ValidatePair(in Vector2 value)
{
int expected = BitConverter.IsLittleEndian ? 0x3F8000FF : unchecked((int)0xFF800000);
Assert.Equal(expected, BitConverter.SingleToInt32Bits(value.X));
Assert.Equal(-2.0f, value.Y);
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static void Validate<T>(in Vector64<T> value, T expected) where T : struct
{
Assert.Equal(expected, value.GetElement(0));

for (int i = 1; i < Vector64<T>.Count; i++)
{
Assert.Equal(default(T), value.GetElement(i));
}
}
}
12 changes: 12 additions & 0 deletions src/tests/JIT/Regression_2/Runtime_133746/Runtime_133746.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>True</Optimize>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
<CLRTestPriority>1</CLRTestPriority>
<RequiresProcessIsolation>true</RequiresProcessIsolation>
</PropertyGroup>
<ItemGroup>
<Compile Include="Runtime_133746.cs" />
<CLRTestEnvironmentVariable Include="DOTNET_TieredCompilation" Value="0" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<Project>
<Import Project="Runtime_133746.csproj" />
<ItemGroup>
Comment thread
tannergooding marked this conversation as resolved.
<CLRTestEnvironmentVariable Include="DOTNET_EnableHWIntrinsic" Value="0" />
</ItemGroup>
</Project>
Loading