Created attachment 22966 [details] memset.src.ll ``` $ cat memset.src.ll ; Transforms/MemCpyOpt/form-memset.ll define void @test6(i32* nocapture %P) nounwind ssp { entry: %0 = bitcast i32* %P to i8* tail call void @llvm.memset.p0i8.i64(i8* %0, i8 0, i64 12, i1 false) %add.ptr = getelementptr inbounds i32, i32* %P, i64 3 %1 = bitcast i32* %add.ptr to i8* tail call void @llvm.memset.p0i8.i64(i8* %1, i8 0, i64 12, i1 false) ret void } declare void @llvm.memset.p0i8.i64(i8* nocapture, i8, i64, i1) nounwind $ ../llvm/build/bin/opt -memcpyopt memset.src.ll -S -o - ; ModuleID = 'memset.src.ll' source_filename = "memset.src.ll" ; Function Attrs: nounwind ssp define void @test6(i32* nocapture %P) #0 { entry: %0 = bitcast i32* %P to i8* %add.ptr = getelementptr inbounds i32, i32* %P, i64 3 %1 = bitcast i32* %add.ptr to i8* %2 = bitcast i32* %P to i8* call void @llvm.memset.p0i8.i64(i8* align 4 %2, i8 0, i64 24, i1 false) ret void } ; Function Attrs: argmemonly nounwind willreturn declare void @llvm.memset.p0i8.i64(i8* nocapture writeonly, i8, i64, i1 immarg) #1 attributes #0 = { nounwind ssp } attributes #1 = { argmemonly nounwind willreturn } ``` memcpyopt merges two memsets if they overlap and write the same value. After merging, align 4 is added, which is incorrect because %P is not guaranteed to have alignment 4.
Fixed (https://reviews.llvm.org/D74083)