[llvm] [DSE] Enable initializes improvement (PR #119116)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 11 02:00:23 PST 2024
nikic wrote:
For reference, the IR is:
```llvm
@g = global [12 x i8] zeroinitializer, align 1
@str = private constant [13 x i8] [i8 97, i8 98, i8 99, i8 100, i8 101, i8 102, i8 103, i8 104, i8 105, i8 106, i8 107, i8 108, i8 0], align 1
define void @copyGto(ptr initializes((0, 12)) %agg.result) nounwind {
entry:
tail call void @llvm.memmove.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(12) %agg.result, ptr noundef nonnull align 1 dereferenceable(12) @g, i32 12, i1 false)
ret void
}
define i16 @main() {
entry:
tail call void @llvm.memcpy.p0.p0.i32(ptr noundef nonnull align 1 dereferenceable(12) @g, ptr noundef nonnull align 1 dereferenceable(12) @str, i32 12, i1 false)
tail call void @copyGto(ptr @g)
call void @check(ptr @g)
ret i16 0
}
declare void @llvm.memmove.p0.p0.i32(ptr nocapture writeonly, ptr nocapture readonly, i32, i1 immarg)
declare void @llvm.memcpy.p0.p0.i32(ptr noalias nocapture writeonly, ptr noalias nocapture readonly, i32, i1 immarg)
declare void @check(ptr noundef)
```
I believe that the `initializes` attribute on copyGto is correct, at least per the current spec:
> This attribute only holds for the memory accessed via this pointer parameter. Other arbitrary accesses to the same memory via other pointers are allowed.
I think the problem here is that https://github.com/llvm/llvm-project/blob/14dcf8214f9c66172d17c1cfaec6aec0030748e0/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp#L2265 only looks at the call arguments, but doesn't account for the fact that the pointer may also be read via escaped memory (prior to initialization).
https://github.com/llvm/llvm-project/pull/119116
More information about the llvm-commits
mailing list