Bug 38212 - restrict implementation causes wrong-code
restrict implementation causes wrong-code
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: middle-end
4.4.0
: P3 normal
: 4.5.0
Assigned To: Richard Biener
: alias, wrong-code
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2008-11-21 13:28 UTC by Richard Biener
Modified: 2009-06-29 12:25 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.3.2 4.4.0
Last reconfirmed: 2009-06-22 10:56:35


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2008-11-21 13:28:24 UTC
The following is miscompiled by RTL cse at -O2 

int __attribute__((noinline))
foo (int *__restrict p, int i)
{
  int *__restrict q;
  int *__restrict r;
  int v, w;
  q = p + 1;
  r = q - i;
  v = *r;
  *p = 1;
  w = *r;
  return v + w;
}
extern void abort (void);
int main()
{
  int i = 0;
  if (foo (&i, 1) != 1)
    abort ();
  return 0;
}
Comment 1 Richard Biener 2008-11-21 13:41:02 UTC
Shorter testcase:

int __attribute__((noinline))
foo (int *__restrict p, int i)
{
  int *__restrict q = p + i;
  int v = *q;
  *p = 1;
  return v + *q;
}
extern void abort (void);
int main()
{
  int i = 0;
  if (foo (&i, 0) != 1)
    abort ();
  return 0;
}
Comment 2 Richard Biener 2008-11-21 15:28:11 UTC
int __attribute__((noinline))
foo (int *__restrict p, int i)
{
  int *__restrict q = p + i;
  int v = *(p + i);
  *p = 1;
  return v + *q;
}
extern void abort (void);
int main()
{
  int i = 0;
  if (foo (&i, 0) != 1)
    abort ();
  return 0;
}

also breaks, even though *p and *(p + i) conflict we still CSE *q to be
equal to *(p + i) because we CSE p + i to be q which makes us go back
to square one.
Comment 3 Richard Biener 2009-06-22 10:56:35 UTC
Mine.
Comment 4 Richard Biener 2009-06-29 12:20:53 UTC
Subject: Bug 38212

Author: rguenth
Date: Mon Jun 29 12:20:39 2009
New Revision: 149047

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

	PR middle-end/38212
	* alias.c (find_base_decl): Remove.
	(get_deref_alias_set_1): Remove restrict handling.
	* c-common.c (c_apply_type_quals_to_decl): Do not set
	DECL_POINTER_ALIAS_SET.
	* gimplify.c (find_single_pointer_decl_1): Remove.
	(find_single_pointer_decl): Likewise.
	(internal_get_tmp_var): Remove restrict handling.
	(gimple_regimplify_operands): Likewise.
	* omp-low.c (expand_omp_atomic_pipeline): Do not set
	DECL_POINTER_ALIAS_SET. Use ref-all pointers.
	* print-tree.c (print_node): Do not print DECL_POINTER_ALIAS_SET.
	* tree.c (restrict_base_for_decl): Remove.
	(init_ttree): Do not allocate it.
	(make_node_stat): Do not set DECL_POINTER_ALIAS_SET.  Set
	LABEL_DECL_UID for label decls.
	(copy_node_stat): Do not copy restrict information.
	(decl_restrict_base_lookup): Remove.
	(decl_restrict_base_insert): Likewise.
	(print_restrict_base_statistics): Likewise.
	(dump_tree_statistics): Do not call print_restrict_base_statistics.
	* tree.h (DECL_POINTER_ALIAS_SET): Remove.
	(DECL_POINTER_ALIAS_SET_KNOWN_P): Likewise.
	(struct tree_decl_common): Rename pointer_alias_set to label_decl_uid.
	(LABEL_DECL_UID): Adjust.
	(DECL_BASED_ON_RESTRICT_P): Remove.
	(DECL_GET_RESTRICT_BASE): Likewise.
	(SET_DECL_RESTRICT_BASE): Likewise.
	(struct tree_decl_with_vis): Remove based_on_restrict_p flag.

	* config/i386/i386.c (ix86_gimplify_va_arg): Use ref-all pointers
	instead of DECL_POINTER_ALIAS_SET.
	* config/rs6000/rs6000.c (rs6000_gimplify_va_arg): Likewise.
	* config/s390/s390.c (s390_gimplify_va_arg): Likewise.
	* config/spu/spu.c (spu_gimplify_va_arg_expr): Likewise.

	* gcc.c-torture/execute/pr38212.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.c-torture/execute/pr38212.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/alias.c
    trunk/gcc/c-common.c
    trunk/gcc/config/i386/i386.c
    trunk/gcc/config/rs6000/rs6000.c
    trunk/gcc/config/s390/s390.c
    trunk/gcc/config/spu/spu.c
    trunk/gcc/gimplify.c
    trunk/gcc/omp-low.c
    trunk/gcc/print-tree.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree.c
    trunk/gcc/tree.h

Comment 5 Richard Biener 2009-06-29 12:25:41 UTC
Fixed.