public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/115483] New: Missed optimization for loop invariant code
@ 2024-06-14  0:49 zhiwuyazhe154 at gmail dot com
  2024-06-14  1:18 ` [Bug tree-optimization/115483] " pinskia at gcc dot gnu.org
  2024-06-14  5:48 ` rguenth at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: zhiwuyazhe154 at gmail dot com @ 2024-06-14  0:49 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115483
           Summary: Missed optimization for loop invariant code
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhiwuyazhe154 at gmail dot com
  Target Milestone: ---

Godbolt example: https://godbolt.org/z/s75d4GfTT

code example:
unsigned m,n;
unsigned func(unsigned a, unsigned b, 
            unsigned c, unsigned d)
{
    for(unsigned i=0; i<100; i++)
    {
        m += 1024;
        b += c/n + (c + d) + m;
        m += m;
    }
    return b;
} 

In this case, c/n + (c + d) is loop invariant code.
It seems that reassociate breaks the optimization of licm.
There are a few other issues that mention the shortcomings of reassociate, but
there doesn't seem to be an issue that shows its negative impact.

GCC -O3:
func(unsigned int, unsigned int, unsigned int, unsigned int):
        mov     eax, edx
        mov     r9d, edx
        xor     edx, edx
        mov     r8d, esi
        div     DWORD PTR n[rip]
        mov     esi, DWORD PTR m[rip]
        mov     edi, 100
.L2:
        add     esi, 1024
        lea     edx, [rsi+rcx]
        add     esi, esi
        add     edx, r9d
        add     edx, eax
        add     r8d, edx
        sub     edi, 1
        jne     .L2
        mov     DWORD PTR m[rip], esi
        mov     eax, r8d
        ret

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

* [Bug tree-optimization/115483] Missed optimization for loop invariant code
  2024-06-14  0:49 [Bug tree-optimization/115483] New: Missed optimization for loop invariant code zhiwuyazhe154 at gmail dot com
@ 2024-06-14  1:18 ` pinskia at gcc dot gnu.org
  2024-06-14  5:48 ` rguenth at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-06-14  1:18 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=114701

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>There are a few other issues that mention the shortcomings of reassociate, but there doesn't seem to be an issue that shows its negative impact.

Actually there are a few.

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

* [Bug tree-optimization/115483] Missed optimization for loop invariant code
  2024-06-14  0:49 [Bug tree-optimization/115483] New: Missed optimization for loop invariant code zhiwuyazhe154 at gmail dot com
  2024-06-14  1:18 ` [Bug tree-optimization/115483] " pinskia at gcc dot gnu.org
@ 2024-06-14  5:48 ` rguenth at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-06-14  5:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
it's again the interaction of store motion, re-assoc and then invariant motion.

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

end of thread, other threads:[~2024-06-14  5:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-14  0:49 [Bug tree-optimization/115483] New: Missed optimization for loop invariant code zhiwuyazhe154 at gmail dot com
2024-06-14  1:18 ` [Bug tree-optimization/115483] " pinskia at gcc dot gnu.org
2024-06-14  5:48 ` 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).