From 0022738e10a22c6ffa121604a86c99d45fc3ea78 Mon Sep 17 00:00:00 2001 From: SingleAccretion <62474226+SingleAccretion@users.noreply.github.com> Date: Mon, 7 Mar 2022 13:58:04 +0300 Subject: [PATCH] Count `OBJ/BLK` as memory uses (#66135) * Fix memory liveness for OBJ/BLK We need to count OBJ/BLK as uses, otherwise SSA can fail to insert a memory PHI where one is needed. * Add a test --- src/coreclr/jit/liveness.cpp | 2 ++ .../JIT/Directed/lifetime/ObjBlkMemLiveness.cs | 36 ++++++++++++++++++++++ .../JIT/Directed/lifetime/ObjBlkMemLiveness.csproj | 14 +++++++++ 3 files changed, 52 insertions(+) create mode 100644 src/tests/JIT/Directed/lifetime/ObjBlkMemLiveness.cs create mode 100644 src/tests/JIT/Directed/lifetime/ObjBlkMemLiveness.csproj diff --git a/src/coreclr/jit/liveness.cpp b/src/coreclr/jit/liveness.cpp index 06b7d16..ba1a653 100644 --- a/src/coreclr/jit/liveness.cpp +++ b/src/coreclr/jit/liveness.cpp @@ -245,6 +245,8 @@ void Compiler::fgPerNodeLocalVarLiveness(GenTree* tree) break; case GT_IND: + case GT_OBJ: + case GT_BLK: // For Volatile indirection, first mutate GcHeap/ByrefExposed // see comments in ValueNum.cpp (under case GT_CLS_VAR) // This models Volatile reads as def-then-use of memory. diff --git a/src/tests/JIT/Directed/lifetime/ObjBlkMemLiveness.cs b/src/tests/JIT/Directed/lifetime/ObjBlkMemLiveness.cs new file mode 100644 index 0000000..d9ea48e --- /dev/null +++ b/src/tests/JIT/Directed/lifetime/ObjBlkMemLiveness.cs @@ -0,0 +1,36 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. +// + +// Test that memory liveness does not miss a memory use (in the form of an OBJ/BLK). + +using System; +using System.Runtime.Intrinsics; +using System.Runtime.CompilerServices; + +unsafe class ObjBlkLiveness +{ + public static int Main() + { + var a = Vector128.Zero; + return Problem(&a, 1) ? 100 : 101; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static bool Problem(Vector128* p, int b) + { + var a = 2 * *p; + + if (b is 1) + { + *p = Vector128.AllBitsSet; + } + + if (a + *p == Vector128.Zero) + { + return false; + } + + return true; + } +} diff --git a/src/tests/JIT/Directed/lifetime/ObjBlkMemLiveness.csproj b/src/tests/JIT/Directed/lifetime/ObjBlkMemLiveness.csproj new file mode 100644 index 0000000..d750325 --- /dev/null +++ b/src/tests/JIT/Directed/lifetime/ObjBlkMemLiveness.csproj @@ -0,0 +1,14 @@ + + + Exe + 1 + true + + + None + True + + + + + -- 2.7.4