public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug tree-optimization/109943] New: [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-6834-g41ade3399bd @ 2023-05-23 13:30 theodort at inf dot ethz.ch 2023-05-23 15:56 ` [Bug tree-optimization/109943] " rguenth at gcc dot gnu.org ` (6 more replies) 0 siblings, 7 replies; 8+ messages in thread From: theodort at inf dot ethz.ch @ 2023-05-23 13:30 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109943 Bug ID: 109943 Summary: [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-6834-g41ade3399bd Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: theodort at inf dot ethz.ch Target Milestone: --- void foo(void); static int b = 5; static int *c = &b; static char(a)(char d, char g) { ; return d % g; } static void e(unsigned char d, unsigned g) { char h = a(g, d); if (h) if ((d) >= 0) { foo(); }; } static void f(int d) { e(b, d); } int main() { f(*c); *c = 0; } gcc-trunk -O3 generates: main: movl $0, b(%rip) xorl %eax, %eax ret However, including additional info via __builtin_unreachable results to worse code: void foo(void); static int b = 5; static int *c = &b; static char(a)(char d, char g) { if ((g) <= 0) { __builtin_unreachable(); } return d % g; } static void e(unsigned char d, unsigned g) { char h = a(g, d); if (h) if ((d) >= 0) { foo(); }; } static void f(int d) { e(b, d); } int main() { f(*c); *c = 0; } gcc-trunk (and 13) -O3 generates: main: movl b(%rip), %ecx movsbl %cl, %eax movzbl %cl, %ecx cltd idivl %ecx testl %edx, %edx jne .L11 movl $0, b(%rip) xorl %eax, %eax ret .L11: pushq %rax call foo xorl %edx, %edx xorl %eax, %eax movl %edx, b(%rip) popq %rcx ret https://godbolt.org/z/n34Tsr3vq gcc-12 can generate optimized code for both cases Started with r13-6834-g41ade3399bd ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/109943] [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-6834-g41ade3399bd 2023-05-23 13:30 [Bug tree-optimization/109943] New: [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-6834-g41ade3399bd theodort at inf dot ethz.ch @ 2023-05-23 15:56 ` rguenth at gcc dot gnu.org 2023-06-20 16:34 ` theodort at inf dot ethz.ch ` (5 subsequent siblings) 6 siblings, 0 replies; 8+ messages in thread From: rguenth at gcc dot gnu.org @ 2023-05-23 15:56 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109943 Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |missed-optimization Target Milestone|--- |13.2 CC| |aldyh at gcc dot gnu.org --- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> --- Without looking in detail if it now fails to undo a propagation that might now confuse ranger. ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/109943] [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-6834-g41ade3399bd 2023-05-23 13:30 [Bug tree-optimization/109943] New: [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-6834-g41ade3399bd theodort at inf dot ethz.ch 2023-05-23 15:56 ` [Bug tree-optimization/109943] " rguenth at gcc dot gnu.org @ 2023-06-20 16:34 ` theodort at inf dot ethz.ch 2023-07-27 9:26 ` rguenth at gcc dot gnu.org ` (4 subsequent siblings) 6 siblings, 0 replies; 8+ messages in thread From: theodort at inf dot ethz.ch @ 2023-06-20 16:34 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109943 --- Comment #2 from Theodoros Theodoridis <theodort at inf dot ethz.ch> --- Not sure if it's useful but the following also started with the same commit: https://godbolt.org/z/Tqha4K976 Given the following code: void foo(void); static int d, e, h; static int *f = &e, *q; static int **g = &f; static long j, p; static short k; void __assert_fail() __attribute__((__noreturn__)); static short(a)(short b, short c) { if (!(((b) >= -90) && ((b) <= 0))) { __builtin_unreachable(); } return c == 0 || b == 1 && c == 1 ?: b % c; } static int **i(); static int l(int *m, long n) { j = 0 >= d; k = j - 34834; if (a(-n, k)) *g = m; if (f == 0 || f == &e) ; else __assert_fail(); for (; h; ++h) ; return *m; } static int *o() { l(f, 90); g = i(); if (f == 0 || f == &e) ; else foo(); return &d; } static int **i() { a(p, h); return &q; } int main() { o(); } gcc-trunk -O2 generates: main: subq $8, %rsp movq f(%rip), %rax movq g(%rip), %rdx movq %rax, (%rdx) cmpq $e, %rax je .L7 testq %rax, %rax jne .L2 .L7: movl h(%rip), %edx testl %edx, %edx je .L5 movl $0, h(%rip) .L5: movq $q, g(%rip) cmpq $e, %rax je .L6 call foo .L6: xorl %eax, %eax addq $8, %rsp ret .L2: xorl %eax, %eax call __assert_fail gcc-12.3.0 -O2 generates: main: movq f(%rip), %rax movq g(%rip), %rdx movq %rax, (%rdx) cmpq $e, %rax je .L6 testq %rax, %rax jne .L2 .L6: movl h(%rip), %edx testl %edx, %edx je .L5 movl $0, h(%rip) .L5: movq $q, g(%rip) xorl %eax, %eax ret .L2: pushq %rax xorl %eax, %eax call __assert_fail ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/109943] [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-6834-g41ade3399bd 2023-05-23 13:30 [Bug tree-optimization/109943] New: [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-6834-g41ade3399bd theodort at inf dot ethz.ch 2023-05-23 15:56 ` [Bug tree-optimization/109943] " rguenth at gcc dot gnu.org 2023-06-20 16:34 ` theodort at inf dot ethz.ch @ 2023-07-27 9:26 ` rguenth at gcc dot gnu.org 2023-08-21 23:09 ` pinskia at gcc dot gnu.org ` (3 subsequent siblings) 6 siblings, 0 replies; 8+ messages in thread From: rguenth at gcc dot gnu.org @ 2023-07-27 9:26 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109943 Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|13.2 |13.3 --- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> --- GCC 13.2 is being released, retargeting bugs to GCC 13.3. ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/109943] [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-6834-g41ade3399bd 2023-05-23 13:30 [Bug tree-optimization/109943] New: [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-6834-g41ade3399bd theodort at inf dot ethz.ch ` (2 preceding siblings ...) 2023-07-27 9:26 ` rguenth at gcc dot gnu.org @ 2023-08-21 23:09 ` pinskia at gcc dot gnu.org 2024-01-12 13:50 ` rguenth at gcc dot gnu.org ` (2 subsequent siblings) 6 siblings, 0 replies; 8+ messages in thread From: pinskia at gcc dot gnu.org @ 2023-08-21 23:09 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109943 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Ever confirmed|0 |1 Last reconfirmed| |2023-08-21 Status|UNCONFIRMED |NEW --- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> --- For the testcase in comment #0, fre3 is able to optmize it away (in GCC 12.3.0): Applying pattern match.pd:636, gimple-match.cc:47124 Match-and-simplified _10 % _8 to 0 That is because we figure out that _10 is the same as _8 somehow. Confirmed. ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/109943] [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-6834-g41ade3399bd 2023-05-23 13:30 [Bug tree-optimization/109943] New: [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-6834-g41ade3399bd theodort at inf dot ethz.ch ` (3 preceding siblings ...) 2023-08-21 23:09 ` pinskia at gcc dot gnu.org @ 2024-01-12 13:50 ` rguenth at gcc dot gnu.org 2024-01-12 13:52 ` rguenth at gcc dot gnu.org 2024-05-21 9:15 ` [Bug tree-optimization/109943] [13/14/15 " jakub at gcc dot gnu.org 6 siblings, 0 replies; 8+ messages in thread From: rguenth at gcc dot gnu.org @ 2024-01-12 13:50 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109943 --- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> --- With the __builtin_unreachable present (thus g >= 0) we simplify (int)(char)d to d & 255 which causes the VN difference: Value numbering stmt = _9 = (int) _8; +d.4_7 is available for d.4_7 +_2 is available for _2 Setting value number of _9 to _9 (changed) -Making available beyond BB2 _9 for value _9 -Value numbering stmt = _10 = (int) d.4_7; -Setting value number of _10 to _9 (changed) +Making available beyond BB4 _9 for value _9 +Value numbering stmt = _10 = b.3_6 & 255; +_2 is available for _2 +Setting value number of _10 to _10 (changed) +Making available beyond BB4 _10 for value _10 Value numbering stmt = _11 = _9 % _10; in particular we have _2 = b; b.3_6 = b; d.4_7 = (char) b.3_6; _8 = (char) _2; _9 = (int) _8; _10 = (int) d.4_7; _11 = _9 % _10; vs. _2 = b; b.3_6 = b; d.4_7 = (char) b.3_6; _8 = (char) _2; if (d.4_7 <= 0) goto <bb 3>; [0.00%] else goto <bb 4>; [100.00%] <bb 3> [count: 0]: __builtin_unreachable (); <bb 4> [local count: 1073741824]: _9 = (int) _8; _10 = b.3_6 & 255; _11 = _9 % _10; where the trivial equivalence is no longer visible. ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/109943] [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-6834-g41ade3399bd 2023-05-23 13:30 [Bug tree-optimization/109943] New: [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-6834-g41ade3399bd theodort at inf dot ethz.ch ` (4 preceding siblings ...) 2024-01-12 13:50 ` rguenth at gcc dot gnu.org @ 2024-01-12 13:52 ` rguenth at gcc dot gnu.org 2024-05-21 9:15 ` [Bug tree-optimization/109943] [13/14/15 " jakub at gcc dot gnu.org 6 siblings, 0 replies; 8+ messages in thread From: rguenth at gcc dot gnu.org @ 2024-01-12 13:52 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109943 Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Priority|P3 |P2 --- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> --- The rev. in question must be an odd coincidence - I suppose we're undoing the forwprop somehow before it. ^ permalink raw reply [flat|nested] 8+ messages in thread
* [Bug tree-optimization/109943] [13/14/15 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-6834-g41ade3399bd 2023-05-23 13:30 [Bug tree-optimization/109943] New: [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-6834-g41ade3399bd theodort at inf dot ethz.ch ` (5 preceding siblings ...) 2024-01-12 13:52 ` rguenth at gcc dot gnu.org @ 2024-05-21 9:15 ` jakub at gcc dot gnu.org 6 siblings, 0 replies; 8+ messages in thread From: jakub at gcc dot gnu.org @ 2024-05-21 9:15 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109943 Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|13.3 |13.4 --- Comment #7 from Jakub Jelinek <jakub at gcc dot gnu.org> --- GCC 13.3 is being released, retargeting bugs to GCC 13.4. ^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2024-05-21 9:15 UTC | newest] Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-05-23 13:30 [Bug tree-optimization/109943] New: [13/14 Regression] Missed Dead Code Elimination when using __builtin_unreachable since r13-6834-g41ade3399bd theodort at inf dot ethz.ch 2023-05-23 15:56 ` [Bug tree-optimization/109943] " rguenth at gcc dot gnu.org 2023-06-20 16:34 ` theodort at inf dot ethz.ch 2023-07-27 9:26 ` rguenth at gcc dot gnu.org 2023-08-21 23:09 ` pinskia at gcc dot gnu.org 2024-01-12 13:50 ` rguenth at gcc dot gnu.org 2024-01-12 13:52 ` rguenth at gcc dot gnu.org 2024-05-21 9:15 ` [Bug tree-optimization/109943] [13/14/15 " jakub 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).