Skip to content

Commit f981e2a

Browse files
authored
JIT: Skip bitcast transformation for promoted locals (#120435)
The bitcast transformation produces `BITCAST(LCL_VAR)`, but for SIMDs the local can be promoted and this ends up resulting in invalid IR. We would normally go through the `LCL_FLD` path that DNERs the local, so make sure we still do that.
1 parent b38de35 commit f981e2a

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

src/coreclr/jit/lclmorph.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2020,7 +2020,7 @@ class LocalAddressVisitor final : public GenTreeVisitor<LocalAddressVisitor>
20202020
}
20212021

20222022
if ((genTypeSize(indir) == genTypeSize(varDsc)) && (genTypeSize(indir) <= TARGET_POINTER_SIZE) &&
2023-
(varTypeIsFloating(indir) || varTypeIsFloating(varDsc)))
2023+
(varTypeIsFloating(indir) || varTypeIsFloating(varDsc)) && !varDsc->lvPromoted)
20242024
{
20252025
return IndirTransform::BitCast;
20262026
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Numerics;
6+
using System.Runtime.Intrinsics;
7+
using System.Runtime.CompilerServices;
8+
using Xunit;
9+
10+
public class Runtime_120414
11+
{
12+
[MethodImpl(MethodImplOptions.NoInlining)]
13+
private static Vector128<float> DuplicateFromVec2(Vector2 s) =>
14+
Vector128.Create(Unsafe.As<Vector2, double>(ref s)).AsSingle();
15+
16+
[Fact]
17+
public static void TestEntryPoint()
18+
{
19+
Vector2 testVec = new Vector2(1.0f, 0.5f);
20+
Vector128<float> result = DuplicateFromVec2(testVec);
21+
Assert.Equal(1.0f, result[0]);
22+
Assert.Equal(0.5f, result[1]);
23+
Assert.Equal(1.0f, result[2]);
24+
Assert.Equal(0.5f, result[3]);
25+
}
26+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<DebugType>None</DebugType>
4+
<Optimize>True</Optimize>
5+
</PropertyGroup>
6+
<ItemGroup>
7+
<Compile Include="$(MSBuildProjectName).cs" />
8+
</ItemGroup>
9+
</Project>

0 commit comments

Comments
 (0)