From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id EE46C385F015; Thu, 25 Aug 2022 19:31:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EE46C385F015 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1661455917; bh=YntbdPNL0HKyQNw9yxl+p1QyWW+k8hToUmwkJzh2y0s=; h=From:To:Subject:Date:In-Reply-To:References:From; b=AlpUIFoRbFxOcvNK8G4Ly5JDRusTZKSkpnsuFiij4MIPafF4bmgIZW76WIpJOFTY4 7QCuUREuLgX4mBbHyHKZqiPXsWW44aCyEHg8P79oeYdB4PO+TZdOe3dwHoj5zpq2RW bZTlak03UobbxDfvpiSLK9TdB/o+ce8JaggzKXo8= From: "anlauf at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/41453] use INTENT(out) for optimization Date: Thu, 25 Aug 2022 19:31:56 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 4.5.0 X-Bugzilla-Keywords: missed-optimization X-Bugzilla-Severity: enhancement X-Bugzilla-Who: anlauf at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cc Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D41453 anlauf at gcc dot gnu.org changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |anlauf at gcc dot gnu.org --- Comment #8 from anlauf at gcc dot gnu.org --- Sometimes we now generate a clobber for the wrong variable when a function result is involved. An example, derived from PR105012: ! compile with -fdump-tree-original module m contains SUBROUTINE Y (Z) real, intent(out) :: Z Z =3D 1. END SUBROUTINE Y FUNCTION X () real :: X CALL Y (X) ! direct use of function result, bad clobber END FUNCTION X FUNCTION F () result(res) real :: res CALL Y (res) ! using explicit result variable, good clobber END FUNCTION F end With current trunk this produces: __attribute__((fn spec (". "))) real(kind=3D4) f () { real(kind=3D4) res; res =3D {CLOBBER}; y (&res); return res; } __attribute__((fn spec (". "))) real(kind=3D4) x () { real(kind=3D4) __result_x; x =3D {CLOBBER}; y (&__result_x); return __result_x; } __attribute__((fn spec (". w "))) void y (real(kind=3D4) & restrict z) { *z =3D 1.0e+0; } For function X (without the result clause) we should have: __result_x =3D {CLOBBER}; instead. We probably need to have a closer look here: (gdb) l 9539,9548 9539 else if (add_clobber && expr->ref =3D=3D NULL) 9540 { 9541 tree clobber; 9542 tree var; 9543 /* FIXME: This fails if var is passed by reference, see PR 9544 41453. */ 9545 var =3D expr->symtree->n.sym->backend_decl; 9546 clobber =3D build_clobber (TREE_TYPE (var)); 9547 gfc_add_modify (&se->pre, var, clobber); 9548 }=