Skip to content

Commit c6a1d8a

Browse files
committed
Also preserve DebugLoc for replacement stores
1 parent 520d3ec commit c6a1d8a

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

llvm/lib/Transforms/IPO/GlobalOpt.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -965,11 +965,12 @@ OptimizeGlobalAddressOfAllocation(GlobalVariable *GV, CallInst *CI,
965965
if (StoreInst *SI = dyn_cast<StoreInst>(U)) {
966966
// The global is initialized when the store to it occurs. If the stored
967967
// value is null value, the global bool is set to false, otherwise true.
968-
new StoreInst(ConstantInt::getBool(
969-
GV->getContext(),
970-
!isa<ConstantPointerNull>(SI->getValueOperand())),
971-
InitBool, false, Align(1), SI->getOrdering(),
972-
SI->getSyncScopeID(), SI->getIterator());
968+
auto *NewSI = new StoreInst(
969+
ConstantInt::getBool(GV->getContext(), !isa<ConstantPointerNull>(
970+
SI->getValueOperand())),
971+
InitBool, false, Align(1), SI->getOrdering(), SI->getSyncScopeID(),
972+
SI->getIterator());
973+
NewSI->setDebugLoc(SI->getDebugLoc());
973974
SI->eraseFromParent();
974975
continue;
975976
}

llvm/test/Transforms/GlobalOpt/X86/preserve-load-of-bool-dbgloc.ll renamed to llvm/test/Transforms/GlobalOpt/X86/preserve-dbgloc-of-load-store-to-bool.ll

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,25 @@ bb:
3737
ret void
3838
}
3939

40-
define void @bar() {
41-
; CHECK-LABEL: define void @bar() local_unnamed_addr {
40+
define void @bar() !dbg !13 {
41+
; CHECK-LABEL: define void @bar(
42+
; CHECK-SAME: ) local_unnamed_addr !dbg [[DBG8:![0-9]+]] {
4243
; CHECK-NEXT: [[ENTRY:.*:]]
43-
; CHECK-NEXT: store i1 true, ptr @global.1.init, align 1
44+
; CHECK-NEXT: store i1 true, ptr @global.1.init, align 1, !dbg [[DBG9:![0-9]+]]
4445
; CHECK-NEXT: ret void
4546
;
4647
entry:
4748
%call = tail call noalias nonnull dereferenceable(48) ptr @_Znwm(i64 48)
48-
store ptr %call, ptr @global.1, align 8
49+
store ptr %call, ptr @global.1, align 8, !dbg !14
4950
ret void
5051
}
5152

5253
define void @pluto() !dbg !10 {
5354
; CHECK-LABEL: define void @pluto(
54-
; CHECK-SAME: ) local_unnamed_addr !dbg [[DBG8:![0-9]+]] {
55+
; CHECK-SAME: ) local_unnamed_addr !dbg [[DBG10:![0-9]+]] {
5556
; CHECK-NEXT: [[ENTRY:.*:]]
56-
; CHECK-NEXT: [[GLOBAL_1_INIT_VAL:%.*]] = load i1, ptr @global.1.init, align 1, !dbg [[DBG9:![0-9]+]]
57-
; CHECK-NEXT: [[NOTINIT:%.*]] = xor i1 [[GLOBAL_1_INIT_VAL]], true, !dbg [[DBG10:![0-9]+]]
57+
; CHECK-NEXT: [[GLOBAL_1_INIT_VAL:%.*]] = load i1, ptr @global.1.init, align 1, !dbg [[DBG11:![0-9]+]]
58+
; CHECK-NEXT: [[NOTINIT:%.*]] = xor i1 [[GLOBAL_1_INIT_VAL]], true, !dbg [[DBG12:![0-9]+]]
5859
; CHECK-NEXT: unreachable
5960
;
6061
entry:
@@ -80,6 +81,8 @@ declare ptr @_Znwm(i64)
8081
!10 = distinct !DISubprogram(name: "pluto", scope: !6, file: !6, line: 20, type: !8, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
8182
!11 = !DILocation(line: 20, column: 2, scope: !10)
8283
!12 = !DILocation(line: 21, column: 3, scope: !10)
84+
!13 = distinct !DISubprogram(name: "bar", scope: !6, file: !6, line: 230, type: !8, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
85+
!14 = !DILocation(line: 11, column: 4, scope: !13)
8386
;.
8487
; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: [[META2:![0-9]+]], retainedTypes: [[META2]], globals: [[META2]], splitDebugInlining: false, nameTableKind: None)
8588
; CHECK: [[META1]] = !DIFile(filename: "preserve-load-dbgloc.c", directory: {{.*}})
@@ -88,7 +91,9 @@ declare ptr @_Znwm(i64)
8891
; CHECK: [[META5]] = distinct !DISubroutineType(types: [[META2]])
8992
; CHECK: [[DBG6]] = !DILocation(line: 10, column: 1, scope: [[META7:![0-9]+]])
9093
; CHECK: [[META7]] = distinct !DILexicalBlock(scope: [[DBG4]], file: [[META1]], line: 1524, column: 3)
91-
; CHECK: [[DBG8]] = distinct !DISubprogram(name: "pluto", scope: [[META1]], file: [[META1]], line: 20, type: [[META5]], flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META2]])
92-
; CHECK: [[DBG9]] = !DILocation(line: 20, column: 2, scope: [[DBG8]])
93-
; CHECK: [[DBG10]] = !DILocation(line: 21, column: 3, scope: [[DBG8]])
94+
; CHECK: [[DBG8]] = distinct !DISubprogram(name: "bar", scope: [[META1]], file: [[META1]], line: 230, type: [[META5]], flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META2]])
95+
; CHECK: [[DBG9]] = !DILocation(line: 11, column: 4, scope: [[DBG8]])
96+
; CHECK: [[DBG10]] = distinct !DISubprogram(name: "pluto", scope: [[META1]], file: [[META1]], line: 20, type: [[META5]], flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META2]])
97+
; CHECK: [[DBG11]] = !DILocation(line: 20, column: 2, scope: [[DBG10]])
98+
; CHECK: [[DBG12]] = !DILocation(line: 21, column: 3, scope: [[DBG10]])
9499
;.

0 commit comments

Comments
 (0)