From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1820) id 479123858027; Wed, 26 Oct 2022 08:53:37 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 479123858027 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666774417; bh=OV6H//FFsfQO7uzDPqUI4il0enHW5ib0j5j4iR1bFNg=; h=From:To:Subject:Date:From; b=cRas4p2PZvvKO5g3Txp1m9cRYgzs5EAV0EiBvtKvsnTkvXuxZGEEKuE2dl1WMwIFd wJXDYPVIcWwjBIkb+J9SBezaKV+m7PFSBxSQTtg7x4cd6XC8B/aPBK//pWoNRhKhAs TEChe3DpQFPaTcj4NvTYKc2YIWjydddaV26/vtqs= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Hafiz Abid Qadeer To: gcc-cvs@gcc.gnu.org Subject: [gcc/devel/omp/gcc-12] Handle operator new with alignment in usm transform. X-Act-Checkin: gcc X-Git-Author: Hafiz Abid Qadeer X-Git-Refname: refs/heads/devel/omp/gcc-12 X-Git-Oldrev: 4226421e6d6d4f94706ed92082581661cedf8071 X-Git-Newrev: 9c461798d5d2dadb5e74357ae0eae95a4478d968 Message-Id: <20221026085337.479123858027@sourceware.org> Date: Wed, 26 Oct 2022 08:53:37 +0000 (GMT) List-Id: https://gcc.gnu.org/g:9c461798d5d2dadb5e74357ae0eae95a4478d968 commit 9c461798d5d2dadb5e74357ae0eae95a4478d968 Author: Hafiz Abid Qadeer Date: Wed Oct 26 09:51:01 2022 +0100 Handle operator new with alignment in usm transform. Since C++17, the is a variant of operator new with alignment. This patch converts it to omp_aligned_alloc when unified shared memory is being used. gcc/ChangeLog: * omp-low.cc (usm_transform): Handle operator new with alignment. libgomp/ChangeLog: * testsuite/libgomp.c++/usm-2.C: New test. gcc/testsuite/ChangeLog: * g++.dg/gomp/usm-4.C: New test. * g++.dg/gomp/usm-5.C: New test. Diff: --- gcc/ChangeLog.omp | 4 ++++ gcc/omp-low.cc | 16 ++++++++++++---- gcc/testsuite/ChangeLog.omp | 5 +++++ gcc/testsuite/g++.dg/gomp/usm-4.C | 32 ++++++++++++++++++++++++++++++++ gcc/testsuite/g++.dg/gomp/usm-5.C | 30 ++++++++++++++++++++++++++++++ libgomp/ChangeLog.omp | 4 ++++ libgomp/testsuite/libgomp.c++/usm-2.C | 33 +++++++++++++++++++++++++++++++++ 7 files changed, 120 insertions(+), 4 deletions(-) diff --git a/gcc/ChangeLog.omp b/gcc/ChangeLog.omp index 9b2a2007ac1..53cbfbab603 100644 --- a/gcc/ChangeLog.omp +++ b/gcc/ChangeLog.omp @@ -1,3 +1,7 @@ +2022-10-25 Abid Qadeer + + * omp-low.cc (usm_transform): Handle operator new with alignment. + 2022-10-25 Marcel Vollweiler * omp-offload.cc (oacc_loop_auto_partitions): Removed OLF reduction diff --git a/gcc/omp-low.cc b/gcc/omp-low.cc index f171181e2c4..b5b2681b654 100644 --- a/gcc/omp-low.cc +++ b/gcc/omp-low.cc @@ -16339,6 +16339,7 @@ usm_transform (gimple_stmt_iterator *gsi_p, bool *, { gcall *gs = as_a (stmt); tree fndecl = gimple_call_fndecl (gs); + unsigned int args = gimple_call_num_args (gs); if (fndecl) { tree allocator = build_int_cst (pointer_sized_int_node, @@ -16347,7 +16348,8 @@ usm_transform (gimple_stmt_iterator *gsi_p, bool *, if ((strcmp (name, "malloc") == 0) || (fndecl_built_in_p (fndecl, BUILT_IN_NORMAL) && DECL_FUNCTION_CODE (fndecl) == BUILT_IN_MALLOC) - || DECL_IS_REPLACEABLE_OPERATOR_NEW_P (fndecl) + || (DECL_IS_REPLACEABLE_OPERATOR_NEW_P (fndecl) + && args == 1) || strcmp (name, "omp_target_alloc") == 0) { tree omp_alloc_type @@ -16361,7 +16363,9 @@ usm_transform (gimple_stmt_iterator *gsi_p, bool *, gimple_set_location (g, gimple_location (stmt)); gsi_replace (gsi_p, g, true); } - else if (strcmp (name, "aligned_alloc") == 0) + else if ((strcmp (name, "aligned_alloc") == 0) + || (DECL_IS_REPLACEABLE_OPERATOR_NEW_P (fndecl) + && args == 2)) { /* May be we can also use this for new operator with std::align_val_t parameter. */ @@ -16372,8 +16376,12 @@ usm_transform (gimple_stmt_iterator *gsi_p, bool *, NULL_TREE); tree repl = build_fn_decl ("omp_aligned_alloc", omp_alloc_type); - tree align = gimple_call_arg (gs, 0); - tree size = gimple_call_arg (gs, 1); + int align_arg + = DECL_IS_REPLACEABLE_OPERATOR_NEW_P (fndecl) ? 1: 0; + int size_arg + = DECL_IS_REPLACEABLE_OPERATOR_NEW_P (fndecl) ? 0: 1; + tree align = gimple_call_arg (gs, align_arg); + tree size = gimple_call_arg (gs, size_arg); gimple *g = gimple_build_call (repl, 3, align, size, allocator); gimple_call_set_lhs (g, gimple_call_lhs (gs)); diff --git a/gcc/testsuite/ChangeLog.omp b/gcc/testsuite/ChangeLog.omp index 677a4c6ee12..d5548ebff3b 100644 --- a/gcc/testsuite/ChangeLog.omp +++ b/gcc/testsuite/ChangeLog.omp @@ -1,3 +1,8 @@ +2022-10-25 Abid Qadeer + + * g++.dg/gomp/usm-4.C: New test. + * g++.dg/gomp/usm-5.C: New test. + 2022-10-24 Tobias Burnus * g++.dg/ext/unroll-1.C: Change 'cunrolli' to 'cunrolli1' in diff --git a/gcc/testsuite/g++.dg/gomp/usm-4.C b/gcc/testsuite/g++.dg/gomp/usm-4.C new file mode 100644 index 00000000000..9096c445363 --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/usm-4.C @@ -0,0 +1,32 @@ +// { dg-do compile { target c++17 } } +// { dg-options "-fopenmp -fdump-tree-usm_transform" } + +#pragma omp requires unified_shared_memory + +struct t1 +{ + int a; + int b; +}; + +typedef unsigned char uint8_t; + +void +foo (__SIZE_TYPE__ x, __SIZE_TYPE__ y) +{ + uint8_t *p1 = new (std::align_val_t(128)) uint8_t; + uint8_t *p2 = new (std::align_val_t(128)) uint8_t[40]; + t1 *p3 = new (std::align_val_t(128)) t1; + t1 *p4 = new (std::align_val_t(128)) t1[y]; + delete p1; + delete p3; + delete [] p2; + delete [] p4; +} + +/* { dg-final { scan-tree-dump-times "omp_aligned_alloc \\(128, 1, 10\\)" 1 "usm_transform" } } */ +/* { dg-final { scan-tree-dump-times "omp_aligned_alloc \\(128, 40, 10\\)" 1 "usm_transform" } } */ +/* { dg-final { scan-tree-dump-times "omp_aligned_alloc" 4 "usm_transform" } } */ +/* { dg-final { scan-tree-dump-times "omp_free" 4 "usm_transform" } } */ +/* { dg-final { scan-tree-dump-not "operator new" "usm_transform" } } */ +/* { dg-final { scan-tree-dump-not "operator delete" "usm_transform" } } */ diff --git a/gcc/testsuite/g++.dg/gomp/usm-5.C b/gcc/testsuite/g++.dg/gomp/usm-5.C new file mode 100644 index 00000000000..2cc8a625f64 --- /dev/null +++ b/gcc/testsuite/g++.dg/gomp/usm-5.C @@ -0,0 +1,30 @@ +// { dg-do compile { target c++17 } } +// { dg-options "-fopenmp -foffload-memory=unified -fdump-tree-usm_transform" } + +struct t1 +{ + int a; + int b; +}; + +typedef unsigned char uint8_t; + +void +foo (__SIZE_TYPE__ x, __SIZE_TYPE__ y) +{ + uint8_t *p1 = new (std::align_val_t(128)) uint8_t; + uint8_t *p2 = new (std::align_val_t(128)) uint8_t[40]; + t1 *p3 = new (std::align_val_t(128)) t1; + t1 *p4 = new (std::align_val_t(128)) t1[y]; + delete p1; + delete p3; + delete [] p2; + delete [] p4; +} + +/* { dg-final { scan-tree-dump-times "omp_aligned_alloc \\(128, 1, 10\\)" 1 "usm_transform" } } */ +/* { dg-final { scan-tree-dump-times "omp_aligned_alloc \\(128, 40, 10\\)" 1 "usm_transform" } } */ +/* { dg-final { scan-tree-dump-times "omp_aligned_alloc" 4 "usm_transform" } } */ +/* { dg-final { scan-tree-dump-times "omp_free" 4 "usm_transform" } } */ +/* { dg-final { scan-tree-dump-not "operator new" "usm_transform" } } */ +/* { dg-final { scan-tree-dump-not "operator delete" "usm_transform" } } */ diff --git a/libgomp/ChangeLog.omp b/libgomp/ChangeLog.omp index ee0f09ead13..f31fdfe373c 100644 --- a/libgomp/ChangeLog.omp +++ b/libgomp/ChangeLog.omp @@ -1,3 +1,7 @@ +2022-10-25 Abid Qadeer + + * testsuite/libgomp.c++/usm-2.C: New test. + 2022-10-24 Tobias Burnus Backport from mainline: diff --git a/libgomp/testsuite/libgomp.c++/usm-2.C b/libgomp/testsuite/libgomp.c++/usm-2.C new file mode 100644 index 00000000000..d12e550d507 --- /dev/null +++ b/libgomp/testsuite/libgomp.c++/usm-2.C @@ -0,0 +1,33 @@ +/* { dg-do run } */ +/* { dg-additional-options "-std=c++17" } */ +/* { dg-require-effective-target omp_usm } */ +#include + +#pragma omp requires unified_shared_memory + +struct s1 +{ + int a; +}; + +int +main () +{ + s1 *p1 = new s1; + s1 *p2 = new s1[10]; + + if (!p1 || !p2) + __builtin_abort (); + + uintptr_t pp1 = (uintptr_t)p1; + uintptr_t pp2 = (uintptr_t)p2; + if (pp1 & 0x7f != 0) + __builtin_abort (); + + if (pp2 & 0x7f != 0) + __builtin_abort (); + + delete [] p2; + delete p1; + return 0; +}