From patchwork Sat Jul 13 09:48:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mikael Morin X-Patchwork-Id: 93886 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D5BC1385DC20 for ; Sat, 13 Jul 2024 09:48:54 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from msa.smtpout.orange.fr (msa-208.smtpout.orange.fr [193.252.23.208]) by sourceware.org (Postfix) with ESMTPS id B35773858D26; Sat, 13 Jul 2024 09:48:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B35773858D26 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 B35773858D26 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=193.252.23.208 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720864107; cv=none; b=nEF03q/GH1hicJNV6d0YqpIB+lKG+Qh7FvtJDtbYMH64u4+KSXlLD019LAMC/Nh9NY61mo7gXPB6rlQ9saaQ3c5mdW7DA6RwbNWDHuf02E2oYpcNUCouvZ+QaHNACWs/U0JshE13kodTCgIXXFlFuBtQkVH/CbCLPY9cGiSPsfI= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720864107; c=relaxed/simple; bh=ArjSLVZmNQCBqqGu6y0JmQ4vsGSjVHCXPbiRZA5HKtU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=TwynaQiFEtTIepKzUsECM7kT1KrRqiP/CTh80cSpYT4sHpNyLz+D+QH53IrQ43t9xYThqlljnWL9YeiuvUbkmVgVuxqgQ8TJH0xYod5eMcpblGLz/CufrtzAxNn6tIedPLI/7+hZmIJCnP+VfcHxmrKE3UdhPrIdlO/fWdL1qYA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: from cyrano.home ([86.215.161.51]) by smtp.orange.fr with ESMTPA id SZMXsFbQTHEYLSZMcsiBqx; Sat, 13 Jul 2024 11:48:24 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=orange.fr; s=t20230301; t=1720864104; bh=AUlzKU4qRD/9dU8HHMF+vMfjdkggscWBw2xdh8f7030=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=SHWdCa1rliH0DHzCvSrvbCwzW43UAdXN01Kp0btLA422ebJSyAiezrsW8O+4WAjBY vGBWV//2cl//euPXAN+oRT0Y1qzZj2A1VL7tgEev2V0GiBiU18LvFdCXY9sOFoK4xK nOPYckrke6guTi+UuWyVR4ylpTtPVld0xpQMREzvYpizPvr+L3a0UdtigSlKoCDqN2 U1cx/hjL54cxKPiSS8FeqGVBFl4yRp8WiHhtRfL8sZo2Y8leQSCZt/JMQBmz6xgByY YWT19yAP/BMM0WFgdQOY0yu5CzbnZa3S2uzPZdSY55PbDYSOWprdt2S+oS37iBAiKJ 7XPcgQjjVlPcA== X-ME-Helo: cyrano.home X-ME-Auth: bW9yaW4tbWlrYWVsQG9yYW5nZS5mcg== X-ME-Date: Sat, 13 Jul 2024 11:48:24 +0200 X-ME-IP: 86.215.161.51 From: Mikael Morin To: gcc-patches@gcc.gnu.org, fortran@gcc.gnu.org Subject: [PATCH] fortran: Correctly evaluate the MASK argument of MINLOC/MAXLOC Date: Sat, 13 Jul 2024 11:48:18 +0200 Message-ID: <20240713094818.399842-1-morin-mikael@orange.fr> X-Mailer: git-send-email 2.43.0 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~patchwork=sourceware.org@gcc.gnu.org From: Mikael Morin Hello, I'm currently testing this on x86_64-linux. I plan to push to master if all goes well. Mikael -- 8< -- Add the preliminary code that the generated expression for MASK may depend on when generating the inline code to evaluate MINLOC or MAXLOC with a scalar MASK. The generated code was only keeping the generated expression but not the preliminary code, which was sufficient for simple cases such as data references or simple (scalar) function calls, but was bogus with more complicated ones. gcc/fortran/ChangeLog: * trans-intrinsic.cc (gfc_conv_intrinsic_minmaxloc): Add the preliminary code generated for MASK to the preliminary code of MINLOC/MAXLOC. gcc/testsuite/ChangeLog: * gfortran.dg/minmaxloc_17.f90: New test. --- gcc/fortran/trans-intrinsic.cc | 1 + gcc/testsuite/gfortran.dg/minmaxloc_17.f90 | 33 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/minmaxloc_17.f90 diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc index cadbd177452..180d0d7a88c 100644 --- a/gcc/fortran/trans-intrinsic.cc +++ b/gcc/fortran/trans-intrinsic.cc @@ -5749,6 +5749,7 @@ gfc_conv_intrinsic_minmaxloc (gfc_se * se, gfc_expr * expr, enum tree_code op) gfc_init_se (&maskse, NULL); gfc_conv_expr_val (&maskse, maskexpr); + gfc_add_block_to_block (&se->pre, &maskse.pre); gfc_init_block (&block); gfc_add_block_to_block (&block, &loop.pre); gfc_add_block_to_block (&block, &loop.post); diff --git a/gcc/testsuite/gfortran.dg/minmaxloc_17.f90 b/gcc/testsuite/gfortran.dg/minmaxloc_17.f90 new file mode 100644 index 00000000000..7e6e586ab03 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/minmaxloc_17.f90 @@ -0,0 +1,33 @@ +! { dg-do run } +! +! Check that the code necessary to evaluate MINLOC's or MAXLOC's MASK +! argument is correctly generated. + +program p + implicit none + integer, parameter :: data10(*) = (/ 2, 5, 2, 0, 6, 5, 3, 6, 0, 1 /) + logical, parameter :: mask10(*) = (/ .false., .true., .false., & + .false., .true., .true., & + .true. , .true., .false., & + .false. /) + type bool_wrapper + logical :: l + end type + call check_minloc + call check_maxloc +contains + subroutine check_minloc + integer :: a(10) + integer :: r + a = data10 + r = minloc(a, dim = 1, mask = sum(a) > 0) + if (r /= 4) stop 11 + end subroutine + subroutine check_maxloc + integer :: a(10) + integer :: r + a = data10 + r = maxloc(a, dim = 1, mask = sum(a) > 0) + if (r /= 5) stop 18 + end subroutine +end program