But in MLIR LLVM dialect, I did not see a way to stick the attributes to the parameters of an indirect call (only CallableOpInterface seems to have parameter attributes).
Would it make sense to optionally add such attributes to the LLVM::CallOp operation?
On the general basis, if something is supported by LLVM IR, it should also be supported by the LLVM dialect. So yes, we should add support for argument attributes on indirect calls.
Thanks for the reply. Interestingly, clang is setting the call instruction argument attributes even for direct call (this can be observed with clang -emit-llvm for the program below). But removing the attributes on the CallOp seems to have no effect on the resulting assembly for direct calls as long as they are on the function declaration (flang does not generate those call attributes for direct calls and this has not been an issue so far).
However, the attributes on an llvm call instruction will be applied for direct calls even if they are not on the function declaration. For instance the same assembly is not generated for the two direct calls to the same symbol in the IR below.
So MLIR LLVM call instructions likely needs to be able to carry argument attributes for both direct and indirect calls to be like LLVM IR (although I also cannot say if it is an intended feature).
So MLIR LLVM call instructions likely needs to be able to carry argument attributes for both direct and indirect calls to be like LLVM IR (although I also cannot say if it is an intended feature).
Yes both direct and indirect calls can have parameter attributes in LLVM and LLVM dialect should probably be able to replicate this. Argument / parameter attributes are quite diverse. While it makes sense to annotate alignment on the call, something like byval makes more sense on the function (for direct calls…). Maybe clang choses to annotate both to be on the safe side…
It is valid to have attributes on both calls and functions. Furthermore, these arguments can be different, which can be useful for localized analyses and optimizations.
As an extreme example that I don’t think LLVM does (because it is not supposed to know about the C standard library):
this specific memmove can be replaced by a memcpy because we know that pointers don’t alias, but it doesn’t indicate anything for other call sites or the function itself. Attributes are often used to store analysis results in the IR, and there are other opportunities for local optimization or even function specialization thanks to that.