Alignment parameter attributes

I have a question about how to communicate alignment via function
parameters. The IR supports an attribute specifying the alignment of a
pointer parameter:

define void @func(double* noalias align 64 %p)

This says that %p is 64-byte aligned. Great!

Is there any way to convey the alignment of a pointer pointed to by a **
argument? I'd like something like this:

define void @func(double* align 64 * noalias %p)

Or even this to add a noalias attribute:

define void @func(double* noalias align 64 * noalias %p)

I don't think either of these is legal today.

Has anyone else run into this need? If so, any advice would be much
appreciated!

                  -David

If you have this knowledge during code generation you can associate
align metadata to the loads from %p.

We could use a custom tag on `llvm.assume`, as an extension of
https://reviews.llvm.org/D72475, but that is not yet implemented.

Cheers,
  Johannes

"Doerfert, Johannes via llvm-dev" <llvm-dev@lists.llvm.org> writes:

We could use a custom tag on `llvm.assume`, as an extension of
https://reviews.llvm.org/D72475, but that is not yet implemented.

I had thought about using llvm.assume but was wondering if there is a
better way. Tagging the loads with metadata really seems about the same
amount of effort. Both require major surgery to code generation.

Thanks for your help Johannes!

                  -David

It might be interesting to add "pointee" attributes on pointers, that is attributes that are attached to the pointee, however that requires a larger discussion.

"Doerfert, Johannes via llvm-dev" <llvm-dev@lists.llvm.org> writes:

It might be interesting to add "pointee" attributes on pointers, that
is attributes that are attached to the pointee, however that requires
a larger discussion.

For sure. I think it could be useful but we would need more use-cases
to justify it. I'm not sure my situation rises to the level of being a
really compelling case since there are other ways to fix this issue,
they just aren't very pleasant to implement. :slight_smile:

                        -David

Haven’t followed the discussion in detail - but just in case: pointee types aren’t something you should build further reliance on as the long term plan is to remove them. (to have opaque pointer types that don’t carry any information about what they point to) - in part because LLVM doesn’t provide any guarantees about the type safety of pointers, etc.