From patchwork Sun Jun 2 13:34:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Koenig X-Patchwork-Id: 1108946 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-502158-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=quarantine dis=none) header.from=netcologne.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="NY9D+Dj1"; dkim=pass (2048-bit key; unprotected) header.d=netcologne.de header.i=@netcologne.de header.b="OI9XxRLL"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45Gzgr5j6Qz9s5c for ; Sun, 2 Jun 2019 23:34:47 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=LeyXZXcuic4eaYChv4vZlyZ0Y3JFpy9FLNZ8YJHHBcvE9ZA+sG NI3GEgCRkRkOxDtIuclK+6HEJPL0SA8ymyAfPMWTPfy6v2cdfgTvKxA41++84qp9 x9OSrOEBcosu1rJbRKIuWxF7ErrF4YqF/UEiGsVRa2IraKQTh0NSWi4Tc= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=oaTp4Y1zW0ElDDKoWrWfBONcPM4=; b=NY9D+Dj1/tHGsAJBajlZ a02aWCqkTr92GEmP4o+ii8pyfQ9t+p3DE2fiUDX27qTDe7rEPjL6pCUKq7gsxVfb ArfK6znetZY/hMIzAhdXxHhkB/kmKHsMi59dFng+DcETaMLT2svNVqAanQPuoKeS 1WP0b5pShw8hxuDMLozucfA= Received: (qmail 99153 invoked by alias); 2 Jun 2019 13:34:35 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 99092 invoked by uid 89); 2 Jun 2019 13:34:34 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.8 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.1 spammy=sk:gfc_fin, estimated, eq_expr, build_int_cst X-HELO: cc-smtpout1.netcologne.de Received: from cc-smtpout1.netcologne.de (HELO cc-smtpout1.netcologne.de) (89.1.8.211) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 02 Jun 2019 13:34:32 +0000 Received: from cc-smtpin2.netcologne.de (cc-smtpin2.netcologne.de [89.1.8.202]) by cc-smtpout1.netcologne.de (Postfix) with ESMTP id 4879F1336B; Sun, 2 Jun 2019 15:34:26 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=netcologne.de; s=nc1116a; t=1559482466; bh=xalNEGpwJ8i5oQvMyMVdpn/dDC69i7pV8VePhk67DUk=; h=To:From:Subject:Message-ID:Date:From; b=OI9XxRLLDIY9gaCQXJ/G2SbxiJdFLxQXX5qAStCtZ+PHUVtdq+YjZwv/pVlIRPLEO 0/z7br9iqNL1Vl56B2y+9LU/wRmNMCo9Qv1JwqmzCm2WwwkXHTiLz3P/LPp8XKb714 /b7IgGhrBE1AvkOa8kiaueJxsrcBvGE6+LjWhaGIdtCEzkpq16sYes/37gg4l5FVyW FQTQ/pUjA2grNL0U/QLh6MpTHKkkap7jwkG9PpL/EUf47o4EU10DFY/v90dOPI5WSQ QmfYskaZZ/8sONlEIVETxFsUhPGwizleogEzrEo5dzINGTT5nHTJ3GTo7VAPQgOF+x xo09iiNNitFug== Received: from localhost (localhost [127.0.0.1]) by cc-smtpin2.netcologne.de (Postfix) with ESMTP id 39F0911EF1; Sun, 2 Jun 2019 15:34:26 +0200 (CEST) Received: from [2001:4dd6:101c:0:7285:c2ff:fe6c:992d] (helo=cc-smtpin2.netcologne.de) by localhost with ESMTP (eXpurgate 4.6.0) (envelope-from ) id 5cf3d062-018f-7f0000012729-7f0000019f8a-1 for ; Sun, 02 Jun 2019 15:34:26 +0200 Received: from [IPv6:2001:4dd6:101c:0:7285:c2ff:fe6c:992d] (2001-4dd6-101c-0-7285-c2ff-fe6c-992d.ipv6dyn.netcologne.de [IPv6:2001:4dd6:101c:0:7285:c2ff:fe6c:992d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by cc-smtpin2.netcologne.de (Postfix) with ESMTPSA; Sun, 2 Jun 2019 15:34:24 +0200 (CEST) To: "fortran@gcc.gnu.org" , gcc-patches From: Thomas Koenig Subject: [patch, fortran] Two tweaks to argument repacking Message-ID: Date: Sun, 2 Jun 2019 15:34:23 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1 MIME-Version: 1.0 Hello world, this patch adds two tweaks to the argument repacking. First, when the size of an argument is known to be one, as in a(n1:n1), we can directly pass a pointer - the stride may not be one, but it does not matter. Second, the case where the array passed is actually contiguous is more likely in practice, so it should get the fast path. I have done this by defining a new predictor and setting the estimated likelyhood at 75%, which ensured a path without jumps when the arguments passed to bar were contiguous: module y contains subroutine bar(a,b) real, dimension(:) :: a,b call foo(a,b,size(a)) end subroutine bar end module y Test case is only for the first part - making one for the second part would have been a bit too much. Regression-tested. OK for trunk? Regards Thomas 2019-06-02 Thomas Koenig PR fortran/90539 * trans-expr.c (gfc_conv_subref_array_arg): If the size of the expression can be determined to be one, treat it as contiguous. Set likelyhood of presence of an actual argument according to PRED_FORTRAN_ABSENT_DUMMY and likelyhood of being contiguous according to PRED_FORTRAN_CONTIGUOUS. 2019-06-02 Thomas Koenig PR fortran/90539 * predict.def (PRED_FORTRAN_CONTIGUOUS): New predictor. Index: fortran/trans-expr.c =================================================================== --- fortran/trans-expr.c (Revision 271751) +++ fortran/trans-expr.c (Arbeitskopie) @@ -4922,16 +4922,36 @@ class_array_fcn: gfc_se cont_se, array_se; stmtblock_t if_block, else_block; tree if_stmt, else_stmt; + mpz_t size; + bool size_set; cont_var = gfc_create_var (boolean_type_node, "contiguous"); - /* cont_var = is_contiguous (expr); . */ - gfc_init_se (&cont_se, parmse); - gfc_conv_is_contiguous_expr (&cont_se, expr); - gfc_add_block_to_block (&se->pre, &(&cont_se)->pre); - gfc_add_modify (&se->pre, cont_var, cont_se.expr); - gfc_add_block_to_block (&se->pre, &(&cont_se)->post); + /* If the size is known to be one at compile-time, set + cont_var to true unconditionally. This may look + inelegant, but we're only doing this during + optimization, so the statements will be optimized away, + and this saves complexity here. */ + size_set = gfc_array_size (expr, &size); + if (size_set && mpz_cmp_ui (size, 1) == 0) + { + gfc_add_modify (&se->pre, cont_var, + build_one_cst (boolean_type_node)); + } + else + { + /* cont_var = is_contiguous (expr); . */ + gfc_init_se (&cont_se, parmse); + gfc_conv_is_contiguous_expr (&cont_se, expr); + gfc_add_block_to_block (&se->pre, &(&cont_se)->pre); + gfc_add_modify (&se->pre, cont_var, cont_se.expr); + gfc_add_block_to_block (&se->pre, &(&cont_se)->post); + } + + if (size_set) + mpz_clear (size); + /* arrayse->expr = descriptor of a. */ gfc_init_se (&array_se, se); gfc_conv_expr_descriptor (&array_se, expr); @@ -4953,7 +4973,9 @@ class_array_fcn: /* And put the above into an if statement. */ pre_stmts = fold_build3_loc (input_location, COND_EXPR, void_type_node, - cont_var, if_stmt, else_stmt); + gfc_likely (cont_var, + PRED_FORTRAN_CONTIGUOUS), + if_stmt, else_stmt); } else { @@ -4976,11 +4998,11 @@ class_array_fcn: gfc_add_modify (&else_block, pointer, build_int_cst (type, 0)); else_stmt = gfc_finish_block (&else_block); - tmp = fold_build3_loc (input_location, COND_EXPR, void_type_node, present_var, + tmp = fold_build3_loc (input_location, COND_EXPR, void_type_node, + gfc_likely (present_var, + PRED_FORTRAN_ABSENT_DUMMY), pre_stmts, else_stmt); gfc_add_expr_to_block (&se->pre, tmp); - - } else gfc_add_expr_to_block (&se->pre, pre_stmts); @@ -4995,9 +5017,16 @@ class_array_fcn: tmp = fold_build2_loc (input_location, EQ_EXPR, boolean_type_node, cont_var, build_zero_cst (boolean_type_node)); + tmp = gfc_unlikely (tmp, PRED_FORTRAN_CONTIGUOUS); + if (pass_optional) - post_cond = fold_build2_loc (input_location, TRUTH_ANDIF_EXPR, - boolean_type_node, present_var, tmp); + { + tree present_likely = gfc_likely (present_var, + PRED_FORTRAN_ABSENT_DUMMY); + post_cond = fold_build2_loc (input_location, TRUTH_ANDIF_EXPR, + boolean_type_node, present_likely, + tmp); + } else post_cond = tmp; } Index: predict.def =================================================================== --- predict.def (Revision 271629) +++ predict.def (Arbeitskopie) @@ -229,3 +229,10 @@ DEF_PREDICTOR (PRED_FORTRAN_ABSENT_DUMMY, "Fortran to be very likely. */ DEF_PREDICTOR (PRED_FORTRAN_LOOP_PREHEADER, "Fortran loop preheader", \ HITRATE (99), 0) + +/* Fortran assumed size arrays can be non-contiguous, so they need + to be repacked. */ + +DEF_PREDICTOR (PRED_FORTRAN_CONTIGUOUS, "Fortran contiguous", \ + HITRATE (75), 0) +