public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
* [Bug tree-optimization/110919] New: [14 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 @ 2023-08-06 11:05 scherrer.sv at gmail dot com 2023-08-06 11:35 ` [Bug tree-optimization/110919] " scherrer.sv at gmail dot com ` (10 more replies) 0 siblings, 11 replies; 12+ messages in thread From: scherrer.sv at gmail dot com @ 2023-08-06 11:05 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110919 Bug ID: 110919 Summary: [14 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: tree-optimization Assignee: unassigned at gcc dot gnu.org Reporter: scherrer.sv at gmail dot com Target Milestone: --- static short a, b; static int e; static int *j = &e; void bar151_(void); void foo(void); void bar162_(void); static int(d)(int k, int l) { return l == k && l - 1 ? k : 0; } static void f(); static void g(unsigned short, unsigned); static void h() { g(0, 4); f(); int i = -1; g(0, i); } static void f(int k) { g(k, 0); } static void g(unsigned short k, unsigned l) { if (k) bar151_(); if (l) if (k) bar162_(); short c = l; b = c == 0 || a; if (d(*j, b)) foo(); } int main() { h(); } gcc-87b0749cfb9 (trunk) -O3 cannot eliminate the call to foo but gcc-releases/gcc-13.1.0 -O3 can. ----------------------------------------------------------------------- gcc-87b0749cfb9406790b108208b466cf507ae3c431 -O3 case.c -S -o case.s --------- OUTPUT --------- main: .LFB4: .cfi_startproc subq $8, %rsp .cfi_def_cfa_offset 16 movl $4, %esi xorl %edi, %edi call g xorl %esi, %esi xorl %edi, %edi call g movl $-1, %esi xorl %edi, %edi call g xorl %eax, %eax addq $8, %rsp .cfi_def_cfa_offset 8 ret ---------- END OUTPUT --------- ----------------------------------------------------------------------- gcc-2b98cc24d6af0432a74f6dad1c722ce21c1f7458 -O3 case.c -S -o case.s --------- OUTPUT --------- main: .LFB4: .cfi_startproc subq $8, %rsp .cfi_def_cfa_offset 16 movl $4, %esi xorl %edi, %edi call g xorl %esi, %esi xorl %edi, %edi call g movl $-1, %esi xorl %edi, %edi call g xorl %eax, %eax addq $8, %rsp .cfi_def_cfa_offset 8 ret ---------- END OUTPUT --------- ----------------------------------------------------------------------- Bisects to r14-1691-gbc5a2c2e793 ^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug tree-optimization/110919] [14 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 2023-08-06 11:05 [Bug tree-optimization/110919] New: [14 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 scherrer.sv at gmail dot com @ 2023-08-06 11:35 ` scherrer.sv at gmail dot com 2023-08-06 16:55 ` pinskia at gcc dot gnu.org ` (9 subsequent siblings) 10 siblings, 0 replies; 12+ messages in thread From: scherrer.sv at gmail dot com @ 2023-08-06 11:35 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110919 --- Comment #1 from Scherrer Svenja <scherrer.sv at gmail dot com> --- My apologies, the assembly above is incomplete. The following shows the bug gcc-87b0749cfb9406790b108208b466cf507ae3c431 -O3 case.c -S -o case.s --------- OUTPUT --------- .file "case.c" .text .p2align 4 .type g, @function g: .LFB3: .cfi_startproc pushq %rbx .cfi_def_cfa_offset 16 .cfi_offset 3, -16 movl %esi, %ebx testw %di, %di jne .L2 xorl %eax, %eax testl %esi, %esi sete %al .L3: movl e(%rip), %edx cmpl %eax, %edx sete %cl testl %edx, %edx setne %dl testb %dl, %cl je .L1 testl %eax, %eax je .L15 .L1: popq %rbx .cfi_remember_state .cfi_def_cfa_offset 8 ret .L2: .cfi_restore_state call bar151_ testl %ebx, %ebx je .L1 call bar162_ xorl %eax, %eax jmp .L3 .L15: popq %rbx .cfi_def_cfa_offset 8 jmp foo .cfi_endproc .LFE3: .size g, .-g .section .text.startup,"ax",@progbits .p2align 4 .globl main .type main, @function main: .LFB4: .cfi_startproc subq $8, %rsp .cfi_def_cfa_offset 16 movl $4, %esi xorl %edi, %edi call g xorl %esi, %esi xorl %edi, %edi call g movl $-1, %esi xorl %edi, %edi call g xorl %eax, %eax addq $8, %rsp .cfi_def_cfa_offset 8 ret .cfi_endproc .LFE4: .size main, .-main .local e .comm e,4,4 .ident "GCC: (GNU) 14.0.0 20230806 (experimental)" .section .note.GNU-stack,"",@progbits ---------- END OUTPUT --------- ----------------------------------------------------------------------- gcc-2b98cc24d6af0432a74f6dad1c722ce21c1f7458 -O3 case.c -S -o case.s --------- OUTPUT --------- .file "case.c" .text .p2align 4 .type g, @function g: .LFB3: .cfi_startproc testw %di, %di jne .L11 ret .L11: pushq %rbx .cfi_def_cfa_offset 16 .cfi_offset 3, -16 movl %esi, %ebx call bar151_ testl %ebx, %ebx je .L1 popq %rbx .cfi_remember_state .cfi_restore 3 .cfi_def_cfa_offset 8 jmp bar162_ .L1: .cfi_restore_state popq %rbx .cfi_def_cfa_offset 8 ret .cfi_endproc .LFE3: .size g, .-g .section .text.startup,"ax",@progbits .p2align 4 .globl main .type main, @function main: .LFB4: .cfi_startproc subq $8, %rsp .cfi_def_cfa_offset 16 movl $4, %esi xorl %edi, %edi call g xorl %esi, %esi xorl %edi, %edi call g movl $-1, %esi xorl %edi, %edi call g xorl %eax, %eax addq $8, %rsp .cfi_def_cfa_offset 8 ret .cfi_endproc .LFE4: .size main, .-main .ident "GCC: (GNU) 13.1.0" .section .note.GNU-stack,"",@progbits ---------- END OUTPUT --------- ^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug tree-optimization/110919] [14 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 2023-08-06 11:05 [Bug tree-optimization/110919] New: [14 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 scherrer.sv at gmail dot com 2023-08-06 11:35 ` [Bug tree-optimization/110919] " scherrer.sv at gmail dot com @ 2023-08-06 16:55 ` pinskia at gcc dot gnu.org 2023-08-06 17:12 ` pinskia at gcc dot gnu.org ` (8 subsequent siblings) 10 siblings, 0 replies; 12+ messages in thread From: pinskia at gcc dot gnu.org @ 2023-08-06 16:55 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110919 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|--- |14.0 Keywords| |missed-optimization ^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug tree-optimization/110919] [14 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 2023-08-06 11:05 [Bug tree-optimization/110919] New: [14 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 scherrer.sv at gmail dot com 2023-08-06 11:35 ` [Bug tree-optimization/110919] " scherrer.sv at gmail dot com 2023-08-06 16:55 ` pinskia at gcc dot gnu.org @ 2023-08-06 17:12 ` pinskia at gcc dot gnu.org 2023-08-20 9:11 ` pinskia at gcc dot gnu.org ` (7 subsequent siblings) 10 siblings, 0 replies; 12+ messages in thread From: pinskia at gcc dot gnu.org @ 2023-08-06 17:12 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110919 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Last reconfirmed| |2023-08-06 Status|UNCONFIRMED |NEW Ever confirmed|0 |1 --- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Confirmed. Note I think what EVRP produces for some thing makes it harder to optimize too. EVRP does: Folding statement: _23 = _4 != 1; Folded into: _23 = (_Bool) _3; And at the end we get: _19 = _6 == iftmp.1_8; _3 = iftmp.1_8 ^ 1; _21 = (_Bool) _3; _23 = _6 != 0; _10 = _19 & _23; _5 = _10 & _21; Which is basically: (a == b) & (a == 0) & (b != 0) ^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug tree-optimization/110919] [14 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 2023-08-06 11:05 [Bug tree-optimization/110919] New: [14 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 scherrer.sv at gmail dot com ` (2 preceding siblings ...) 2023-08-06 17:12 ` pinskia at gcc dot gnu.org @ 2023-08-20 9:11 ` pinskia at gcc dot gnu.org 2023-08-20 18:36 ` pinskia at gcc dot gnu.org ` (6 subsequent siblings) 10 siblings, 0 replies; 12+ messages in thread From: pinskia at gcc dot gnu.org @ 2023-08-20 9:11 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110919 --- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> --- The first change we get is threadfull1 where there is an extra jump threading. And then phiopt2 changes: <bb 3> [local count: 719407024]: if (l_15(D) != 0) goto <bb 6>; [50.00%] else goto <bb 7>; [50.00%] into: <bb 3> [local count: 719407024]: _17 = l_15(D) == 0; _36 = (int) _17; And then DOM2 does not do jump threading along: <bb 6> [local count: 628138968]: # iftmp.1_8 = PHI <_36(3), 0(5)> As I mentioned in comment #2 we don't see that: _19 = _6 == iftmp.1_8; _3 = iftmp.1_8 ^ 1; _21 = (_Bool) _3; _22 = _19 & _21; _23 = _6 != 0; _5 = _22 & _23; is always 0. ^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug tree-optimization/110919] [14 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 2023-08-06 11:05 [Bug tree-optimization/110919] New: [14 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 scherrer.sv at gmail dot com ` (3 preceding siblings ...) 2023-08-20 9:11 ` pinskia at gcc dot gnu.org @ 2023-08-20 18:36 ` pinskia at gcc dot gnu.org 2023-08-20 18:41 ` pinskia at gcc dot gnu.org ` (5 subsequent siblings) 10 siblings, 0 replies; 12+ messages in thread From: pinskia at gcc dot gnu.org @ 2023-08-20 18:36 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110919 Andrew Pinski <pinskia at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |ASSIGNED Assignee|unassigned at gcc dot gnu.org |pinskia at gcc dot gnu.org --- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> --- After reassoc1 we have: _19 = _6 == iftmp.1_8; _3 = iftmp.1_8 ^ 1; _21 = (_Bool) _3; _23 = _6 != 0; _10 = _19 & _23; _5 = _10 & _21; Which is: (_6 != 0) & (_6 == iftmp.1_8) But since we know that iftmp.1_8 only has 2 values, we could optimize this to: (_6 == 1) & (iftmp.1_8 == 1) Reduced testcase: ``` _Bool f(int a, int b) { b &= 1; _Bool t = a == b; int c = b^1; _Bool d = c; _Bool e = a; _Bool g = t & d; _Bool h = g & e; return h; } ``` This should return false always. So something like: (simplify (bit_and:c (eq:c @0 @1) (ne:c @0 INTEGER_CST@2)) (if (has_two_value_range (@1)) (with { tree other_value = ...; } (bit_and (eq @0 { other_value; }) (eq @1 { other_value; })) ) ) ) ^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug tree-optimization/110919] [14 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 2023-08-06 11:05 [Bug tree-optimization/110919] New: [14 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 scherrer.sv at gmail dot com ` (4 preceding siblings ...) 2023-08-20 18:36 ` pinskia at gcc dot gnu.org @ 2023-08-20 18:41 ` pinskia at gcc dot gnu.org 2023-09-04 5:53 ` pinskia at gcc dot gnu.org ` (4 subsequent siblings) 10 siblings, 0 replies; 12+ messages in thread From: pinskia at gcc dot gnu.org @ 2023-08-20 18:41 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110919 --- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Or take: ``` _Bool g(int a, int b) { b &= 1; _Bool t = a == b; _Bool e = a != 0; _Bool g = t & e; return g; } int g0(int a, int b) { b &= 1; _Bool t = 1 == b; _Bool e = a == 1; _Bool g = t & e; return g; } ``` These two should produce the same code generation. ^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug tree-optimization/110919] [14 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 2023-08-06 11:05 [Bug tree-optimization/110919] New: [14 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 scherrer.sv at gmail dot com ` (5 preceding siblings ...) 2023-08-20 18:41 ` pinskia at gcc dot gnu.org @ 2023-09-04 5:53 ` pinskia at gcc dot gnu.org 2023-09-04 6:09 ` pinskia at gcc dot gnu.org ` (3 subsequent siblings) 10 siblings, 0 replies; 12+ messages in thread From: pinskia at gcc dot gnu.org @ 2023-09-04 5:53 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110919 --- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> --- For -O1 we have: _24 = c_16 == 0; _6 = (int) _24; _2 = (short int) _24; _3 = (int) _24; _5 = e; _20 = _3 == _5; _21 = c_16 != 0; _22 = _20 & _21; ((c_16 == 0) == _5) & (c_16 != 0) ((!b) ? 0 : 1) == _5 & (b) (c_16 != 0) & (0 == _5) This fixes -O1 (which didn't work before): (simplify (bit_and:c zero_one_valued_p@0 (eq:c @1 (convert @2))) (with { bool wascmp; } (if (bitwise_inverted_equal_p (@0, @2, wascmp)) (bit_and @0 (eq @1 { build_zero_cst (TREE_TYPE (@1)); }))))) But -O2 is still broken. ^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug tree-optimization/110919] [14 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 2023-08-06 11:05 [Bug tree-optimization/110919] New: [14 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 scherrer.sv at gmail dot com ` (6 preceding siblings ...) 2023-09-04 5:53 ` pinskia at gcc dot gnu.org @ 2023-09-04 6:09 ` pinskia at gcc dot gnu.org 2023-09-04 6:55 ` pinskia at gcc dot gnu.org ` (2 subsequent siblings) 10 siblings, 0 replies; 12+ messages in thread From: pinskia at gcc dot gnu.org @ 2023-09-04 6:09 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110919 --- Comment #7 from Andrew Pinski <pinskia at gcc dot gnu.org> --- Generalized for -O1 case: // (a & (b & ~a)) -> 0 // (a & (b | ~a)) -> a & b // (a & (b ^ ~a)) -> a & b // (a & (b cmp !a)) -> a & (b cmp 0) (for op (tcc_comparison bit_and bit_xor bit_and) (simplify (bit_and:c zero_one_valued_p@0 (op:c @1 (convert? @2))) (with { bool wascmp; } (if (bitwise_inverted_equal_p (@0, @2, wascmp)) (bit_and @0 (op @1 { build_zero_cst (TREE_TYPE (@1)); }))))) Note I filed PR 111282 for `(a & (b ^ ~a))` also. ^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug tree-optimization/110919] [14 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 2023-08-06 11:05 [Bug tree-optimization/110919] New: [14 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 scherrer.sv at gmail dot com ` (7 preceding siblings ...) 2023-09-04 6:09 ` pinskia at gcc dot gnu.org @ 2023-09-04 6:55 ` pinskia at gcc dot gnu.org 2024-03-07 23:26 ` law at gcc dot gnu.org 2024-05-07 7:41 ` [Bug tree-optimization/110919] [14/15 " rguenth at gcc dot gnu.org 10 siblings, 0 replies; 12+ messages in thread From: pinskia at gcc dot gnu.org @ 2023-09-04 6:55 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110919 --- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> --- (In reply to Andrew Pinski from comment #7) > Generalized for -O1 case: > // (a & (b & ~a)) -> 0 > // (a & (b | ~a)) -> a & b > // (a & (b ^ ~a)) -> a & b > // (a & (b cmp !a)) -> a & (b cmp 0) > (for op (tcc_comparison bit_and bit_xor bit_and) > (simplify > (bit_and:c zero_one_valued_p@0 (op:c @1 (convert? @2))) > (with { bool wascmp; } > (if (bitwise_inverted_equal_p (@0, @2, wascmp)) > (bit_and @0 (op @1 { build_zero_cst (TREE_TYPE (@1)); }))))) > > > Note I filed PR 111282 for `(a & (b ^ ~a))` also. The corrected version is: // (a & (b & ~a)) -> 0 // (a & (b | ~a)) -> a & b // (a & (b ^ ~a)) -> a & b // (a & (b cmp !a)) -> a & (b cmp 0) (for op (tcc_comparison bit_and bit_xor bit_and) (simplify (bit_and:c zero_one_valued_p@0 (op:c @1 (convert? zero_one_valued_p@2))) (with { bool wascmp; } (if (bitwise_inverted_equal_p (@0, @2, wascmp)) (bit_and @0 (op @1 { build_zero_cst (TREE_TYPE (@1)); })))))) ^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug tree-optimization/110919] [14 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 2023-08-06 11:05 [Bug tree-optimization/110919] New: [14 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 scherrer.sv at gmail dot com ` (8 preceding siblings ...) 2023-09-04 6:55 ` pinskia at gcc dot gnu.org @ 2024-03-07 23:26 ` law at gcc dot gnu.org 2024-05-07 7:41 ` [Bug tree-optimization/110919] [14/15 " rguenth at gcc dot gnu.org 10 siblings, 0 replies; 12+ messages in thread From: law at gcc dot gnu.org @ 2024-03-07 23:26 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110919 Jeffrey A. Law <law at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |law at gcc dot gnu.org Priority|P3 |P2 ^ permalink raw reply [flat|nested] 12+ messages in thread
* [Bug tree-optimization/110919] [14/15 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 2023-08-06 11:05 [Bug tree-optimization/110919] New: [14 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 scherrer.sv at gmail dot com ` (9 preceding siblings ...) 2024-03-07 23:26 ` law at gcc dot gnu.org @ 2024-05-07 7:41 ` rguenth at gcc dot gnu.org 10 siblings, 0 replies; 12+ messages in thread From: rguenth at gcc dot gnu.org @ 2024-05-07 7:41 UTC (permalink / raw) To: gcc-bugs https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110919 Richard Biener <rguenth at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Target Milestone|14.0 |14.2 --- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> --- GCC 14.1 is being released, retargeting bugs to GCC 14.2. ^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2024-05-07 7:41 UTC | newest] Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2023-08-06 11:05 [Bug tree-optimization/110919] New: [14 Regression] Dead Code Elimination Regression at -O3 since r14-1691-gbc5a2c2e793 scherrer.sv at gmail dot com 2023-08-06 11:35 ` [Bug tree-optimization/110919] " scherrer.sv at gmail dot com 2023-08-06 16:55 ` pinskia at gcc dot gnu.org 2023-08-06 17:12 ` pinskia at gcc dot gnu.org 2023-08-20 9:11 ` pinskia at gcc dot gnu.org 2023-08-20 18:36 ` pinskia at gcc dot gnu.org 2023-08-20 18:41 ` pinskia at gcc dot gnu.org 2023-09-04 5:53 ` pinskia at gcc dot gnu.org 2023-09-04 6:09 ` pinskia at gcc dot gnu.org 2023-09-04 6:55 ` pinskia at gcc dot gnu.org 2024-03-07 23:26 ` law at gcc dot gnu.org 2024-05-07 7:41 ` [Bug tree-optimization/110919] [14/15 " 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).