Bug 87535 - multiple attribute assume_aligned interpreted inconsistently
Summary: multiple attribute assume_aligned interpreted inconsistently
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 9.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: missed-optimization
Depends on: 64236
Blocks:
  Show dependency treegraph
 
Reported: 2018-10-05 18:21 UTC by Martin Sebor
Modified: 2024-04-09 04:58 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Sebor 2018-10-05 18:21:26 UTC
The example below shows that attribute assume_aligned is interpreted inconsistently between apparently equivalent declarations of the same function.  When two such attributes are specified on the same declaration the one specified last wins.  When the same pair are specified on distinct declarations of the same function, the first one wins.

Clang treats both forms consistently, but honors the attribute that was specified last.  I think it's debatable whether that's preferable to honoring the most restrictive one as specified for _Alignas by C11.  I'm leaning toward going with the C11 approach to minimize surprises due to an inconsistency.

$ cat c.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout c.c
__attribute ((assume_aligned (8),     // ignored
              assume_aligned (32)))   // overrdides prior attribute
char* f (void);

void f1 (void)
{
  char *p = f ();
  if ((__INTPTR_TYPE__)p & 31)   // folded to false
    __builtin_abort ();
}

__attribute ((assume_aligned (8)))   // overrides subsequent attribute
void* g (void);

__attribute ((assume_aligned (32)))   // attribute ignored
void* g (void);

void g1 (void)
{
  void *p = g ();
  if ((__INTPTR_TYPE__)p & 31)   // not folded
    __builtin_abort ();
}


;; Function f1 (f1, funcdef_no=0, decl_uid=1908, cgraph_uid=1, symbol_order=0)

f1 ()
{
  <bb 2> [local count: 1073741824]:
  f (); [tail call]
  return;

}



;; Function g1 (g1, funcdef_no=1, decl_uid=1916, cgraph_uid=2, symbol_order=1)

g1 ()
{
  void * p;
  long int p.1_1;
  long int _2;

  <bb 2> [local count: 1073741824]:
  p_5 = g ();
  p.1_1 = (long int) p_5;
  _2 = p.1_1 & 31;
  if (_2 != 0)
    goto <bb 3>; [0.00%]
  else
    goto <bb 4>; [99.96%]

  <bb 3> [count: 0]:
  __builtin_abort ();

  <bb 4> [local count: 1073312328]:
  return;

}
Comment 1 Martin Sebor 2018-10-05 22:58:25 UTC
See also pr81871 for other problems with the handling of the assume_aligned attribute.
Comment 2 Martin Sebor 2018-10-05 22:59:50 UTC
(In reply to Martin Sebor from comment #1)

That should have been pr87533.
Comment 3 Andrew Pinski 2024-04-09 04:58:21 UTC
I think this is basically a dup of bug 64236.