diff --git a/src/coreclr/jit/scev.cpp b/src/coreclr/jit/scev.cpp index 4f81d66a4e5ae3..7960c730472363 100644 --- a/src/coreclr/jit/scev.cpp +++ b/src/coreclr/jit/scev.cpp @@ -1736,7 +1736,7 @@ bool ScalarEvolutionContext::AddRecMayOverflow(ScevAddRec* } int64_t startCns; - if (addRec->Start->GetConstantValue(m_compiler, &startCns) && (startCns != 0)) + if (!addRec->Start->GetConstantValue(m_compiler, &startCns) || (startCns != 0)) { return true; } diff --git a/src/tests/JIT/Regression_ro_2/Runtime_133759.cs b/src/tests/JIT/Regression_ro_2/Runtime_133759.cs new file mode 100644 index 00000000000000..e7bc35e383e9e4 --- /dev/null +++ b/src/tests/JIT/Regression_ro_2/Runtime_133759.cs @@ -0,0 +1,41 @@ +// 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; +using Xunit; + +public class Runtime_133759 +{ + [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] + private static void Test(int seed, long[] dst) + { + int c = seed; + for (int i = 0; i < 10; i++) + { + dst[i] = (uint)c * 8L; + c++; + } + } + + [Fact] + public static void TestEntryPoint() + { + long[] actual = new long[10]; + Test(-3, actual); + + Assert.Equal( + [ + 34359738344, + 34359738352, + 34359738360, + 0, + 8, + 16, + 24, + 32, + 40, + 48, + ], + actual); + } +}