From patchwork Wed Jul 31 20:07:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 1967286 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=orange.fr header.i=@orange.fr header.a=rsa-sha256 header.s=t20230301 header.b=HE+hDoW/; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WZ37V6HZqz1ybb for ; Thu, 1 Aug 2024 06:08:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E2CA5385B529 for ; Wed, 31 Jul 2024 20:08:20 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from msa.smtpout.orange.fr (smtp-83.smtpout.orange.fr [80.12.242.83]) by sourceware.org (Postfix) with ESMTPS id 2C124385828B; Wed, 31 Jul 2024 20:07:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 2C124385828B Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=orange.fr Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=orange.fr ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 2C124385828B Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=80.12.242.83 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722456466; cv=none; b=efgHihKQeNMeNoSL4iEsWdJT4/NTFSkKi5+TXWWYUmQe2piS1w3jhDMAQUsZm7dvZfVBoh30+wLbLymLkkPdjRcmr54X7Qv+yQ5PPDm04sjM9JLMna54ZdUhLFikyFiw5WaEi7j8f14acnQjIu7xXgqPJ1Rt8F3skdukhx4mg+s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722456466; c=relaxed/simple; bh=ucnKPqdpjIBfZlqctZLoaPqDwB/oAqd2y9lTgdMHUZg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=jqGo+AK7aEI0/1MAIh5leq/Cf0jf0MHVTJmKJlP7WoTPE1ZA+6GOl4nlbGmXZX6CW3Cn2sUH2UhsKIv+HFq/nw5ixGzDscus0gUZWFr/gwZ/GiLp4OROl/f5VkVp5FfbTS5F+6I7Dk7zYBZPKPg4rmGTELm8UUzL5l73IHKtHYM= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from cyrano.home ([86.215.161.51]) by smtp.orange.fr with ESMTPA id ZFbisBHiIYjQzZFbrsqYRQ; Wed, 31 Jul 2024 22:07:43 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=orange.fr; s=t20230301; t=1722456463; bh=AAKXMOQNt5JxVGO/990fNewV0RM98WrhXm0myUYAwBs=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=HE+hDoW/8na++zaAXpR9X6ydkyzXLyWaesnIM+9Aogu1qJljNN6bRbpMQdcBiY235 8EffYRFlrXAMGmAniiLBo71WCRFaysxoKA+kUldYB/UaY6mfw6fK3q4MBjENwu2lQO Kf8KPZ+d0v4ZDEgcLVrztpZPllw/A9seJTStMMLfGUR8iiJk42gY+Rdv90Hxw/mKxc TpGgFGqi9kqUJvuvDi5HEzqsvQuepOP5iBg2W2yqP+IA4h9QruurEmIIYYm3oYLnGw BkEvE6f+SlozxCNHMCUn0vy2nuWJl5/I1L4rlQVUugFHzE11Kuf2qjLEMXo1UnYbTa U0ZPqjccpIXng== X-ME-Helo: cyrano.home X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Wed, 31 Jul 2024 22:07:43 +0200 X-ME-IP: 86.215.161.51 From: Mikael Morin To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH 2/8] fortran: Disable frontend passes for inlinable MINLOC/MAXLOC [PR90608] Date: Wed, 31 Jul 2024 22:07:29 +0200 Message-ID: <20240731200735.229898-3-morin-mikael@orange.fr> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240731200735.229898-1-morin-mikael@orange.fr> References: <20240731200735.229898-1-morin-mikael@orange.fr> MIME-Version: 1.0 X-Spam-Status: No, score=-10.9 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org From: Mikael Morin Regression-tested on x86_64-pc-linux-gnu. OK for master? -- >8 -- Disable rewriting of MINLOC/MAXLOC expressions for which inline code generation is supported. Update the gfc_inline_intrinsic_function_p predicate (already existing) for that, with the current state of MINLOC/MAXLOC inlining support, that is only the cases of a scalar result and non-CHARACTER argument for now. This change has no effect currently, as the MINLOC/MAXLOC front-end passes only change expressions of rank 1, but the inlining control predicate gfc_inline_intrinsic_function_p returns false for those. However, later changes will extend MINLOC/MAXLOC inline expansion support to array expressions and update the inlining control predicate, and this will become effective. PR fortran/90608 gcc/fortran/ChangeLog: * frontend-passes.cc (optimize_minmaxloc): Skip if we can generate inline code for the unmodified expression. * trans-intrinsic.cc (gfc_inline_intrinsic_function_p): Add MINLOC and MAXLOC cases. --- gcc/fortran/frontend-passes.cc | 3 ++- gcc/fortran/trans-intrinsic.cc | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/gcc/fortran/frontend-passes.cc b/gcc/fortran/frontend-passes.cc index 3c06018fdbb..8e4c6310ba8 100644 --- a/gcc/fortran/frontend-passes.cc +++ b/gcc/fortran/frontend-passes.cc @@ -2277,7 +2277,8 @@ optimize_minmaxloc (gfc_expr **e) || fn->value.function.actual == NULL || fn->value.function.actual->expr == NULL || fn->value.function.actual->expr->ts.type == BT_CHARACTER - || fn->value.function.actual->expr->rank != 1) + || fn->value.function.actual->expr->rank != 1 + || gfc_inline_intrinsic_function_p (fn)) return; *e = gfc_get_array_expr (fn->ts.type, fn->ts.kind, &fn->where); diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc index 9f3c3ce47bc..cc0d00f4e39 100644 --- a/gcc/fortran/trans-intrinsic.cc +++ b/gcc/fortran/trans-intrinsic.cc @@ -11650,6 +11650,29 @@ gfc_inline_intrinsic_function_p (gfc_expr *expr) case GFC_ISYM_TRANSPOSE: return true; + case GFC_ISYM_MINLOC: + case GFC_ISYM_MAXLOC: + { + /* Disable inline expansion if code size matters. */ + if (optimize_size) + return false; + + gfc_actual_arglist *array_arg = expr->value.function.actual; + gfc_actual_arglist *dim_arg = array_arg->next; + + gfc_expr *array = array_arg->expr; + gfc_expr *dim = dim_arg->expr; + + if (!(array->ts.type == BT_INTEGER + || array->ts.type == BT_REAL)) + return false; + + if (array->rank == 1 && dim != nullptr) + return true; + + return false; + } + default: return false; }