From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 9758038582AD; Tue, 25 Oct 2022 07:57:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9758038582AD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1666684634; bh=dX+Niqhg5BNO5bSAlrs01GGR6O93+64/fNLCvvXpc8Q=; h=From:To:Subject:Date:From; b=VtFVDE2Q2sm+NJHMw1CRzViI0R0LXfd0UWE7npEE0lPQCHiNT5MPh7Bp+cN38a2wy tOBIbBrrrJi2ydR7WgYkX2f7k1If3QdHJCJdczHUyIeSunv08GDUO/bSvDdbNMrwm2 3oNQ7t8iRhxIjwuKvoCUZPD8mTeXrPF9Vs1ZV8J8= From: "rth at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/107389] New: Alignment not inferred from type at -O0 Date: Tue, 25 Oct 2022 07:57:14 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: rth at gcc dot gnu.org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107389 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) =3D=3D 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 =3D TREE_TYPE (exp); + tree obj_type =3D TREE_TYPE (ptr_type); + *alignp =3D TYPE_ALIGN (obj_type); *bitposp =3D 0; - *alignp =3D 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.=