public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111003] New: [14 Regression] Dead Code Elimination Regression at -O3 since r14-2161-g237e83e2158
@ 2023-08-12 13:53 scherrer.sv at gmail dot com
  2023-08-12 17:39 ` [Bug tree-optimization/111003] " pinskia at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: scherrer.sv at gmail dot com @ 2023-08-12 13:53 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111003

            Bug ID: 111003
           Summary: [14 Regression] Dead Code Elimination Regression at
                    -O3 since r14-2161-g237e83e2158
           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 int c, d, e, f;
static short g;
static int *h = &c;
void foo(void);
short(a)();
static unsigned b(unsigned char j, int l) { return j > l ? j : j << l; }
static int *i();
static void k(int j, unsigned char l) {
  i();
  g = f;
  f = g;
  for (; g;) {
    int m;
    d = a();
    for (; d;) {
      if (l)
        if (!(j >= -639457069 && j <= -639457069))
          if (m)
            foo();
      m = (10 != (l ^ b(j, 6))) < (0 > e);
    }
  }
}
static int *i() {
  for (; e; e = a(e, 6))
    ;
  return h;
}
int main() { k(c, c); }

gcc-8441841a1b9 (trunk) -O3 cannot eliminate the call to foo but
gcc-releases/gcc-13.1.0 -O3 can.
-----------------------------------------------------------------------
gcc-8441841a1b985d68245954af1ff023db121b0635 -O3 case.c -S -o case.s
--------- OUTPUT ---------
main:
.LFB3:
        .cfi_startproc
        pushq   %r13
        .cfi_def_cfa_offset 16
        .cfi_offset 13, -16
        pushq   %r12
        .cfi_def_cfa_offset 24
        .cfi_offset 12, -24
        pushq   %rbp
        .cfi_def_cfa_offset 32
        .cfi_offset 6, -32
        pushq   %rbx
        .cfi_def_cfa_offset 40
        .cfi_offset 3, -40
        subq    $8, %rsp
        .cfi_def_cfa_offset 48
        movl    e(%rip), %edi
        movl    c(%rip), %ebx
        testl   %edi, %edi
        je      .L5
        .p2align 4,,10
        .p2align 3
.L2:
        movl    $6, %esi
        xorl    %eax, %eax
        call    a
        movswl  %ax, %edi
        movl    %edi, e(%rip)
        testl   %edi, %edi
        jne     .L2
.L5:
        movl    f(%rip), %eax
        movswl  %ax, %edx
        movw    %ax, g(%rip)
        movl    %edx, f(%rip)
        testw   %ax, %ax
        je      .L36
        movzbl  %bl, %ebp
        testb   %bl, %bl
        je      .L39
        movl    %ebp, %eax
        sall    $6, %eax
        xorl    %ebp, %eax
        cmpl    $10, %eax
        setne   %r12b
        .p2align 4,,10
        .p2align 3
.L18:
        xorl    %eax, %eax
        call    a
        cwtl
        movl    %eax, d(%rip)
        testl   %eax, %eax
        je      .L14
        cmpl    $-639457069, %ebx
        jne     .L17
.L19:
        jmp     .L19
        .p2align 4,,10
        .p2align 3
.L16:
        cmpl    $6, %ebp
        jg      .L20
        movl    e(%rip), %eax
        xorl    %r13d, %r13d
        shrl    $31, %eax
        cmpb    %al, %r12b
        setb    %r13b
        .p2align 4,,10
        .p2align 3
.L17:
        testl   %r13d, %r13d
        je      .L16
        call    foo
        movl    e(%rip), %eax
        shrl    $31, %eax
        cmpl    $6, %ebp
        setg    %dl
        xorl    %r13d, %r13d
        orl     %r12d, %edx
        cmpb    %al, %dl
        movl    d(%rip), %eax
        setb    %r13b
        testl   %eax, %eax
        jne     .L17
.L14:
        cmpw    $0, g(%rip)
        jne     .L18
.L36:
        addq    $8, %rsp
        .cfi_remember_state
        .cfi_def_cfa_offset 40
        xorl    %eax, %eax
        popq    %rbx
        .cfi_def_cfa_offset 32
        popq    %rbp
        .cfi_def_cfa_offset 24
        popq    %r12
        .cfi_def_cfa_offset 16
        popq    %r13
        .cfi_def_cfa_offset 8
        ret
.L39:
        .cfi_restore_state
        cmpl    $6, %ebp
        jg      .L7
        .p2align 4,,10
        .p2align 3
.L10:
        xorl    %eax, %eax
        call    a
        cwtl
        movl    %eax, d(%rip)
        testl   %eax, %eax
        je      .L8
.L9:
        jmp     .L9
        .p2align 4,,10
        .p2align 3
.L12:
        cmpw    $0, g(%rip)
        je      .L36
.L7:
        xorl    %eax, %eax
        call    a
        cwtl
        movl    %eax, d(%rip)
        testl   %eax, %eax
        je      .L12
.L13:
        jmp     .L13
        .p2align 4,,10
        .p2align 3
.L8:
        cmpw    $0, g(%rip)
        jne     .L10
        jmp     .L36
        .p2align 4,,10
        .p2align 3
.L20:
        cmpl    $-639457069, %ebx
        jne     .L20
        jmp     .L19
---------- END OUTPUT ---------

-----------------------------------------------------------------------
gcc-2b98cc24d6af0432a74f6dad1c722ce21c1f7458 -O3 case.c -S -o case.s
--------- OUTPUT ---------
main:
.LFB3:
        .cfi_startproc
        movl    e(%rip), %edi
        pushq   %rbx
        .cfi_def_cfa_offset 16
        .cfi_offset 3, -16
        movl    c(%rip), %ebx
        testl   %edi, %edi
        je      .L5
        .p2align 4,,10
        .p2align 3
.L2:
        movl    $6, %esi
        xorl    %eax, %eax
        call    a
        movswl  %ax, %edi
        movl    %edi, e(%rip)
        testl   %edi, %edi
        jne     .L2
.L5:
        movl    f(%rip), %eax
        movswl  %ax, %edx
        movw    %ax, g(%rip)
        movl    %edx, f(%rip)
        testw   %ax, %ax
        je      .L37
        movzbl  %bl, %eax
        cmpl    $6, %eax
        jg      .L6
        testb   %bl, %bl
        jne     .L7
        .p2align 4,,10
        .p2align 3
.L10:
        xorl    %eax, %eax
        call    a
        cwtl
        movl    %eax, d(%rip)
        testl   %eax, %eax
        je      .L8
.L9:
        jmp     .L9
        .p2align 4,,10
        .p2align 3
.L18:
        cmpw    $0, g(%rip)
        je      .L37
.L6:
        xorl    %eax, %eax
        call    a
        cwtl
        movl    %eax, d(%rip)
        testl   %eax, %eax
        je      .L18
        cmpl    $-639457069, %ebx
        je      .L39
.L19:
        testl   %eax, %eax
        je      .L18
        cmpl    $-639457069, %ebx
        jne     .L19
.L39:
        jmp     .L39
        .p2align 4,,10
        .p2align 3
.L8:
        cmpw    $0, g(%rip)
        jne     .L10
.L37:
        xorl    %eax, %eax
        popq    %rbx
        .cfi_remember_state
        .cfi_def_cfa_offset 8
        ret
.L7:
        .cfi_restore_state
        cmpl    $-639457069, %ebx
        je      .L15
        .p2align 4,,10
        .p2align 3
.L12:
        xorl    %eax, %eax
        call    a
        cwtl
        movl    %eax, d(%rip)
        testl   %eax, %eax
        je      .L16
.L17:
        jmp     .L17
        .p2align 4,,10
        .p2align 3
.L13:
        cmpw    $0, g(%rip)
        je      .L37
.L15:
        xorl    %eax, %eax
        call    a
        cwtl
        movl    %eax, d(%rip)
        testl   %eax, %eax
        je      .L13
.L14:
        jmp     .L14
        .p2align 4,,10
        .p2align 3
.L16:
        cmpw    $0, g(%rip)
        jne     .L12
        jmp     .L37
---------- END OUTPUT ---------

-----------------------------------------------------------------------
Bisects to r14-2161-g237e83e2158
CC to include: rguenther@suse.de

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/111003] [14 Regression] Dead Code Elimination Regression at -O3 since r14-2161-g237e83e2158
  2023-08-12 13:53 [Bug tree-optimization/111003] New: [14 Regression] Dead Code Elimination Regression at -O3 since r14-2161-g237e83e2158 scherrer.sv at gmail dot com
@ 2023-08-12 17:39 ` pinskia at gcc dot gnu.org
  2023-08-12 17:45 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-12 17:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111003

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |14.0

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/111003] [14 Regression] Dead Code Elimination Regression at -O3 since r14-2161-g237e83e2158
  2023-08-12 13:53 [Bug tree-optimization/111003] New: [14 Regression] Dead Code Elimination Regression at -O3 since r14-2161-g237e83e2158 scherrer.sv at gmail dot com
  2023-08-12 17:39 ` [Bug tree-optimization/111003] " pinskia at gcc dot gnu.org
@ 2023-08-12 17:45 ` pinskia at gcc dot gnu.org
  2023-08-14  8:03 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-12 17:45 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111003

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-08-12
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmned.
The good news is the issue can be reproduced even without < (replaced with !&)
and m being initialized:
```
static int c, d, e, f;
static short g;
static int *h = &c;
void foo(void);
short(a)();
static unsigned b(unsigned char j, int l) { return j > l ? j : j << l; }
static int *i();
static void k(int j, unsigned char l) {
  i();
  g = f;
  f = g;
  for (; g;) {
    int m = 0;
    d = a();
    for (; d;) {
      if (l)
        if (!(j >= -639457069 && j <= -639457069))
          if (m)
            foo();
      m = !(10 != (l ^ b(j, 6))) & (0 > e);
    }
  }
}
static int *i() {
  for (; e; e = a(e, 6))
    ;
  return h;
}
int main() { k(c, c); }
```

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/111003] [14 Regression] Dead Code Elimination Regression at -O3 since r14-2161-g237e83e2158
  2023-08-12 13:53 [Bug tree-optimization/111003] New: [14 Regression] Dead Code Elimination Regression at -O3 since r14-2161-g237e83e2158 scherrer.sv at gmail dot com
  2023-08-12 17:39 ` [Bug tree-optimization/111003] " pinskia at gcc dot gnu.org
  2023-08-12 17:45 ` pinskia at gcc dot gnu.org
@ 2023-08-14  8:03 ` rguenth at gcc dot gnu.org
  2023-11-24  4:33 ` 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-08-14  8:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111003

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|rguenther at suse dot de           |rguenth at gcc dot gnu.org

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
So the only additional hoisting is in LIM4

Moving statement
_60 = _13 ^ iftmp.9_18;
(cost 1) out of loop 1.

Moving statement
_62 = _60 == 10;
(cost 21) out of loop 1.


@@ -239,6 +279,8 @@
   goto <bb 31>; [100.00%]

   <bb 50> [local count: 477815112]:
+  _60 = _13 ^ iftmp.9_18;
+  _62 = _60 == 10;

   <bb 7> [local count: 4343774241]:
   _9 = a ();
@@ -296,8 +338,6 @@
   goto <bb 15>; [100.00%]

   <bb 14> [local count: 14585209535]:
-  _60 = _13 ^ iftmp.9_18;
-  _62 = _60 == 10;

   <bb 15> [local count: 35145083376]:
   # prephitmp_63 = PHI <0(73), _62(14), 0(74)>

and -fdisable-tree-lim4 restores the missed optimization.  The difference
is then in CCP4 which is able to remove the call to foo() when not hoisting
the compare.  When not hoisting the global range of _60 is stricter:

-  # RANGE [irange] unsigned int [0, 511] MASK 0x1c7 VALUE 0x0
-  _60 = _13 ^ iftmp.9_18;
+  # RANGE [irange] unsigned int [0, 16383] MASK 0x3fff VALUE 0x0
+  _60 = _13 ^ iftmp.9_18;

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/111003] [14 Regression] Dead Code Elimination Regression at -O3 since r14-2161-g237e83e2158
  2023-08-12 13:53 [Bug tree-optimization/111003] New: [14 Regression] Dead Code Elimination Regression at -O3 since r14-2161-g237e83e2158 scherrer.sv at gmail dot com
                   ` (2 preceding siblings ...)
  2023-08-14  8:03 ` rguenth at gcc dot gnu.org
@ 2023-11-24  4:33 ` pinskia at gcc dot gnu.org
  2024-01-10 14:39 ` jamborm at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-11-24  4:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111003

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |needs-bisection

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This seems to be fixed on the trunk ...

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/111003] [14 Regression] Dead Code Elimination Regression at -O3 since r14-2161-g237e83e2158
  2023-08-12 13:53 [Bug tree-optimization/111003] New: [14 Regression] Dead Code Elimination Regression at -O3 since r14-2161-g237e83e2158 scherrer.sv at gmail dot com
                   ` (3 preceding siblings ...)
  2023-11-24  4:33 ` pinskia at gcc dot gnu.org
@ 2024-01-10 14:39 ` jamborm at gcc dot gnu.org
  2024-01-11  7:52 ` rguenth at gcc dot gnu.org
  2024-01-11  8:15 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: jamborm at gcc dot gnu.org @ 2024-01-10 14:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111003

Martin Jambor <jamborm at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|needs-bisection             |
                 CC|                            |jamborm at gcc dot gnu.org

--- Comment #4 from Martin Jambor <jamborm at gcc dot gnu.org> ---
This has been fixed with r14-4786-gd118738e71cf46 (Richi's restrict invariant
motion of shifts).

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/111003] [14 Regression] Dead Code Elimination Regression at -O3 since r14-2161-g237e83e2158
  2023-08-12 13:53 [Bug tree-optimization/111003] New: [14 Regression] Dead Code Elimination Regression at -O3 since r14-2161-g237e83e2158 scherrer.sv at gmail dot com
                   ` (4 preceding siblings ...)
  2024-01-10 14:39 ` jamborm at gcc dot gnu.org
@ 2024-01-11  7:52 ` rguenth at gcc dot gnu.org
  2024-01-11  8:15 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-01-11  7:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111003

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
Of course that's not really a "fix", but it's restoring of not doing the extra
hoisting.  So it does fix the regression but not maybe the underlying issue.

We're not anticipating more imprecise range-info on DEFs when hoisting here.

The "real" fix would be to improve conditional hoisting - we have

  <bb 12> [local count: 29170419070]:
  # prephitmp_61 = PHI <pretmp_60(11), prephitmp_59(10)>
  _13 = (unsigned int) _3;
  if (_3 > 6)
    goto <bb 73>; [50.00%]
  else 
    goto <bb 13>; [50.00%]

  <bb 73> [local count: 14585209535]:
  goto <bb 14>; [100.00%]

  <bb 13> [local count: 14585209535]:
  iftmp.9_18 = _13 << 6;
  _63 = _13 ^ iftmp.9_18;
  _65 = _63 != 10;

  <bb 14> [local count: 35145083376]:
  # prephitmp_66 = PHI <1(73), _65(13), 1(74)>
  # prephitmp_67 = PHI <prephitmp_61(73), prephitmp_61(13), prephitmp_59(74)>

and the diamond with if (_3 > 6) including the precceding def of _13
(which wasn't sunk) is invariant.  There's an existing bug about LIM
missing a way to hoist a sub-CFG (it can only hoist PHIs as COND_EXPRs).
It might not exactly fit "LIM" but could be integrated with this pass.

I'd say we close this bug, I'll add the testcase.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug tree-optimization/111003] [14 Regression] Dead Code Elimination Regression at -O3 since r14-2161-g237e83e2158
  2023-08-12 13:53 [Bug tree-optimization/111003] New: [14 Regression] Dead Code Elimination Regression at -O3 since r14-2161-g237e83e2158 scherrer.sv at gmail dot com
                   ` (5 preceding siblings ...)
  2024-01-11  7:52 ` rguenth at gcc dot gnu.org
@ 2024-01-11  8:15 ` cvs-commit at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-01-11  8:15 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111003

--- Comment #6 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:96fb3908d9b8e30f8d8355fbb133d25625a0fee9

commit r14-7130-g96fb3908d9b8e30f8d8355fbb133d25625a0fee9
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Jan 11 08:52:48 2024 +0100

    tree-optimization/111003 - new testcase

    Testcase for fixed PR.

            PR tree-optimization/111003
    gcc/testsuite/
            * gcc.dg/tree-ssa/pr111003.c: New testcase.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-01-11  8:15 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-12 13:53 [Bug tree-optimization/111003] New: [14 Regression] Dead Code Elimination Regression at -O3 since r14-2161-g237e83e2158 scherrer.sv at gmail dot com
2023-08-12 17:39 ` [Bug tree-optimization/111003] " pinskia at gcc dot gnu.org
2023-08-12 17:45 ` pinskia at gcc dot gnu.org
2023-08-14  8:03 ` rguenth at gcc dot gnu.org
2023-11-24  4:33 ` pinskia at gcc dot gnu.org
2024-01-10 14:39 ` jamborm at gcc dot gnu.org
2024-01-11  7:52 ` rguenth at gcc dot gnu.org
2024-01-11  8:15 ` cvs-commit 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).