public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/112123] New: Missed optimization of loop deletion because loop invariants are not identified
@ 2023-10-28 13:00 652023330028 at smail dot nju.edu.cn
  2023-10-28 17:50 ` [Bug tree-optimization/112123] " pinskia at gcc dot gnu.org
  2023-10-30 13:16 ` rguenth at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: 652023330028 at smail dot nju.edu.cn @ 2023-10-28 13:00 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112123
           Summary: Missed optimization of loop deletion because loop
                    invariants are not identified
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: 652023330028 at smail dot nju.edu.cn
  Target Milestone: ---

Hello, we noticed that in the following loop, a+b is a loop invariant, so the
value of m can be computed directly. The values of a and b can also be computed
without loop iteration.

https://godbolt.org/z/6xTE7zrPj

int m;

int a, b;
void test() {
  for (int c = 0; c < 4087153; c += 1) {
    m = a + b;
    a += b;
    b += -b;
  }
}

GCC:
test():
        mov     edx, DWORD PTR a[rip]
        mov     ecx, DWORD PTR b[rip]
        mov     eax, 4087153
.L2:
        add     edx, ecx
        xor     ecx, ecx
        sub     eax, 1
        jne     .L2
        mov     DWORD PTR m[rip], edx
        mov     DWORD PTR a[rip], edx
        mov     DWORD PTR b[rip], 0
        ret

Expected code (Clang):
test():                               # @test()
        mov     eax, dword ptr [rip + b]
        add     eax, dword ptr [rip + a]
        mov     dword ptr [rip + a], eax
        mov     dword ptr [rip + b], 0
        mov     dword ptr [rip + m], eax
        ret

Thank you very much for your time and effort! We look forward to hearing from
you.

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

* [Bug tree-optimization/112123] Missed optimization of loop deletion because loop invariants are not identified
  2023-10-28 13:00 [Bug tree-optimization/112123] New: Missed optimization of loop deletion because loop invariants are not identified 652023330028 at smail dot nju.edu.cn
@ 2023-10-28 17:50 ` pinskia at gcc dot gnu.org
  2023-10-30 13:16 ` rguenth at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-28 17:50 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

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

* [Bug tree-optimization/112123] Missed optimization of loop deletion because loop invariants are not identified
  2023-10-28 13:00 [Bug tree-optimization/112123] New: Missed optimization of loop deletion because loop invariants are not identified 652023330028 at smail dot nju.edu.cn
  2023-10-28 17:50 ` [Bug tree-optimization/112123] " pinskia at gcc dot gnu.org
@ 2023-10-30 13:16 ` rguenth at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-10-30 13:16 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-10-30
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed.

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

end of thread, other threads:[~2023-10-30 13:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-28 13:00 [Bug tree-optimization/112123] New: Missed optimization of loop deletion because loop invariants are not identified 652023330028 at smail dot nju.edu.cn
2023-10-28 17:50 ` [Bug tree-optimization/112123] " pinskia at gcc dot gnu.org
2023-10-30 13:16 ` 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).