public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug ipa/94693] New: IPA SRA should elide unused out parameters @ 2020-04-21 14:28 rguenth at gcc dot gnu.org 2020-04-21 14:28 ` [Bug ipa/94693] " rguenth at gcc dot gnu.org ` (4 more replies) 0 siblings, 5 replies; 6+ messages in thread From: rguenth at gcc dot gnu.org @ 2020-04-21 14:28 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94693 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 == 0) ; else out->i = out->kind; } int main() { struct outs out; out.kind = 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 = kind; struct outs *out = out_; if (out->kind == 0) ; else out->i = out->kind; } int main() { struct outs out; out.kind = 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 = 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). ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug ipa/94693] IPA SRA should elide unused out parameters 2020-04-21 14:28 [Bug ipa/94693] New: IPA SRA should elide unused out parameters rguenth at gcc dot gnu.org @ 2020-04-21 14:28 ` rguenth at gcc dot gnu.org 2020-04-21 14:29 ` rguenth at gcc dot gnu.org ` (3 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: rguenth at gcc dot gnu.org @ 2020-04-21 14:28 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94693 Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jamborm at gcc dot gnu.org Keywords| |missed-optimization Severity|normal |enhancement ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug ipa/94693] IPA SRA should elide unused out parameters 2020-04-21 14:28 [Bug ipa/94693] New: IPA SRA should elide unused out parameters rguenth at gcc dot gnu.org 2020-04-21 14:28 ` [Bug ipa/94693] " rguenth at gcc dot gnu.org @ 2020-04-21 14:29 ` rguenth at gcc dot gnu.org 2020-04-21 14:47 ` rguenth at gcc dot gnu.org ` (2 subsequent siblings) 4 siblings, 0 replies; 6+ messages in thread From: rguenth at gcc dot gnu.org @ 2020-04-21 14:29 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94693 Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |90591 --- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> --- Inspired by the testcase in PR90591. Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90591 [Bug 90591] Avoid unnecessary data transfer out of OMP construct ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug ipa/94693] IPA SRA should elide unused out parameters 2020-04-21 14:28 [Bug ipa/94693] New: IPA SRA should elide unused out parameters rguenth at gcc dot gnu.org 2020-04-21 14:28 ` [Bug ipa/94693] " rguenth at gcc dot gnu.org 2020-04-21 14:29 ` rguenth at gcc dot gnu.org @ 2020-04-21 14:47 ` rguenth at gcc dot gnu.org 2020-04-21 14:54 ` rguenth at gcc dot gnu.org 2020-04-21 15:30 ` egallager at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: rguenth at gcc dot gnu.org @ 2020-04-21 14:47 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94693 --- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> --- Another testcase would be like int foo (void **ret) { *ret = NULL; return 0; } int bar () { void *dummy; return bar (&dummy); } int main() { void *dummy; if (!foo (&dummy)) return 0; abort (); } and ret/dummy can be elided. I've included the twist that we pass two different 'dummy' (but I understand IPA SRA works per call and doesn't try "sharing" the clones?) ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug ipa/94693] IPA SRA should elide unused out parameters 2020-04-21 14:28 [Bug ipa/94693] New: IPA SRA should elide unused out parameters rguenth at gcc dot gnu.org ` (2 preceding siblings ...) 2020-04-21 14:47 ` rguenth at gcc dot gnu.org @ 2020-04-21 14:54 ` rguenth at gcc dot gnu.org 2020-04-21 15:30 ` egallager at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: rguenth at gcc dot gnu.org @ 2020-04-21 14:54 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94693 --- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> --- Or a bit more twisty struct A { int key; double payload_A; }; struct B { int key; int payload_B; }; void foo (int *key) { switch (*key) { case 1: ((struct A *)key)->payload_A = 1.0; break; case 2: ((struct B *)key)->payload_B = 1; break; default:; } } void bar() { struct A s; s.key = 1; foo (&s); } void baz() { struct B s; s.key = 2; foo (&s); } to show that the type of the variable to instantiate as storage in the callee is non-trivial (the only real constraint is it should be the maximum size of the storage actually accessed). Possibly simply make sure the actually passed types are types_compatible_p and use one of those. With the above cases it also appears that IPA CP could be the one handling this since &s is a (non-IP invariant) constant and the initializer is a constant as well. But I guess it's more IPA SRA. ^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug ipa/94693] IPA SRA should elide unused out parameters 2020-04-21 14:28 [Bug ipa/94693] New: IPA SRA should elide unused out parameters rguenth at gcc dot gnu.org ` (3 preceding siblings ...) 2020-04-21 14:54 ` rguenth at gcc dot gnu.org @ 2020-04-21 15:30 ` egallager at gcc dot gnu.org 4 siblings, 0 replies; 6+ messages in thread From: egallager at gcc dot gnu.org @ 2020-04-21 15:30 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94693 Eric Gallager <egallager at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- See Also| |https://gcc.gnu.org/bugzill | |a/show_bug.cgi?id=68230 CC| |egallager at gcc dot gnu.org --- Comment #4 from Eric Gallager <egallager at gcc dot gnu.org> --- is there an opportunity to extend -Wunused-parameter here, too? I don't get anything from it currently... (see also bug 68230 for another case where IPA SRA could help extend -Wunused-parameter) ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-04-21 15:30 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-04-21 14:28 [Bug ipa/94693] New: IPA SRA should elide unused out parameters rguenth at gcc dot gnu.org 2020-04-21 14:28 ` [Bug ipa/94693] " rguenth at gcc dot gnu.org 2020-04-21 14:29 ` rguenth at gcc dot gnu.org 2020-04-21 14:47 ` rguenth at gcc dot gnu.org 2020-04-21 14:54 ` rguenth at gcc dot gnu.org 2020-04-21 15:30 ` egallager at gcc dot gnu.org
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).