From 343b99afa593e7307bf0f9810653ad8abeb4859a Mon Sep 17 00:00:00 2001 From: Andy Ayers Date: Thu, 16 Aug 2018 09:22:05 -0700 Subject: [PATCH] JIT: bail out in optExtractArrIndex for constant array length (dotnet/coreclr#19493) Generalize the bail out pattern to handle cases from spans where we may see a known array length in a bounds check. Fixes dotnet/coreclr#19454 Commit migrated from https://github.com/dotnet/coreclr/commit/a52128e8f59f7f824862ff4ecde0d8d9ae1631ef --- src/coreclr/src/jit/optimizer.cpp | 6 ++-- .../JitBlue/GitHub_19454/Github_19454.cs | 40 ++++++++++++++++++++++ .../JitBlue/GitHub_19454/Github_19454.csproj | 34 ++++++++++++++++++ 3 files changed, 76 insertions(+), 4 deletions(-) create mode 100644 src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_19454/Github_19454.cs create mode 100644 src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_19454/Github_19454.csproj diff --git a/src/coreclr/src/jit/optimizer.cpp b/src/coreclr/src/jit/optimizer.cpp index a77a869..9a1e015 100644 --- a/src/coreclr/src/jit/optimizer.cpp +++ b/src/coreclr/src/jit/optimizer.cpp @@ -8366,11 +8366,9 @@ bool Compiler::optExtractArrIndex(GenTree* tree, ArrIndex* result, unsigned lhsN return false; } - // For span we may see gtArrLen is a local var or local field. + // For span we may see gtArrLen is a local var or local field or constant. // We won't try and extract those. - const genTreeOps arrayOp = arrBndsChk->gtArrLen->gtOper; - - if ((arrayOp == GT_LCL_VAR) || (arrayOp == GT_LCL_FLD)) + if (arrBndsChk->gtArrLen->OperIs(GT_LCL_VAR, GT_LCL_FLD, GT_CNS_INT)) { return false; } diff --git a/src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_19454/Github_19454.cs b/src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_19454/Github_19454.cs new file mode 100644 index 0000000..1e440f8 --- /dev/null +++ b/src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_19454/Github_19454.cs @@ -0,0 +1,40 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// See the LICENSE file in the project root for more information. +// +// This test was extracted from the corefx System.Numerics.Vectors tests, +// and was failing with minOpts because a SIMD12 was being spilled using +// a 16-byte load, but only a 12-byte location had been allocated. + +using System; + +public struct MyStruct +{ + public Span Span1 + { + get { return Span.Empty; } + } +} + +public struct MyReader +{ + public void ReadBytesInner(int batch) + { + MyStruct value = new MyStruct(); + for (int i = 0; i < batch; i++) + { + value.Span1[i] = 0; + } + } +} + +class GitHub_19454 +{ + static int Main() + { + MyReader r = new MyReader(); + r.ReadBytesInner(0); + return 100; + } +} + diff --git a/src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_19454/Github_19454.csproj b/src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_19454/Github_19454.csproj new file mode 100644 index 0000000..66784b2 --- /dev/null +++ b/src/coreclr/tests/src/JIT/Regression/JitBlue/GitHub_19454/Github_19454.csproj @@ -0,0 +1,34 @@ + + + + + Debug + AnyCPU + $(MSBuildProjectName) + 2.0 + {ADEEA3D1-B67B-456E-8F2B-6DCCACC2D34C} + Exe + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + + + + + + + False + + + + Full + True + + + + + + + + + + -- 2.7.4