https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107389
Bug ID: 107389 Summary: Alignment not inferred from type at -O0 Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: rth at gcc dot gnu.org Target Milestone: --- Consider typedef __uint128_t aligned_type __attribute__((aligned(16))); _Static_assert(__alignof(aligned_type) == 16); __uint128_t foo(aligned_type *p) { return __atomic_load_n(p, 0); } For s390x, atomic_loadti should expand this to LPQ. For my purposes, it must also do this at -O0, not just with optimization. But the alignment seen by gen_atomic_loadti is only 8, so it FAILs the expansion and falls back to libatomic. The following appears to solve the problem: --- a/gcc/builtins.cc +++ b/gcc/builtins.cc @@ -468,8 +468,11 @@ get_pointer_alignment_1 } else { + /* Assume alignment from the type. */ + tree ptr_type = TREE_TYPE (exp); + tree obj_type = TREE_TYPE (ptr_type); + *alignp = TYPE_ALIGN (obj_type); *bitposp = 0; - *alignp = BITS_PER_UNIT; return false; } } but I have an inkling that would have undesired effects for other usages. If so, perhaps a special case could be made for the usage in get_builtin_sync_mem.