From: Jakob Botsch Nielsen Date: Wed, 8 Feb 2023 15:38:24 +0000 (+0100) Subject: JIT: Avoid omitting copies for struct fields passed implicitly byrefs (#81787) X-Git-Tag: accepted/tizen/unified/riscv/20231226.055536~4159 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=5b2ceeb8c240f8c6248ff9bee1b696014004a7af;p=platform%2Fupstream%2Fdotnet%2Fruntime.git JIT: Avoid omitting copies for struct fields passed implicitly byrefs (#81787) The code does not properly mark the parent struct as address exposed, but also doing so would completely disable any tracking/optimization for these locals which we do not want to do. Fix #81739 --- diff --git a/src/coreclr/jit/lclvars.cpp b/src/coreclr/jit/lclvars.cpp index eec8e0d..7cd22c1 100644 --- a/src/coreclr/jit/lclvars.cpp +++ b/src/coreclr/jit/lclvars.cpp @@ -2575,6 +2575,7 @@ unsigned Compiler::lvaGetFieldLocal(const LclVarDsc* varDsc, unsigned int fldOff void Compiler::lvaSetVarAddrExposed(unsigned varNum DEBUGARG(AddressExposedReason reason)) { LclVarDsc* varDsc = lvaGetDesc(varNum); + assert(!varDsc->lvIsStructField); varDsc->SetAddressExposed(true DEBUGARG(reason)); diff --git a/src/coreclr/jit/morph.cpp b/src/coreclr/jit/morph.cpp index 4d20705..7216b77 100644 --- a/src/coreclr/jit/morph.cpp +++ b/src/coreclr/jit/morph.cpp @@ -3976,7 +3976,7 @@ void Compiler::fgMakeOutgoingStructArgCopy(GenTreeCall* call, CallArg* arg) if (!omitCopy && fgGlobalMorph) { - omitCopy = !varDsc->lvPromoted && ((lcl->gtFlags & GTF_VAR_DEATH) != 0); + omitCopy = !varDsc->lvPromoted && !varDsc->lvIsStructField && ((lcl->gtFlags & GTF_VAR_DEATH) != 0); } if (!omitCopy && (totalAppearances == 1)) diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_81739/Runtime_81739.cs b/src/tests/JIT/Regression/JitBlue/Runtime_81739/Runtime_81739.cs new file mode 100644 index 0000000..9b49d8c --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_81739/Runtime_81739.cs @@ -0,0 +1,21 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Numerics; +using System.Runtime.CompilerServices; + +public class Runtime_81739 +{ + public static int Main() + { + Plane p; + p.Normal = default; + Consume(p.Normal); + return 100; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static void Consume(T v) + { + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_81739/Runtime_81739.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_81739/Runtime_81739.csproj new file mode 100644 index 0000000..c0a5f3d --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_81739/Runtime_81739.csproj @@ -0,0 +1,9 @@ + + + Exe + True + + + + + \ No newline at end of file