User account creation filtered due to spam.

Bug 14187 - [tree-ssa] C restricted pointers are not properly implemented
Summary: [tree-ssa] C restricted pointers are not properly implemented
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: tree-ssa
: P2 enhancement
Target Milestone: 4.5.0
Assignee: Not yet assigned to anyone
URL:
Keywords: alias, missed-optimization
: 14192 16306 16913 28030 29239 32273 33272 33705 (view as bug list)
Depends on:
Blocks: 14192 15623 16913 33272 37694 37695 37696
  Show dependency treegraph
 
Reported: 2004-02-18 08:20 UTC by Dan Nicolaescu
Modified: 2014-02-17 14:00 UTC (History)
16 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2006-01-13 04:45:16


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Nicolaescu 2004-02-18 08:20:19 UTC
Given:
extern void link_error (void);

void bar0 (int * __restrict__ arr1, int * __restrict__ arr2)
{
  arr1[0] = 1;
  arr2[0] = 1;
  if (arr1[0] != 1)
    link_error ();
}

arr1 and arr2 should not alias, hence the "if" should be eliminated

The .optimized dump is: 

bar0 (arr1, arr2)
{
<bb 0>:
  #   TMT.46_5 = VDEF <TMT.46_4>;
  *arr1 = 1;
  #   TMT.46_6 = VDEF <TMT.46_5>;
  *arr2 = 1;
  if (*arr1 != 1) goto <L0>; else goto <L1>;

<L0>:;
  #   TMT.46_7 = VDEF <TMT.46_6>;
  link_error ();

<L1>:;
  return;

}
Comment 1 Falk Hueffner 2004-02-18 11:04:29 UTC
Works for me with GNU C version 3.5-tree-ssa 20040217 (merged
20040211) (alphaev68-unknown-linux-gnu):

0000000000000000 <bar0>:
   0:   01 00 3f 20     lda     t0,1
   4:   00 00 31 b0     stl     t0,0(a1)
   8:   00 00 30 b0     stl     t0,0(a0)
   c:   01 80 fa 6b     ret

Which version and target are you seeing this problem for?
Comment 2 Andrew Pinski 2004-02-18 13:06:01 UTC
Confirmed.
Comment 3 Dan Nicolaescu 2004-03-12 17:15:14 UTC
Interestingly the following code is optimized:

#include <stdlib.h>

extern int foo (int * , int *);
void bar1 (void)
{
  int * arr1 = malloc (12);
  int * arr2 = malloc (12);
  arr1[0] = 1;
  arr2[0] = 1;
  if (arr1[0] != 1)
    link_error ();
  foo (arr1, arr2);
}
Comment 4 Andrew Pinski 2004-07-02 00:19:42 UTC
Patch here: <http://gcc.gnu.org/ml/gcc-patches/2004-07/msg00116.html>.
Comment 5 Andrew Pinski 2007-06-11 00:48:31 UTC
(In reply to comment #3)
> Interestingly the following code is optimized:
That is because we create a new may_alias variable for malloc to point to so we know that it cannot alias anything.
Comment 6 Richard Biener 2008-10-01 14:28:18 UTC
*** Bug 14192 has been marked as a duplicate of this bug. ***
Comment 7 Richard Biener 2008-10-01 14:30:28 UTC
Note that C restrict semantics make it necessary to properly track what
pointer is based on what other pointer.  For this we miss both annotations
and a (simple) propagator that propagates this information, maybe as part
of PTA analysis.

Note that the current implementation has both missed-optimization and latent
wrong-code issues.
Comment 8 Richard Biener 2008-10-01 14:32:28 UTC
*** Bug 16306 has been marked as a duplicate of this bug. ***
Comment 9 Richard Biener 2008-10-01 14:33:29 UTC
*** Bug 16913 has been marked as a duplicate of this bug. ***
Comment 10 Richard Biener 2008-10-01 14:34:08 UTC
*** Bug 28030 has been marked as a duplicate of this bug. ***
Comment 11 Richard Biener 2008-10-01 14:35:09 UTC
*** Bug 29239 has been marked as a duplicate of this bug. ***
Comment 12 Richard Biener 2008-10-01 14:35:57 UTC
*** Bug 32273 has been marked as a duplicate of this bug. ***
Comment 13 Richard Biener 2008-10-01 14:38:03 UTC
*** Bug 33272 has been marked as a duplicate of this bug. ***
Comment 14 Richard Biener 2008-10-01 14:40:08 UTC
*** Bug 33705 has been marked as a duplicate of this bug. ***
Comment 15 Richard Biener 2008-10-01 15:01:39 UTC
This is not solely a tree issue.
Comment 16 Richard Biener 2009-06-29 12:23:37 UTC
Subject: Bug 14187

Author: rguenth
Date: Mon Jun 29 12:23:21 2009
New Revision: 149048

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=149048
Log:
2009-06-29  Richard Guenther  <rguenther@suse.de>

	PR middle-end/14187
	* tree-ssa-alias.h (struct pt_solution): Add vars_contains_restrict
	flag.
	(pt_solutions_same_restrict_base): Declare.
	* tree-ssa-structalias.c (struct variable_info): Add is_restrict_var
	flag.
	(new_var_info): Initialize is_global_var properly for SSA_NAMEs.
	(make_constraint_from, make_copy_constraint): Move earlier.
	(make_constraint_from_heapvar): New function.
	(make_constraint_from_restrict): Likewise.
	(handle_lhs_call): Use it.
	(find_func_aliases): Use it to track conversions to restrict
	qualified pointers.
	(struct fieldoff): Add only_restrict_pointers flag.
	(push_fields_onto_fieldstack): Initialize it.
	(create_variable_info_for): Track global restrict qualified pointers.
	(intra_create_variable_infos): Use make_constraint_from_heapvar.
	Track restrict qualified pointer arguments.
	(set_uids_in_ptset): Use varinfo is_global_var flag.
	(find_what_var_points_to): Set the vars_contains_restrict flag.
	Always create the points-to solution for sets including restrict tags.
	(pt_solutions_same_restrict_base): New function.
	* tree-ssa-alias.c (ptr_derefs_may_alias_p): For two restrict
	qualified pointers use pt_solutions_same_restrict_base as
	additional source for disambiguation.

	* gcc.dg/tree-ssa/restrict-1.c: New testcase.
	* gcc.dg/tree-ssa/restrict-2.c: Likewise.
	* gcc.dg/tree-ssa/restrict-3.c: Likewise.
	* gcc.c-torture/execute/20090623-1.c: Likewise.
	* gcc.dg/tree-ssa/ldist-13.c: Likewise.
	* gcc.dg/tree-ssa/ldist-14.c: Likewise.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/20090623-1.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/ldist-13.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/ldist-14.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/restrict-1.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/restrict-2.c
    trunk/gcc/testsuite/gcc.dg/tree-ssa/restrict-3.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-alias.c
    trunk/gcc/tree-ssa-alias.h
    trunk/gcc/tree-ssa-structalias.c

Comment 17 Richard Biener 2009-06-29 12:24:34 UTC
Fixed.
Comment 18 Manuel López-Ibáñez 2010-01-11 19:23:00 UTC
(In reply to comment #17)
> Fixed.
> 

Richard, since this is a new feature of GCC 4.5, shouldn't we mention it in the GCC 4.5 changes.html?

Even something short would be welcome by users, such as:

"Better optimizations when using the <a href="http://gcc.gnu.org/onlinedocs/gcc/Restricted-Pointers.html">restrict keyword</a>".



Comment 19 rguenther@suse.de 2010-01-12 09:54:52 UTC
Subject: Re:  [tree-ssa] C restricted pointers are not
 properly implemented

On Mon, 11 Jan 2010, manu at gcc dot gnu dot org wrote:

> ------- Comment #18 from manu at gcc dot gnu dot org  2010-01-11 19:23 -------
> (In reply to comment #17)
> > Fixed.
> > 
> 
> Richard, since this is a new feature of GCC 4.5, shouldn't we mention it in the
> GCC 4.5 changes.html?
> 
> Even something short would be welcome by users, such as:
> 
> "Better optimizations when using the <a
> href="http://gcc.gnu.org/onlinedocs/gcc/Restricted-Pointers.html">restrict
> keyword</a>".

It's not universally better tho due to limitations on the RTL export
side.  I'll think of sth.

Richard.
Comment 20 Steven Bosscher 2010-01-30 22:29:36 UTC
Richi, is restrict working now, even with -fno-strict aliasing?
Comment 21 Richard Biener 2010-01-30 22:46:00 UTC
(In reply to comment #20)
> Richi, is restrict working now, even with -fno-strict aliasing?

Yes, it is.  See PR42617 for patches still required on the RTL side, it's
a bit late to apply them for 4.5 now.