This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/79518] New: __builtin_assume_aligned should mark argument as aligned


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

            Bug ID: 79518
           Summary: __builtin_assume_aligned should mark argument as
                    aligned
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: evan@coeus-group.com
  Target Milestone: ---

TL;DR: It would be very helpful if __builtin_assume_aligned() would mark its
first argument as aligned (assuming it represents a variable).

I'm trying to implement a macro to abstract away compiler differences, but
__builtin_assume_aligned works very differently than other compiler's
alternatives, and it's making it impossible to support GCC.

ICC's __assume_aligned marks the argument as aligned:

    __assume_aligned(arg, 16)
    /* Compiler knows arg is 16-byte aligned */

MSVC wants you to use __assume, which is ugly, but can be made to work the same
way (people often wrap it up in a macro that looks like the Intel version):

    __assume((((char*) arg) - ((char*) 0)) % (16) == 0)
    /* Compiler knows arg is 16-byte aligned */

clang can also (I believe) be made to work similarly.  They have an internal
macro
(http://llvm.org/docs/doxygen/html/Compiler_8h.html#a2fd576fb00a760ba803c8a171bff051a)
called LLVM_ASSUME_ALIGNED which is defined as

    # define LLVM_ASSUME_ALIGNED(p, a) \
               (((uintptr_t(p) % (a)) == 0) ? (p) : (LLVM_BUILTIN_UNREACHABLE,
(p)))

This doesn't seem to have an effect on GCC (using __builtin_unreachable and a C
style cast), though.  FWIW, I'd consider making that work to be an acceptable
solution, too, though I think improving __builtin_assume_aligned would be much
better as it would be more discoverable.

Unfortunately, it's not easy to smooth out this particular difference.  There
are some details at <https://github.com/nemequ/hedley/issues/1>, but basically
I can't find a good solution which works with both styles, mostly due to the
standard multiple-evaluation of macro arguments SNAFU.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]