Bug 41186 - VN doesn't look through non-aliasing by offset memcpy
Summary: VN doesn't look through non-aliasing by offset memcpy
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 4.5.0
: P3 enhancement
Target Milestone: 4.5.0
Assignee: Richard Biener
URL:
Keywords: alias, missed-optimization
Depends on:
Blocks:
 
Reported: 2009-08-29 12:43 UTC by Richard Biener
Modified: 2009-09-26 15:27 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-08-29 13:49:04


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Richard Biener 2009-08-29 12:43:39 UTC
The C++ FE now creates memcpy for class copies to avoid copying objects in
tail-padding.

struct Foo {
  Foo() {};
  int i;
  short f;
};
struct Bar : public Foo {
  Bar() {};
  short b;
};

extern "C" void abort(void);

int main()
{
  Bar b1, b2;
  b2.i = 0;
  b1.f = 0;
  b1.b = 1;
  b2.f = 1;
  b2.b = 2;
  static_cast<Foo&>(b1) = static_cast<Foo&>(b2);
  if (b1.i != 0 || b1.b != 1)
    abort ();
  if (b1.f != 1)
    abort ();
  return 0;
}

The alias-oracle does consider the memcpy to clobber b1.b and the
look-through doesn't find b1.f or b1.i either.

Note that with combining the tests like

  if (b1.i != 0 || b1.b != 1 || b1.f != 1)
    abort ();

fold creates a BIT_FIELD_REF covering both b and f which confuses us
even more.  But I have considered this a bad habit of fold earlier.
Comment 1 Richard Biener 2009-08-29 13:49:04 UTC
Mine.
Comment 2 Richard Biener 2009-08-30 11:52:29 UTC
Subject: Bug 41186

Author: rguenth
Date: Sun Aug 30 11:52:13 2009
New Revision: 151226

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

	PR tree-optimization/41186
	* tree-ssa-alias.c (ptr_deref_may_alias_ref_p): Remove.
	(ao_ref_init_from_ptr_and_size): New function.
	(ref_maybe_used_by_call_p_1): Be more precise tracking
	used ranges for builtin functions.
	(ref_maybe_used_by_call_p): Adjust.
	(call_may_clobber_ref_p_1): Be more precise tracking clobbered
	ranges for builtin functions.
	* tree-ssa-alias.h (ao_ref_init_from_ptr_and_size): Declare.

	* g++.dg/torture/pr41186.C: New testcase.
	* g++.dg/tree-ssa/pr41186.C: Likewise.

Added:
    trunk/gcc/testsuite/g++.dg/torture/pr41186.C
    trunk/gcc/testsuite/g++.dg/tree-ssa/pr41186.C
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-ssa-alias.c
    trunk/gcc/tree-ssa-alias.h

Comment 3 Richard Biener 2009-09-26 15:27:55 UTC
Fixed.  Related is PR13954 where VN does not look through (partial) struct copies
using memcpy.