Skip to content

Commit 411be14

Browse files
authored
[AgressiveInstCombine] Merge debug info on merged stores (llvm#164449)
A bit of debug info maintenaince for llvm#147540.
1 parent 64a8d73 commit 411be14

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -907,10 +907,20 @@ static bool mergeConsecutivePartStores(ArrayRef<PartStore> Parts,
907907
StoreInst *Store = Builder.CreateAlignedStore(
908908
Val, First.Store->getPointerOperand(), First.Store->getAlign());
909909

910+
// Merge various metadata onto the new store.
910911
AAMDNodes AATags = First.Store->getAAMetadata();
911-
for (const PartStore &Part : drop_begin(Parts))
912+
SmallVector<Instruction *> Stores = {First.Store};
913+
Stores.reserve(Parts.size());
914+
SmallVector<DebugLoc> DbgLocs = {First.Store->getDebugLoc()};
915+
DbgLocs.reserve(Parts.size());
916+
for (const PartStore &Part : drop_begin(Parts)) {
912917
AATags = AATags.concat(Part.Store->getAAMetadata());
918+
Stores.push_back(Part.Store);
919+
DbgLocs.push_back(Part.Store->getDebugLoc());
920+
}
913921
Store->setAAMetadata(AATags);
922+
Store->mergeDIAssignID(Stores);
923+
Store->setDebugLoc(DebugLoc::getMergedLocations(DbgLocs));
914924

915925
// Remove the old stores.
916926
for (const PartStore &Part : Parts)
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
; RUN: opt -S -passes=aggressive-instcombine -mtriple=x86_64-unknown-linux-gnu < %s | FileCheck %s
2+
3+
;; Aggressive instcombine merges the two i8 stores into an i16 store. Check
4+
;; the debug location and DIAssignID metadata get merged.
5+
6+
; CHECK: define void @test_i16(i16 %x, ptr %p) !dbg ![[#]] {
7+
; CHECK-NEXT: store i16 %x, ptr %p, align 1, !dbg ![[DBG:[0-9]+]], !DIAssignID ![[ID:[0-9]+]]
8+
; CHECK-NEXT: #dbg_assign(i16 %x, ![[#]],
9+
; CHECK-SAME: !DIExpression(DW_OP_LLVM_convert, 16, DW_ATE_unsigned, DW_OP_LLVM_convert, 8, DW_ATE_unsigned, DW_OP_stack_value, DW_OP_LLVM_fragment, 0, 8),
10+
; CHECK-SAME: ![[ID]], ptr %p, !DIExpression(), ![[#]])
11+
; CHECK-NEXT: #dbg_assign(i16 %x, ![[#]],
12+
; CHECK-SAME: !DIExpression(DW_OP_constu, 8, DW_OP_shr, DW_OP_LLVM_convert, 16, DW_ATE_unsigned, DW_OP_LLVM_convert, 8, DW_ATE_unsigned, DW_OP_stack_value, DW_OP_LLVM_fragment, 8, 8),
13+
; CHECK-SAME: ![[ID]], ptr %p, !DIExpression(DW_OP_plus_uconst, 1), ![[#]])
14+
; CHECK-NEXT: ret void
15+
16+
; CHECK: ![[DBG]] = !DILocation(line: 0, scope: ![[#]])
17+
18+
define void @test_i16(i16 %x, ptr %p) !dbg !5 {
19+
%x.0 = trunc i16 %x to i8
20+
store i8 %x.0, ptr %p, align 1, !dbg !16, !DIAssignID !17
21+
#dbg_assign(i8 %x.0, !9, !DIExpression(DW_OP_LLVM_fragment, 0, 8), !17, ptr %p, !DIExpression(), !18)
22+
%shr.1 = lshr i16 %x, 8
23+
%x.1 = trunc i16 %shr.1 to i8
24+
%gep.1 = getelementptr i8, ptr %p, i64 1
25+
store i8 %x.1, ptr %gep.1, align 1, !dbg !19, !DIAssignID !20
26+
#dbg_assign(i8 %x.1, !9, !DIExpression(DW_OP_LLVM_fragment, 8, 8), !20, ptr %gep.1, !DIExpression(), !18)
27+
ret void
28+
}
29+
30+
!llvm.dbg.cu = !{!0}
31+
!llvm.debugify = !{!2, !3}
32+
!llvm.module.flags = !{!4}
33+
34+
!0 = distinct !DICompileUnit(language: DW_LANG_C, file: !1, producer: "debugify", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug)
35+
!1 = !DIFile(filename: "/app/example.ll", directory: "/")
36+
!2 = !{i32 7}
37+
!3 = !{i32 4}
38+
!4 = !{i32 2, !"Debug Info Version", i32 3}
39+
!5 = distinct !DISubprogram(name: "test_i16", linkageName: "test_i16", scope: null, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !8)
40+
!6 = !DISubroutineType(types: !7)
41+
!7 = !{}
42+
!8 = !{!9}
43+
!9 = !DILocalVariable(name: "1", scope: !5, file: !1, line: 1, type: !10)
44+
!10 = !DIBasicType(name: "ty16", size: 16, encoding: DW_ATE_unsigned)
45+
!16 = !DILocation(line: 2, column: 1, scope: !5)
46+
!17 = distinct !DIAssignID()
47+
!18 = !DILocation(line: 1, column: 1, scope: !5)
48+
!19 = !DILocation(line: 6, column: 1, scope: !5)
49+
!20 = distinct !DIAssignID()

0 commit comments

Comments
 (0)