public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/20638] New: [3.4,4.0,4.1] gcc doesn't take advantage of attribute malloc on alloca
@ 2005-03-25 20:02 ghazi at gcc dot gnu dot org
  2005-03-25 21:00 ` [Bug middle-end/20638] " pinskia at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: ghazi at gcc dot gnu dot org @ 2005-03-25 20:02 UTC (permalink / raw)
  To: gcc-bugs

The alloca builtin has the attribute __malloc__ set on it but GCC doesn't seem 
to take advantage of that fact for optimization.  The testcase gcc.dg/builtins-
13.c tests an optimization when calling the malloc/calloc functions.  When I 
try a similar case for alloca such as in the patch below, the testcase fails.

diff -rup orig/egcc-CVS20050323/gcc/testsuite/gcc.dg/builtins-13.c egcc-
CVS20050323/gcc/testsuite/gcc.dg/builtins-13.c
--- orig/egcc-CVS20050323/gcc/testsuite/gcc.dg/builtins-13.c    2003-04-13 
22:55:31.000000000 -0400
+++ egcc-CVS20050323/gcc/testsuite/gcc.dg/builtins-13.c 2005-03-24 
17:16:50.098461000 -0500
@@ -1,4 +1,4 @@
-/* Copyright (C) 2003  Free Software Foundation.
+/* Copyright (C) 2003, 2005  Free Software Foundation.

    Verify that the malloc-like __builtin_ allocation functions are
    correctly aliased by the compiler.
@@ -12,6 +12,7 @@ typedef __SIZE_TYPE__ size_t;
 extern void abort (void);
 extern void *malloc (size_t);
 extern void *calloc (size_t,size_t);
+extern void *alloca (size_t);

 extern void link_error (void);

@@ -45,10 +46,25 @@ void test2(void)
     link_error ();
 }

+void test3(void)
+{
+  int *ptr1, *ptr2;
+
+  ptr1 = &x;
+  ptr2 = (int*) alloca (sizeof (int));
+
+  *ptr1 = 12;
+  *ptr2 = 8;
+
+  if (*ptr1 != 12)
+    link_error();
+}
+
 int main()
 {
   test1 ();
   test2 ();
+  test3 ();
   return 0;
 }

-- 
           Summary: [3.4,4.0,4.1] gcc doesn't take advantage of attribute
                    malloc on alloca
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ghazi at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org,roger at eyesopen dot
                    com
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


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


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

* [Bug middle-end/20638] gcc doesn't take advantage of attribute malloc on alloca
  2005-03-25 20:02 [Bug middle-end/20638] New: [3.4,4.0,4.1] gcc doesn't take advantage of attribute malloc on alloca ghazi at gcc dot gnu dot org
@ 2005-03-25 21:00 ` pinskia at gcc dot gnu dot org
  2005-04-28 13:11 ` ghazi at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-03-25 21:00 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-03-25 21:00 -------
Confirmed, I also noticed that we don't take advantage of the malloc attribute on the tree level either, 
see PR 20641.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
  BugsThisDependsOn|                            |20641
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
           Keywords|                            |alias, missed-optimization
   Last reconfirmed|0000-00-00 00:00:00         |2005-03-25 21:00:42
               date|                            |
            Summary|[3.4,4.0,4.1] gcc doesn't   |gcc doesn't take advantage
                   |take advantage of attribute |of attribute malloc on
                   |malloc on alloca            |alloca


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


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

* [Bug middle-end/20638] gcc doesn't take advantage of attribute malloc on alloca
  2005-03-25 20:02 [Bug middle-end/20638] New: [3.4,4.0,4.1] gcc doesn't take advantage of attribute malloc on alloca ghazi at gcc dot gnu dot org
  2005-03-25 21:00 ` [Bug middle-end/20638] " pinskia at gcc dot gnu dot org
@ 2005-04-28 13:11 ` ghazi at gcc dot gnu dot org
  2005-09-21  2:13 ` pinskia at gcc dot gnu dot org
  2005-09-21  2:13 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 6+ messages in thread
From: ghazi at gcc dot gnu dot org @ 2005-04-28 13:11 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From ghazi at gcc dot gnu dot org  2005-04-28 13:11 -------
Roger Sayle provided this feedback to me in private email and agreed to have it 
copied here:

------------------------------------------------------------------

I've glanced through the code and I suspect I know why this isn't
working.  The MALLOC attribute is traditionally handled in calls.c
where it attaches a REG_NOALIAS note to the relevant call_insn.
In the case of alloca, however, we don't go through calls.c and
instead inline calls to alloca via expand_builtin_alloca in
builtins.c instead.  My guess is that we need to add a REG_NOALIAS
note, or mark/assign the alias set of this pointer in builtins.c.

Interestingly, this doesn't explain why the builtins-13.c tests
aren't now being optimized by tree-ssa, where the "malloc" attribute
should now be getting used during the early alias analysis passes.

Unfortunately, I'm not an expert of how to present aliasing information
at the RTL-level.  But the above should help explain why alloca behaves
differently to malloc/calloc/strdup etc.

Roger


-- 


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


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

* [Bug middle-end/20638] gcc doesn't take advantage of attribute malloc on alloca
  2005-03-25 20:02 [Bug middle-end/20638] New: [3.4,4.0,4.1] gcc doesn't take advantage of attribute malloc on alloca ghazi at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2005-09-21  2:13 ` pinskia at gcc dot gnu dot org
@ 2005-09-21  2:13 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-21  2:13 UTC (permalink / raw)
  To: gcc-bugs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-09-21 02:13 -------
Note this is now fixed on the mainline by tree optimizers.

-- 


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


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

* [Bug middle-end/20638] gcc doesn't take advantage of attribute malloc on alloca
  2005-03-25 20:02 [Bug middle-end/20638] New: [3.4,4.0,4.1] gcc doesn't take advantage of attribute malloc on alloca ghazi at gcc dot gnu dot org
  2005-03-25 21:00 ` [Bug middle-end/20638] " pinskia at gcc dot gnu dot org
  2005-04-28 13:11 ` ghazi at gcc dot gnu dot org
@ 2005-09-21  2:13 ` pinskia at gcc dot gnu dot org
  2005-09-21  2:13 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-21  2:13 UTC (permalink / raw)
  To: gcc-bugs



-- 
Bug 20638 depends on bug 20641, which changed state.

Bug 20641 Summary: Missed optimization on the tree level (malloc attribute)
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20641

           What    |Old Value                   |New Value
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED

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


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

* [Bug middle-end/20638] gcc doesn't take advantage of attribute malloc on alloca
       [not found] <bug-20638-578@http.gcc.gnu.org/bugzilla/>
@ 2005-10-09 16:54 ` pinskia at gcc dot gnu dot org
  0 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-10-09 16:54 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2005-10-09 16:54 -------
Fixed on the mainline.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.1.0


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


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

end of thread, other threads:[~2005-10-09 16:54 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-25 20:02 [Bug middle-end/20638] New: [3.4,4.0,4.1] gcc doesn't take advantage of attribute malloc on alloca ghazi at gcc dot gnu dot org
2005-03-25 21:00 ` [Bug middle-end/20638] " pinskia at gcc dot gnu dot org
2005-04-28 13:11 ` ghazi at gcc dot gnu dot org
2005-09-21  2:13 ` pinskia at gcc dot gnu dot org
2005-09-21  2:13 ` pinskia at gcc dot gnu dot org
     [not found] <bug-20638-578@http.gcc.gnu.org/bugzilla/>
2005-10-09 16:54 ` pinskia at gcc dot gnu dot 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).