From 5ff9efa553655c707aba44aa8fa69be4d00f1fd9 Mon Sep 17 00:00:00 2001 From: SingleAccretion <62474226+SingleAccretion@users.noreply.github.com> Date: Mon, 7 Mar 2022 12:54:35 +0300 Subject: [PATCH] Do not create small constants while morphing cascading addition (#66270) * Do not create small constants * Add a test --- src/coreclr/jit/morph.cpp | 6 +++--- .../Regression/JitBlue/Runtime_66269/Runtime_66269.cs | 18 ++++++++++++++++++ .../JitBlue/Runtime_66269/Runtime_66269.csproj | 9 +++++++++ 3 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_66269/Runtime_66269.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_66269/Runtime_66269.csproj 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 -- 2.7.4