From patchwork Tue Nov 14 11:59:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 164875 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b909:0:b0:403:3b70:6f57 with SMTP id t9csp1805733vqg; Tue, 14 Nov 2023 03:59:34 -0800 (PST) X-Google-Smtp-Source: AGHT+IFemv6esbvHdm4THxU1D8U/YO4XNb7uT8PBoQp0H7NupAWRtatyBdAaGrVgMArKPfPHRLhq X-Received: by 2002:a05:6358:882c:b0:169:845b:3441 with SMTP id hv44-20020a056358882c00b00169845b3441mr2118665rwb.22.1699963173838; Tue, 14 Nov 2023 03:59:33 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1699963173; cv=pass; d=google.com; s=arc-20160816; b=gfVsMV+F0lttF3KP2h9YN6iQw5+lKB+sN+voROgOp33sG2DiWVrDj9AW9JLc2CT5gt fveL5ADG7PD/SPB8o5JVAOZecV21eDRPZDR62+3PqEBiGdCswR7PQ83fsd4DZBm7OyTj MFmIh9+KjNn3D78J2mb1htXj++9/RGRRocqi8xGlr58v6e0RrIzdWP8Kv5FREQb1IuQ1 DVgVNuydgvdxcywzNBnxJDFhZBfx39KNgnB1RQfvvZPqpXrnH72Gyn+Y+dL8s74ryFQ2 80Y7Z/qf/RPsdDhf1TaUD26lsCslTjPID/sYKbMltteTkbZd72aqma1tbjhMy2lhHww1 Qp3A== 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=wJOIHM5g2Tuo/lbHrVPfYbUoTzPT2iR/yIgWD42Xjlk=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=cbvPAvXH/AqHYDLUoAr5JyqhBMi/YhSxBC4GyyW8D5WKGusL9Q1vEo4iPB5H9o/i0h NUc9+ZfSuQJQpWfQ4Fm1TrhLuvGjhWhG9Hl7MVoubXF4MEn2Mv3KDOZ6nPIVfu8XQdLf /q89iAxr7nOwOBaycpAY90fdwyXnwqHPTAqhai5L1jqE7GdQhYJqKbrIsTLxe2lj3SmJ sIqOpL45MqMXZwKkkn6GjFik2CuyCeJBMr9kWZ7BT0dIkgggXVQb0Jkyeo433Xgvin+g qL2LXEoidb6flxV56alAlVB/CNxrLfcrnS397V/wt5T7ZZVPB4/luFvu6V4iXbla0sQY 3nxw== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@suse.de header.s=susede2_rsa header.b=IGiI7oPo; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b="DSsHtMN/"; 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 u13-20020ac858cd000000b0041243a5cf43si6364582qta.593.2023.11.14.03.59.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Nov 2023 03:59:33 -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=IGiI7oPo; dkim=neutral (no key) header.i=@suse.de header.s=susede2_ed25519 header.b="DSsHtMN/"; 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 833533857342 for ; Tue, 14 Nov 2023 11:59:33 +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 [IPv6:2001:67c:2178:6::1d]) by sourceware.org (Postfix) with ESMTPS id 4ACA6385842A for ; Tue, 14 Nov 2023 11:59:08 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4ACA6385842A 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 4ACA6385842A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2001:67c:2178:6::1d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699963151; cv=none; b=yCWLk12WQdtk1FiQ0oleCig5hi1U8CyXy0N4vIwuXIDlB5iXnOVeRERxd5MqmJOZiAHg1Nv+R/Kf0mTCZKePc0cr/FoBO0vJCHexXCnr4SFjNFiLTOT86gsStQwF0V5jHzoeaaB+UJCbkxeSayPbAnEmcDkjvRcZsFKRHE+qkWQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699963151; c=relaxed/simple; bh=VB8KQJEdR5wlURl+baJqyNkkPOrORyFMtiXmjlrkzRU=; h=DKIM-Signature:DKIM-Signature:Date:From:To:Subject:MIME-Version; b=qyDpOH3D6vcmtdfdlPOf/veRH4h0gccoGrdoWVgEZWtElVAeOs5c3yJroY6AJUMNuSMXZfuOl91UagwuaS59VpXi2oaSU1Y3AFVO85goTgFbpteHVndOLjfKbGdHZSv/wBM/0huoCQzd4gFK+0oYokQT41Cq/qxOt4MNOxTSbQ4= 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 EACF71F86A for ; Tue, 14 Nov 2023 11:59:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1699963144; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=wJOIHM5g2Tuo/lbHrVPfYbUoTzPT2iR/yIgWD42Xjlk=; b=IGiI7oPoYjMSYLA4bTAvnP2kgdiCuOCMup+oYBAumqrXTwFMHLQ0CMc3BOwf+aWKt2MZDo a+ljJic91hI9hns+a23aSNAE5pjdLYvdy1+HfRvzdslThzHj4puJrSE8/+RXlrm2DcSaYZ YHIOmqDEdCFkyFJyX4sf17SnQd2afyo= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1699963144; h=from:from:reply-to:date:date:to:to:cc:mime-version:mime-version: content-type:content-type; bh=wJOIHM5g2Tuo/lbHrVPfYbUoTzPT2iR/yIgWD42Xjlk=; b=DSsHtMN/dw4+NElRKiDc/vjFZHlY1IWCncHNtreR2Ln62hvesAZR4YV3SJ8igxficOERuv vVT8iAaX5uuIMTAA== 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 D0AD12D352 for ; Tue, 14 Nov 2023 11:59:04 +0000 (UTC) Date: Tue, 14 Nov 2023 11:59:04 +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-Spam-Level: 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: rspamd2 X-Spamd-Result: default: False [-0.01 / 50.00]; ARC_NA(0.00)[]; FROM_HAS_DN(0.00)[]; RWL_MAILSPIKE_GOOD(0.00)[149.44.160.134:from]; TO_MATCH_ENVRCPT_ALL(0.00)[]; NEURAL_HAM_LONG(-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(0.60)[~all:c]; RCPT_COUNT_ONE(0.00)[1]; MISSING_MID(2.50)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; MX_GOOD(-0.01)[]; NEURAL_HAM_SHORT(-1.00)[-1.000]; DMARC_NA(0.20)[suse.de]; VIOLATED_DIRECT_SPF(3.50)[]; RCVD_NO_TLS_LAST(0.10)[]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.20)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; BAYES_HAM(-3.00)[100.00%] X-Spam-Score: -0.01 X-Rspamd-Queue-Id: EACF71F86A 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: <20231114115933.833533857342@sourceware.org> X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1782540584848990832 X-GMAIL-MSGID: 1782540584848990832 We currently distribute for (c = 2; c; c--) for (e = 0; e < 2; e++) { d[c] = b = d[c + 1]; d[c + 1].a = 0; } in a wrong way where the inner loop zero dependence distance should make us preserve stmt execution order. We fail to do so since we only look for a fully zero distance vector rather than looking at the innermost loop distance. This is somewhat similar to PR87022 where we instead looked at the outermost loop distance and changed this to what we do now. The following switches us to look at the innermost loop distance. Bootstrapped and tested on x86_64-unknown-linux-gnu. I'm double-checking because of the very high number of FAILs currently. Richard. PR tree-optimization/112281 * tree-loop-distribution.cc (pg_add_dependence_edges): Preserve stmt order when the innermost loop has exact overlap. * gcc.dg/torture/pr112281.c: New testcase. --- gcc/testsuite/gcc.dg/torture/pr112281.c | 19 +++++++++++++++++++ gcc/tree-loop-distribution.cc | 7 ++++--- 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/torture/pr112281.c diff --git a/gcc/testsuite/gcc.dg/torture/pr112281.c b/gcc/testsuite/gcc.dg/torture/pr112281.c new file mode 100644 index 00000000000..3f0a61a9376 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr112281.c @@ -0,0 +1,19 @@ +/* { 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/tree-loop-distribution.cc b/gcc/tree-loop-distribution.cc index 8abfa992070..8e92af61c57 100644 --- a/gcc/tree-loop-distribution.cc +++ b/gcc/tree-loop-distribution.cc @@ -2163,9 +2163,10 @@ loop_distribution::pg_add_dependence_edges (struct graph *rdg, int dir, gcc.dg/tree-ssa/pr94969.c. */ if (DDR_NUM_DIST_VECTS (ddr) != 1) this_dir = 2; - /* If the overlap is exact preserve stmt order. */ - else if (lambda_vector_zerop (DDR_DIST_VECT (ddr, 0), - DDR_NB_LOOPS (ddr))) + /* If the dependence distance is zero in the innermost + loop preserve stmt order. */ + else if (DDR_DIST_VECT (ddr, 0) + [DDR_LOOP_NEST (ddr).length () - 1] == 0) ; /* Else as the distance vector is lexicographic positive swap the dependence direction. */