From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 177813858D33 for ; Tue, 31 Jan 2023 11:37:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 177813858D33 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1675165037; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=3S6bD6v+G3LELVf7ToVNmh+dVaRRr2cB6NznsD2nNAw=; b=YmuXf55vpbCRKGZyu+a6ycNCPrARL9RJPsxdJVgAXZaJKTCLTVuTOJ4wLEF3VveF4GSdtW SQcqt7AnYE41iTeKzmmJR4IL7vONE7Cl5dxLS3AZpsC8LyXnuk0A2ZKeax/ru587pRhz+x jwBQuEAHmLhATPWXBPvpBdvI2qeiGw0= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-563-MaFSnRRKMH25XQlFKSpfWw-1; Tue, 31 Jan 2023 06:37:14 -0500 X-MC-Unique: MaFSnRRKMH25XQlFKSpfWw-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 30667858F09; Tue, 31 Jan 2023 11:37:14 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.223]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DFF0D492C3E; Tue, 31 Jan 2023 11:37:13 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 30VBbA6W1045588 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Tue, 31 Jan 2023 12:37:11 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 30VBb92P1045586; Tue, 31 Jan 2023 12:37:09 +0100 Date: Tue, 31 Jan 2023 12:37:09 +0100 From: Jakub Jelinek To: Tobias Burnus Cc: gcc-patches , fortran Subject: Re: [Patch][v2] OpenMP/Fortran: Partially fix non-rect loop nests [PR107424] Message-ID: Reply-To: Jakub Jelinek References: <18c3aed8-71dd-9b7f-6c7c-da529876d3f5@codesourcery.com> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Wed, Jan 25, 2023 at 03:47:18PM +0100, Tobias Burnus wrote: > updated patch included, i.e. avoiding 'count' for 'j' when a 'j.0' would > do (i.e. only local var without the different step calculation). I also > now reject if there is a non-unit step on the loop using an outer var. > > Eventually still to be done: replace the 'sorry' by working code, i.e. > implement the suggestions to handle some/all non-unit iteration steps as > proposed in this thread. > > On 20.01.23 18:39, Jakub Jelinek wrote: > > I think instead of non-unity etc. it is better to talk about constant > > step 1 or -1. > > I concur. > > > > The actual problem with non-simple loops for non-rectangular loops is > > both in case it is an inner loop which uses some outer loop's iterator, > > or if it is outer loop whose iterator is used, both of those cases > > will not be handled properly. > > I have now added a check for the other case as well. > > Just to confirm, the following is fine, isn't it? > > !$omp simd collapse(4) > do i = 1, 10, 2 > do outer_var = 1, 10 ! step = + 1 > do j = 1, 10, 2 > do inner_var = 1, outer_var ! step = 1 > > i.e. both the inner_var and outer_var have 'step = 1', > even if other loops in the 'collapse' have step != 1. > I think it should be fine. Yes, the loops which don't define outer_var for other loops nor use outer_var from other loops can be in any form, we can compute their number of iterations before the whole loop nest for them, so for the non-rectangular iterations computations we can ignore those except for multiplication by the pre-computed count. > OpenMP/Fortran: Partially fix non-rect loop nests [PR107424] > > This patch ensures that loop bounds depending on outer loop vars use the > proper TREE_VEC format. It additionally gives a sorry if such an outer > var has a non-one/non-minus-one increment as currently a count variable > is used in this case (see PR). > > Finally, it avoids 'count' and just uses a local loop variable if the > step increment is +/-1. > > PR fortran/107424 > > gcc/fortran/ChangeLog: > > * trans-openmp.cc (struct dovar_init_d): Add 'sym' and > 'non_unit_incr' members. > (gfc_nonrect_loop_expr): New. > (gfc_trans_omp_do): Call it; use normal loop bounds > for unit stride - and only create local loop var. > > libgomp/ChangeLog: > > * testsuite/libgomp.fortran/non-rectangular-loop-1.f90: New test. > * testsuite/libgomp.fortran/non-rectangular-loop-1a.f90: New test. > * testsuite/libgomp.fortran/non-rectangular-loop-2.f90: New test. > * testsuite/libgomp.fortran/non-rectangular-loop-3.f90: New test. > * testsuite/libgomp.fortran/non-rectangular-loop-4.f90: New test. > * testsuite/libgomp.fortran/non-rectangular-loop-5.f90: New test. > > gcc/testsuite/ChangeLog: > > * gfortran.dg/goacc/privatization-1-compute-loop.f90: Update dg-note. > * gfortran.dg/goacc/privatization-1-routine_gang-loop.f90: Likewise. > > +static bool > +gfc_nonrect_loop_expr (stmtblock_t *pblock, gfc_se *sep, int loop_n, > + gfc_code *code, gfc_expr *expr, vec *inits, > + int simple, gfc_expr *curr_loop_var) > +{ > + int i; > + for (i = 0; i < loop_n; i++) > + { > + gcc_assert (code->ext.iterator->var->expr_type == EXPR_VARIABLE); > + if (gfc_find_sym_in_expr (code->ext.iterator->var->symtree->n.sym, expr)) > + break; > + code = code->block->next; > + } > + if (i >= loop_n) > + return false; > + > + /* Canonic format: TREE_VEC with [var, multiplier, offset]. */ I think we use everywhere Canonical rather than Canonic > + gfc_symbol *var = code->ext.iterator->var->symtree->n.sym; > + > + tree tree_var = NULL_TREE; > + tree a1 = integer_one_node; > + tree a2 = integer_zero_node; > + > + if (!simple) > + { > + /* FIXME: Handle non-unit iter steps, cf. PR fortran/107424. */ > + sorry_at (gfc_get_location (&curr_loop_var->where), > + "non-rectangular loop nest with step other than constant 1 " > + "or -1 for %qs", curr_loop_var->symtree->n.sym->name); > + return false; > + } > + > + dovar_init *di; > + unsigned ix; > + FOR_EACH_VEC_ELT (*inits, ix, di) > + if (di->sym == var && !di->non_unit_iter) > + { > + tree_var = di->init; > + gcc_assert (DECL_P (tree_var)); > + break; > + } > + else if (di->sym == var) > + { > + /* FIXME: Handle non-unit iter steps, cf. PR fortran/107424. */ > + sorry_at (gfc_get_location (&code->loc), > + "non-rectangular loop nest with step other than constant 1 " > + "or -1 for %qs", var->name); > + inform (gfc_get_location (&expr->where), "Used here"); > + return false; > + } I think it would be better formatted as if (di->sym == var) { if (!di->non_unit_iter) { ... } else { ... } } > + if (simple && !DECL_P (dovar)) > + { > + const char *name = code->ext.iterator->var->symtree->n.sym->name; > + local_dovar = gfc_create_var (type, name); > + dovar_init e = {code->ext.iterator->var->symtree->n.sym, > + dovar, local_dovar, false}; > + inits.safe_push (e); > + } For the separate local_dovar case, I'd be worried if we handle lastprivate right. From quick skimming I see some lastprivate clauses in some of the tests, so if they verify the right value has been computed (say the same as one would get with -fno-openmp), then fine. Jakub