From 3800df91364fac77a85a512a9988c71302726e65 Mon Sep 17 00:00:00 2001 From: Carol Eidt Date: Thu, 13 Feb 2020 14:27:22 -0800 Subject: Port PR #258 to 3.1 (#27984) * Port PR #258 to 3.1 * Fix test proj file --- src/jit/gentree.cpp | 17 ++++++---- .../coreclr/GitHub_27937/Test27937.csproj | 31 +++++++++++++++++ .../Regressions/coreclr/GitHub_27937/test27937.cs | 39 ++++++++++++++++++++++ 3 files changed, 81 insertions(+), 6 deletions(-) create mode 100644 tests/src/Regressions/coreclr/GitHub_27937/Test27937.csproj create mode 100644 tests/src/Regressions/coreclr/GitHub_27937/test27937.cs diff --git a/src/jit/gentree.cpp b/src/jit/gentree.cpp index c635c327c5..6de4f36bf2 100644 --- a/src/jit/gentree.cpp +++ b/src/jit/gentree.cpp @@ -15741,16 +15741,21 @@ unsigned GenTree::IsLclVarUpdateTree(GenTree** pOtherTree, genTreeOps* pOper) if (OperIs(GT_ASG)) { GenTree* lhs = gtOp.gtOp1; - if (lhs->OperGet() == GT_LCL_VAR) + GenTree* rhs = AsOp()->gtOp2; + if ((lhs->OperGet() == GT_LCL_VAR) && rhs->OperIsBinary()) { unsigned lhsLclNum = lhs->AsLclVarCommon()->gtLclNum; - GenTree* rhs = gtOp.gtOp2; - if (rhs->OperIsBinary() && (rhs->gtOp.gtOp1->gtOper == GT_LCL_VAR) && - (rhs->gtOp.gtOp1->AsLclVarCommon()->gtLclNum == lhsLclNum)) + GenTree* rhsOp1 = rhs->AsOp()->gtOp1; + GenTree* rhsOp2 = rhs->AsOp()->gtOp2; + + // Some operators, such as HWINTRINSIC, are currently declared as binary but + // may not have two operands. We must check that both operands actually exist. + if ((rhsOp1 != nullptr) && (rhsOp2 != nullptr) && (rhsOp1->OperGet() == GT_LCL_VAR) && + (rhsOp1->AsLclVarCommon()->GetLclNum() == lhsLclNum)) { lclNum = lhsLclNum; - *pOtherTree = rhs->gtOp.gtOp2; - *pOper = rhs->gtOper; + *pOtherTree = rhsOp2; + *pOper = rhs->OperGet(); } } } diff --git a/tests/src/Regressions/coreclr/GitHub_27937/Test27937.csproj b/tests/src/Regressions/coreclr/GitHub_27937/Test27937.csproj new file mode 100644 index 0000000000..d120acc6d7 --- /dev/null +++ b/tests/src/Regressions/coreclr/GitHub_27937/Test27937.csproj @@ -0,0 +1,31 @@ + + + + + Debug + AnyCPU + 2.0 + {CBD0D777-3583-49CC-8538-DD84447F6522} + Exe + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + ..\..\ + true + BuildAndRun + 1 + None + True + + + + + + + False + + + + + + + + diff --git a/tests/src/Regressions/coreclr/GitHub_27937/test27937.cs b/tests/src/Regressions/coreclr/GitHub_27937/test27937.cs new file mode 100644 index 0000000000..7056ed8577 --- /dev/null +++ b/tests/src/Regressions/coreclr/GitHub_27937/test27937.cs @@ -0,0 +1,39 @@ +// 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. +using System.Runtime.Intrinsics; + +class Test27937 +{ + static unsafe void calc(float* fa, float* fb) + { + float* pb = fb; + float* eb = pb + 16; + + do + { + float* pa = fa; + float* ea = pa + 16; + var va = Vector128.Zero; + + do + { + *pa = va.ToScalar(); + + pa += Vector128.Count; + pb += Vector128.Count; + } while (pa < ea); + + } while (pb < eb); + } + + static unsafe int Main() + { + float* a = stackalloc float[16]; + float* b = stackalloc float[16]; + + calc(a, b); + + return 100; + } +} -- cgit v1.2.3