public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/110931] New: [14 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875
@ 2023-08-07 10:33 theodort at inf dot ethz.ch
  2023-08-07 14:57 ` [Bug tree-optimization/110931] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: theodort at inf dot ethz.ch @ 2023-08-07 10:33 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110931
           Summary: [14 Regression] Dead Code Elimination Regression since
                    r14-2890-gcc2003cd875
           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: ---

https://godbolt.org/z/zPTeo8Mj9

Given the following code:

void foo(void);
static int a = 7, c;
static int *d = &a, *e;
static int **f = &e;
static short g;
static char(h)(char b) {
    if (!(((b) >= 1) && ((b) <= 1))) {
        __builtin_unreachable();
    }
    return 0;
}
static void k(unsigned i) {
    short j = i;
    if (j)
        ;
    else {
        h(i);
        if ((e && i) <= 0)
            ;
        else
            foo();
        *f = &c;
    }
    h(0 >= 0);
}
int main() {
    int l = *d;
    g = l;
    k(g);
}

gcc-trunk -O3 does not eliminate the call to foo:

main:
        cmpw    $0, a(%rip)
        jne     .L5
        cmpq    $0, e(%rip)
        je      .L6
        pushq   %rax
        call    foo
        xorl    %eax, %eax
        movq    $c, e(%rip)
        popq    %rdx
        ret
.L6:
        movq    $c, e(%rip)
.L5:
        xorl    %eax, %eax
        ret

gcc-13.2.0 -O3 eliminates the call to foo:

main:
        xorl    %eax, %eax
        ret

Bisects to r14-2890-gcc2003cd875

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

* [Bug tree-optimization/110931] [14 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875
  2023-08-07 10:33 [Bug tree-optimization/110931] New: [14 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875 theodort at inf dot ethz.ch
@ 2023-08-07 14:57 ` pinskia at gcc dot gnu.org
  2023-08-07 15:11 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-07 14:57 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
   Target Milestone|---                         |14.0

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

* [Bug tree-optimization/110931] [14 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875
  2023-08-07 10:33 [Bug tree-optimization/110931] New: [14 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875 theodort at inf dot ethz.ch
  2023-08-07 14:57 ` [Bug tree-optimization/110931] " pinskia at gcc dot gnu.org
@ 2023-08-07 15:11 ` pinskia at gcc dot gnu.org
  2023-08-07 15:25 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-07 15:11 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Reduced testcase:
```
void foo(void);
int l=1000;

int main(void)
{
  short t = l;
  unsigned t1 = t;
  if (t1 == 0) {
#if 1
    char b = t1;
#else
    char b = l;
#endif
    if (b != 1) __builtin_unreachable();
    foo();
  }
}
```

Changing 1 to 0 in the #if, shows the missed optimization too.

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

* [Bug tree-optimization/110931] [14 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875
  2023-08-07 10:33 [Bug tree-optimization/110931] New: [14 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875 theodort at inf dot ethz.ch
  2023-08-07 14:57 ` [Bug tree-optimization/110931] " pinskia at gcc dot gnu.org
  2023-08-07 15:11 ` pinskia at gcc dot gnu.org
@ 2023-08-07 15:25 ` pinskia at gcc dot gnu.org
  2023-08-07 16:07 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-07 15:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Basically there is a missing VRP happening here:
l.0_1   [irange] int [-INF, -65536][0, 0][65536, +INF]
Partial equiv (b_6 pe8 l.0_1)
    <bb 3> :
    b_6 = (char) l.0_1;
...
Obvious that b_6 will have the range [0,0] as the other parts of l.0_1 is
outside of that range. But for some reason VRP didn't figure that out here ...

I don't understand how this is supposed to work

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

* [Bug tree-optimization/110931] [14 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875
  2023-08-07 10:33 [Bug tree-optimization/110931] New: [14 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875 theodort at inf dot ethz.ch
                   ` (2 preceding siblings ...)
  2023-08-07 15:25 ` pinskia at gcc dot gnu.org
@ 2023-08-07 16:07 ` pinskia at gcc dot gnu.org
  2023-08-09  1:35 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-07 16:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Here is one that has always failed due to a similar issue where the inner cast
was removed:
```
void foo(void);
int l=1000;

int main(void)
{
  short t = l;
  int t1 = t;
  if (t1 == 0) {
    signed char b = t1;
    if (b != 1) __builtin_unreachable();
    foo();
  }
}
```

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

* [Bug tree-optimization/110931] [14 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875
  2023-08-07 10:33 [Bug tree-optimization/110931] New: [14 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875 theodort at inf dot ethz.ch
                   ` (3 preceding siblings ...)
  2023-08-07 16:07 ` pinskia at gcc dot gnu.org
@ 2023-08-09  1:35 ` pinskia at gcc dot gnu.org
  2024-03-07 23:25 ` law at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-09  1:35 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|                            |85316

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #2)
> Basically there is a missing VRP happening here:
> l.0_1	[irange] int [-INF, -65536][0, 0][65536, +INF]
> Partial equiv (b_6 pe8 l.0_1)
>     <bb 3> :
>     b_6 = (char) l.0_1;
> ...
> Obvious that b_6 will have the range [0,0] as the other parts of l.0_1 is
> outside of that range. But for some reason VRP didn't figure that out here
> ...

Oh it looks like we don't prop NONZERO back and I missed that when I first
looked at this.

In this case we have:
l&(short)(-1) == 0

But we don't record that in the above, only a range ...


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85316
[Bug 85316] [meta-bug] VRP range propagation missed cases

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

* [Bug tree-optimization/110931] [14 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875
  2023-08-07 10:33 [Bug tree-optimization/110931] New: [14 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875 theodort at inf dot ethz.ch
                   ` (4 preceding siblings ...)
  2023-08-09  1:35 ` pinskia at gcc dot gnu.org
@ 2024-03-07 23:25 ` law at gcc dot gnu.org
  2024-03-09  6:50 ` law at gcc dot gnu.org
  2024-05-07  7:41 ` [Bug tree-optimization/110931] [14/15 " rguenth at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: law at gcc dot gnu.org @ 2024-03-07 23:25 UTC (permalink / raw)
  To: gcc-bugs

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

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] 9+ messages in thread

* [Bug tree-optimization/110931] [14 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875
  2023-08-07 10:33 [Bug tree-optimization/110931] New: [14 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875 theodort at inf dot ethz.ch
                   ` (5 preceding siblings ...)
  2024-03-07 23:25 ` law at gcc dot gnu.org
@ 2024-03-09  6:50 ` law at gcc dot gnu.org
  2024-05-07  7:41 ` [Bug tree-optimization/110931] [14/15 " rguenth at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: law at gcc dot gnu.org @ 2024-03-09  6:50 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jeffrey A. Law <law at gcc dot gnu.org> ---
One could also look at this as a failure to propagate.

  l.0_1 = l;
  t_4 = (short int) l.0_1;
  if (t_4 == 0)
    goto <bb 3>; [50.00%]
  else
    goto <bb 6>; [50.00%]


We ought to be able to propagate l.0_1 into the conditional for t_4.  If we do
that, then we'll be able to propagate 0 for l.0_1 in this block:

;;   basic block 3, loop depth 0, count 536870912 (estimated locally, freq
0.5000)
;;    prev block 2, next block 4, flags: (NEW, VISITED)
;;    pred:       2 [50.0% (guessed)]  count:536870912 (estimated locally, freq
0.5000) (TRUE_VALUE,EXECUTABLE)
  b_5 = (char) l.0_1;
  if (b_5 != 1)
    goto <bb 4>; [0.00%]
  else
    goto <bb 5>; [100.00%]


And once we propagate the value 0 that will make the make bb5 (containing the
call to foo) unreachable.

IIRC we have (had?) some code to do these kinds of propagations through
conversions.  IIRC it was fairly conservative, perhaps overly so.

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

* [Bug tree-optimization/110931] [14/15 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875
  2023-08-07 10:33 [Bug tree-optimization/110931] New: [14 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875 theodort at inf dot ethz.ch
                   ` (6 preceding siblings ...)
  2024-03-09  6:50 ` law at gcc dot gnu.org
@ 2024-05-07  7:41 ` rguenth at gcc dot gnu.org
  7 siblings, 0 replies; 9+ 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=110931

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

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

--- Comment #6 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] 9+ messages in thread

end of thread, other threads:[~2024-05-07  7:41 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-08-07 10:33 [Bug tree-optimization/110931] New: [14 Regression] Dead Code Elimination Regression since r14-2890-gcc2003cd875 theodort at inf dot ethz.ch
2023-08-07 14:57 ` [Bug tree-optimization/110931] " pinskia at gcc dot gnu.org
2023-08-07 15:11 ` pinskia at gcc dot gnu.org
2023-08-07 15:25 ` pinskia at gcc dot gnu.org
2023-08-07 16:07 ` pinskia at gcc dot gnu.org
2023-08-09  1:35 ` pinskia at gcc dot gnu.org
2024-03-07 23:25 ` law at gcc dot gnu.org
2024-03-09  6:50 ` law at gcc dot gnu.org
2024-05-07  7:41 ` [Bug tree-optimization/110931] [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).