From patchwork Wed Aug 5 08:58:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 1341142 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@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=lY1oyrDL; 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 4BM5Bj3FY5z9sPC for ; Wed, 5 Aug 2020 18:58:36 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 633F13851C3C; Wed, 5 Aug 2020 08:58:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 633F13851C3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1596617913; bh=k6KvL2iLNiH4VQtg4Kp1+Pcg2uXUen+fXd6aB0LkrQs=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=lY1oyrDLzTvMXtfvNo8W6vc+mc8UouBFOeUnN9xpPeBcedILp+D7IquGutfMkQjsY 2RklxiPDUoiIi+Z27Cvc+xh3zFMuSdBHhC7DtaXHOi6SFoutQiGQfVcZu8kHfbjIeV opjXy6fEWnDjJhTzwB7x+fDrqUOyDBEIf1HiXlsI= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id 2D72E3851C3C for ; Wed, 5 Aug 2020 08:58:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 2D72E3851C3C Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-320-omPLQKMwOaC7QEEHtk3IRQ-1; Wed, 05 Aug 2020 04:58:28 -0400 X-MC-Unique: omPLQKMwOaC7QEEHtk3IRQ-1 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 593508015F4 for ; Wed, 5 Aug 2020 08:58:27 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-113-174.ams2.redhat.com [10.36.113.174]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 063AE60BF3 for ; Wed, 5 Aug 2020 08:58:26 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id 0758wJ0F028758 for ; Wed, 5 Aug 2020 10:58:19 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id 0758wIrH028757 for gcc-patches@gcc.gnu.org; Wed, 5 Aug 2020 10:58:18 +0200 Date: Wed, 5 Aug 2020 10:58:18 +0200 To: gcc-patches@gcc.gnu.org Subject: [committed] openmp: Use more efficient logical -> actual computation even if # iterations is computed at runtime Message-ID: <20200805085818.GQ2375@tucnak> MIME-Version: 1.0 User-Agent: Mutt/1.11.3 (2019-02-01) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-7.3 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_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Hi! For triangular loops use more efficient logical iteration number to actual iterator values computation even for non-rectangular loops where number of loop iterations could not be computed at compile time. Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk. 2020-08-05 Jakub Jelinek * omp-expand.c (expand_omp_for_init_counts): Remember first_inner_iterations, factor and n1o from the number of iterations computation in *fd. (expand_omp_for_init_vars): Use more efficient logical iteration number to actual iterator values computation even for non-rectangular loops where number of loop iterations could not be computed at compile time. Jakub --- gcc/omp-expand.c.jj 2020-08-04 10:53:03.114637202 +0200 +++ gcc/omp-expand.c 2020-08-04 13:05:18.522759444 +0200 @@ -2181,6 +2181,13 @@ expand_omp_for_init_counts (struct omp_f set_immediate_dominator (CDI_DOMINATORS, bb3, bb1); set_immediate_dominator (CDI_DOMINATORS, bb5, bb2); set_immediate_dominator (CDI_DOMINATORS, entry_bb, bb1); + + if (fd->first_nonrect + 1 == fd->last_nonrect) + { + fd->first_inner_iterations = first_inner_iterations; + fd->factor = factor; + fd->adjn1 = n1o; + } } else { @@ -2469,8 +2476,11 @@ expand_omp_for_init_vars (struct omp_for build_zero_cst (type), true); basic_block bb_triang = NULL, bb_triang_dom = NULL; if (fd->first_nonrect + 1 == fd->last_nonrect - /* For now. */ - && TREE_CODE (fd->loop.n2) == INTEGER_CST + && (TREE_CODE (fd->loop.n2) == INTEGER_CST + || (fd->first_inner_iterations + /* For now. Later add clauses to propagate the + values. */ + && !gimple_omp_for_combined_into_p (fd->for_stmt))) && (optab_handler (sqrt_optab, TYPE_MODE (double_type_node)) != CODE_FOR_nothing)) { @@ -2567,14 +2577,19 @@ expand_omp_for_init_vars (struct omp_for build_one_cst (ulltype)); t = fold_build2 (MULT_EXPR, ulltype, c, t); t = fold_build2 (RSHIFT_EXPR, ulltype, t, integer_one_node); - t = fold_build2 (MULT_EXPR, ulltype, fd->factor, t); - tree t2 = fold_build2 (MULT_EXPR, ulltype, c, - fd->first_inner_iterations); + t = fold_build2 (MULT_EXPR, ulltype, + fold_convert (ulltype, fd->factor), t); + tree t2 + = fold_build2 (MULT_EXPR, ulltype, c, + fold_convert (ulltype, + fd->first_inner_iterations)); t = fold_build2 (PLUS_EXPR, ulltype, t, t2); expand_omp_build_assign (gsi, d, t, true); - t = fold_build2 (MULT_EXPR, ulltype, fd->factor, c); + t = fold_build2 (MULT_EXPR, ulltype, + fold_convert (ulltype, fd->factor), c); t = fold_build2 (PLUS_EXPR, ulltype, - t, fd->first_inner_iterations); + t, fold_convert (ulltype, + fd->first_inner_iterations)); t2 = force_gimple_operand_gsi (gsi, t, true, NULL_TREE, false, GSI_CONTINUE_LINKING); cond_stmt = gimple_build_cond (GE_EXPR, stopvalull, d,