From patchwork Mon Nov 20 14:00:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 167148 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9910:0:b0:403:3b70:6f57 with SMTP id i16csp2216695vqn; Mon, 20 Nov 2023 06:00:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IHjgHjCwPkSy+y8gJUYvoCC8OvUy2On/YMMR//bzn0jxQ18lEft1tqUnZA5SGy+7rT4yTBH X-Received: by 2002:ac8:5d07:0:b0:418:eee:15ed with SMTP id f7-20020ac85d07000000b004180eee15edmr10615405qtx.64.1700488847599; Mon, 20 Nov 2023 06:00:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1700488847; cv=pass; d=google.com; s=arc-20160816; b=LckcVy5MRdFBvRmh/NqyYcFBSxmQBXrXXn3RmkjJz1+vu980cVxJFwUmepKOOMFOdb enIR8I2yjeFYsL/GkgJLzABe/jymjEZTE++NDW0nUS4ez05GZ9KJ23eJaixxYhoalT6s X071fUPPThGNi2R80DFaCNb/18vyOb+MXerGEVlUPwtx6osE3qxS4BwrPxfRio3HW60t uYxT5C7h8JVkEtsmutEPUcuJqzJzXUfw3aa5uD35rwr4pacNTR9fcl/lt2CXpr84wKXK 2A0Ilq5Lcla85xVg5ikurRMZ1bUHdKX9DNot7kYYx4k3dwy5GmMqh7hAVmzvPcHc4Lu1 oYIA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:errors-to:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:mime-version :user-agent:subject:to:from:date:dkim-signature:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=kRN3nbA8zi6myWmjAxh/N56adijLJ0BBTk8rI5R7npk=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=M5JEbfTBpl6eK4O6UhoHhD1AHc89Av2xfRQjvz35F8nZVwOZifYsTlTnoKjYGLCTsP C6VzfJsJnEJl18qtVKRF2iA/AIUNhDWPzq0csK8GmhOU+kylHRa4NiJdAhpMwVxWzWS1 gxKUamN4V6zCnsWA2ytKHPsTcWNvhsKmAkSSbMyDqrDGO5WKwOUhABR/UZpu0jECZ5UN wbQ+G6ZG6sIyz6I5orVHqLqhBl12UbziZj1kATdnQhoSmhAnWCpTb3uZ95FvAwo2nH98 MV4BD5RVUojjSTGiooJizLsce7Mv2bpursmS2dXrmWDHw7v5yr/qpt6ISlR8eriCr+B6 Io/w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=OnQaZ4BT; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1); 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id v4-20020ac85784000000b004198b50a2c1si7583388qta.520.2023.11.20.06.00.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Nov 2023 06:00:47 -0800 (PST) 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=OnQaZ4BT; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519; arc=pass (i=1); 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 CEB293882060 for ; Mon, 20 Nov 2023 14:00: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.220.29]) by sourceware.org (Postfix) with ESMTPS id B6E543857C4B for ; Mon, 20 Nov 2023 14:00:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B6E543857C4B 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 B6E543857C4B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=195.135.220.29 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700488812; cv=none; b=RuGKfa+sXIY1DELj71ScGKyCauJVY8manKixTxdc9hoc0EGcOqXpFpr2yTVuuzILth0z5O3X7RagSEhbPm3/2mFb/bFI3LqUnOp6SLOYmrSSjNlz4u4R1QI/4AI8l+NP1TsflGevPqXmXZ8h/t/n1us00BE9U6ei2jGVgottvpM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1700488812; c=relaxed/simple; bh=f79PhFVKuc4fssJ11QC6jkMua8+H+Qz4e+eZ/cqfzAE=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:MIME-Version; b=YMMgL2zmnNu0vBuQhYGbhw4an5egU7qtlG7yC1hf17YbHu8Zd2K1SxluxrIVOH89RB3ubKWFaFvOoMtvjMz5SaY+KqlW19s4lXveJqGc/KzoomBJLW9xgy4a90TZ+VMuT+yq8wTs+5n5xGXjPZe/WXPgKHMI3DF5GEh/IGpxApc= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id 8EEF81F891 for ; Mon, 20 Nov 2023 14:00:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1700488809; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=kRN3nbA8zi6myWmjAxh/N56adijLJ0BBTk8rI5R7npk=; b=OnQaZ4BTWmmdL3s/jHc2ogNWR9CuyuuhwXz06R9ZSmGgD0GeFAHCiv/fbHGgflunc1WOA2 sUYgcP3CEk62gMMheGHrdk2ckjvQqDON91rMZoqO2JdCvAIaeIG+yaZLMyrZp7D6u5ziuC w63zFxGUsXjt71r5ad92QiFVyRUpBWs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1700488809; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=kRN3nbA8zi6myWmjAxh/N56adijLJ0BBTk8rI5R7npk=; b=vyepJvJnQZCKduQVZykwsV/ewzISH1tB50FkIpjwRx7MKnF7mBA7jMhzXi9A3hcDknrBk0 xXgqzeGOesOHhbBA== Received: from wotan.suse.de (wotan.suse.de [10.160.0.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id 8C7952C23C for ; Mon, 20 Nov 2023 14:00:09 +0000 (UTC) Date: Mon, 20 Nov 2023 14:00:09 +0000 (UTC) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/112281 - loop distribution and zero dependence distances User-Agent: Alpine 2.22 (LSU 394 2020-01-19) MIME-Version: 1.0 X-Spamd-Bar: ++++++++++++++++ Authentication-Results: smtp-out2.suse.de; dkim=none; dmarc=none; spf=softfail (smtp-out2.suse.de: 149.44.160.134 is neither permitted nor denied by domain of rguenther@suse.de) smtp.mailfrom=rguenther@suse.de X-Rspamd-Server: rspamd1 X-Spamd-Result: default: False [16.49 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; RWL_MAILSPIKE_GOOD(-1.00)[149.44.160.134:from]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_SPAM_SHORT(3.00)[1.000]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[gcc-patches@gcc.gnu.org]; TO_DN_NONE(0.00)[]; R_SPF_SOFTFAIL(4.60)[~all:c]; RCPT_COUNT_ONE(0.00)[1]; CLAM_VIRUS_FAIL(0.00)[failed to scan and retransmits exceed]; MISSING_MID(2.50)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MX_GOOD(-0.01)[]; NEURAL_SPAM_LONG(3.50)[1.000]; DMARC_NA(1.20)[suse.de]; VIOLATED_DIRECT_SPF(3.50)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_NO_TLS_LAST(0.10)[]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(2.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: 16.49 X-Rspamd-Queue-Id: 8EEF81F891 X-Spam-Status: No, score=-10.7 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+ouuuleilei=gmail.com@gcc.gnu.org Message-Id: <20231120140036.CEB293882060@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1783091793898970938 X-GMAIL-MSGID: 1783091793898970938 The following fixes an omission in dependence testing for loop distribution. When the overall dependence distance is not zero but the dependence direction in the innermost common loop is = there is a conflict between the partitions and we have to merge them. Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. PR tree-optimization/112281 * tree-loop-distribution.cc (loop_distribution::pg_add_dependence_edges): For = in the innermost common loop record a partition conflict. * gcc.dg/torture/pr112281-1.c: New testcase. * gcc.dg/torture/pr112281-2.c: Likewise. --- gcc/testsuite/gcc.dg/torture/pr112281-1.c | 18 ++++++++++++++++++ gcc/testsuite/gcc.dg/torture/pr112281-2.c | 18 ++++++++++++++++++ gcc/tree-loop-distribution.cc | 18 ++++++++++++++---- 3 files changed, 50 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr112281-1.c create mode 100644 gcc/testsuite/gcc.dg/torture/pr112281-2.c diff --git a/gcc/testsuite/gcc.dg/torture/pr112281-1.c b/gcc/testsuite/gcc.dg/torture/pr112281-1.c new file mode 100644 index 00000000000..711f5663195 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr112281-1.c @@ -0,0 +1,18 @@ +/* { dg-do run } */ +/* { dg-additional-options "-ftree-loop-distribution" } */ + +struct { + int : 8; + int a; +} b, d[4] = {{0}, {0}, {0}, {5}}; +int c, e; +int main() { + for (c = 2; c; c--) + for (e = 0; e < 2; e++) { + d[c] = b = d[c + 1]; + d[c + 1].a = 0; + } + if (b.a != 0) + __builtin_abort(); + return 0; +} diff --git a/gcc/testsuite/gcc.dg/torture/pr112281-2.c b/gcc/testsuite/gcc.dg/torture/pr112281-2.c new file mode 100644 index 00000000000..d7671e3322b --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr112281-2.c @@ -0,0 +1,18 @@ +/* { dg-do run } */ +/* { dg-additional-options "-ftree-loop-distribution" } */ + +struct { + int : 8; + int a; +} b, d[4] = {{5}, {0}, {0}, {0}}; +int c, e; +int main() { + for (c = 0; c < 2; c++) + for (e = 0; e < 2; e++) { + d[c + 1] = b = d[c]; + d[c].a = 0; + } + if (b.a != 0) + __builtin_abort(); + return 0; +} diff --git a/gcc/tree-loop-distribution.cc b/gcc/tree-loop-distribution.cc index ffca535064b..95c1eea65be 100644 --- a/gcc/tree-loop-distribution.cc +++ b/gcc/tree-loop-distribution.cc @@ -2155,9 +2155,6 @@ loop_distribution::pg_add_dependence_edges (struct graph *rdg, int dir, } else if (DDR_ARE_DEPENDENT (ddr) == NULL_TREE) { - if (DDR_REVERSED_P (ddr)) - this_dir = -this_dir; - /* Known dependences can still be unordered througout the iteration space, see gcc.dg/tree-ssa/ldist-16.c and gcc.dg/tree-ssa/pr94969.c. */ @@ -2170,7 +2167,20 @@ loop_distribution::pg_add_dependence_edges (struct graph *rdg, int dir, /* Else as the distance vector is lexicographic positive swap the dependence direction. */ else - this_dir = -this_dir; + { + if (DDR_REVERSED_P (ddr)) + this_dir = -this_dir; + this_dir = -this_dir; + + /* When then dependence distance of the innermost common + loop of the DRs is zero we have a conflict. */ + auto l1 = gimple_bb (DR_STMT (dr1))->loop_father; + auto l2 = gimple_bb (DR_STMT (dr2))->loop_father; + int idx = index_in_loop_nest (find_common_loop (l1, l2)->num, + DDR_LOOP_NEST (ddr)); + if (DDR_DIST_VECT (ddr, 0)[idx] == 0) + this_dir = 2; + } } else this_dir = 0;