From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by sourceware.org (Postfix) with ESMTPS id 3392D3858412 for ; Tue, 1 Mar 2022 08:52:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3392D3858412 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 13347218E0 for ; Tue, 1 Mar 2022 08:52:51 +0000 (UTC) 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 F301F13B32 for ; Tue, 1 Mar 2022 08:52:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id GDc8OuLeHWKITAAAMHmgww (envelope-from ) for ; Tue, 01 Mar 2022 08:52:50 +0000 Date: Tue, 1 Mar 2022 09:52:50 +0100 (CET) From: Richard Biener To: gcc-patches@gcc.gnu.org Subject: [PATCH] tree-optimization/104716 - check if we can copy loop in loop distribution MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Message-Id: <20220301085250.F301F13B32@imap2.suse-dmz.suse.de> X-Spam-Status: No, score=-11.7 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, T_SCC_BODY_TEXT_LINE 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: , X-List-Received-Date: Tue, 01 Mar 2022 08:52:54 -0000 The following checks whether we can copy the loop before attempting to do so in loop distribution. In the testcase there's a computed goto and thus abnormal edges which we cannot redirect. Bootstrapped on x86_64-unknown-linux-gnu, testing in progress. 2022-03-01 Richard Biener PR tree-optimization/104716 * tree-loop-distribution.cc (find_seed_stmts_for_distribution): Check if we can copy the loop. * gfortran.dg/pr104716.f: New testcase. --- gcc/testsuite/gfortran.dg/pr104716.f | 31 ++++++++++++++++++++++++++++ gcc/tree-loop-distribution.cc | 14 +++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/pr104716.f diff --git a/gcc/testsuite/gfortran.dg/pr104716.f b/gcc/testsuite/gfortran.dg/pr104716.f new file mode 100644 index 00000000000..97f899a9201 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr104716.f @@ -0,0 +1,31 @@ +! { dg-do compile } +! { dg-options "-std=legacy -O2 -ftree-loop-distribution -fno-move-loop-stores -fno-tree-dominator-opts" } + + SUBROUTINE FOO() + + COMMON /WORK/ C2(2, 2) + + DIMENSION D11(2) + + EQUIVALENCE (D11(1), C2(1, 1)) + + DO 40 I = 1, 2 + DO 30 J = 1, 2 + ASSIGN 10 TO ILBL + IF (C2(J, I) .NE. 0.0) THEN + ASSIGN 20 TO ILBL + ENDIF + GO TO ILBL + 10 CONTINUE + 20 CONTINUE + C2(J, I) = C2(J, I) + 1 + 30 CONTINUE + 40 CONTINUE + + DO 50 I = 1, 2 + PRINT 90, I + 50 CONTINUE + + RETURN + 90 FORMAT(I5) + END diff --git a/gcc/tree-loop-distribution.cc b/gcc/tree-loop-distribution.cc index 8ee40d88816..c2ca746e237 100644 --- a/gcc/tree-loop-distribution.cc +++ b/gcc/tree-loop-distribution.cc @@ -3237,6 +3237,20 @@ find_seed_stmts_for_distribution (class loop *loop, vec *work_list) work_list->truncate (0); break; } + edge_iterator ei; + edge e; + /* We cannot redirect abnormal edges so loop copying will fail. */ + FOR_EACH_EDGE (e, ei, bbs[i]->succs) + if (e->flags & EDGE_ABNORMAL) + { + if (dump_file && (dump_flags & TDF_DETAILS)) + fprintf (dump_file, "loop %d is the source of abnormal edges.\n", + loop->num); + work_list->truncate (0); + break; + } + if (e) + break; for (gphi_iterator gsi = gsi_start_phis (bbs[i]); !gsi_end_p (gsi); gsi_next (&gsi)) { -- 2.34.1