From: SingleAccretion <62474226+SingleAccretion@users.noreply.github.com> Date: Mon, 7 Mar 2022 09:54:35 +0000 (+0300) Subject: Do not create small constants while morphing cascading addition (#66270) X-Git-Tag: accepted/tizen/unified/riscv/20231226.055536~10475 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5ff9efa553655c707aba44aa8fa69be4d00f1fd9;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Do not create small constants while morphing cascading addition (#66270) * Do not create small constants * Add a test --- diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index cc53236..a99d7b9 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -18500,8 +18500,8 @@ GenTree* Compiler::fgMorphReduceAddOps(GenTree* tree) return tree; } - int foldCount = 0; - unsigned int lclNum = op2->AsLclVarCommon()->GetLclNum(); + int foldCount = 0; + unsigned lclNum = op2->AsLclVarCommon()->GetLclNum(); // Search for pattern of shape ADD(ADD(ADD(lclNum, lclNum), lclNum), lclNum). while (true) @@ -18530,7 +18530,7 @@ GenTree* Compiler::fgMorphReduceAddOps(GenTree* tree) // V0 + V0 ... + V0 becomes V0 * foldCount, where postorder transform will optimize // accordingly - consTree->BashToConst(foldCount, lclVarTree->TypeGet()); + consTree->BashToConst(foldCount, tree->TypeGet()); GenTree* morphed = gtNewOperNode(GT_MUL, tree->TypeGet(), lclVarTree, consTree); DEBUG_DESTROY_NODE(tree); diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_66269/Runtime_66269.cs b/src/tests/JIT/Regression/JitBlue/Runtime_66269/Runtime_66269.cs new file mode 100644 index 0000000..a5eba4a --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_66269/Runtime_66269.cs @@ -0,0 +1,18 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +public class Runtime_66269 +{ + public static int Main() + { + return Problem(1) == 2 ? 100 : 101; + } + + private static ushort Problem(ushort arg1) + { + arg1 += arg1; + + return arg1; + } +} + diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_66269/Runtime_66269.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_66269/Runtime_66269.csproj new file mode 100644 index 0000000..f492aea --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_66269/Runtime_66269.csproj @@ -0,0 +1,9 @@ + + + Exe + True + + + + + \ No newline at end of file