https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66430

            Bug ID: 66430
           Summary: IPA CP alignment information is not used for
                    expression simplification
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: miyuki at gcc dot gnu.org
  Target Milestone: ---

Consider the following example:

static int __attribute__((noinline)) foo(char *p)
{
    return (unsigned long)p % 8;
}

int bar()
{
    char *data = __builtin_malloc(64);
    return foo(data + 5) + ((unsigned long)(data + 5) % 8);
}

When this code is compiled at -O3, alignment of "data" is propagated to foo:

$ cat align_test.c.060i.cp
[...snip...]
IPA lattices after all propagation:

Lattices:
  Node: bar/1:
  Node: foo/0:
    param [0]: VARIABLE
         ctxs: VARIABLE
         Alignment 8, misalignment 5
        AGGS VARIABLE
[...snip...]
Modification phase of node foo/0
  Adjusting alignment of param 0 to 8, misalignment to 5
[...snip...]

But it is not used:

$ cat align_test.c.191t.optimized

;; Function foo (foo, funcdef_no=0, decl_uid=1831, cgraph_uid=0,
symbol_order=0)

foo (char * p)
{
  long int p.0_2;
  int _3;
  int _4;

  <bb 2>:
  p.0_2 = (long int) p_1(D);
  _3 = (int) p.0_2;
  _4 = _3 & 7;
  return _4;

}

;; Function bar (bar, funcdef_no=1, decl_uid=1833, cgraph_uid=1,
symbol_order=1)

bar ()
{
  char * data;
  char * _4;
  int _5;
  unsigned int _6;
  unsigned int _7;
  int _8;

  <bb 2>:
  data_3 = __builtin_malloc (64);
  _4 = data_3 + 5;
  _5 = foo (_4);
  _6 = (unsigned int) _5;
  _7 = _6 + 5;
  _8 = (int) _7;
  return _8;

}

Notice, that in function bar the same expression is folded into constant.

Reply via email to