The bug is proposed here: https://bugs.llvm.org/show_bug.cgi?id=49270
Nobody has commented on the bug yet, but I think it clearly deviates from the description in our LLVM how-to-update-debug-info guide here: https://llvm.org/docs/HowToUpdateDebugInfo.html#when-to-merge-instruction-locations
"(Merges should be applied when) peephole optimizations which combine multiple instructions together, like (add (mul A B) C) => llvm.fma.f32(A, B, C)".
Multiple store instructions in the same basic block are merged into one memset instruction:
In the original ll file:
%arrayidx = getelementptr inbounds i32, i32* %P, i64 1, !dbg !13 call void @llvm.dbg.value(metadata i32* %arrayidx, metadata !9, metadata !DIExpression()), !dbg !13 store i32 0, i32* %arrayidx, align 4, !dbg !14 %add.ptr = getelementptr inbounds i32, i32* %P, i64 2, !dbg !15 call void @llvm.dbg.value(metadata i32* %add.ptr, metadata !11, metadata !DIExpression()), !dbg !15 %0 = bitcast i32* %add.ptr to i8*, !dbg !16 call void @llvm.dbg.value(metadata i8* %0, metadata !12, metadata !DIExpression()), !dbg !16 tail call void @llvm.memset.p0i8.i64(i8* %0, i8 0, i64 11, i1 false), !dbg !17 ret void, !dbg !18
The ll file after apply -memcpyopt pass:
%arrayidx = getelementptr inbounds i32, i32* %P, i64 1, !dbg !13 call void @llvm.dbg.value(metadata i32* %arrayidx, metadata !9, metadata !DIExpression()), !dbg !13 %add.ptr = getelementptr inbounds i32, i32* %P, i64 2, !dbg !14 call void @llvm.dbg.value(metadata i32* %add.ptr, metadata !11, metadata !DIExpression()), !dbg !14 %0 = bitcast i32* %add.ptr to i8*, !dbg !15 call void @llvm.dbg.value(metadata i8* %0, metadata !12, metadata !DIExpression()), !dbg !15 %1 = bitcast i32* %arrayidx to i8*, !dbg !16 call void @llvm.memset.p0i8.i64(i8* align 4 %1, i8 0, i64 15, i1 false), !dbg !17 ret void, !dbg !16
There are two stores: "stores i32 0, i32* %arrayidx, align 4, !dbg !14" and "tail call void @llvm.memset.p0i8.i64(i8* %0, i8 0, i64 11, i1 false), !dbg !17".
They are merged into one memset instruction " call void @llvm.memset.p0i8.i64(i8* align 4 %1, i8 0, i64 15, i1 false), !dbg !17".
The new memset instruction only takes the debug location from one of the merged instructions. However, it should take the merged debug location from the two instructions.
Please use llvm::SmallVector instead.
Please use camel naming convention here.