diff --git a/src/coreclr/jit/rationalize.cpp b/src/coreclr/jit/rationalize.cpp index 404759497a3c38..0f64c90e3bb63d 100644 --- a/src/coreclr/jit/rationalize.cpp +++ b/src/coreclr/jit/rationalize.cpp @@ -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; @@ -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()); diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_70466/Runtime_70466.cs b/src/tests/JIT/Regression/JitBlue/Runtime_70466/Runtime_70466.cs new file mode 100644 index 00000000000000..d4a5b9d3014922 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_70466/Runtime_70466.cs @@ -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 arg) { } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static void JitUse(T arg) { } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_70466/Runtime_70466.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_70466/Runtime_70466.csproj new file mode 100644 index 00000000000000..f492aeac9d056b --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_70466/Runtime_70466.csproj @@ -0,0 +1,9 @@ + + + Exe + True + + + + + \ No newline at end of file