public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/102648] New: Dead Code Elimination Regression at -O3 (trunk vs 11.2.0)
@ 2021-10-08 13:35 theodort at inf dot ethz.ch
  2021-10-11  8:30 ` [Bug tree-optimization/102648] [12 Regression] " rguenth at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: theodort at inf dot ethz.ch @ 2021-10-08 13:35 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102648
           Summary: Dead Code Elimination Regression at -O3 (trunk vs
                    11.2.0)
           Product: gcc
           Version: 12.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: ---

cat case.c   
void foo(void);
static int b, c, d = 40000;
static short e;
unsigned char f = 1;
static short a(short f, short g) { return f * g; }
int main() {
    for (; e; e++) {
        c = 0;
        while (c - 1)
            if (a(d, !f) > 1)
                foo();
    }
    return 0;
}

11.2.0 at -O3 can eliminate the call to foo but trunk at -O3 cannot:

gcc-11 -v
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 11.2.0 (GCC)


gcc-11 -O3 case.c -S -o /dev/stdout
...
main:
.LFB1:
        .cfi_startproc
        cmpw    $0, e(%rip)
        je      .L2
        movl    $0, c(%rip)
.L3:
        jmp     .L3
        .p2align 4,,10
        .p2align 3
.L2:
        xorl    %eax, %eax
        ret

gcc-trunk -v
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++ 
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.0.0 20211008 (experimental) (GCC)

gcc-trunk -O3 case.c -S -o /dev/stdout
...
main:
.LFB1:
        .cfi_startproc
        cmpw    $0, e(%rip)
        movzbl  f(%rip), %edx
        je      .L12
        subq    $8, %rsp
        .cfi_def_cfa_offset 16
        .p2align 4,,10
        .p2align 3
.L5:
        movl    $0, c(%rip)
        xorl    %eax, %eax
        testb   %dl, %dl
        sete    %al
        imulw   $-25536, %ax, %ax
        cmpw    $1, %ax
        jg      .L15
.L3:
.L10:
        jmp     .L10
        .p2align 4,,10
        .p2align 3
.L15:
        call    foo
        cmpl    $1, c(%rip)
        movzbl  f(%rip), %edx
        jne     .L3
        addw    $1, e(%rip)
        jne     .L5
        xorl    %eax, %eax
        addq    $8, %rsp
        .cfi_def_cfa_offset 8
        ret
.L12:
        xorl    %eax, %eax
        ret


704e8a825c78b9a8424c291509413bbb48e602c7 introduced this regression

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

* [Bug tree-optimization/102648] [12 Regression] Dead Code Elimination Regression at -O3 (trunk vs 11.2.0)
  2021-10-08 13:35 [Bug tree-optimization/102648] New: Dead Code Elimination Regression at -O3 (trunk vs 11.2.0) theodort at inf dot ethz.ch
@ 2021-10-11  8:30 ` rguenth at gcc dot gnu.org
  2021-10-11 10:09 ` [Bug tree-optimization/102648] [12 Regression] Dead Code Elimination Regression at -O3 (trunk vs 11.2.0) since r12-2381-g704e8a825c78b9a8 marxin at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-10-11  8:30 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0
            Summary|Dead Code Elimination       |[12 Regression] Dead Code
                   |Regression at -O3 (trunk vs |Elimination Regression at
                   |11.2.0)                     |-O3 (trunk vs 11.2.0)
           Keywords|                            |missed-optimization

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

* [Bug tree-optimization/102648] [12 Regression] Dead Code Elimination Regression at -O3 (trunk vs 11.2.0) since r12-2381-g704e8a825c78b9a8
  2021-10-08 13:35 [Bug tree-optimization/102648] New: Dead Code Elimination Regression at -O3 (trunk vs 11.2.0) theodort at inf dot ethz.ch
  2021-10-11  8:30 ` [Bug tree-optimization/102648] [12 Regression] " rguenth at gcc dot gnu.org
@ 2021-10-11 10:09 ` marxin at gcc dot gnu.org
  2021-10-13 20:20 ` amacleod at redhat dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: marxin at gcc dot gnu.org @ 2021-10-11 10:09 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |marxin at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
            Summary|[12 Regression] Dead Code   |[12 Regression] Dead Code
                   |Elimination Regression at   |Elimination Regression at
                   |-O3 (trunk vs 11.2.0)       |-O3 (trunk vs 11.2.0) since
                   |                            |r12-2381-g704e8a825c78b9a8
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-10-11

--- Comment #1 from Martin Liška <marxin at gcc dot gnu.org> ---
Started with r12-2381-g704e8a825c78b9a8.

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

* [Bug tree-optimization/102648] [12 Regression] Dead Code Elimination Regression at -O3 (trunk vs 11.2.0) since r12-2381-g704e8a825c78b9a8
  2021-10-08 13:35 [Bug tree-optimization/102648] New: Dead Code Elimination Regression at -O3 (trunk vs 11.2.0) theodort at inf dot ethz.ch
  2021-10-11  8:30 ` [Bug tree-optimization/102648] [12 Regression] " rguenth at gcc dot gnu.org
  2021-10-11 10:09 ` [Bug tree-optimization/102648] [12 Regression] Dead Code Elimination Regression at -O3 (trunk vs 11.2.0) since r12-2381-g704e8a825c78b9a8 marxin at gcc dot gnu.org
@ 2021-10-13 20:20 ` amacleod at redhat dot com
  2021-11-25 14:03 ` cvs-commit at gcc dot gnu.org
  2021-11-25 14:03 ` amacleod at redhat dot com
  4 siblings, 0 replies; 6+ messages in thread
From: amacleod at redhat dot com @ 2021-10-13 20:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Macleod <amacleod at redhat dot com> ---
This is another case of insufficient range representation in the old
value_range.  The patch causing the issue allows us to produce better subranges
when the source ranges have small numbers of constants in them.

We have the sequence:

g.8_18 = (unsigned short) _2;
_19 = g.8_18 * 40000;
_20 = (short int) _19;
if (_20 > 1)

we calculate that g.8_18 has a range of [0,1]
before this patch, we calculated:

_19 = unsigned short ~[1, 39999]
_20 =   short int [-25536, 0]
if (_20 > 1) could then be folded as never taken.

With the precision change, we calculate _19 as [0,0][40000,40000], which when
converted to a value range, becomes [0,40000].  This then causes
_20 be calculated as short int ~[-25535, -1] 
which can no longer correctly predict that the branch can never be taken.

This problem goes away if we run another evrp instance later instead of VRP as
this is a non issue with multi-ranges as we get:

g.8_18 : unsigned short [0, 1]
_19 : unsigned short [0, 0][40000, 40000]
_20 : short int [-25536, -25536][0, 0]
and can easily fold away the condition.

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

* [Bug tree-optimization/102648] [12 Regression] Dead Code Elimination Regression at -O3 (trunk vs 11.2.0) since r12-2381-g704e8a825c78b9a8
  2021-10-08 13:35 [Bug tree-optimization/102648] New: Dead Code Elimination Regression at -O3 (trunk vs 11.2.0) theodort at inf dot ethz.ch
                   ` (2 preceding siblings ...)
  2021-10-13 20:20 ` amacleod at redhat dot com
@ 2021-11-25 14:03 ` cvs-commit at gcc dot gnu.org
  2021-11-25 14:03 ` amacleod at redhat dot com
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-11-25 14:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Andrew Macleod <amacleod@gcc.gnu.org>:

https://gcc.gnu.org/g:1598bd47b2a4a5f12b5a987d16d82634644db4b6

commit r12-5524-g1598bd47b2a4a5f12b5a987d16d82634644db4b6
Author: Andrew MacLeod <amacleod@redhat.com>
Date:   Thu Nov 25 08:58:19 2021 -0500

    Add the testcase for this PR to the testsuite.

    Various ranger-enabled patches like threading and VRP2 can do this now, so
add the testcase for posterity.

            gcc/testsuite/
            PR tree-optimization/102648
            * gcc.dg/pr102648.c: New.

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

* [Bug tree-optimization/102648] [12 Regression] Dead Code Elimination Regression at -O3 (trunk vs 11.2.0) since r12-2381-g704e8a825c78b9a8
  2021-10-08 13:35 [Bug tree-optimization/102648] New: Dead Code Elimination Regression at -O3 (trunk vs 11.2.0) theodort at inf dot ethz.ch
                   ` (3 preceding siblings ...)
  2021-11-25 14:03 ` cvs-commit at gcc dot gnu.org
@ 2021-11-25 14:03 ` amacleod at redhat dot com
  4 siblings, 0 replies; 6+ messages in thread
From: amacleod at redhat dot com @ 2021-11-25 14:03 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Macleod <amacleod at redhat dot com> changed:

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

--- Comment #4 from Andrew Macleod <amacleod at redhat dot com> ---
Should be fixed.

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

end of thread, other threads:[~2021-11-25 14:03 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-08 13:35 [Bug tree-optimization/102648] New: Dead Code Elimination Regression at -O3 (trunk vs 11.2.0) theodort at inf dot ethz.ch
2021-10-11  8:30 ` [Bug tree-optimization/102648] [12 Regression] " rguenth at gcc dot gnu.org
2021-10-11 10:09 ` [Bug tree-optimization/102648] [12 Regression] Dead Code Elimination Regression at -O3 (trunk vs 11.2.0) since r12-2381-g704e8a825c78b9a8 marxin at gcc dot gnu.org
2021-10-13 20:20 ` amacleod at redhat dot com
2021-11-25 14:03 ` cvs-commit at gcc dot gnu.org
2021-11-25 14:03 ` amacleod at redhat dot com

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).