[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 gcc-bugzilla@gcc.gnu.org
Fri Oct 22 09:40:37 GMT 2021


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


More information about the Gcc-bugs mailing list