public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/58817] New: optimize alloca with constant size
@ 2013-10-21  4:12 glisse at gcc dot gnu.org
  2013-10-21  6:54 ` [Bug tree-optimization/58817] " jakub at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-10-21  4:12 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58817

            Bug ID: 58817
           Summary: optimize alloca with constant size
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: glisse at gcc dot gnu.org

Hello,

I thought gcc already had this optimization but apparently not. We don't
produce the same code with alloca and with arrays:

void f(int*);
void g(){
#if 1
  const int n=4;
  int a[n];
#elif 1
  int a[4];
#else
  int*a=__builtin_alloca(16);
#endif
  f(a);
}

possibly because arrays give alloca_with_align, not alloca.

There may be reasons why the transformation would be illegal though, I am not
sure.


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

* [Bug tree-optimization/58817] optimize alloca with constant size
  2013-10-21  4:12 [Bug tree-optimization/58817] New: optimize alloca with constant size glisse at gcc dot gnu.org
@ 2013-10-21  6:54 ` jakub at gcc dot gnu.org
  2013-10-21  8:25 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-10-21  6:54 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58817

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Transforming VLAs that way isn't a good idea, at least if the size isn't really
small, at least when the VLA isn't in a scope that dies at the function's end
(or if there is a chance the function might be inlined because of that
optimization).  Because, unlike normal alloca, VLAs are deallocated already
when leading the scope they were declared in, and tons of programs rely on that
deallocation, otherwise you might have too big stack requirements.


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

* [Bug tree-optimization/58817] optimize alloca with constant size
  2013-10-21  4:12 [Bug tree-optimization/58817] New: optimize alloca with constant size glisse at gcc dot gnu.org
  2013-10-21  6:54 ` [Bug tree-optimization/58817] " jakub at gcc dot gnu.org
@ 2013-10-21  8:25 ` rguenth at gcc dot gnu.org
  2013-10-22  8:36 ` glisse at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2013-10-21  8:25 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58817

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
We do this transform in fold_builtin_alloca_with_align (), I'm not sure but
maybe it does not happen because 'a' escapes to f.


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

* [Bug tree-optimization/58817] optimize alloca with constant size
  2013-10-21  4:12 [Bug tree-optimization/58817] New: optimize alloca with constant size glisse at gcc dot gnu.org
  2013-10-21  6:54 ` [Bug tree-optimization/58817] " jakub at gcc dot gnu.org
  2013-10-21  8:25 ` rguenth at gcc dot gnu.org
@ 2013-10-22  8:36 ` glisse at gcc dot gnu.org
  2021-12-23  7:24 ` pinskia at gcc dot gnu.org
  2021-12-23  7:24 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: glisse at gcc dot gnu.org @ 2013-10-22  8:36 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58817

--- Comment #3 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to Jakub Jelinek from comment #1)
> Transforming VLAs that way isn't a good idea, at least if the size isn't
> really small, at least when the VLA isn't in a scope that dies at the
> function's end (or if there is a chance the function might be inlined
> because of that optimization).  Because, unlike normal alloca, VLAs are
> deallocated already when leading the scope they were declared in, and tons
> of programs rely on that deallocation, otherwise you might have too big
> stack requirements.

Currently we are turning VLAs into regular arrays, but not alloca. From your
explanations, I understand we should basically do the converse? (do it for
alloca but not VLA)


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

* [Bug tree-optimization/58817] optimize alloca with constant size
  2013-10-21  4:12 [Bug tree-optimization/58817] New: optimize alloca with constant size glisse at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2013-10-22  8:36 ` glisse at gcc dot gnu.org
@ 2021-12-23  7:24 ` pinskia at gcc dot gnu.org
  2021-12-23  7:24 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-23  7:24 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2021-12-23
             Status|UNCONFIRMED                 |NEW

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed, we handle the VLA case since GCC 4.7.0.

alloca has not been handled yet.

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

* [Bug tree-optimization/58817] optimize alloca with constant size
  2013-10-21  4:12 [Bug tree-optimization/58817] New: optimize alloca with constant size glisse at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2021-12-23  7:24 ` pinskia at gcc dot gnu.org
@ 2021-12-23  7:24 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-23  7:24 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sdmike9r at liargroup dot com

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
*** Bug 89889 has been marked as a duplicate of this bug. ***

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

end of thread, other threads:[~2021-12-23  7:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-10-21  4:12 [Bug tree-optimization/58817] New: optimize alloca with constant size glisse at gcc dot gnu.org
2013-10-21  6:54 ` [Bug tree-optimization/58817] " jakub at gcc dot gnu.org
2013-10-21  8:25 ` rguenth at gcc dot gnu.org
2013-10-22  8:36 ` glisse at gcc dot gnu.org
2021-12-23  7:24 ` pinskia at gcc dot gnu.org
2021-12-23  7:24 ` pinskia 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).