diff --git a/src/coreclr/jit/rangecheck.cpp b/src/coreclr/jit/rangecheck.cpp index 8c2b6a170a1f5f..5bac19f82f8978 100644 --- a/src/coreclr/jit/rangecheck.cpp +++ b/src/coreclr/jit/rangecheck.cpp @@ -1930,9 +1930,7 @@ Range RangeCheck::GetRangeFromType(var_types type) } // Compute the range for a local var definition. -Range RangeCheck::ComputeRangeForLocalDef(BasicBlock* block, - GenTreeLclVarCommon* lcl, - bool monIncreasing DEBUGARG(int indent)) +Range RangeCheck::ComputeRangeForLocalDef(GenTreeLclVarCommon* lcl, bool monIncreasing DEBUGARG(int indent)) { LclSsaVarDsc* ssaDef = GetSsaDefStore(lcl); if (ssaDef == nullptr) @@ -1947,17 +1945,7 @@ Range RangeCheck::ComputeRangeForLocalDef(BasicBlock* block, JITDUMP("----------------------------------------------------\n"); } #endif - Range range = GetRangeWorker(ssaDef->GetBlock(), ssaDef->GetDefNode()->Data(), monIncreasing DEBUGARG(indent)); - if (!BitVecOps::MayBeUninit(block->bbAssertionIn) && (m_compiler->GetAssertionCount() > 0)) - { - JITDUMP("Merge assertions from " FMT_BB ": ", block->bbNum); - Compiler::optDumpAssertionIndices(block->bbAssertionIn, " "); - JITDUMP("for definition [%06d]\n", Compiler::dspTreeID(ssaDef->GetDefNode())) - - MergeEdgeAssertions(ssaDef->GetDefNode(), block->bbAssertionIn, &range); - JITDUMP("done merging\n"); - } - return range; + return GetRangeWorker(ssaDef->GetBlock(), ssaDef->GetDefNode()->Data(), monIncreasing DEBUGARG(indent)); } // Get the limit's maximum possible value. @@ -2320,7 +2308,8 @@ Range RangeCheck::ComputeRange(BasicBlock* block, GenTree* expr, bool monIncreas // If local, find the definition from the def map and evaluate the range for rhs. else if (expr->IsLocal()) { - range = ComputeRangeForLocalDef(block, expr->AsLclVarCommon(), monIncreasing DEBUGARG(indent + 1)); + range = ComputeRangeForLocalDef(expr->AsLclVarCommon(), monIncreasing DEBUGARG(indent + 1)); + // Phi arguments need edge assertions, not the assertions of a block that jump threading may have bypassed. MergeAssertion(block, expr, &range DEBUGARG(indent + 1)); } // compute the range for binary operation diff --git a/src/coreclr/jit/rangecheck.h b/src/coreclr/jit/rangecheck.h index 74c4df51e2ea1c..64c38ac7b687b9 100644 --- a/src/coreclr/jit/rangecheck.h +++ b/src/coreclr/jit/rangecheck.h @@ -882,7 +882,7 @@ class RangeCheck // Given the local variable, first find the definition of the local and find the range of the rhs. // Helper for GetRangeWorker. - Range ComputeRangeForLocalDef(BasicBlock* block, GenTreeLclVarCommon* lcl, bool monIncreasing DEBUGARG(int indent)); + Range ComputeRangeForLocalDef(GenTreeLclVarCommon* lcl, bool monIncreasing DEBUGARG(int indent)); // Compute the range, rather than retrieve a cached value. Helper for GetRangeWorker. Range ComputeRange(BasicBlock* block, GenTree* expr, bool monIncreasing DEBUGARG(int indent)); diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_133267/Runtime_133267.cs b/src/tests/JIT/Regression/JitBlue/Runtime_133267/Runtime_133267.cs new file mode 100644 index 00000000000000..cafddb9c3dd323 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_133267/Runtime_133267.cs @@ -0,0 +1,32 @@ +// 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.Runtime.CompilerServices; +using Xunit; + +public class Runtime_133267 +{ + [Fact] + public static void TestEntryPoint() + { + Assert.Equal(4, Test(new object[4], [1, 1, 1, 1])); + } + + [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] + private static int Test(object[] key, int[] fields) + { + int c = key != null ? key.Length : 0; + if (key is null || c <= 0 || fields.Length != c) + { + throw new ArgumentException(); + } + + int sum = 0; + for (int i = 0; i < key.Length; i++) + { + sum += fields[i]; + } + return sum; + } +} diff --git a/src/tests/JIT/Regression/Regression_ro_2.csproj b/src/tests/JIT/Regression/Regression_ro_2.csproj index 24f82122800d0c..f92ea74829ffbd 100644 --- a/src/tests/JIT/Regression/Regression_ro_2.csproj +++ b/src/tests/JIT/Regression/Regression_ro_2.csproj @@ -66,6 +66,7 @@ +