Skip to content
Merged
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
15 changes: 5 additions & 10 deletions src/coreclr/jit/rationalize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -556,13 +556,6 @@ Compiler::fgWalkResult Rationalizer::RewriteNode(GenTree** useEdge, Compiler::Ge
RewriteAssignment(use);
break;

case GT_BOX:
case GT_ARR_ADDR:
// BOX/ARR_ADDR at this level are just NOPs.
use.ReplaceWith(node->gtGetOp1());
BlockRange().Remove(node);
break;

case GT_ADDR:
RewriteAddress(use);
break;
Expand Down Expand Up @@ -594,9 +587,11 @@ Compiler::fgWalkResult Rationalizer::RewriteNode(GenTree** useEdge, Compiler::Ge
break;

case GT_NOP:
// fgMorph sometimes inserts NOP nodes between defs and uses
// supposedly 'to prevent constant folding'. In this case, remove the
// NOP.
case GT_BOX:
case GT_ARR_ADDR:
// "optNarrowTree" sometimes inserts NOP nodes between defs and uses.
// In this case, remove the NOP. BOX/ARR_ADDR are such "passthrough"
// nodes by design, and at this point we no longer need them.
if (node->gtGetOp1() != nullptr)
{
use.ReplaceWith(node->gtGetOp1());
Expand Down
38 changes: 38 additions & 0 deletions src/tests/JIT/Regression/JitBlue/Runtime_70466/Runtime_70466.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// 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.CompilerServices;

public class Runtime_70466
{
public static int Main()
{
Problem(1, 0);
return 100;
}

// This method is carefully crafted such that we end up with an unused ARR_ADDR node by rationalization
// time, of which the child operand will need to be explicitly marked "unused value" for LIR purposes.
//
[MethodImpl(MethodImplOptions.NoInlining)]
private static void Problem(byte b, int idx)
{
var a = new byte[] { b };
var a1 = new byte[] { b, b };
var a2 = new byte[] { b, b, b };

if (idx == 0)
{
if (a[idx] == 1)
{
Use(1);
}
JitUse(a1[idx] + a2[idx]);
}
}

public static void Use<T>(T arg) { }

[MethodImpl(MethodImplOptions.NoInlining)]
public static void JitUse<T>(T arg) { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
</Project>