public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/102893] New: [8/9/10/11/12 Regression] CDDCE does not detect empty infinite nested loops
@ 2021-10-22  9:40 tnfchris at gcc dot gnu.org
  2021-10-22 10:44 ` [Bug tree-optimization/102893] [9/10/11/12 " rguenth at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: tnfchris at gcc dot gnu.org @ 2021-10-22  9:40 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 102893
           Summary: [8/9/10/11/12 Regression] CDDCE does not detect empty
                    infinite nested loops
           Product: gcc
           Version: 8.5.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tnfchris at gcc dot gnu.org
  Target Milestone: ---

The following example

int main() {
  while(1) {
    for(int i=0; i<9000000; i++){}
  }
}

In GCC 7 compiled to

main:
.L2:
        b       .L2

but since GCC 8 compiles to

main:
.L3:
        mov     w0, 21568
        movk    w0, 0x89, lsl 16
.L2:
        subs    w0, w0, #1
        bne     .L2
        b       .L3

The difference seems to be in cddce which previously was able to detect the
code as dead:

;; 3 loops found
;;
;; Loop 0
;;  header 0, latch 1
;;  depth 0, outer -1
;;  nodes: 0 1 2 3 4 5 6
;;
;; Loop 1
;;  header 3, latch 6
;;  depth 1, outer 0
;;  nodes: 3 6 5 4
;;
;; Loop 2
;;  header 5, latch 4
;;  depth 2, outer 1
;;  nodes: 5 4
;; 2 succs { 3 }
;; 3 succs { 5 }
;; 4 succs { 5 }
;; 5 succs { 4 6 }
;; 6 succs { 3 }
can not prove finiteness of loop 1
Removing basic block 4
Merging blocks 3 and 5
Removing basic block 6

but since GCC 8 does

;; 3 loops found
;;
;; Loop 0
;;  header 0, latch 1
;;  depth 0, outer -1
;;  nodes: 0 1 2 3 4 5 6
;;
;; Loop 1
;;  header 3, latch 6
;;  depth 1, outer 0
;;  nodes: 3 6 5 4
;;
;; Loop 2
;;  header 5, latch 4
;;  depth 2, outer 1
;;  nodes: 5 4
;; 2 succs { 3 }
;; 3 succs { 5 }
;; 4 succs { 5 }
;; 5 succs { 4 6 }
;; 6 succs { 3 }
cannot prove finiteness of loop 1

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

* [Bug tree-optimization/102893] [9/10/11/12 Regression] CDDCE does not detect empty infinite nested loops
  2021-10-22  9:40 [Bug tree-optimization/102893] New: [8/9/10/11/12 Regression] CDDCE does not detect empty infinite nested loops tnfchris at gcc dot gnu.org
@ 2021-10-22 10:44 ` rguenth at gcc dot gnu.org
  2021-10-22 11:43 ` cvs-commit at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-10-22 10:44 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org
   Target Milestone|---                         |9.5
   Last reconfirmed|                            |2021-10-22
            Summary|[8/9/10/11/12 Regression]   |[9/10/11/12 Regression]
                   |CDDCE does not detect empty |CDDCE does not detect empty
                   |infinite nested loops       |infinite nested loops

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Hm, there's

        /* For loops without an exit do not mark any condition.  */
        if (loop->exits->next && !finite_loop_p (loop))

but here

(gdb) p loop->exits
$2 = (loop_exit *) 0x7ffff6690440
(gdb) p loop->exits->next
$3 = (loop_exit *) 0x7ffff6690440
(gdb) p *loop->exits
$5 = {e = <edge 0x0>, prev = 0x7ffff6690440, next = 0x7ffff6690440, 
  next_e = 0x0}

so I suppose I misunderstood how loop->exits works, looks like ->e has to be
non-NULL as well.  But that means the testcase I added this check for
somehow did not have loop->exits->next?!

Mine.

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

* [Bug tree-optimization/102893] [9/10/11/12 Regression] CDDCE does not detect empty infinite nested loops
  2021-10-22  9:40 [Bug tree-optimization/102893] New: [8/9/10/11/12 Regression] CDDCE does not detect empty infinite nested loops tnfchris at gcc dot gnu.org
  2021-10-22 10:44 ` [Bug tree-optimization/102893] [9/10/11/12 " rguenth at gcc dot gnu.org
@ 2021-10-22 11:43 ` cvs-commit at gcc dot gnu.org
  2021-10-22 11:43 ` [Bug tree-optimization/102893] [9/10/11 " rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-22 11:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CVS 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:c2a9a98a369528c8689ecb68db576f8e7dc2fa45

commit r12-4627-gc2a9a98a369528c8689ecb68db576f8e7dc2fa45
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Oct 22 12:45:32 2021 +0200

    tree-optimization/102893 - properly DCE empty loops inside infinite loops

    The following fixes the test for an exit edge I put in place for
    the fix for PR45178 where I somehow misunderstood how the cyclic
    list works.

    2021-10-22  Richard Biener  <rguenther@suse.de>

            PR tree-optimization/102893
            * tree-ssa-dce.c (find_obviously_necessary_stmts): Fix the
            test for an exit edge.

            * gcc.dg/tree-ssa/ssa-dce-9.c: New testcase.

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

* [Bug tree-optimization/102893] [9/10/11 Regression] CDDCE does not detect empty infinite nested loops
  2021-10-22  9:40 [Bug tree-optimization/102893] New: [8/9/10/11/12 Regression] CDDCE does not detect empty infinite nested loops tnfchris at gcc dot gnu.org
  2021-10-22 10:44 ` [Bug tree-optimization/102893] [9/10/11/12 " rguenth at gcc dot gnu.org
  2021-10-22 11:43 ` cvs-commit at gcc dot gnu.org
@ 2021-10-22 11:43 ` rguenth at gcc dot gnu.org
  2021-10-22 12:07 ` tnfchris at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-10-22 11:43 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2
      Known to work|                            |12.0
            Summary|[9/10/11/12 Regression]     |[9/10/11 Regression] CDDCE
                   |CDDCE does not detect empty |does not detect empty
                   |infinite nested loops       |infinite nested loops

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Not sure if worth backporting.

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

* [Bug tree-optimization/102893] [9/10/11 Regression] CDDCE does not detect empty infinite nested loops
  2021-10-22  9:40 [Bug tree-optimization/102893] New: [8/9/10/11/12 Regression] CDDCE does not detect empty infinite nested loops tnfchris at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2021-10-22 11:43 ` [Bug tree-optimization/102893] [9/10/11 " rguenth at gcc dot gnu.org
@ 2021-10-22 12:07 ` tnfchris at gcc dot gnu.org
  2022-02-17 10:17 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: tnfchris at gcc dot gnu.org @ 2021-10-22 12:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Tamar Christina <tnfchris at gcc dot gnu.org> ---
Thanks for the fix!

This was reported to us by a user of the arm embedded toolchains that was
upgrading from gcc 7.  We won't be releasing any new releases for GCC 8 and 9,
but may be for 10 and 11 is certain.

So a backport to 11 and if possible 10 would be great as it avoids us having to
possibly carry the patch in a vendor branch.

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

* [Bug tree-optimization/102893] [9/10/11 Regression] CDDCE does not detect empty infinite nested loops
  2021-10-22  9:40 [Bug tree-optimization/102893] New: [8/9/10/11/12 Regression] CDDCE does not detect empty infinite nested loops tnfchris at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2021-10-22 12:07 ` tnfchris at gcc dot gnu.org
@ 2022-02-17 10:17 ` rguenth at gcc dot gnu.org
  2022-02-17 11:26 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-02-17 10:17 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Depends on|                            |45178

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
The fix depends on the fix for PR45178.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=45178
[Bug 45178] CDDCE doesn't eliminate conditional code in infinite loop

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

* [Bug tree-optimization/102893] [9/10/11 Regression] CDDCE does not detect empty infinite nested loops
  2021-10-22  9:40 [Bug tree-optimization/102893] New: [8/9/10/11/12 Regression] CDDCE does not detect empty infinite nested loops tnfchris at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2022-02-17 10:17 ` rguenth at gcc dot gnu.org
@ 2022-02-17 11:26 ` cvs-commit at gcc dot gnu.org
  2022-05-27  9:46 ` [Bug tree-optimization/102893] [10 " rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-02-17 11:26 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:6d9c2ed02128ddf327465333f5563500b6cf8886

commit r11-9587-g6d9c2ed02128ddf327465333f5563500b6cf8886
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Oct 22 12:45:32 2021 +0200

    tree-optimization/102893 - properly DCE empty loops inside infinite loops

    The following fixes the test for an exit edge I put in place for
    the fix for PR45178 where I somehow misunderstood how the cyclic
    list works.

    2021-10-22  Richard Biener  <rguenther@suse.de>

            PR tree-optimization/102893
            * tree-ssa-dce.c (find_obviously_necessary_stmts): Fix the
            test for an exit edge.

            * gcc.dg/tree-ssa/ssa-dce-9.c: New testcase.

    (cherry picked from commit c2a9a98a369528c8689ecb68db576f8e7dc2fa45)

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

* [Bug tree-optimization/102893] [10 Regression] CDDCE does not detect empty infinite nested loops
  2021-10-22  9:40 [Bug tree-optimization/102893] New: [8/9/10/11/12 Regression] CDDCE does not detect empty infinite nested loops tnfchris at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2022-02-17 11:26 ` cvs-commit at gcc dot gnu.org
@ 2022-05-27  9:46 ` rguenth at gcc dot gnu.org
  2022-06-28 10:46 ` jakub at gcc dot gnu.org
  2023-07-07  9:47 ` rguenth at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-27  9:46 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|9.5                         |10.4

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 9 branch is being closed

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

* [Bug tree-optimization/102893] [10 Regression] CDDCE does not detect empty infinite nested loops
  2021-10-22  9:40 [Bug tree-optimization/102893] New: [8/9/10/11/12 Regression] CDDCE does not detect empty infinite nested loops tnfchris at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2022-05-27  9:46 ` [Bug tree-optimization/102893] [10 " rguenth at gcc dot gnu.org
@ 2022-06-28 10:46 ` jakub at gcc dot gnu.org
  2023-07-07  9:47 ` rguenth at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-28 10:46 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.4                        |10.5

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 10.4 is being released, retargeting bugs to GCC 10.5.

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

* [Bug tree-optimization/102893] [10 Regression] CDDCE does not detect empty infinite nested loops
  2021-10-22  9:40 [Bug tree-optimization/102893] New: [8/9/10/11/12 Regression] CDDCE does not detect empty infinite nested loops tnfchris at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2022-06-28 10:46 ` jakub at gcc dot gnu.org
@ 2023-07-07  9:47 ` rguenth at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07  9:47 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.5                        |11.3
             Status|ASSIGNED                    |RESOLVED
      Known to fail|                            |10.5.0
         Resolution|---                         |FIXED

--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed.

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

end of thread, other threads:[~2023-07-07  9:47 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-22  9:40 [Bug tree-optimization/102893] New: [8/9/10/11/12 Regression] CDDCE does not detect empty infinite nested loops tnfchris at gcc dot gnu.org
2021-10-22 10:44 ` [Bug tree-optimization/102893] [9/10/11/12 " rguenth at gcc dot gnu.org
2021-10-22 11:43 ` cvs-commit at gcc dot gnu.org
2021-10-22 11:43 ` [Bug tree-optimization/102893] [9/10/11 " rguenth at gcc dot gnu.org
2021-10-22 12:07 ` tnfchris at gcc dot gnu.org
2022-02-17 10:17 ` rguenth at gcc dot gnu.org
2022-02-17 11:26 ` cvs-commit at gcc dot gnu.org
2022-05-27  9:46 ` [Bug tree-optimization/102893] [10 " rguenth at gcc dot gnu.org
2022-06-28 10:46 ` jakub at gcc dot gnu.org
2023-07-07  9:47 ` 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).