public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug tree-optimization/115034] New: Missed optimization: reduntant store of identical value in the slot @ 2024-05-10 14:34 xxs_chy at outlook dot com 2024-05-10 14:43 ` [Bug tree-optimization/115034] " pinskia at gcc dot gnu.org ` (2 more replies) 0 siblings, 3 replies; 4+ messages in thread From: xxs_chy at outlook dot com @ 2024-05-10 14:34 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115034 Bug ID: 115034 Summary: Missed optimization: reduntant store of identical value in the slot Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: xxs_chy at outlook dot com Target Milestone: --- Godbolt link: https://godbolt.org/z/fdxKaxGoj ``` int src(int* outl, bool c1, bool c2) { int a; *outl = 0; if (c1) if (c2) { dummy(); return 0; } else { a = 1; } else { // we don't need to assign a = 0 a = 0; } *outl = a; return 0; } ``` can be transformed into: ``` int tgt(int* outl, bool c1, bool c2) { int a; *outl = 0; if (c1) { if (c2) { dummy(); return 0; } else { a = 1; } } else { return 0; } *outl = 1; return 0; } ``` Because "*outl = 0" is known at the entry, the path "a = 0 -> *outl = 0" can be cut off. That is, we can move "*outl = 1" into the path where c1 is true. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/115034] Missed optimization: reduntant store of identical value in the slot 2024-05-10 14:34 [Bug tree-optimization/115034] New: Missed optimization: reduntant store of identical value in the slot xxs_chy at outlook dot com @ 2024-05-10 14:43 ` pinskia at gcc dot gnu.org 2024-05-10 15:32 ` xxs_chy at outlook dot com 2024-05-13 9:33 ` rguenth at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: pinskia at gcc dot gnu.org @ 2024-05-10 14:43 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115034 --- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Note there is some memory model requirements here that I always forget if this can happen or not. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/115034] Missed optimization: reduntant store of identical value in the slot 2024-05-10 14:34 [Bug tree-optimization/115034] New: Missed optimization: reduntant store of identical value in the slot xxs_chy at outlook dot com 2024-05-10 14:43 ` [Bug tree-optimization/115034] " pinskia at gcc dot gnu.org @ 2024-05-10 15:32 ` xxs_chy at outlook dot com 2024-05-13 9:33 ` rguenth at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: xxs_chy at outlook dot com @ 2024-05-10 15:32 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115034 --- Comment #2 from XChy <xxs_chy at outlook dot com> --- (In reply to Andrew Pinski from comment #1) > Note there is some memory model requirements here that I always forget if > this can happen or not. Hmm. Could you please provide some documents about the memory model of GCC or specific constraints about C language? The semantics of IR in the LLVM issue look good to me, since the store is non-volatile and non-atomic. But I'm not sure how it would be after lifting to C. ^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug tree-optimization/115034] Missed optimization: reduntant store of identical value in the slot 2024-05-10 14:34 [Bug tree-optimization/115034] New: Missed optimization: reduntant store of identical value in the slot xxs_chy at outlook dot com 2024-05-10 14:43 ` [Bug tree-optimization/115034] " pinskia at gcc dot gnu.org 2024-05-10 15:32 ` xxs_chy at outlook dot com @ 2024-05-13 9:33 ` rguenth at gcc dot gnu.org 2 siblings, 0 replies; 4+ messages in thread From: rguenth at gcc dot gnu.org @ 2024-05-13 9:33 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115034 Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Keywords| |missed-optimization Last reconfirmed| |2024-05-13 Ever confirmed|0 |1 --- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> --- This would work if we'd duplicate the path from a = 0 to *outl = 1; return 0; but we don't early enough (on GIMPLE) and we don't do that on RTL until BB reorder where ther's no later pass doing this optimization either. On GIMPLE we see <bb 2> [local count: 1073741824]: *outl_4(D) = 0; if (c1_6(D) != 0) goto <bb 3>; [50.00%] else goto <bb 5>; [50.00%] ... <bb 5> [local count: 965079152]: # a_1 = PHI <1(3), 0(2)> *outl_4(D) = a_1; return 0; but I think tracer doesn't consider paths to exit aka tail duplication, likely because on GIMPLE we force a single return block. There's also no partial redundant store elimination. ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-05-13 9:33 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-05-10 14:34 [Bug tree-optimization/115034] New: Missed optimization: reduntant store of identical value in the slot xxs_chy at outlook dot com 2024-05-10 14:43 ` [Bug tree-optimization/115034] " pinskia at gcc dot gnu.org 2024-05-10 15:32 ` xxs_chy at outlook dot com 2024-05-13 9:33 ` rguenth 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).