public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/114647] New: missing DCE when looping over a VLA
@ 2024-04-08 21:37 franckbehaghel_gcc at protonmail dot com
  2024-04-08 21:40 ` [Bug tree-optimization/114647] missing DSE " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: franckbehaghel_gcc at protonmail dot com @ 2024-04-08 21:37 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114647
           Summary: missing DCE when looping over a VLA
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: franckbehaghel_gcc at protonmail dot com
  Target Milestone: ---

$cat foo.cpp

#include "stdint.h"
#include "stdio.h"

void foo(int n)
{

   uint64_t a[n];
   for (uint32_t i=0;i<n;i++) a[i] = i;

   printf(" ");
}


At O3, gcc vectorize the loop but do not remove it:

foo(int):
        push    rbp
        movsx   rax, edi
        lea     rax, [15+rax*8]
        and     rax, -16
        mov     rbp, rsp
        sub     rsp, rax
        test    edi, edi
        je      .L2
        lea     edx, [rdi-1]
        cmp     edx, 2
        jbe     .L2
        shr     edi, 2
        mov     ecx, 4
        pxor    xmm2, xmm2
        mov     rax, rsp
        mov     edx, edi
        movdqa  xmm1, XMMWORD PTR .LC0[rip]
        movd    xmm4, ecx
        sal     rdx, 5
        pshufd  xmm4, xmm4, 0
        add     rdx, rsp
.L4:
        movdqa  xmm0, xmm1
        add     rax, 32
        paddd   xmm1, xmm4
        movdqa  xmm3, xmm0
        punpckhdq       xmm0, xmm2
        punpckldq       xmm3, xmm2
        movups  XMMWORD PTR [rax-16], xmm0
        movups  XMMWORD PTR [rax-32], xmm3
        cmp     rdx, rax
        jne     .L4
.L2:
        mov     edi, 32
        call    putchar
        leave
        ret


clang ( c or c++ ) does remove the loop :

foo:                                    # @foo
        mov     edi, 32
        jmp     putchar@PLT                     # TAILCALL

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

* [Bug tree-optimization/114647] missing DSE when looping over a VLA
  2024-04-08 21:37 [Bug middle-end/114647] New: missing DCE when looping over a VLA franckbehaghel_gcc at protonmail dot com
@ 2024-04-08 21:40 ` pinskia at gcc dot gnu.org
  2024-04-08 21:46 ` pinskia at gcc dot gnu.org
  2024-04-09  7:12 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-08 21:40 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
           Severity|normal                      |enhancement
          Component|middle-end                  |tree-optimization
            Summary|missing DCE when looping    |missing DSE when looping
                   |over a VLA                  |over a VLA

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

* [Bug tree-optimization/114647] missing DSE when looping over a VLA
  2024-04-08 21:37 [Bug middle-end/114647] New: missing DCE when looping over a VLA franckbehaghel_gcc at protonmail dot com
  2024-04-08 21:40 ` [Bug tree-optimization/114647] missing DSE " pinskia at gcc dot gnu.org
@ 2024-04-08 21:46 ` pinskia at gcc dot gnu.org
  2024-04-09  7:12 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-08 21:46 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2024-04-08
     Ever confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
GCC also does not delete allocated memory when used in loop:
```
void foo(int n)
{
   {
     int *a = __builtin_malloc(n*sizeof(int));
     for (int i=0;i<n;i++) a[i] = i;
     __builtin_free(a);
   }
   printf(" ");
}
```

Let me find the dup.

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

* [Bug tree-optimization/114647] missing DSE when looping over a VLA
  2024-04-08 21:37 [Bug middle-end/114647] New: missing DCE when looping over a VLA franckbehaghel_gcc at protonmail dot com
  2024-04-08 21:40 ` [Bug tree-optimization/114647] missing DSE " pinskia at gcc dot gnu.org
  2024-04-08 21:46 ` pinskia at gcc dot gnu.org
@ 2024-04-09  7:12 ` rguenth at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-04-09  7:12 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
                      /* If we visit this PHI by following a backedge then we
                         have to make sure ref->ref only refers to SSA names
                         that are invariant with respect to the loop
                         represented by this PHI node.  */
                      if (dominated_by_p (CDI_DOMINATORS, gimple_bb (stmt),
                                          gimple_bb (use_stmt))
                          && !for_each_index (ref->ref ? &ref->ref :
&ref->base,
                                              check_name, gimple_bb
(use_stmt)))
                        return DSE_STORE_LIVE;

we could make this bail-out "delayed" until we hit the next possible use in
the loop (of which there is none).

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

end of thread, other threads:[~2024-04-09  7:12 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-08 21:37 [Bug middle-end/114647] New: missing DCE when looping over a VLA franckbehaghel_gcc at protonmail dot com
2024-04-08 21:40 ` [Bug tree-optimization/114647] missing DSE " pinskia at gcc dot gnu.org
2024-04-08 21:46 ` pinskia at gcc dot gnu.org
2024-04-09  7:12 ` 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).