public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/107389] New: Alignment not inferred from type at -O0
@ 2022-10-25  7:57 rth at gcc dot gnu.org
  2022-10-25 12:46 ` [Bug c/107389] " rguenth at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: rth at gcc dot gnu.org @ 2022-10-25  7:57 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2022-11-28 22:15 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-25  7:57 [Bug c/107389] New: Alignment not inferred from type at -O0 rth at gcc dot gnu.org
2022-10-25 12:46 ` [Bug c/107389] " rguenth at gcc dot gnu.org
2022-10-25 12:52 ` rguenth at gcc dot gnu.org
2022-10-25 15:12 ` rth at gcc dot gnu.org
2022-10-26  8:15 ` [Bug middle-end/107389] Always propagate __builtin_assume_aligned rth at gcc dot gnu.org
2022-10-28  9:19 ` rguenth at gcc dot gnu.org
2022-10-28  9:30 ` rguenth at gcc dot gnu.org
2022-11-08 15:39 ` cvs-commit at gcc dot gnu.org
2022-11-08 15:40 ` rguenth at gcc dot gnu.org
2022-11-28 22:15 ` pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).