From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lxmtout2.gsi.de (lxmtout2.gsi.de [140.181.3.112]) by sourceware.org (Postfix) with ESMTPS id 25EB53857827 for ; Mon, 19 Jul 2021 07:33:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 25EB53857827 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=gsi.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gsi.de Received: from localhost (localhost [127.0.0.1]) by lxmtout2.gsi.de (Postfix) with ESMTP id AB3FE202AD72; Mon, 19 Jul 2021 09:33:41 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at lxmtout2.gsi.de Received: from lxmtout2.gsi.de ([127.0.0.1]) by localhost (lxmtout2.gsi.de [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Rbhi6-RunTdp; Mon, 19 Jul 2021 09:33:41 +0200 (CEST) Received: from srvex1.campus.gsi.de (unknown [10.10.4.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) by lxmtout2.gsi.de (Postfix) with ESMTPS id 8F830202AD5D; Mon, 19 Jul 2021 09:33:41 +0200 (CEST) Received: from excalibur.localnet (140.181.3.12) by srvex1.campus.gsi.de (10.10.4.11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2242.10; Mon, 19 Jul 2021 09:33:40 +0200 From: Matthias Kretz To: CC: Richard Biener Subject: [PATCH] c-family: Add __builtin_assoc_barrier Date: Mon, 19 Jul 2021 09:33:40 +0200 Message-ID: <2312888.R4OtGj9PrH@excalibur> Organization: GSI Helmholtzzentrum =?UTF-8?B?ZsO8cg==?= Schwerionenforschung MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart3179372.TO5rdG3zkT" Content-Transfer-Encoding: 7Bit X-Originating-IP: [140.181.3.12] X-ClientProxiedBy: srvex1.Campus.gsi.de (10.10.4.11) To srvex1.campus.gsi.de (10.10.4.11) X-Spam-Status: No, score=-10.5 required=5.0 tests=BAYES_00, BODY_8BITS, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_PASS, TXREP, T_SPF_HELO_PERMERROR autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Jul 2021 07:33:45 -0000 --nextPart3179372.TO5rdG3zkT Content-Transfer-Encoding: base64 Content-Type: text/plain; charset="UTF-8" dGVzdGVkIG9uIHg4Nl82NC1wYy1saW51eC1nbnUgd2l0aCBubyBuZXcgZmFpbHVyZXMuIE9LIGZv ciBtYXN0ZXI/CgpOZXcgYnVpbHRpbiB0byBlbmFibGUgZXhwbGljaXQgdXNlIG9mIFBBUkVOX0VY UFIgaW4gQyAmIEMrKyBjb2RlLgoKU2lnbmVkLW9mZi1ieTogTWF0dGhpYXMgS3JldHogPG0ua3Jl dHpAZ3NpLmRlPgoKZ2NjL3Rlc3RzdWl0ZS9DaGFuZ2VMb2c6CgoJKiBjLWMrKy1jb21tb24vYnVp bHRpbi1hc3NvYy1iYXJyaWVyLTEuYzogTmV3IHRlc3QuCgpnY2MvY3AvQ2hhbmdlTG9nOgoKCSog Y3Atb2JqY3AtY29tbW9uLmMgKG5hbWVzX2J1aWx0aW5fcCk6IEhhbmRsZQoJUklEX0JVSUxUSU5f QVNTT0NfQkFSUklFUi4KCSogcGFyc2VyLmMgKGNwX3BhcnNlcl9wb3N0Zml4X2V4cHJlc3Npb24p OiBIYW5kbGUKCVJJRF9CVUlMVElOX0FTU09DX0JBUlJJRVIuCgpnY2MvYy1mYW1pbHkvQ2hhbmdl TG9nOgoKCSogYy1jb21tb24uYyAoY19jb21tb25fcmVzd29yZHMpOiBBZGQgX19idWlsdGluX2Fz c29jX2JhcnJpZXIuCgkqIGMtY29tbW9uLmggKGVudW0gcmlkKTogQWRkIFJJRF9CVUlMVElOX0FT U09DX0JBUlJJRVIuCgpnY2MvYy9DaGFuZ2VMb2c6CgoJKiBjLWRlY2wuYyAobmFtZXNfYnVpbHRp bl9wKTogSGFuZGxlIFJJRF9CVUlMVElOX0FTU09DX0JBUlJJRVIuCgkqIGMtcGFyc2VyLmMgKGNf cGFyc2VyX3Bvc3RmaXhfZXhwcmVzc2lvbik6IExpa2V3aXNlLgoKZ2NjL0NoYW5nZUxvZzoKCgkq IGRvYy9leHRlbmQudGV4aTogRG9jdW1lbnQgX19idWlsdGluX2Fzc29jX2JhcnJpZXIuCi0tLQog Z2NjL2MtZmFtaWx5L2MtY29tbW9uLmMgICAgICAgICAgICAgICAgICAgICAgIHwgIDEgKwogZ2Nj L2MtZmFtaWx5L2MtY29tbW9uLmggICAgICAgICAgICAgICAgICAgICAgIHwgIDIgKy0KIGdjYy9j L2MtZGVjbC5jICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB8ICAxICsKIGdjYy9jL2Mt cGFyc2VyLmMgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB8IDIwICsrKysrKysrKysrKysr KysKIGdjYy9jcC9jcC1vYmpjcC1jb21tb24uYyAgICAgICAgICAgICAgICAgICAgICB8ICAxICsK IGdjYy9jcC9wYXJzZXIuYyAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB8IDE0ICsrKysr KysrKysrCiBnY2MvZG9jL2V4dGVuZC50ZXhpICAgICAgICAgICAgICAgICAgICAgICAgICAgfCAx OCArKysrKysrKysrKysrKwogLi4uL2MtYysrLWNvbW1vbi9idWlsdGluLWFzc29jLWJhcnJpZXIt MS5jICAgIHwgMjQgKysrKysrKysrKysrKysrKysrKwogOCBmaWxlcyBjaGFuZ2VkLCA4MCBpbnNl cnRpb25zKCspLCAxIGRlbGV0aW9uKC0pCiBjcmVhdGUgbW9kZSAxMDA2NDQgZ2NjL3Rlc3RzdWl0 ZS9jLWMrKy1jb21tb24vYnVpbHRpbi1hc3NvYy1iYXJyaWVyLTEuYwoKCi0tCuKUgOKUgOKUgOKU gOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKU gOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKU gOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKU gOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgOKUgAogRHIuIE1hdHRoaWFzIEty ZXR6ICAgICAgICAgICAgICAgICAgICAgICAgICAgaHR0cHM6Ly9tYXR0a3JldHouZ2l0aHViLmlv CiBHU0kgSGVsbWhvbHR6IENlbnRyZSBmb3IgSGVhdnkgSW9uIFJlc2VhcmNoICAgICAgICAgICAg ICAgaHR0cHM6Ly9nc2kuZGUKIHN0ZDo6ZXhwZXJpbWVudGFsOjpzaW1kICAgICAgICAgICAgICBo dHRwczovL2dpdGh1Yi5jb20vVmNEZXZlbC9zdGQtc2ltZArilIDilIDilIDilIDilIDilIDilIDi lIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDi lIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDi lIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDilIDi lIDilIDilIDilIDilIDilIDilIDilIDilIDilIA= --nextPart3179372.TO5rdG3zkT Content-Disposition: inline; filename="0001-c-family-Add-__builtin_assoc_barrier.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="utf-8"; name="0001-c-family-Add-__builtin_assoc_barrier.patch" diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 681fcc972f4..c62a6398a47 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -384,6 +384,7 @@ const struct c_common_resword c_common_reswords[] = { "__builtin_convertvector", RID_BUILTIN_CONVERTVECTOR, 0 }, { "__builtin_has_attribute", RID_BUILTIN_HAS_ATTRIBUTE, 0 }, { "__builtin_launder", RID_BUILTIN_LAUNDER, D_CXXONLY }, + { "__builtin_assoc_barrier", RID_BUILTIN_ASSOC_BARRIER, 0 }, { "__builtin_shuffle", RID_BUILTIN_SHUFFLE, 0 }, { "__builtin_shufflevector", RID_BUILTIN_SHUFFLEVECTOR, 0 }, { "__builtin_tgmath", RID_BUILTIN_TGMATH, D_CONLY }, diff --git a/gcc/c-family/c-common.h b/gcc/c-family/c-common.h index 50ca8fb6ebd..f34dc47c2ba 100644 --- a/gcc/c-family/c-common.h +++ b/gcc/c-family/c-common.h @@ -108,7 +108,7 @@ enum rid RID_EXTENSION, RID_IMAGPART, RID_REALPART, RID_LABEL, RID_CHOOSE_EXPR, RID_TYPES_COMPATIBLE_P, RID_BUILTIN_COMPLEX, RID_BUILTIN_SHUFFLE, RID_BUILTIN_SHUFFLEVECTOR, RID_BUILTIN_CONVERTVECTOR, RID_BUILTIN_TGMATH, - RID_BUILTIN_HAS_ATTRIBUTE, + RID_BUILTIN_HAS_ATTRIBUTE, RID_BUILTIN_ASSOC_BARRIER, RID_DFLOAT32, RID_DFLOAT64, RID_DFLOAT128, /* TS 18661-3 keywords, in the same sequence as the TI_* values. */ diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c index 983d65e930c..dcf4a2d7c32 100644 --- a/gcc/c/c-decl.c +++ b/gcc/c/c-decl.c @@ -10557,6 +10557,7 @@ names_builtin_p (const char *name) case RID_BUILTIN_HAS_ATTRIBUTE: case RID_BUILTIN_SHUFFLE: case RID_BUILTIN_SHUFFLEVECTOR: + case RID_BUILTIN_ASSOC_BARRIER: case RID_CHOOSE_EXPR: case RID_OFFSETOF: case RID_TYPES_COMPATIBLE_P: diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c index 9a56e0c04c6..fffd81f4e5b 100644 --- a/gcc/c/c-parser.c +++ b/gcc/c/c-parser.c @@ -8931,6 +8931,7 @@ c_parser_predefined_identifier (c_parser *parser) assignment-expression , assignment-expression, ) __builtin_convertvector ( assignment-expression , type-name ) + __builtin_assoc_barrier ( assignment-expression ) offsetof-member-designator: identifier @@ -10076,6 +10077,25 @@ c_parser_postfix_expression (c_parser *parser) } } break; + case RID_BUILTIN_ASSOC_BARRIER: + { + location_t start_loc = loc; + c_parser_consume_token (parser); + matching_parens parens; + if (!parens.require_open (parser)) + { + expr.set_error (); + break; + } + e1 = c_parser_expr_no_commas (parser, NULL); + mark_exp_read (e1.value); + location_t end_loc = c_parser_peek_token (parser)->get_finish (); + parens.skip_until_found_close (parser); + expr.value = build1_loc (loc, PAREN_EXPR, TREE_TYPE (e1.value), + e1.value); + set_c_expr_source_range (&expr, start_loc, end_loc); + } + break; case RID_AT_SELECTOR: { gcc_assert (c_dialect_objc ()); diff --git a/gcc/cp/cp-objcp-common.c b/gcc/cp/cp-objcp-common.c index ee255732d5a..04522a23eda 100644 --- a/gcc/cp/cp-objcp-common.c +++ b/gcc/cp/cp-objcp-common.c @@ -395,6 +395,7 @@ names_builtin_p (const char *name) case RID_BUILTIN_SHUFFLE: case RID_BUILTIN_SHUFFLEVECTOR: case RID_BUILTIN_LAUNDER: + case RID_BUILTIN_ASSOC_BARRIER: case RID_BUILTIN_BIT_CAST: case RID_OFFSETOF: case RID_HAS_NOTHROW_ASSIGN: diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 62f3465539b..4ee7899ce66 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -7316,6 +7316,7 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p, case RID_BUILTIN_SHUFFLE: case RID_BUILTIN_SHUFFLEVECTOR: case RID_BUILTIN_LAUNDER: + case RID_BUILTIN_ASSOC_BARRIER: { vec *vec; @@ -7358,6 +7359,19 @@ cp_parser_postfix_expression (cp_parser *parser, bool address_p, bool cast_p, } break; + case RID_BUILTIN_ASSOC_BARRIER: + if (vec->length () == 1) + postfix_expression = build1_loc (loc, PAREN_EXPR, + TREE_TYPE ((*vec)[0]), + (*vec)[0]); + else + { + error_at (loc, "wrong number of arguments to " + "%<__builtin_assoc_barrier%>"); + postfix_expression = error_mark_node; + } + break; + case RID_BUILTIN_SHUFFLE: if (vec->length () == 2) postfix_expression diff --git a/gcc/doc/extend.texi b/gcc/doc/extend.texi index 96640ba156f..cb08f830940 100644 --- a/gcc/doc/extend.texi +++ b/gcc/doc/extend.texi @@ -13951,6 +13951,24 @@ int g (int c) @end deftypefn +@deftypefn {Built-in Function} @var{type} __builtin_assoc_barrier (@var{type} @var{expr}) +This built-in represents a re-association barrier for the floating-point +expression @var{expr} with operations following the built-in. The expression +@var{expr} itself can be reordered, and the whole expression @var{expr} can be +reordered with operations after the barrier. The barrier is only relevant when +@code{-fassociative-math} is active, since otherwise floating-point is not +treated as associative. + +@smallexample +float x0 = a + b - b; +float x1 = __builtin_assoc_barrier(a + b) - b; +@end smallexample + +@noindent +means that, with @code{-fassociative-math}, @code{x0} can be optimized to +@code{x0 = a} but @code{x1} cannot. +@end deftypefn + @deftypefn {Built-in Function} {void *} __builtin_assume_aligned (const void *@var{exp}, size_t @var{align}, ...) This function returns its first argument, and allows the compiler to assume that the returned pointer is at least @var{align} bytes diff --git a/gcc/testsuite/c-c++-common/builtin-assoc-barrier-1.c b/gcc/testsuite/c-c++-common/builtin-assoc-barrier-1.c new file mode 100644 index 00000000000..51efb1ab96c --- /dev/null +++ b/gcc/testsuite/c-c++-common/builtin-assoc-barrier-1.c @@ -0,0 +1,24 @@ +/* { dg-do run } */ + +float a = 1.f; +float b = 1.e20f; + +__attribute__((optimize("-ffast-math"))) +float +fast() +{ + return __builtin_assoc_barrier (a + b) - b; +} + +float +normal() +{ + return a + b - b; +} + +int main() +{ + if (fast() != normal()) + __builtin_abort(); + return 0; +} --nextPart3179372.TO5rdG3zkT--