Bug 39744

Summary: component references with VIEW_CONVERT_EXPR should be canonicalized
Product: gcc Reporter: Richard Biener <rguenth>
Component: middle-endAssignee: Not yet assigned to anyone <unassigned>
Status: NEW ---    
Severity: enhancement CC: gcc-bugs
Priority: P3 Keywords: missed-optimization
Version: 4.5.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed: 2012-02-01 00:00:00

Description Richard Biener 2009-04-12 18:35:39 UTC
VIEW_CONVERT_EXPR <T>(a.b.c.d).e.f.g.h

should be canonicalized to strip zero-offset and same size as T component
references off the VIEW_CONVERT_EXPR argument.  The same should be applied
to component references of the VIEW_CONVERT_EXPR result by adjusting the
type T the VIEW_CONVERT_EXPR converts to.

This missed canonicalization will help folding and value numbering.
Comment 1 Richard Biener 2009-04-14 14:02:45 UTC
Testcase for the second case:

struct Y { int z; };
struct X { struct Y y; };
int foo()
  int z = 1;
  struct X *x = (struct X *)&z;
  return x->y.z;

a testcase for the first case is harder.
Comment 2 Andrew Pinski 2012-02-01 20:43:54 UTC
Confirmed, right now we get:
  D.1711_2 = VIEW_CONVERT_EXPR<struct X>(1).y.z;
  return D.1711_2;