From patchwork Thu Jul 1 11:38:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Biener X-Patchwork-Id: 1499506 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=p7WsMBAA; dkim=pass header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=w7tVQKfk; dkim=pass (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=p7WsMBAA; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=w7tVQKfk; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (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 ozlabs.org (Postfix) with ESMTPS id 4GFx914bSpz9sWk for ; Thu, 1 Jul 2021 21:40:21 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BB2D3396E011 for ; Thu, 1 Jul 2021 11:40:18 +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 [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 7DF04382E830 for ; Thu, 1 Jul 2021 11:38:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7DF04382E830 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.de Received: from imap.suse.de (imap-alt.suse-dmz.suse.de [192.168.254.47]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 5465522820; Thu, 1 Jul 2021 11:38:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1625139534; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=LI8MrFbLom0XoWcFm+wUbnTE9zeW2ynrN0Ns0HpEKa0=; b=p7WsMBAAlAx+qTEZ8KJnuBMogBNT41JcJalEMwudQaYNrBtYcxGRdVEFLV/BvQ6nxIX0Jh CZKV1QNgL95L7g7CE2DcrsTAwU70qEkhP38pPtH6XZUnq6SyzuZYW2mZ6rY6WEWRLbqmNC chIYpeS629ufrRCBxU0u6g1LGPxAYtk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1625139534; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=LI8MrFbLom0XoWcFm+wUbnTE9zeW2ynrN0Ns0HpEKa0=; b=w7tVQKfkKV+pb/a24BNRqL/ax7KznPMsoyV83D/SuQHlmtjZ98PF9rE/Pn1OtQ0fbiapmX SH0Pk0C+pby0IvAg== Received: from imap3-int (imap-alt.suse-dmz.suse.de [192.168.254.47]) by imap.suse.de (Postfix) with ESMTP id 3315F11CC0; Thu, 1 Jul 2021 11:38:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1625139534; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=LI8MrFbLom0XoWcFm+wUbnTE9zeW2ynrN0Ns0HpEKa0=; b=p7WsMBAAlAx+qTEZ8KJnuBMogBNT41JcJalEMwudQaYNrBtYcxGRdVEFLV/BvQ6nxIX0Jh CZKV1QNgL95L7g7CE2DcrsTAwU70qEkhP38pPtH6XZUnq6SyzuZYW2mZ6rY6WEWRLbqmNC chIYpeS629ufrRCBxU0u6g1LGPxAYtk= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1625139534; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type; bh=LI8MrFbLom0XoWcFm+wUbnTE9zeW2ynrN0Ns0HpEKa0=; b=w7tVQKfkKV+pb/a24BNRqL/ax7KznPMsoyV83D/SuQHlmtjZ98PF9rE/Pn1OtQ0fbiapmX SH0Pk0C+pby0IvAg== Received: from director2.suse.de ([192.168.254.72]) by imap3-int with ESMTPSA id d9l8C06p3WAhBAAALh3uQQ (envelope-from ); Thu, 01 Jul 2021 11:38:54 +0000 Date: Thu, 1 Jul 2021 13:38:53 +0200 (CEST) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/101280 - revise interchange fix for PR101173 Message-ID: MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, SPF_HELO_NONE, SPF_PASS, TXREP 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: , Cc: bin.cheng@linux.alibaba.com Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" The following revises the original fix for PR101173 to correctly check for a reversed dependence rather than disallowing a zero distance. It also adds a check from TSVC which asks for this kind of interchange (but with a valid dependence). Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed. 2021-07-01 Richard Biener PR tree-optimization/101280 PR tree-optimization/101173 * gimple-loop-interchange.cc (tree_loop_interchange::valid_data_dependences): Revert previous change and instead correctly handle DDR_REVERSED_P dependence. * gcc.dg/tree-ssa/loop-interchange-16.c: New testcase. --- gcc/gimple-loop-interchange.cc | 7 ++++-- .../gcc.dg/tree-ssa/loop-interchange-16.c | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/loop-interchange-16.c diff --git a/gcc/gimple-loop-interchange.cc b/gcc/gimple-loop-interchange.cc index 43045c5455e..43ef112a2d0 100644 --- a/gcc/gimple-loop-interchange.cc +++ b/gcc/gimple-loop-interchange.cc @@ -1043,8 +1043,11 @@ tree_loop_interchange::valid_data_dependences (unsigned i_idx, unsigned o_idx, continue; /* Be conservative, skip case if either direction at i_idx/o_idx - levels is not '=' (for the inner loop) or '<'. */ - if (dist_vect[i_idx] < 0 || dist_vect[o_idx] <= 0) + levels is not '=' or '<'. */ + if (dist_vect[i_idx] < 0 + || (DDR_REVERSED_P (ddr) && dist_vect[i_idx] > 0) + || dist_vect[o_idx] < 0 + || (DDR_REVERSED_P (ddr) && dist_vect[o_idx] > 0)) return false; } } diff --git a/gcc/testsuite/gcc.dg/tree-ssa/loop-interchange-16.c b/gcc/testsuite/gcc.dg/tree-ssa/loop-interchange-16.c new file mode 100644 index 00000000000..781555e085d --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/loop-interchange-16.c @@ -0,0 +1,22 @@ +/* PR/101280 */ +/* { dg-do compile } */ +/* { dg-options "-O3 -fdump-tree-linterchange-details" } */ + +void dummy (double *, double *); +#define LEN_2D 32 +double aa[LEN_2D][LEN_2D], bb[LEN_2D][LEN_2D]; +double s231(int iterations) +{ +// loop interchange +// loop with data dependency + for (int nl = 0; nl < 100*(iterations/LEN_2D); nl++) { + for (int i = 0; i < LEN_2D; ++i) { + for (int j = 1; j < LEN_2D; j++) { + aa[j][i] = aa[j - 1][i] + bb[j][i]; + } + } + dummy(aa[0],bb[0]); + } +} + +/* { dg-final { scan-tree-dump "loops interchanged" "linterchange" } } */