Skip to content

LLVM memcpy/set optimizations prevented by uninitialized padding #172326

@MacDue

Description

@MacDue

Reduced from a C++ class initialization. It should be possible to rewrite:

define void @src(ptr %a) {
  %alloca = alloca <{ [2 x i8], i64, i64, i64 }>, align 2
  %3 = getelementptr inbounds nuw i8, ptr %alloca, i64 2
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 2 dereferenceable(24) %3, i8 0, i64 24, i1 false)
  call void @llvm.memcpy.p0.p0.i64(ptr noundef nonnull align 2 dereferenceable(26) %a, ptr noundef nonnull align 2 dereferenceable(26) %alloca, i64 26, i1 false)
  ret void
}

Into something like:

define void @tgt(ptr %a) {
  %3 = getelementptr inbounds nuw i8, ptr %a, i64 2
  call void @llvm.memset.p0.i64(ptr noundef nonnull align 2 dereferenceable(24) %3, i8 0, i64 24, i1 false)
  ret void
}

Which eliminates an alloca and a copy, but LLVM current fails to do so: https://godbolt.org/z/hKqnzs7v7

Proof: https://alive2.llvm.org/ce/z/2rqejL

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions