[llvm] 4ba08d5 - [Assignment Tracking][24/*] Always RemoveRedundantDbgInstrs in instcombine in assignment tracking builds
via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 18 04:38:56 PST 2022
Author: OCHyams
Date: 2022-11-18T12:36:41Z
New Revision: 4ba08d512c8774de431824f37faf9e54d73a3119
URL: https://github.com/llvm/llvm-project/commit/4ba08d512c8774de431824f37faf9e54d73a3119
DIFF: https://github.com/llvm/llvm-project/commit/4ba08d512c8774de431824f37faf9e54d73a3119.diff
LOG: [Assignment Tracking][24/*] Always RemoveRedundantDbgInstrs in instcombine in assignment tracking builds
The Assignment Tracking debug-info feature is outlined in this RFC:
https://discourse.llvm.org/t/
rfc-assignment-tracking-a-better-way-of-specifying-variable-locations-in-ir
This reduces peak memory overhead by 15% when building CTMark's tramp3d-v4 with
-O2 -g with assignment tracking enabled.
Reviewed By: jmorse
Differential Revision: https://reviews.llvm.org/D133321
Added:
llvm/test/DebugInfo/Generic/assignment-tracking/instcombine/do-not-remove-redundant-dbg.ll
llvm/test/DebugInfo/Generic/assignment-tracking/instcombine/remove-redundant-dbg.ll
Modified:
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/DebugInfo/Generic/assignment-tracking/salvage-value.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 9719ace5eb8e..81467cf6fbcb 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -99,6 +99,7 @@
#include "llvm/Support/KnownBits.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/InstCombine/InstCombine.h"
+#include "llvm/Transforms/Utils/BasicBlockUtils.h"
#include "llvm/Transforms/Utils/Local.h"
#include <algorithm>
#include <cassert>
@@ -4593,6 +4594,13 @@ static bool combineInstructionsOverFunction(
bool MadeIRChange = false;
if (ShouldLowerDbgDeclare)
MadeIRChange = LowerDbgDeclare(F);
+ // LowerDbgDeclare calls RemoveRedundantDbgInstrs, but LowerDbgDeclare will
+ // almost never return true when running an assignment tracking build. Take
+ // this opportunity to do some clean up for assignment tracking builds too.
+ if (!MadeIRChange && getEnableAssignmentTracking()) {
+ for (auto &BB : F)
+ RemoveRedundantDbgInstrs(&BB);
+ }
// Iterate while there is work to do.
unsigned Iteration = 0;
diff --git a/llvm/test/DebugInfo/Generic/assignment-tracking/instcombine/do-not-remove-redundant-dbg.ll b/llvm/test/DebugInfo/Generic/assignment-tracking/instcombine/do-not-remove-redundant-dbg.ll
new file mode 100644
index 000000000000..f14a6e63b63f
--- /dev/null
+++ b/llvm/test/DebugInfo/Generic/assignment-tracking/instcombine/do-not-remove-redundant-dbg.ll
@@ -0,0 +1,49 @@
+; RUN: opt -passes=instcombine -S %s -o - \
+; RUN: | FileCheck %s --implicit-check-not="call void @llvm.dbg"
+
+;; Based on the test remove-redundant-dbg.ll.
+;;
+;; Check that instcombine does not remove redundant debug intrinsics when
+;; assignment tracking is turned off. This test is here to check the existing
+;; behaviour is maintained. If it is discovered that it is profitable to remove
+;; these intrinsics in instcombine then it's okay to remove this test.
+
+; CHECK: @llvm.dbg.value(metadata i32 undef
+; CHECK: @llvm.dbg.value(metadata i32 0
+; CHECK: @llvm.dbg.value(metadata i32 1
+
+define dso_local void @_Z3funv() local_unnamed_addr !dbg !7 {
+entry:
+ call void @llvm.dbg.value(metadata i32 undef, metadata !11, metadata !DIExpression()), !dbg !14
+ call void @_Z3extv(), !dbg !15
+ call void @llvm.dbg.value(metadata i32 0, metadata !11, metadata !DIExpression()), !dbg !14
+ call void @llvm.dbg.value(metadata i32 1, metadata !11, metadata !DIExpression()), !dbg !14
+ ret void, !dbg !16
+}
+
+declare !dbg !17 dso_local void @_Z3extv() local_unnamed_addr
+declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 14.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "test.cpp", directory: "/")
+!2 = !{i32 7, !"Dwarf Version", i32 5}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !{i32 1, !"wchar_size", i32 4}
+!5 = !{i32 7, !"uwtable", i32 1}
+!6 = !{!"clang version 14.0.0)"}
+!7 = distinct !DISubprogram(name: "fun", linkageName: "_Z3funv", scope: !1, file: !1, line: 2, type: !8, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !10)
+!8 = !DISubroutineType(types: !9)
+!9 = !{null}
+!10 = !{!11}
+!11 = !DILocalVariable(name: "a", scope: !7, file: !1, line: 2, type: !12)
+!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!13 = distinct !DIAssignID()
+!14 = !DILocation(line: 0, scope: !7)
+!15 = !DILocation(line: 2, column: 25, scope: !7)
+!16 = !DILocation(line: 2, column: 32, scope: !7)
+!17 = !DISubprogram(name: "ext", linkageName: "_Z3extv", scope: !1, file: !1, line: 1, type: !8, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !18)
+!18 = !{}
diff --git a/llvm/test/DebugInfo/Generic/assignment-tracking/instcombine/remove-redundant-dbg.ll b/llvm/test/DebugInfo/Generic/assignment-tracking/instcombine/remove-redundant-dbg.ll
new file mode 100644
index 000000000000..b22d1ab95acd
--- /dev/null
+++ b/llvm/test/DebugInfo/Generic/assignment-tracking/instcombine/remove-redundant-dbg.ll
@@ -0,0 +1,45 @@
+; RUN: opt -passes=instcombine -S %s -o - -experimental-assignment-tracking \
+; RUN: | FileCheck %s --implicit-check-not="call void @llvm.dbg"
+
+;; Check that instcombine removes redundant debug intrinsics. This has a
+;; significant positive impact on peak memory. CTMark's tramp3d-v4's peak
+;; memory with assignment tracking enabled is reduced by about 15% with this
+;; change.
+
+; CHECK: @llvm.dbg.assign(metadata i32 1
+
+define dso_local void @_Z3funv() local_unnamed_addr !dbg !7 {
+entry:
+ call void @llvm.dbg.assign(metadata i32 undef, metadata !11, metadata !DIExpression(), metadata !13, metadata ptr undef, metadata !DIExpression()), !dbg !14
+ call void @_Z3extv(), !dbg !15
+ call void @llvm.dbg.assign(metadata i32 0, metadata !11, metadata !DIExpression(), metadata !13, metadata ptr undef, metadata !DIExpression()), !dbg !14
+ call void @llvm.dbg.assign(metadata i32 1, metadata !11, metadata !DIExpression(), metadata !13, metadata ptr undef, metadata !DIExpression()), !dbg !14
+ ret void, !dbg !16
+}
+
+declare !dbg !17 dso_local void @_Z3extv() local_unnamed_addr
+declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata)
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3, !4, !5}
+!llvm.ident = !{!6}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, file: !1, producer: "clang version 14.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "test.cpp", directory: "/")
+!2 = !{i32 7, !"Dwarf Version", i32 5}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !{i32 1, !"wchar_size", i32 4}
+!5 = !{i32 7, !"uwtable", i32 1}
+!6 = !{!"clang version 14.0.0)"}
+!7 = distinct !DISubprogram(name: "fun", linkageName: "_Z3funv", scope: !1, file: !1, line: 2, type: !8, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !10)
+!8 = !DISubroutineType(types: !9)
+!9 = !{null}
+!10 = !{!11}
+!11 = !DILocalVariable(name: "a", scope: !7, file: !1, line: 2, type: !12)
+!12 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!13 = distinct !DIAssignID()
+!14 = !DILocation(line: 0, scope: !7)
+!15 = !DILocation(line: 2, column: 25, scope: !7)
+!16 = !DILocation(line: 2, column: 32, scope: !7)
+!17 = !DISubprogram(name: "ext", linkageName: "_Z3extv", scope: !1, file: !1, line: 1, type: !8, flags: DIFlagPrototyped, spFlags: DISPFlagOptimized, retainedNodes: !18)
+!18 = !{}
diff --git a/llvm/test/DebugInfo/Generic/assignment-tracking/salvage-value.ll b/llvm/test/DebugInfo/Generic/assignment-tracking/salvage-value.ll
index c3bffa4b2bf5..9ef81a8a73ce 100644
--- a/llvm/test/DebugInfo/Generic/assignment-tracking/salvage-value.ll
+++ b/llvm/test/DebugInfo/Generic/assignment-tracking/salvage-value.ll
@@ -13,7 +13,7 @@ entry:
; CHECK: call void @llvm.dbg.assign(metadata i32 %x,{{.+}}metadata !DIExpression(DW_OP_plus_uconst, 1, DW_OP_stack_value),{{.+}}, metadata ptr %p, metadata !DIExpression())
%add1 = add nsw i32 %x, %y, !dbg !29
- call void @llvm.dbg.assign(metadata i32 %add1, metadata !14, metadata !DIExpression(), metadata !31, metadata ptr %p, metadata !DIExpression()), !dbg !16
+ call void @llvm.dbg.assign(metadata i32 %add1, metadata !32, metadata !DIExpression(), metadata !31, metadata ptr %p, metadata !DIExpression()), !dbg !16
;; %add1 is not salvaged as it requires two values and DIArgList is
;; not (yet) supported for dbg.assigns.
; CHECK-NEXT: call void @llvm.dbg.assign(metadata i32 undef,{{.+}}, metadata !DIExpression(),{{.+}}, metadata ptr %p, metadata !DIExpression())
@@ -24,12 +24,12 @@ entry:
; CHECK-NEXT: call void @llvm.dbg.assign(metadata i32 %x,{{.+}}, metadata !DIExpression(),{{.+}}, metadata ptr %p, metadata !DIExpression())
%arrayidx1 = getelementptr inbounds i32, ptr %p, i32 1
- call void @llvm.dbg.assign(metadata i32 %x, metadata !14, metadata !DIExpression(), metadata !18, metadata ptr %arrayidx1, metadata !DIExpression()), !dbg !16
+ call void @llvm.dbg.assign(metadata i32 %x, metadata !33, metadata !DIExpression(), metadata !18, metadata ptr %arrayidx1, metadata !DIExpression()), !dbg !16
;; %arrayidx1 is salvaged.
; CHECK-NEXT: call void @llvm.dbg.assign(metadata i32 %x,{{.+}}, metadata !DIExpression(),{{.+}}, metadata ptr %p, metadata !DIExpression(DW_OP_plus_uconst, 4))
%arrayidx2 = getelementptr inbounds i32, ptr %p, i32 %x
- call void @llvm.dbg.assign(metadata i32 %x, metadata !14, metadata !DIExpression(), metadata !19, metadata ptr %arrayidx2, metadata !DIExpression()), !dbg !16
+ call void @llvm.dbg.assign(metadata i32 %x, metadata !34, metadata !DIExpression(), metadata !19, metadata ptr %arrayidx2, metadata !DIExpression()), !dbg !16
;; Variadic DIExpressions for dbg.assign address component is not supported -
;; set undef.
; CHECK-NEXT: call void @llvm.dbg.assign(metadata i32 %x,{{.+}}, metadata !DIExpression(),{{.+}}, metadata ptr undef, metadata !DIExpression())
@@ -67,3 +67,7 @@ declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata,
!28 = distinct !DIAssignID()
!29 = !DILocation(line: 4, column: 13, scope: !7)
!31 = distinct !DIAssignID()
+!32 = !DILocalVariable(name: "Local1", scope: !7, file: !1, line: 3, type: !10)
+!33 = !DILocalVariable(name: "Local2", scope: !7, file: !1, line: 3, type: !10)
+!34 = !DILocalVariable(name: "Local3", scope: !7, file: !1, line: 3, type: !10)
+!35 = !DILocalVariable(name: "Local4", scope: !7, file: !1, line: 3, type: !10)
More information about the llvm-commits
mailing list