diff --git a/src/coreclr/jit/optimizer.cpp b/src/coreclr/jit/optimizer.cpp index be12db114d5782..71e450d4399238 100644 --- a/src/coreclr/jit/optimizer.cpp +++ b/src/coreclr/jit/optimizer.cpp @@ -9216,6 +9216,8 @@ GenTree* Compiler::optRemoveRangeCheck(GenTreeBoundsChk* check, GenTree* comma, { // TODO-CQ: We should also remove the GT_COMMA, but in any case we can no longer CSE the GT_COMMA. tree->gtFlags |= GTF_DONT_CSE; + // Ensure the other side of the comma can't be moved outside the checked range. + tree->gtGetOp2()->gtFlags |= GTF_ORDER_SIDEEFF; } gtUpdateSideEffects(stmt, tree); diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_78554/Runtime_78554.cs b/src/tests/JIT/Regression/JitBlue/Runtime_78554/Runtime_78554.cs new file mode 100644 index 00000000000000..446b57d03b4a39 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_78554/Runtime_78554.cs @@ -0,0 +1,30 @@ +// 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_78554 +{ + [MethodImpl(MethodImplOptions.NoInlining)] + static void Consume(uint op) + { + return; + } + + [MethodImplAttribute(MethodImplOptions.NoInlining)] + static void ArrayIndexConsume(uint[] a, uint i) + { + if (i < a.Length) + { + i = a[i]; + } + Consume(i); + } + + public static int Main() + { + var arr = new uint[] { 1, 42, 3000 }; + ArrayIndexConsume(arr, 0xffffffff); + return 100; + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_78554/Runtime_78554.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_78554/Runtime_78554.csproj new file mode 100644 index 00000000000000..7a789ed5ed1f58 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_78554/Runtime_78554.csproj @@ -0,0 +1,13 @@ + + + Exe + True + + + + + + + + +