From patchwork Mon Dec 18 11:50:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 82383 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6F3DF3857C50 for ; Mon, 18 Dec 2023 11:51:36 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) by sourceware.org (Postfix) with ESMTPS id 63843385828F for ; Mon, 18 Dec 2023 11:51:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 63843385828F Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 63843385828F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702900279; cv=none; b=um/NnDaATld2OqRIZDyKA6hKMJT82JmSj86Lsq2YaaM7sVr/ja9PbvKAyFP5k9hYUy87FP/nYoLbyM3GX5SbjsPFegEQKR4uGBglccUQdcU+TLOCBn2GndzQpsektD5La9N5XnldHcDfh+cAPGL++u+q/AcEZMC5bzXh2N4IHLg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702900279; c=relaxed/simple; bh=mx12NmCOlCBspwIdr+ZU4WAz1ZFPwzU4XSJ9zAwTYOE=; h=DKIM-Signature:DKIM-Signature:DKIM-Signature:DKIM-Signature:Date: From:To:Subject:MIME-Version; b=o2THYT3Fp1tmG+MMzsO7NOuNmF6bor3kkuHuQZ+/NermDO19YzCPhi/1fHC9RMQ/w5xJgMaIkOA5vGNz1h6ilMeYV9Ca67HB8yrLKAEm3UxRCkWRDdwkEixBZ0mcYdSjajzCs9NGAu/aOV5gf1OOyVInwZ89tp0LsKssrKb9MTc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from [10.168.4.150] (unknown [10.168.4.150]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 307151FDD4 for ; Mon, 18 Dec 2023 11:51:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702900276; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=OJyIlnHz3Qru4ffgU8mlVCGDBWH5y+hQ1I8qqO6t8gs=; b=wtbJn6ygeSbSWLxEJ2hIPEME4s9fAHLQI4vg+FvwENR9PPOoth8YzUZTu92x7B18zGze8z Y0pxiOxvBWvLSP8Vq+xoZ6czyMCica+Fmpp4OwEeVvt09MMMMxVtlo8DxWAoGzhXcaqrl0 q7bigB+8E30zzDFUmoYKcTK6c8gxOeY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702900276; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=OJyIlnHz3Qru4ffgU8mlVCGDBWH5y+hQ1I8qqO6t8gs=; b=zb1k2tNSiOP7dvd8yJ/ZLig9TJr0dAqWHay4xkZCf/b+WLXZ7XQiPniok+2pi+zbpImLmk bJmyEIMQ3jBDLkCw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1702900276; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=OJyIlnHz3Qru4ffgU8mlVCGDBWH5y+hQ1I8qqO6t8gs=; b=wtbJn6ygeSbSWLxEJ2hIPEME4s9fAHLQI4vg+FvwENR9PPOoth8YzUZTu92x7B18zGze8z Y0pxiOxvBWvLSP8Vq+xoZ6czyMCica+Fmpp4OwEeVvt09MMMMxVtlo8DxWAoGzhXcaqrl0 q7bigB+8E30zzDFUmoYKcTK6c8gxOeY= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1702900276; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=OJyIlnHz3Qru4ffgU8mlVCGDBWH5y+hQ1I8qqO6t8gs=; b=zb1k2tNSiOP7dvd8yJ/ZLig9TJr0dAqWHay4xkZCf/b+WLXZ7XQiPniok+2pi+zbpImLmk bJmyEIMQ3jBDLkCw== Date: Mon, 18 Dec 2023 12:50:06 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] c/111975 - GIMPLE FE dumping and parsing of TARGET_MEM_REF MIME-Version: 1.0 Authentication-Results: smtp-out2.suse.de; none X-Spam-Score: 2.31 X-Spamd-Result: default: False [2.31 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-0.09)[-0.092]; MIME_GOOD(-0.10)[text/plain]; TO_DN_NONE(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; MISSING_MID(2.50)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_SPAM_SHORT(3.00)[0.999]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_COUNT_ZERO(0.00)[0]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; BAYES_HAM(-3.00)[100.00%] X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, MISSING_MID, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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+patchwork=sourceware.org@gcc.gnu.org Message-Id: <20231218115136.6F3DF3857C50@sourceware.org> The following adds dumping of TARGET_MEM_REF in -gimple form and adds parsing of it to the GIMPLE FE. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR c/111975 gcc/c/ * gimple-parser.cc (c_parser_gimple_postfix_expression): Parse TARGET_MEM_REF extended operands for __MEM. gcc/testsuite/ * gcc.dg/gimplefe-52.c: New testcase. --- gcc/c/gimple-parser.cc | 66 ++++++++++++++++++++++++++---- gcc/testsuite/gcc.dg/gimplefe-52.c | 21 ++++++++++ gcc/tree-pretty-print.cc | 24 ++++++++++- 3 files changed, 101 insertions(+), 10 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/gimplefe-52.c diff --git a/gcc/c/gimple-parser.cc b/gcc/c/gimple-parser.cc index 72bff1cb305..87ed336e45d 100644 --- a/gcc/c/gimple-parser.cc +++ b/gcc/c/gimple-parser.cc @@ -1487,9 +1487,12 @@ c_parser_gimple_postfix_expression (gimple_parser &parser) location_t loc = c_parser_peek_token (parser)->location; c_parser_consume_token (parser); tree type = c_parser_gimple_typespec (parser); - struct c_expr ptr; + struct c_expr ptr, alias_off, step, index, index2; ptr.value = error_mark_node; - tree alias_off = NULL_TREE; + alias_off.value = NULL_TREE; + step.value = NULL_TREE; + index.value = NULL_TREE; + index2.value = NULL_TREE; if (c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>")) { tree alias_type = NULL_TREE; @@ -1525,12 +1528,52 @@ c_parser_gimple_postfix_expression (gimple_parser &parser) if (c_parser_next_token_is (parser, CPP_PLUS)) { c_parser_consume_token (parser); - alias_off - = c_parser_gimple_postfix_expression (parser).value; - alias_off = fold_convert (alias_type, alias_off); + alias_off = c_parser_gimple_postfix_expression (parser); + } + if (c_parser_next_token_is (parser, CPP_MULT)) + { + std::swap (index, alias_off); + c_parser_consume_token (parser); + step = c_parser_gimple_postfix_expression (parser); + } + else if (c_parser_next_token_is (parser, CPP_PLUS)) + { + c_parser_consume_token (parser); + index = c_parser_gimple_postfix_expression (parser); + if (c_parser_next_token_is (parser, CPP_MULT)) + { + c_parser_consume_token (parser); + step = c_parser_gimple_postfix_expression (parser); + } + else + std::swap (index, index2); + } + else if (alias_off.value + && TREE_CODE (alias_off.value) != INTEGER_CST) + std::swap (alias_off, index2); + if (c_parser_next_token_is (parser, CPP_PLUS)) + { + c_parser_consume_token (parser); + index2 = c_parser_gimple_postfix_expression (parser); + } + if (alias_off.value) + { + if (TREE_CODE (alias_off.value) != INTEGER_CST) + error_at (alias_off.get_start (), + "expected constant offset for %<__MEM%> " + "operand"); + alias_off.value = fold_convert (alias_type, + alias_off.value); + } + else + alias_off.value = build_int_cst (alias_type, 0); + if (step.value) + { + if (TREE_CODE (step.value) != INTEGER_CST) + error_at (step.get_start (), + "expected constant step for %<__MEM%> " + "operand"); } - if (! alias_off) - alias_off = build_int_cst (alias_type, 0); c_parser_skip_until_found (parser, CPP_CLOSE_PAREN, "expected %<)%>"); } @@ -1539,8 +1582,13 @@ c_parser_gimple_postfix_expression (gimple_parser &parser) c_parser_set_error (parser, false); return expr; } - expr.value = build2_loc (loc, MEM_REF, - type, ptr.value, alias_off); + if (index.value || step.value || index2.value) + expr.value = build5_loc (loc, TARGET_MEM_REF, + type, ptr.value, alias_off.value, + index.value, step.value, index2.value); + else + expr.value = build2_loc (loc, MEM_REF, + type, ptr.value, alias_off.value); break; } else if (strcmp (IDENTIFIER_POINTER (id), "__VIEW_CONVERT") == 0) diff --git a/gcc/testsuite/gcc.dg/gimplefe-52.c b/gcc/testsuite/gcc.dg/gimplefe-52.c new file mode 100644 index 00000000000..8b85aacd6b3 --- /dev/null +++ b/gcc/testsuite/gcc.dg/gimplefe-52.c @@ -0,0 +1,21 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple" } */ + +int x; + +float __GIMPLE () +foo (int * p, __UINTPTR_TYPE__ idx, __UINTPTR_TYPE__ idx2) +{ + float f; + float D1800; + unsigned int D1799; + + D1799 = __MEM ((char *)p + 1 + idx * _Literal (__SIZETYPE__) 2); + __MEM ((char *)&f + 0xfffffffffffffffe) = D1799; + __MEM (&x + idx2) = 1; + __MEM (p + idx * _Literal (__SIZETYPE__) 1) = 1; + __MEM (&x + 2 + idx2) = 1; + __MEM ((char *)&x + 4 + idx * _Literal (__SIZETYPE__) 4 + idx2) = 1; + D1800 = f; + return D1800; +} diff --git a/gcc/tree-pretty-print.cc b/gcc/tree-pretty-print.cc index 68857ae1cdf..86a7d162eae 100644 --- a/gcc/tree-pretty-print.cc +++ b/gcc/tree-pretty-print.cc @@ -1687,7 +1687,9 @@ dump_omp_atomic_memory_order (pretty_printer *pp, enum omp_memory_order mo) static void dump_mem_ref (pretty_printer *pp, tree node, int spc, dump_flags_t flags) { - if (TREE_CODE (node) == MEM_REF && (flags & TDF_GIMPLE)) + if ((TREE_CODE (node) == MEM_REF + || TREE_CODE (node) == TARGET_MEM_REF) + && (flags & TDF_GIMPLE)) { pp_string (pp, "__MEM <"); dump_generic_node (pp, TREE_TYPE (node), @@ -1716,6 +1718,26 @@ dump_mem_ref (pretty_printer *pp, tree node, int spc, dump_flags_t flags) dump_generic_node (pp, TREE_OPERAND (node, 1), spc, flags | TDF_SLIM, false); } + if (TREE_CODE (node) == TARGET_MEM_REF) + { + if (TREE_OPERAND (node, 2)) + { + /* INDEX * STEP */ + pp_string (pp, " + "); + dump_generic_node (pp, TREE_OPERAND (node, 2), + spc, flags | TDF_SLIM, false); + pp_string (pp, " * "); + dump_generic_node (pp, TREE_OPERAND (node, 3), + spc, flags | TDF_SLIM, false); + } + if (TREE_OPERAND (node, 4)) + { + /* INDEX2 */ + pp_string (pp, " + "); + dump_generic_node (pp, TREE_OPERAND (node, 4), + spc, flags | TDF_SLIM, false); + } + } pp_right_paren (pp); } else if (TREE_CODE (node) == MEM_REF