From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 96397384B0C1; Tue, 21 Apr 2020 14:28:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 96397384B0C1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1587479290; bh=onjCn3LkQppZHcVIZFo5gj09baieVWenEGfEDHLwG+A=; h=From:To:Subject:Date:From; b=SqxjemtTppvDOv8uZ7EyZXcf5VbMrRTByzKQzraXej54Pn5VwAtKEUSAUt1Qg+iy4 JdhCLIUD5Hneiw/XlYE5gnsmmKxcOTiFd+MvbjdqSMf/P5aC9kZcLbAD/lbmWzbTgp +Wxr3Fnpakr32tlacDHv/P20oLLFEP4PEjGyHfaE= From: "rguenth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug ipa/94693] New: IPA SRA should elide unused out parameters Date: Tue, 21 Apr 2020 14:28:10 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: ipa X-Bugzilla-Version: 10.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rguenth at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone Message-ID: 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Apr 2020 14:28:10 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D94693 Bug ID: 94693 Summary: IPA SRA should elide unused out parameters Product: gcc Version: 10.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: ipa Assignee: unassigned at gcc dot gnu.org Reporter: rguenth at gcc dot gnu.org CC: marxin at gcc dot gnu.org Target Milestone: --- IPA SRA should elide 'out' in struct outs { int kind; int i; }; void foo (struct outs *out) { if (out->kind =3D=3D 0) ; else out->i =3D out->kind; } int main() { struct outs out; out.kind =3D 3; foo (&out); // 'out' is unused [after the call] } IPA SRA transform should then produce void foo.isra (int kind) { struct outs out_; out_.kind =3D kind; struct outs *out =3D out_; if (out->kind =3D=3D 0) ; else out->i =3D out->kind; } int main() { struct outs out; out.kind =3D 3; foo (3); } and DCE can then eliminate the dead code. Note the same can work for the case where out is not written to at all in main () and thus nothing needs to be passed to foo (that might be the most common case, like when passing an alternate output by reference that's not needed). The testcase above is a more general case. If analysis at the call site is flow-sensitive it can check whether any side-effects to 'out' might be observable to handle { struct outs out; if (test) { out.kind =3D 3; foo (&out); // out is dead after the call } else { bar (&out); printf ("%d", out.i); } } but probably IPA SRA local analysis isn't that powerful. Note the advantage is not eliding the out variable at the caller side but possible dead code removal in the callee which need to compute it (similar to the now handled unused return value handling).=