From 4f5450410ec1cc7ec12f15f3394258fcc9ccc8e2 Mon Sep 17 00:00:00 2001 From: SingleAccretion <62474226+SingleAccretion@users.noreply.github.com> Date: Wed, 27 Jul 2022 12:27:06 +0300 Subject: [PATCH] Don't create mismatched block copies in `cpblk` import (#71160) * Don't create questionable IR in "cpblk" import * Add a test --- src/coreclr/jit/importer.cpp | 21 ++++++------------ .../JitBlue/Runtime_71156/Runtime_71156.cs | 22 +++++++++++++++++++ .../Runtime_71156/Runtime_71156.csproj | 10 +++++++++ 3 files changed, 39 insertions(+), 14 deletions(-) create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_71156/Runtime_71156.cs create mode 100644 src/tests/JIT/Regression/JitBlue/Runtime_71156/Runtime_71156.csproj diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index dd7b9c7a5ac7d..61d3977a59db8 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -17330,25 +17330,18 @@ void Compiler::impImportBlockCode(BasicBlock* block) op2 = impPopStack().val; // Src addr op1 = impPopStack().val; // Dst addr - if (op2->OperGet() == GT_ADDR) - { - op2 = op2->AsOp()->gtOp1; - } - else - { - op2 = gtNewOperNode(GT_IND, TYP_STRUCT, op2); - } - if (op3->IsCnsIntOrI()) { - size = (unsigned)op3->AsIntConCommon()->IconValue(); - op1 = new (this, GT_BLK) GenTreeBlk(GT_BLK, TYP_STRUCT, op1, typGetBlkLayout(size)); - op1 = gtNewBlkOpNode(op1, op2, (prefixFlags & PREFIX_VOLATILE) != 0, true); + size = static_cast(op3->AsIntConCommon()->IconValue()); + + op1 = gtNewBlockVal(op1, size); + op2 = gtNewBlockVal(op2, size); + op1 = gtNewBlkOpNode(op1, op2, (prefixFlags & PREFIX_VOLATILE) != 0, /* isCopyBlock */ true); } else { - op1 = new (this, GT_STORE_DYN_BLK) GenTreeStoreDynBlk(op1, op2, op3); - size = 0; + op2 = gtNewOperNode(GT_IND, TYP_STRUCT, op2); + op1 = new (this, GT_STORE_DYN_BLK) GenTreeStoreDynBlk(op1, op2, op3); if ((prefixFlags & PREFIX_VOLATILE) != 0) { diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_71156/Runtime_71156.cs b/src/tests/JIT/Regression/JitBlue/Runtime_71156/Runtime_71156.cs new file mode 100644 index 0000000000000..6debf2bfc7c6a --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_71156/Runtime_71156.cs @@ -0,0 +1,22 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System.Runtime.CompilerServices; + +public unsafe class Runtime_71156 +{ + public static int Main() + { + return Problem() ? 101 : 100; + } + + [MethodImpl(MethodImplOptions.NoInlining)] + private static bool Problem() + { + float a; + var b = 0xFF000000; + Unsafe.CopyBlock(&a, &b, 4); + + return *(uint*)&a != 0xFF000000u; + } +} diff --git a/src/tests/JIT/Regression/JitBlue/Runtime_71156/Runtime_71156.csproj b/src/tests/JIT/Regression/JitBlue/Runtime_71156/Runtime_71156.csproj new file mode 100644 index 0000000000000..cf94135633b19 --- /dev/null +++ b/src/tests/JIT/Regression/JitBlue/Runtime_71156/Runtime_71156.csproj @@ -0,0 +1,10 @@ + + + Exe + True + true + + + + + \ No newline at end of file