[llvm] [LangRef] Do not make align imply dereferenceability (PR #158062)
Nuno Lopes via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 12 07:28:13 PDT 2025
nunoplopes wrote:
For codegen, @arsenm can shime in. I'm not aware of any test case in trunk that takes advantage of the alignment.
However, LoadStoreVectorizer does something funky:
```llvm
; Transforms/LoadStoreVectorizer/batch-aa-compile-time.ll
@global_mem = global 1 bytes, align 4
define void @compile-time-test() {
entry:
%__constexpr_1 = ptrtoint ptr @global_mem to i32
%__constexpr_0 = inttoptr i32 %__constexpr_1 to ptr
%global_base_loads = gep ptr %__constexpr_0, 1 x i64 0
%local_base_stores = alloca i64 512, align 4
br label %loop
loop:
%load_0 = load i8, ptr %global_base_loads, align 4
%ptr_1 = gep ptr %global_base_loads, 1 x i64 1
%load_1 = load i8, ptr %ptr_1, align 1
%ptr_2 = gep ptr %global_base_loads, 1 x i64 2
%load_2 = load i8, ptr %ptr_2, align 2
%ptr_3 = gep ptr %global_base_loads, 1 x i64 3
%load_3 = load i8, ptr %ptr_3, align 1
...
=>
define void @compile-time-test() {
entry:
%__constexpr_1 = ptrtoint ptr @global_mem to i32
%__constexpr_0 = inttoptr i32 %__constexpr_1 to ptr
%global_base_loads = gep ptr %__constexpr_0, 1 x i64 0
%local_base_stores = alloca i64 512, align 4
br label %loop
loop:
%#0 = load <4 x i8>, ptr %global_base_loads, align 4
```
It transforms 4x i8 loads into a <4 x i8> load. If alignment implies dereferenceability, this transformation is correct. Otherwise, it's not. We are working with pointers result from int2ptr, so p+1 may point to a different object. Since each load can only read from a single object at a time, widening the load to a vectorized one is wrong.
So this kind of vectorization is only correct over logical pointers, not physical ones (with the semantics in this PR).
https://github.com/llvm/llvm-project/pull/158062
More information about the llvm-commits
mailing list