From a0140a3712099d169d5e04e5cfd71eace526f652 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 19 Oct 2020 12:34:31 +0300 Subject: [PATCH 1/8] propagate GTF_CALL if needed in GT_LIST --- src/coreclr/src/jit/hwintrinsicarm64.cpp | 6 +++++- src/coreclr/src/jit/hwintrinsicxarch.cpp | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/coreclr/src/jit/hwintrinsicarm64.cpp b/src/coreclr/src/jit/hwintrinsicarm64.cpp index c572f9bf0888a0..80d9a7b807054d 100644 --- a/src/coreclr/src/jit/hwintrinsicarm64.cpp +++ b/src/coreclr/src/jit/hwintrinsicarm64.cpp @@ -398,7 +398,11 @@ GenTree* Compiler::impSpecialIntrinsic(NamedIntrinsic intrinsic, { tmp = gtNewArgList(impPopStack().val); tmp->gtOp2 = op1; - op1 = tmp; + + // propagate GTF_CALL if needed + if ((op1 != nullptr) && (op1->gtFlags & GTF_CALL)) + tmp->gtFlags |= GTF_CALL; + op1 = tmp; } retNode = gtNewSimdHWIntrinsicNode(retType, op1, intrinsic, baseType, simdSize); diff --git a/src/coreclr/src/jit/hwintrinsicxarch.cpp b/src/coreclr/src/jit/hwintrinsicxarch.cpp index e624f18e713f94..c9a6eac4d1deaa 100644 --- a/src/coreclr/src/jit/hwintrinsicxarch.cpp +++ b/src/coreclr/src/jit/hwintrinsicxarch.cpp @@ -776,7 +776,11 @@ GenTree* Compiler::impBaseIntrinsic(NamedIntrinsic intrinsic, { tmp = gtNewArgList(impPopStack().val); tmp->gtOp2 = op1; - op1 = tmp; + + // propagate GTF_CALL if needed + if ((op1 != nullptr) && (op1->gtFlags & GTF_CALL)) + tmp->gtFlags |= GTF_CALL; + op1 = tmp; } retNode = gtNewSimdHWIntrinsicNode(retType, op1, intrinsic, baseType, simdSize); From 2463da1ea4dd1ee64e71df5a069fced67155cff7 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 19 Oct 2020 13:19:11 +0300 Subject: [PATCH 2/8] propagate properly --- src/coreclr/src/jit/hwintrinsicarm64.cpp | 19 ++++++++++--------- src/coreclr/src/jit/hwintrinsicxarch.cpp | 19 ++++++++++--------- 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/coreclr/src/jit/hwintrinsicarm64.cpp b/src/coreclr/src/jit/hwintrinsicarm64.cpp index 80d9a7b807054d..2743a054c3b97f 100644 --- a/src/coreclr/src/jit/hwintrinsicarm64.cpp +++ b/src/coreclr/src/jit/hwintrinsicarm64.cpp @@ -392,18 +392,19 @@ GenTree* Compiler::impSpecialIntrinsic(NamedIntrinsic intrinsic, { assert(sig->numArgs >= 3); - GenTreeArgList* tmp = nullptr; - + GenTreeArgList* tmpList = nullptr; for (unsigned i = 0; i < sig->numArgs; i++) { - tmp = gtNewArgList(impPopStack().val); - tmp->gtOp2 = op1; - - // propagate GTF_CALL if needed - if ((op1 != nullptr) && (op1->gtFlags & GTF_CALL)) - tmp->gtFlags |= GTF_CALL; - op1 = tmp; + if (tmpList == nullptr) + { + tmpList = gtNewArgList(impPopStack().val); + } + else + { + tmpList = new (this, GT_LIST) GenTreeArgList(impPopStack().val, tmpList); + } } + op1 = tmpList; retNode = gtNewSimdHWIntrinsicNode(retType, op1, intrinsic, baseType, simdSize); } diff --git a/src/coreclr/src/jit/hwintrinsicxarch.cpp b/src/coreclr/src/jit/hwintrinsicxarch.cpp index c9a6eac4d1deaa..a2714d4f193628 100644 --- a/src/coreclr/src/jit/hwintrinsicxarch.cpp +++ b/src/coreclr/src/jit/hwintrinsicxarch.cpp @@ -770,18 +770,19 @@ GenTree* Compiler::impBaseIntrinsic(NamedIntrinsic intrinsic, { assert(sig->numArgs >= 3); - GenTreeArgList* tmp = nullptr; - + GenTreeArgList* tmpList = nullptr; for (unsigned i = 0; i < sig->numArgs; i++) { - tmp = gtNewArgList(impPopStack().val); - tmp->gtOp2 = op1; - - // propagate GTF_CALL if needed - if ((op1 != nullptr) && (op1->gtFlags & GTF_CALL)) - tmp->gtFlags |= GTF_CALL; - op1 = tmp; + if (tmpList == nullptr) + { + tmpList = gtNewArgList(impPopStack().val); + } + else + { + tmpList = new (this, GT_LIST) GenTreeArgList(impPopStack().val, tmpList); + } } + op1 = tmpList; retNode = gtNewSimdHWIntrinsicNode(retType, op1, intrinsic, baseType, simdSize); } From 7cf9e70d420450783a9502beebe62e2e2ba16583 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 19 Oct 2020 13:28:18 +0300 Subject: [PATCH 3/8] Make formatting happy --- src/coreclr/src/jit/hwintrinsicarm64.cpp | 3 +-- src/coreclr/src/jit/hwintrinsicxarch.cpp | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/coreclr/src/jit/hwintrinsicarm64.cpp b/src/coreclr/src/jit/hwintrinsicarm64.cpp index 2743a054c3b97f..9f43a386d02b3c 100644 --- a/src/coreclr/src/jit/hwintrinsicarm64.cpp +++ b/src/coreclr/src/jit/hwintrinsicarm64.cpp @@ -404,8 +404,7 @@ GenTree* Compiler::impSpecialIntrinsic(NamedIntrinsic intrinsic, tmpList = new (this, GT_LIST) GenTreeArgList(impPopStack().val, tmpList); } } - op1 = tmpList; - + op1 = tmpList; retNode = gtNewSimdHWIntrinsicNode(retType, op1, intrinsic, baseType, simdSize); } break; diff --git a/src/coreclr/src/jit/hwintrinsicxarch.cpp b/src/coreclr/src/jit/hwintrinsicxarch.cpp index a2714d4f193628..72c5fc06129366 100644 --- a/src/coreclr/src/jit/hwintrinsicxarch.cpp +++ b/src/coreclr/src/jit/hwintrinsicxarch.cpp @@ -782,8 +782,7 @@ GenTree* Compiler::impBaseIntrinsic(NamedIntrinsic intrinsic, tmpList = new (this, GT_LIST) GenTreeArgList(impPopStack().val, tmpList); } } - op1 = tmpList; - + op1 = tmpList; retNode = gtNewSimdHWIntrinsicNode(retType, op1, intrinsic, baseType, simdSize); } break; From de28e9bf8dc593d95271fa6e23547e06659ef101 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 19 Oct 2020 13:34:19 +0300 Subject: [PATCH 4/8] Clean up --- src/coreclr/src/jit/hwintrinsicarm64.cpp | 9 +-------- src/coreclr/src/jit/hwintrinsicxarch.cpp | 9 +-------- 2 files changed, 2 insertions(+), 16 deletions(-) diff --git a/src/coreclr/src/jit/hwintrinsicarm64.cpp b/src/coreclr/src/jit/hwintrinsicarm64.cpp index 9f43a386d02b3c..c5e70e88a9c966 100644 --- a/src/coreclr/src/jit/hwintrinsicarm64.cpp +++ b/src/coreclr/src/jit/hwintrinsicarm64.cpp @@ -395,14 +395,7 @@ GenTree* Compiler::impSpecialIntrinsic(NamedIntrinsic intrinsic, GenTreeArgList* tmpList = nullptr; for (unsigned i = 0; i < sig->numArgs; i++) { - if (tmpList == nullptr) - { - tmpList = gtNewArgList(impPopStack().val); - } - else - { - tmpList = new (this, GT_LIST) GenTreeArgList(impPopStack().val, tmpList); - } + tmpList = new (this, GT_LIST) GenTreeArgList(impPopStack().val, tmpList); } op1 = tmpList; retNode = gtNewSimdHWIntrinsicNode(retType, op1, intrinsic, baseType, simdSize); diff --git a/src/coreclr/src/jit/hwintrinsicxarch.cpp b/src/coreclr/src/jit/hwintrinsicxarch.cpp index 72c5fc06129366..8ba194b2e2cf19 100644 --- a/src/coreclr/src/jit/hwintrinsicxarch.cpp +++ b/src/coreclr/src/jit/hwintrinsicxarch.cpp @@ -773,14 +773,7 @@ GenTree* Compiler::impBaseIntrinsic(NamedIntrinsic intrinsic, GenTreeArgList* tmpList = nullptr; for (unsigned i = 0; i < sig->numArgs; i++) { - if (tmpList == nullptr) - { - tmpList = gtNewArgList(impPopStack().val); - } - else - { - tmpList = new (this, GT_LIST) GenTreeArgList(impPopStack().val, tmpList); - } + tmpList = new (this, GT_LIST) GenTreeArgList(impPopStack().val, tmpList); } op1 = tmpList; retNode = gtNewSimdHWIntrinsicNode(retType, op1, intrinsic, baseType, simdSize); From 866ee6e6c0d02e612707960855d3cd040850e54b Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 19 Oct 2020 15:20:30 +0300 Subject: [PATCH 5/8] Clean up --- src/coreclr/src/jit/hwintrinsicarm64.cpp | 8 +++++--- src/coreclr/src/jit/hwintrinsicxarch.cpp | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/coreclr/src/jit/hwintrinsicarm64.cpp b/src/coreclr/src/jit/hwintrinsicarm64.cpp index c5e70e88a9c966..ba7c3b14d4eef1 100644 --- a/src/coreclr/src/jit/hwintrinsicarm64.cpp +++ b/src/coreclr/src/jit/hwintrinsicarm64.cpp @@ -392,12 +392,14 @@ GenTree* Compiler::impSpecialIntrinsic(NamedIntrinsic intrinsic, { assert(sig->numArgs >= 3); - GenTreeArgList* tmpList = nullptr; + GenTreeArgList* tmp = nullptr; + for (unsigned i = 0; i < sig->numArgs; i++) { - tmpList = new (this, GT_LIST) GenTreeArgList(impPopStack().val, tmpList); + tmp = new (this, GT_LIST) GenTreeArgList(impPopStack().val, tmp); + op1 = tmp; } - op1 = tmpList; + retNode = gtNewSimdHWIntrinsicNode(retType, op1, intrinsic, baseType, simdSize); } break; diff --git a/src/coreclr/src/jit/hwintrinsicxarch.cpp b/src/coreclr/src/jit/hwintrinsicxarch.cpp index 8ba194b2e2cf19..ebf1947009c486 100644 --- a/src/coreclr/src/jit/hwintrinsicxarch.cpp +++ b/src/coreclr/src/jit/hwintrinsicxarch.cpp @@ -770,12 +770,14 @@ GenTree* Compiler::impBaseIntrinsic(NamedIntrinsic intrinsic, { assert(sig->numArgs >= 3); - GenTreeArgList* tmpList = nullptr; + GenTreeArgList* tmp = nullptr; + for (unsigned i = 0; i < sig->numArgs; i++) { - tmpList = new (this, GT_LIST) GenTreeArgList(impPopStack().val, tmpList); + tmp = new (this, GT_LIST) GenTreeArgList(impPopStack().val, tmp); + op1 = tmp; } - op1 = tmpList; + retNode = gtNewSimdHWIntrinsicNode(retType, op1, intrinsic, baseType, simdSize); } break; From 6a21df90471f620359ec528b216e641c7b405590 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 19 Oct 2020 15:32:19 +0300 Subject: [PATCH 6/8] Add a test --- .../Regression/GitHub_43569/GitHub_43569.cs | 74 +++++++++++++++++++ .../GitHub_43569/GitHub_43569.csproj | 12 +++ 2 files changed, 86 insertions(+) create mode 100644 src/tests/JIT/HardwareIntrinsics/General/Regression/GitHub_43569/GitHub_43569.cs create mode 100644 src/tests/JIT/HardwareIntrinsics/General/Regression/GitHub_43569/GitHub_43569.csproj diff --git a/src/tests/JIT/HardwareIntrinsics/General/Regression/GitHub_43569/GitHub_43569.cs b/src/tests/JIT/HardwareIntrinsics/General/Regression/GitHub_43569/GitHub_43569.cs new file mode 100644 index 00000000000000..c0602c46385c70 --- /dev/null +++ b/src/tests/JIT/HardwareIntrinsics/General/Regression/GitHub_43569/GitHub_43569.cs @@ -0,0 +1,74 @@ +// 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; +using System.Runtime.Intrinsics; + +namespace GitHub_43569 +{ + class Program + { + public static int Main() + { + if ((int)Vector64_Create_short(100) != 100) + return 1; + if ((int)Vector128_Create_float(100) != 100) + return 2; + if ((int)Vector128_Create_byte(100) != 100) + return 3; + if ((int)Vector256_Create_float(100) != 100) + return 4; + if ((int)Vector256_Create_double(100) != 100) + return 5; + return 100; + } + + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static T Inline(T t) => t; + + [MethodImpl(MethodImplOptions.NoInlining)] + public static short Vector64_Create_short(short a) + { + Vector64 x = default; + for (int i = 0; i < 1; i++) + x = Vector64.Create(1, 2, 3, Inline(a)); + return x.GetElement(3); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static float Vector128_Create_float(float a) + { + Vector128 x = default; + for (int i = 0; i < 1; i++) + x = Vector128.Create(1, 2, 3, Inline(a)); + return x.GetElement(3); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static byte Vector128_Create_byte(byte a) + { + Vector128 x = default; + for (int i = 0; i < 1; i++) + x = Vector128.Create(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, Inline(a)); + return x.GetElement(15); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static float Vector256_Create_float(float a) + { + Vector256 x = default; + for (int i = 0; i < 1; i++) + x = Vector256.Create(1, 2, 3, 4, 5, 6, 7, Inline(a)); + return x.GetElement(7); + } + + [MethodImpl(MethodImplOptions.NoInlining)] + public static double Vector256_Create_double(double a) + { + Vector256 x = default; + for (int i = 0; i < 1; i++) + x = Vector256.Create(1, 2, 3, Inline(a)); + return x.GetElement(3); + } + } +} diff --git a/src/tests/JIT/HardwareIntrinsics/General/Regression/GitHub_43569/GitHub_43569.csproj b/src/tests/JIT/HardwareIntrinsics/General/Regression/GitHub_43569/GitHub_43569.csproj new file mode 100644 index 00000000000000..86679f81639122 --- /dev/null +++ b/src/tests/JIT/HardwareIntrinsics/General/Regression/GitHub_43569/GitHub_43569.csproj @@ -0,0 +1,12 @@ + + + Exe + + + Embedded + True + + + + + From ca767c6ffeb0f6a17c6c88298411231e6a2bfce5 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Mon, 19 Oct 2020 19:01:48 +0300 Subject: [PATCH 7/8] Use gtNewListNode --- src/coreclr/src/jit/hwintrinsicarm64.cpp | 4 ++-- src/coreclr/src/jit/hwintrinsicxarch.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/coreclr/src/jit/hwintrinsicarm64.cpp b/src/coreclr/src/jit/hwintrinsicarm64.cpp index ba7c3b14d4eef1..0d0021b0b8c65d 100644 --- a/src/coreclr/src/jit/hwintrinsicarm64.cpp +++ b/src/coreclr/src/jit/hwintrinsicarm64.cpp @@ -396,10 +396,10 @@ GenTree* Compiler::impSpecialIntrinsic(NamedIntrinsic intrinsic, for (unsigned i = 0; i < sig->numArgs; i++) { - tmp = new (this, GT_LIST) GenTreeArgList(impPopStack().val, tmp); - op1 = tmp; + tmp = gtNewListNode(impPopStack().val, tmp); } + op1 = tmp; retNode = gtNewSimdHWIntrinsicNode(retType, op1, intrinsic, baseType, simdSize); } break; diff --git a/src/coreclr/src/jit/hwintrinsicxarch.cpp b/src/coreclr/src/jit/hwintrinsicxarch.cpp index ebf1947009c486..141daafa04c985 100644 --- a/src/coreclr/src/jit/hwintrinsicxarch.cpp +++ b/src/coreclr/src/jit/hwintrinsicxarch.cpp @@ -774,10 +774,10 @@ GenTree* Compiler::impBaseIntrinsic(NamedIntrinsic intrinsic, for (unsigned i = 0; i < sig->numArgs; i++) { - tmp = new (this, GT_LIST) GenTreeArgList(impPopStack().val, tmp); - op1 = tmp; + tmp = gtNewListNode(impPopStack().val, tmp); } + op1 = tmp; retNode = gtNewSimdHWIntrinsicNode(retType, op1, intrinsic, baseType, simdSize); } break; From 746f4c06c6b84edf66166739b73aad5ea37af888 Mon Sep 17 00:00:00 2001 From: EgorBo Date: Wed, 21 Oct 2020 14:40:32 +0300 Subject: [PATCH 8/8] ignore test for Mono --- src/tests/issues.targets | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/tests/issues.targets b/src/tests/issues.targets index 92403cade25a2d..74c59e11d16d08 100644 --- a/src/tests/issues.targets +++ b/src/tests/issues.targets @@ -943,6 +943,9 @@ + + https://github.com/dotnet/runtime/issues/43676 + Tests features specific to coreclr