From patchwork Tue Sep 19 10:39:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 141813 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp3279200vqi; Tue, 19 Sep 2023 03:39:35 -0700 (PDT) X-Google-Smtp-Source: AGHT+IErkVrWEhRfr7/xtGMa7B6mahsDHRFQlpBJlfHqpTy/mda+2Qtvdkwevo3JP7z6bTgi3mUF X-Received: by 2002:a17:906:4c2:b0:9a1:bee8:9252 with SMTP id g2-20020a17090604c200b009a1bee89252mr8995326eja.29.1695119975688; Tue, 19 Sep 2023 03:39:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695119975; cv=none; d=google.com; s=arc-20160816; b=xyp0JG84a9glR83CBUztlwha6W8GKlF4bYSlqS/cw/2I/N8hAS8WAjAtLS9DVVUZdh XJ5i8EO3iOHMIV/56BZl2a6tikrkqhBrSADeqx1dAoxk+IZl7z+b74dInJyVqRaewc/q rgf/8RA6gRzTGkgSzKhFPtmgPk1XhyCQ1ctViVEpbp0jZr+XxlSbT+w6LgRVLJjsqoc+ dYTXTcenNQe6ytvo1KpQrM3vg/gerog9T++DrHkcbwbkx1XJZiwc32EBzRxm+6J67hsy 5IuE6H3JW7gwln6mAhNwGE75QPF2lVtZ6RUSFg111wqYtSIKVDu88TWoUpbzeVMrMzRS XsKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:message-id:mime-version:subject :to:from:date:dkim-signature:dkim-signature:dmarc-filter :delivered-to; bh=DBhzRSzlLlHmNMILHz4Mw9hg2GqNNtBatOky1SKbCmc=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=znqpnVfJXyhacFu9Rg4gxC9/0VbnGTaXhuGoDOwJO5oFfn3TbilWSv26Ghadxh6yt1 bz+MwLd/OSE+YGd9juHQuzcNfWJ/5SC5XUszOqyBYrfWtO85VRklvgQlU9qwVcd0InQq /IkWdUV/nfwMZpZJH9qzturQUfSZ/eW4B33byR/KwFSmrzPjkNpAlF++R4RVXyxtU7L0 Ct7UOj0alLB1KevDUqyRDKC7M8XkaV5sz/QJyeKoMnnHeRWRwQs6H9iTh8Ktqw8P6eOI 27iIgnSgeFzBu3t16b4FaPBQiJTwGgRRnbizeVP0484n8/6akN438EoVP4NQAanBegq3 5NkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=0fXDycNC; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from server2.sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id fy13-20020a170906b7cd00b009ad7f125733si9894853ejb.770.2023.09.19.03.39.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Sep 2023 03:39:35 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=0fXDycNC; dkim=neutral (no key) header.i=@suse.de; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=suse.de Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 82086385770A for ; Tue, 19 Sep 2023 10:39:34 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id D9C9E3858D32 for ; Tue, 19 Sep 2023 10:39:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D9C9E3858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id BC7FD22910 for ; Tue, 19 Sep 2023 10:39:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1695119940; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=DBhzRSzlLlHmNMILHz4Mw9hg2GqNNtBatOky1SKbCmc=; b=0fXDycNCcm+7IevQcqlbN/0rEY9nzdNOeQUahIlzOJGpNX2jC6ae6neg7WGzxqoztUyE8U oycE1TfXJzpZPsd2VfdMDSpXX+rCbbY7AV2CCDfpoJWOL/aK64BGnDZKCK0lS/hgyXb6io 8RIcI42EqIhX0O0W6pVhQSmyWz2KXDE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1695119940; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type; bh=DBhzRSzlLlHmNMILHz4Mw9hg2GqNNtBatOky1SKbCmc=; b=qWcAg318ru/9ivZYAggOMShb5CR+bMz49Q/vm3p/SObltDvxyRNX0Ss2DUNuxMJLLv24Tf Gvb38K2YZqer2aBA== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id A8F7D13458 for ; Tue, 19 Sep 2023 10:39:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id h835J0R6CWW/UAAAMHmgww (envelope-from ) for ; Tue, 19 Sep 2023 10:39:00 +0000 Date: Tue, 19 Sep 2023 12:39:00 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] c/111468 - add unordered compare and pointer diff to GIMPLE FE parsing MIME-Version: 1.0 Message-Id: <20230919103900.A8F7D13458@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777462123832364328 X-GMAIL-MSGID: 1777462123832364328 The following adds __UN{LT,LE,GT,GE,EQ}, __UNORDERED and __ORDERED operator parsing support and support for parsing - as POINTER_DIFF_EXPR. Bootstrapped and tested on x86_64-unknown-linux-gnu, will push later. PR c/111468 gcc/c/ * gimple-parser.cc (c_parser_gimple_binary_expression): Add return type argument. (c_parser_gimple_statement): Adjust. (c_parser_gimple_paren_condition): Likewise. (c_parser_gimple_binary_expression): Use passed in return type, add support for - as POINTER_DIFF_EXPR, __UN{LT,LE,GT,GE,EQ}, __UNORDERED and __ORDERED. * gcc.dg/gimplefe-50.c: New testcase. * gcc.dg/gimplefe-51.c: Likewise. --- gcc/c/gimple-parser.cc | 72 +++++++++++++++++++++--------- gcc/testsuite/gcc.dg/gimplefe-50.c | 27 +++++++++++ gcc/testsuite/gcc.dg/gimplefe-51.c | 12 +++++ 3 files changed, 91 insertions(+), 20 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/gimplefe-50.c create mode 100644 gcc/testsuite/gcc.dg/gimplefe-51.c diff --git a/gcc/c/gimple-parser.cc b/gcc/c/gimple-parser.cc index cc3a8899d97..9cf29701c06 100644 --- a/gcc/c/gimple-parser.cc +++ b/gcc/c/gimple-parser.cc @@ -108,7 +108,7 @@ gimple_parser::push_edge (int src, int dest, int flags, static bool c_parser_gimple_compound_statement (gimple_parser &, gimple_seq *); static void c_parser_gimple_label (gimple_parser &, gimple_seq *); static void c_parser_gimple_statement (gimple_parser &, gimple_seq *); -static struct c_expr c_parser_gimple_binary_expression (gimple_parser &); +static struct c_expr c_parser_gimple_binary_expression (gimple_parser &, tree); static struct c_expr c_parser_gimple_unary_expression (gimple_parser &); static struct c_expr c_parser_gimple_postfix_expression (gimple_parser &); static struct c_expr c_parser_gimple_postfix_expression_after_primary @@ -869,7 +869,7 @@ c_parser_gimple_statement (gimple_parser &parser, gimple_seq *seq) return; } - rhs = c_parser_gimple_binary_expression (parser); + rhs = c_parser_gimple_binary_expression (parser, TREE_TYPE (lhs.value)); if (lhs.value != error_mark_node && rhs.value != error_mark_node) { @@ -930,7 +930,7 @@ c_parser_gimple_statement (gimple_parser &parser, gimple_seq *seq) */ static c_expr -c_parser_gimple_binary_expression (gimple_parser &parser) +c_parser_gimple_binary_expression (gimple_parser &parser, tree ret_type) { /* Location of the binary operator. */ struct c_expr ret, lhs, rhs; @@ -939,7 +939,6 @@ c_parser_gimple_binary_expression (gimple_parser &parser) lhs = c_parser_gimple_postfix_expression (parser); if (c_parser_error (parser)) return ret; - tree ret_type = TREE_TYPE (lhs.value); switch (c_parser_peek_token (parser)->type) { case CPP_MULT: @@ -958,7 +957,10 @@ c_parser_gimple_binary_expression (gimple_parser &parser) code = PLUS_EXPR; break; case CPP_MINUS: - code = MINUS_EXPR; + if (POINTER_TYPE_P (TREE_TYPE (lhs.value))) + code = POINTER_DIFF_EXPR; + else + code = MINUS_EXPR; break; case CPP_LSHIFT: code = LSHIFT_EXPR; @@ -968,27 +970,21 @@ c_parser_gimple_binary_expression (gimple_parser &parser) break; case CPP_LESS: code = LT_EXPR; - ret_type = boolean_type_node; break; case CPP_GREATER: code = GT_EXPR; - ret_type = boolean_type_node; break; case CPP_LESS_EQ: code = LE_EXPR; - ret_type = boolean_type_node; break; case CPP_GREATER_EQ: code = GE_EXPR; - ret_type = boolean_type_node; break; case CPP_EQ_EQ: code = EQ_EXPR; - ret_type = boolean_type_node; break; case CPP_NOT_EQ: code = NE_EXPR; - ret_type = boolean_type_node; break; case CPP_AND: code = BIT_AND_EXPR; @@ -1006,14 +1002,49 @@ c_parser_gimple_binary_expression (gimple_parser &parser) c_parser_error (parser, "%<||%> not valid in GIMPLE"); return ret; case CPP_NAME: - { - tree id = c_parser_peek_token (parser)->value; - if (strcmp (IDENTIFIER_POINTER (id), "__MULT_HIGHPART") == 0) - { - code = MULT_HIGHPART_EXPR; - break; - } - } + { + tree id = c_parser_peek_token (parser)->value; + if (strcmp (IDENTIFIER_POINTER (id), "__MULT_HIGHPART") == 0) + { + code = MULT_HIGHPART_EXPR; + break; + } + else if (strcmp (IDENTIFIER_POINTER (id), "__UNLT") == 0) + { + code = UNLT_EXPR; + break; + } + else if (strcmp (IDENTIFIER_POINTER (id), "__UNLE") == 0) + { + code = UNLE_EXPR; + break; + } + else if (strcmp (IDENTIFIER_POINTER (id), "__UNGT") == 0) + { + code = UNGT_EXPR; + break; + } + else if (strcmp (IDENTIFIER_POINTER (id), "__UNGE") == 0) + { + code = UNGE_EXPR; + break; + } + else if (strcmp (IDENTIFIER_POINTER (id), "__UNEQ") == 0) + { + code = UNEQ_EXPR; + break; + } + else if (strcmp (IDENTIFIER_POINTER (id), "__UNORDERED") == 0) + { + code = UNORDERED_EXPR; + break; + } + else if (strcmp (IDENTIFIER_POINTER (id), "__ORDERED") == 0) + { + code = ORDERED_EXPR; + break; + } + } /* Fallthru. */ default: /* Not a binary expression. */ @@ -2158,7 +2189,8 @@ c_parser_gimple_paren_condition (gimple_parser &parser) { if (! c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) return error_mark_node; - tree cond = c_parser_gimple_binary_expression (parser).value; + tree cond + = c_parser_gimple_binary_expression (parser, boolean_type_node).value; if (cond != error_mark_node && ! COMPARISON_CLASS_P (cond) && ! CONSTANT_CLASS_P (cond) diff --git a/gcc/testsuite/gcc.dg/gimplefe-50.c b/gcc/testsuite/gcc.dg/gimplefe-50.c new file mode 100644 index 00000000000..03db786b619 --- /dev/null +++ b/gcc/testsuite/gcc.dg/gimplefe-50.c @@ -0,0 +1,27 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple" } */ + +void __GIMPLE (ssa) +foo (float a, float b) +{ + _Bool x; + + __BB(2): + x_3 = a_1(D) __UNLT b_2(D); + x_4 = a_1(D) __UNLE b_2(D); + x_5 = a_1(D) __UNGT b_2(D); + x_6 = a_1(D) __UNGE b_2(D); + x_7 = a_1(D) __UNEQ b_2(D); + x_8 = a_1(D) __UNORDERED b_2(D); + x_9 = a_1(D) __ORDERED b_2(D); + if (a_1(D) __UNEQ b_2(D)) + goto __BB4; + else + goto __BB3; + + __BB(3): + goto __BB4; + + __BB(4): + return; +} diff --git a/gcc/testsuite/gcc.dg/gimplefe-51.c b/gcc/testsuite/gcc.dg/gimplefe-51.c new file mode 100644 index 00000000000..16e69c11228 --- /dev/null +++ b/gcc/testsuite/gcc.dg/gimplefe-51.c @@ -0,0 +1,12 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple" } */ + +__PTRDIFF_TYPE__ __GIMPLE (ssa) +foo (void *p, void *q) +{ + __PTRDIFF_TYPE__ d; + + __BB(2): + d_3 = p_1(D) - q_2(D); + return d_3; +}