Skip to content

Commit

Permalink
JIT: Remove GT_CAST handling in Lowering::IsValidConstForMovImm (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
amanasifkhalid authored Aug 8, 2024
1 parent 6e0cc88 commit dbdfabf
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 39 deletions.
41 changes: 2 additions & 39 deletions src/coreclr/jit/lowerarmarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1919,8 +1919,6 @@ GenTree* Lowering::LowerHWIntrinsic(GenTreeHWIntrinsic* node)
// Returns:
// true if the node can be replaced by a mov/fmov immediate instruction; otherwise, false
//
// IMPORTANT:
// This check may end up modifying node->gtOp1 if it is a cast node that can be removed
bool Lowering::IsValidConstForMovImm(GenTreeHWIntrinsic* node)
{
assert((node->GetHWIntrinsicId() == NI_Vector64_Create) || (node->GetHWIntrinsicId() == NI_Vector128_Create) ||
Expand All @@ -1934,51 +1932,16 @@ bool Lowering::IsValidConstForMovImm(GenTreeHWIntrinsic* node)
(node->GetHWIntrinsicId() == NI_AdvSimd_Arm64_DuplicateToVector128));
assert(node->GetOperandCount() == 1);

GenTree* op1 = node->Op(1);
GenTree* castOp = nullptr;

// TODO-Casts: why don't we fold the casts? MinOpts?
if (varTypeIsIntegral(node->GetSimdBaseType()) && op1->OperIs(GT_CAST))
{
// We will sometimes get a cast around a constant value (such as for
// certain long constants) which would block the below containment.
// So we will temporarily check what the cast is from instead so we
// can catch those cases as well.

castOp = op1->AsCast()->CastOp();

if (varTypeIsIntegral(castOp))
{
op1 = castOp;
}
else
{
castOp = nullptr;
}
}
GenTree* const op1 = node->Op(1);

if (op1->IsCnsIntOrI())
{
const ssize_t dataValue = op1->AsIntCon()->gtIconVal;

if (comp->GetEmitter()->emitIns_valid_imm_for_movi(dataValue, emitActualTypeSize(node->GetSimdBaseType())))
{
if (castOp != nullptr)
{
// We found a containable immediate under
// a cast, so remove the cast from the LIR.

BlockRange().Remove(node->Op(1));
node->Op(1) = op1;
}
return true;
}
return comp->GetEmitter()->emitIns_valid_imm_for_movi(dataValue, emitActualTypeSize(node->GetSimdBaseType()));
}
else if (op1->IsCnsFltOrDbl())
{
assert(varTypeIsFloating(node->GetSimdBaseType()));
assert(castOp == nullptr);

const double dataValue = op1->AsDblCon()->DconValue();
return comp->GetEmitter()->emitIns_valid_imm_for_fmov(dataValue);
}
Expand Down
27 changes: 27 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_106020/Runtime_106020.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

// Generated by Fuzzlyn v2.2 on 2024-08-05 19:14:52
// Run on Arm64 MacOS
// Seed: 16897731911671998240-vectort,vector64,vector128,armadvsimd,armadvsimdarm64,armaes,armarmbase,armarmbasearm64,armcrc32,armcrc32arm64,armdp,armrdm,armrdmarm64,armsha1,armsha256
// Reduced from 67.3 KiB to 0.3 KiB in 00:00:23
// Hits JIT assert in Debug:
// Assertion failed '(imm < maxVal) || ((imm & signBitsMask) == signBitsMask)' in 'Program:Main(Fuzzlyn.ExecutionServer.IRuntime)' during 'Generate code' (IL size 16; hash 0xade6b36b; MinOpts)
//
// File: /Users/runner/work/1/s/src/coreclr/jit/emitarm64.cpp Line: 2676
//
using System;
using System.Numerics;
using System.Runtime.Intrinsics;
using Xunit;

public class Runtime_106020
{
[Fact]
public static void Method0()
{
int vr2 = 0;
var result = Vector128.Create<short>((short)((0 * vr2) + 2147483647));
Assert.Equal(result, Vector128.Create<short>(-1));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Optimize>False</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>

0 comments on commit dbdfabf

Please sign in to comment.