[Codegen] Set alignment attributes over vectorized memory accessed #20267
Labels
codegen/llvm
LLVM code generation compiler backend
codegen
Shared code generation infrastructure and dialects
performance ⚡
Performance/optimization related work across the compiler and runtime
Hardware like amdgpu generally prefers wide memory accesses (e.g., dwordx4 or b128) but these only get selected by the llvm backend when the alignment is known and sufficiently large. LLVM is able to infer the alignment in some cases, but it's not guaranteed to always do the best job possible.
For example, consider this pseudo-IR:
Ideally, we would like to assume 16-byte alignment (8 * 2 bytes), but this requires knowing:
%b
to be a multiple of 8Just because the accessed type is
vector<8xf16>
is not enough to infer that the alignment is 16.We can already accomplish 1. with the
alignment
attribute supported bymemref.alloc
op, but we have no way of expressing known alignment over memory accesses across memref/vector load/store ops. Similar withinbounds
attributes, the most general representation would be per-dimension, but allowing it over 1-d vector types makes things simpler.I think the following implementation should work:
alignment
attribute tomemref
/vector
memory access ops. To keep it simple, require this to be a single byte value (instead of number of elements) wrt the first element accessed only.alignment
attributes when converting frommemref
/vector
tollvm
/spirv
.The text was updated successfully, but these errors were encountered: