[llvm] [InstCombine][DebugInfo] Update debug value uses in `freelyInvertAllUsersOf` (PR #137013)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Mon May 12 04:09:56 PDT 2025
https://github.com/dtcxzyw updated https://github.com/llvm/llvm-project/pull/137013
>From 414b0c7ceb988998b2a83bfcb2c7ab64a1ea92e5 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Thu, 24 Apr 2025 00:08:29 +0800
Subject: [PATCH 1/6] [InstCombine] Add pre-commit tests. NFC.
---
.../InstCombine/debuginfo-invert.ll | 70 +++++++++++++++++++
1 file changed, 70 insertions(+)
create mode 100644 llvm/test/Transforms/InstCombine/debuginfo-invert.ll
diff --git a/llvm/test/Transforms/InstCombine/debuginfo-invert.ll b/llvm/test/Transforms/InstCombine/debuginfo-invert.ll
new file mode 100644
index 0000000000000..2c82c788197a7
--- /dev/null
+++ b/llvm/test/Transforms/InstCombine/debuginfo-invert.ll
@@ -0,0 +1,70 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
+; RUN: opt -passes=instcombine -S %s -o - | FileCheck %s
+
+target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-unknown-linux-gnu"
+
+define i32 @test(i32 noundef %x, i32 noundef %y) !dbg !10 {
+; CHECK-LABEL: define i32 @test(
+; CHECK-SAME: i32 noundef [[X:%.*]], i32 noundef [[Y:%.*]]) !dbg [[DBG10:![0-9]+]] {
+; CHECK-NEXT: [[ENTRY:.*:]]
+; CHECK-NEXT: #dbg_value(i32 [[X]], [[META15:![0-9]+]], !DIExpression(), [[META18:![0-9]+]])
+; CHECK-NEXT: #dbg_value(i32 [[Y]], [[META16:![0-9]+]], !DIExpression(), [[META18]])
+; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq i32 [[X]], 0, !dbg [[DBG19:![0-9]+]]
+; CHECK-NEXT: #dbg_value(i1 [[CMP_NOT]], [[META17:![0-9]+]], !DIExpression(DW_OP_LLVM_convert, 1, DW_ATE_unsigned, DW_OP_LLVM_convert, 32, DW_ATE_unsigned, DW_OP_stack_value), [[META18]])
+; CHECK-NEXT: [[TMP0:%.*]] = and i32 [[Y]], 1, !dbg [[DBG20:![0-9]+]]
+; CHECK-NEXT: [[AND:%.*]] = select i1 [[CMP_NOT]], i32 0, i32 [[TMP0]], !dbg [[DBG20]]
+; CHECK-NEXT: ret i32 [[AND]], !dbg [[DBG21:![0-9]+]]
+;
+entry:
+ #dbg_value(i32 %x, !15, !DIExpression(), !18)
+ #dbg_value(i32 %y, !16, !DIExpression(), !18)
+ %cmp = icmp ne i32 %x, 0, !dbg !19
+ %conv = zext i1 %cmp to i32, !dbg !19
+ #dbg_value(i32 %conv, !17, !DIExpression(), !18)
+ %and = and i32 %conv, %y, !dbg !20
+ ret i32 %and, !dbg !21
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3, !4, !5, !6, !7, !8}
+!llvm.ident = !{!9}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, producer: "clang version 21.0.0git", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "test.c", directory: "/", checksumkind: CSK_MD5, checksum: "b2d9ffc7905684d8b7c3b52a3136e57c")
+!2 = !{i32 7, !"Dwarf Version", i32 5}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !{i32 1, !"wchar_size", i32 4}
+!5 = !{i32 8, !"PIC Level", i32 2}
+!6 = !{i32 7, !"PIE Level", i32 2}
+!7 = !{i32 7, !"uwtable", i32 2}
+!8 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
+!9 = !{!"clang version 21.0.0git"}
+!10 = distinct !DISubprogram(name: "test", scope: !1, file: !1, line: 1, type: !11, scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !14)
+!11 = !DISubroutineType(types: !12)
+!12 = !{!13, !13, !13}
+!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!14 = !{!15, !16, !17}
+!15 = !DILocalVariable(name: "x", arg: 1, scope: !10, file: !1, line: 1, type: !13)
+!16 = !DILocalVariable(name: "y", arg: 2, scope: !10, file: !1, line: 1, type: !13)
+!17 = !DILocalVariable(name: "z", scope: !10, file: !1, line: 2, type: !13)
+!18 = !DILocation(line: 0, scope: !10)
+!19 = !DILocation(line: 2, column: 13, scope: !10)
+!20 = !DILocation(line: 3, column: 12, scope: !10)
+!21 = !DILocation(line: 3, column: 3, scope: !10)
+;.
+; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+; CHECK: [[META1]] = !DIFile(filename: "test.c", directory: {{.*}})
+; CHECK: [[DBG10]] = distinct !DISubprogram(name: "test", scope: [[META1]], file: [[META1]], line: 1, type: [[META11:![0-9]+]], scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META14:![0-9]+]])
+; CHECK: [[META11]] = !DISubroutineType(types: [[META12:![0-9]+]])
+; CHECK: [[META12]] = !{[[META13:![0-9]+]], [[META13]], [[META13]]}
+; CHECK: [[META13]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+; CHECK: [[META14]] = !{[[META15]], [[META16]], [[META17]]}
+; CHECK: [[META15]] = !DILocalVariable(name: "x", arg: 1, scope: [[DBG10]], file: [[META1]], line: 1, type: [[META13]])
+; CHECK: [[META16]] = !DILocalVariable(name: "y", arg: 2, scope: [[DBG10]], file: [[META1]], line: 1, type: [[META13]])
+; CHECK: [[META17]] = !DILocalVariable(name: "z", scope: [[DBG10]], file: [[META1]], line: 2, type: [[META13]])
+; CHECK: [[META18]] = !DILocation(line: 0, scope: [[DBG10]])
+; CHECK: [[DBG19]] = !DILocation(line: 2, column: 13, scope: [[DBG10]])
+; CHECK: [[DBG20]] = !DILocation(line: 3, column: 12, scope: [[DBG10]])
+; CHECK: [[DBG21]] = !DILocation(line: 3, column: 3, scope: [[DBG10]])
+;.
>From 417f7b2fcb9b971afb4389a4b28d25378eb72c84 Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Thu, 24 Apr 2025 00:15:32 +0800
Subject: [PATCH 2/6] [InstCombine] Update debug value uses in
`freelyInvertAllUsersOf`
---
.../InstCombine/InstructionCombining.cpp | 18 ++++++++++++++++++
.../Transforms/InstCombine/debuginfo-invert.ll | 2 +-
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 206d41e30db2c..6a7e878b2fd80 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1396,6 +1396,24 @@ void InstCombinerImpl::freelyInvertAllUsersOf(Value *I, Value *IgnoredUser) {
"canFreelyInvertAllUsersOf() ?");
}
}
+
+ // Update pre-existing debug value uses.
+ SmallVector<DbgValueInst *, 4> DbgValues;
+ SmallVector<DbgVariableRecord *, 4> DbgVariableRecords;
+ llvm::findDbgValues(DbgValues, I, &DbgVariableRecords);
+ auto ApplyNot = [](DIExpression *Src) {
+ SmallVector<uint64_t> Elements;
+ Elements.reserve(Src->getElements().size() + 1);
+ Elements.push_back(dwarf::DW_OP_not);
+ Elements.append(Src->getElements().begin(), Src->getElements().end());
+ return DIExpression::get(Src->getContext(), Elements);
+ };
+
+ for (auto *DVI : DbgValues)
+ DVI->setExpression(ApplyNot(DVI->getExpression()));
+
+ for (DbgVariableRecord *DVR : DbgVariableRecords)
+ DVR->setExpression(ApplyNot(DVR->getExpression()));
}
/// Given a 'sub' instruction, return the RHS of the instruction if the LHS is a
diff --git a/llvm/test/Transforms/InstCombine/debuginfo-invert.ll b/llvm/test/Transforms/InstCombine/debuginfo-invert.ll
index 2c82c788197a7..8c673e319f7f7 100644
--- a/llvm/test/Transforms/InstCombine/debuginfo-invert.ll
+++ b/llvm/test/Transforms/InstCombine/debuginfo-invert.ll
@@ -11,7 +11,7 @@ define i32 @test(i32 noundef %x, i32 noundef %y) !dbg !10 {
; CHECK-NEXT: #dbg_value(i32 [[X]], [[META15:![0-9]+]], !DIExpression(), [[META18:![0-9]+]])
; CHECK-NEXT: #dbg_value(i32 [[Y]], [[META16:![0-9]+]], !DIExpression(), [[META18]])
; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq i32 [[X]], 0, !dbg [[DBG19:![0-9]+]]
-; CHECK-NEXT: #dbg_value(i1 [[CMP_NOT]], [[META17:![0-9]+]], !DIExpression(DW_OP_LLVM_convert, 1, DW_ATE_unsigned, DW_OP_LLVM_convert, 32, DW_ATE_unsigned, DW_OP_stack_value), [[META18]])
+; CHECK-NEXT: #dbg_value(i1 [[CMP_NOT]], [[META17:![0-9]+]], !DIExpression(DW_OP_not, DW_OP_LLVM_convert, 1, DW_ATE_unsigned, DW_OP_LLVM_convert, 32, DW_ATE_unsigned, DW_OP_stack_value), [[META18]])
; CHECK-NEXT: [[TMP0:%.*]] = and i32 [[Y]], 1, !dbg [[DBG20:![0-9]+]]
; CHECK-NEXT: [[AND:%.*]] = select i1 [[CMP_NOT]], i32 0, i32 [[TMP0]], !dbg [[DBG20]]
; CHECK-NEXT: ret i32 [[AND]], !dbg [[DBG21:![0-9]+]]
>From cc856063830230fee3eaeeb7c3fab9c5fa9ff4fd Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Fri, 25 Apr 2025 15:28:48 +0800
Subject: [PATCH 3/6] [InstCombine] Simplify code. NFC.
---
.../Transforms/InstCombine/InstructionCombining.cpp | 12 +++---------
1 file changed, 3 insertions(+), 9 deletions(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index 6a7e878b2fd80..d44ef0c9e2fbc 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1401,19 +1401,13 @@ void InstCombinerImpl::freelyInvertAllUsersOf(Value *I, Value *IgnoredUser) {
SmallVector<DbgValueInst *, 4> DbgValues;
SmallVector<DbgVariableRecord *, 4> DbgVariableRecords;
llvm::findDbgValues(DbgValues, I, &DbgVariableRecords);
- auto ApplyNot = [](DIExpression *Src) {
- SmallVector<uint64_t> Elements;
- Elements.reserve(Src->getElements().size() + 1);
- Elements.push_back(dwarf::DW_OP_not);
- Elements.append(Src->getElements().begin(), Src->getElements().end());
- return DIExpression::get(Src->getContext(), Elements);
- };
+ SmallVector<uint64_t, 1> Ops = {dwarf::DW_OP_not};
for (auto *DVI : DbgValues)
- DVI->setExpression(ApplyNot(DVI->getExpression()));
+ DVI->setExpression(DIExpression::prependOpcodes(DVI->getExpression(), Ops));
for (DbgVariableRecord *DVR : DbgVariableRecords)
- DVR->setExpression(ApplyNot(DVR->getExpression()));
+ DVR->setExpression(DIExpression::prependOpcodes(DVR->getExpression(), Ops));
}
/// Given a 'sub' instruction, return the RHS of the instruction if the LHS is a
>From b90431110474c9260188ce3870ab1afab4043dde Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Fri, 25 Apr 2025 19:09:02 +0800
Subject: [PATCH 4/6] [InstCombine] Simplify tests. NFC.
---
.../InstCombine/debuginfo-invert.ll | 49 +++++++------------
1 file changed, 17 insertions(+), 32 deletions(-)
diff --git a/llvm/test/Transforms/InstCombine/debuginfo-invert.ll b/llvm/test/Transforms/InstCombine/debuginfo-invert.ll
index 8c673e319f7f7..1848068ae1c08 100644
--- a/llvm/test/Transforms/InstCombine/debuginfo-invert.ll
+++ b/llvm/test/Transforms/InstCombine/debuginfo-invert.ll
@@ -1,29 +1,24 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 5
; RUN: opt -passes=instcombine -S %s -o - | FileCheck %s
-target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
-target triple = "x86_64-unknown-linux-gnu"
+; Make sure that the DIExpression is updated correctly after InstCombinerImpl::freelyInvertAllUsersOf.
define i32 @test(i32 noundef %x, i32 noundef %y) !dbg !10 {
; CHECK-LABEL: define i32 @test(
; CHECK-SAME: i32 noundef [[X:%.*]], i32 noundef [[Y:%.*]]) !dbg [[DBG10:![0-9]+]] {
; CHECK-NEXT: [[ENTRY:.*:]]
-; CHECK-NEXT: #dbg_value(i32 [[X]], [[META15:![0-9]+]], !DIExpression(), [[META18:![0-9]+]])
-; CHECK-NEXT: #dbg_value(i32 [[Y]], [[META16:![0-9]+]], !DIExpression(), [[META18]])
-; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq i32 [[X]], 0, !dbg [[DBG19:![0-9]+]]
-; CHECK-NEXT: #dbg_value(i1 [[CMP_NOT]], [[META17:![0-9]+]], !DIExpression(DW_OP_not, DW_OP_LLVM_convert, 1, DW_ATE_unsigned, DW_OP_LLVM_convert, 32, DW_ATE_unsigned, DW_OP_stack_value), [[META18]])
-; CHECK-NEXT: [[TMP0:%.*]] = and i32 [[Y]], 1, !dbg [[DBG20:![0-9]+]]
-; CHECK-NEXT: [[AND:%.*]] = select i1 [[CMP_NOT]], i32 0, i32 [[TMP0]], !dbg [[DBG20]]
-; CHECK-NEXT: ret i32 [[AND]], !dbg [[DBG21:![0-9]+]]
+; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq i32 [[X]], 0
+; CHECK-NEXT: #dbg_value(i1 [[CMP_NOT]], [[META15:![0-9]+]], !DIExpression(DW_OP_not, DW_OP_LLVM_convert, 1, DW_ATE_unsigned, DW_OP_LLVM_convert, 32, DW_ATE_unsigned, DW_OP_stack_value), [[META16:![0-9]+]])
+; CHECK-NEXT: [[TMP0:%.*]] = and i32 [[Y]], 1
+; CHECK-NEXT: [[AND:%.*]] = select i1 [[CMP_NOT]], i32 0, i32 [[TMP0]]
+; CHECK-NEXT: ret i32 [[AND]]
;
entry:
- #dbg_value(i32 %x, !15, !DIExpression(), !18)
- #dbg_value(i32 %y, !16, !DIExpression(), !18)
- %cmp = icmp ne i32 %x, 0, !dbg !19
- %conv = zext i1 %cmp to i32, !dbg !19
- #dbg_value(i32 %conv, !17, !DIExpression(), !18)
- %and = and i32 %conv, %y, !dbg !20
- ret i32 %and, !dbg !21
+ %cmp = icmp ne i32 %x, 0
+ %conv = zext i1 %cmp to i32
+ #dbg_value(i32 %conv, !15, !DIExpression(), !16)
+ %and = and i32 %conv, %y
+ ret i32 %and
}
!llvm.dbg.cu = !{!0}
@@ -44,14 +39,9 @@ entry:
!11 = !DISubroutineType(types: !12)
!12 = !{!13, !13, !13}
!13 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
-!14 = !{!15, !16, !17}
-!15 = !DILocalVariable(name: "x", arg: 1, scope: !10, file: !1, line: 1, type: !13)
-!16 = !DILocalVariable(name: "y", arg: 2, scope: !10, file: !1, line: 1, type: !13)
-!17 = !DILocalVariable(name: "z", scope: !10, file: !1, line: 2, type: !13)
-!18 = !DILocation(line: 0, scope: !10)
-!19 = !DILocation(line: 2, column: 13, scope: !10)
-!20 = !DILocation(line: 3, column: 12, scope: !10)
-!21 = !DILocation(line: 3, column: 3, scope: !10)
+!14 = !{!15}
+!15 = !DILocalVariable(name: "z", scope: !10, file: !1, line: 2, type: !13)
+!16 = !DILocation(line: 0, scope: !10)
;.
; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
; CHECK: [[META1]] = !DIFile(filename: "test.c", directory: {{.*}})
@@ -59,12 +49,7 @@ entry:
; CHECK: [[META11]] = !DISubroutineType(types: [[META12:![0-9]+]])
; CHECK: [[META12]] = !{[[META13:![0-9]+]], [[META13]], [[META13]]}
; CHECK: [[META13]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
-; CHECK: [[META14]] = !{[[META15]], [[META16]], [[META17]]}
-; CHECK: [[META15]] = !DILocalVariable(name: "x", arg: 1, scope: [[DBG10]], file: [[META1]], line: 1, type: [[META13]])
-; CHECK: [[META16]] = !DILocalVariable(name: "y", arg: 2, scope: [[DBG10]], file: [[META1]], line: 1, type: [[META13]])
-; CHECK: [[META17]] = !DILocalVariable(name: "z", scope: [[DBG10]], file: [[META1]], line: 2, type: [[META13]])
-; CHECK: [[META18]] = !DILocation(line: 0, scope: [[DBG10]])
-; CHECK: [[DBG19]] = !DILocation(line: 2, column: 13, scope: [[DBG10]])
-; CHECK: [[DBG20]] = !DILocation(line: 3, column: 12, scope: [[DBG10]])
-; CHECK: [[DBG21]] = !DILocation(line: 3, column: 3, scope: [[DBG10]])
+; CHECK: [[META14]] = !{[[META15]]}
+; CHECK: [[META15]] = !DILocalVariable(name: "z", scope: [[DBG10]], file: [[META1]], line: 2, type: [[META13]])
+; CHECK: [[META16]] = !DILocation(line: 0, scope: [[DBG10]])
;.
>From 20070fbe56c3869b39a54ca7c07e51f46be6e81b Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Fri, 25 Apr 2025 19:45:52 +0800
Subject: [PATCH 5/6] [InstCombine] Address review comments. NFC.
---
llvm/test/Transforms/InstCombine/debuginfo-invert.ll | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/test/Transforms/InstCombine/debuginfo-invert.ll b/llvm/test/Transforms/InstCombine/debuginfo-invert.ll
index 1848068ae1c08..bc36b7dfb631a 100644
--- a/llvm/test/Transforms/InstCombine/debuginfo-invert.ll
+++ b/llvm/test/Transforms/InstCombine/debuginfo-invert.ll
@@ -16,7 +16,7 @@ define i32 @test(i32 noundef %x, i32 noundef %y) !dbg !10 {
entry:
%cmp = icmp ne i32 %x, 0
%conv = zext i1 %cmp to i32
- #dbg_value(i32 %conv, !15, !DIExpression(), !16)
+ #dbg_value(i32 %conv, !15, !DIExpression(), !16)
%and = and i32 %conv, %y
ret i32 %and
}
>From a572e79215437d440dcf00cdd2e3aecaaad56dfc Mon Sep 17 00:00:00 2001
From: Yingwei Zheng <dtcxzyw2333 at gmail.com>
Date: Mon, 12 May 2025 18:59:53 +0800
Subject: [PATCH 6/6] [InstCombine] Handle `!DIArgList`
---
.../InstCombine/InstructionCombining.cpp | 16 ++++++++++++----
.../Transforms/InstCombine/debuginfo-invert.ll | 7 ++++++-
2 files changed, 18 insertions(+), 5 deletions(-)
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index d44ef0c9e2fbc..8dd144ed2933e 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -1402,12 +1402,20 @@ void InstCombinerImpl::freelyInvertAllUsersOf(Value *I, Value *IgnoredUser) {
SmallVector<DbgVariableRecord *, 4> DbgVariableRecords;
llvm::findDbgValues(DbgValues, I, &DbgVariableRecords);
- SmallVector<uint64_t, 1> Ops = {dwarf::DW_OP_not};
- for (auto *DVI : DbgValues)
- DVI->setExpression(DIExpression::prependOpcodes(DVI->getExpression(), Ops));
+ auto InvertDbgValueUse = [&](auto *DbgVal) {
+ SmallVector<uint64_t, 1> Ops = {dwarf::DW_OP_not};
+ for (unsigned Idx = 0, End = DbgVal->getNumVariableLocationOps();
+ Idx != End; ++Idx)
+ if (DbgVal->getVariableLocationOp(Idx) == I)
+ DbgVal->setExpression(
+ DIExpression::appendOpsToArg(DbgVal->getExpression(), Ops, Idx));
+ };
+
+ for (DbgValueInst *DVI : DbgValues)
+ InvertDbgValueUse(DVI);
for (DbgVariableRecord *DVR : DbgVariableRecords)
- DVR->setExpression(DIExpression::prependOpcodes(DVR->getExpression(), Ops));
+ InvertDbgValueUse(DVR);
}
/// Given a 'sub' instruction, return the RHS of the instruction if the LHS is a
diff --git a/llvm/test/Transforms/InstCombine/debuginfo-invert.ll b/llvm/test/Transforms/InstCombine/debuginfo-invert.ll
index bc36b7dfb631a..990078258d956 100644
--- a/llvm/test/Transforms/InstCombine/debuginfo-invert.ll
+++ b/llvm/test/Transforms/InstCombine/debuginfo-invert.ll
@@ -9,6 +9,7 @@ define i32 @test(i32 noundef %x, i32 noundef %y) !dbg !10 {
; CHECK-NEXT: [[ENTRY:.*:]]
; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq i32 [[X]], 0
; CHECK-NEXT: #dbg_value(i1 [[CMP_NOT]], [[META15:![0-9]+]], !DIExpression(DW_OP_not, DW_OP_LLVM_convert, 1, DW_ATE_unsigned, DW_OP_LLVM_convert, 32, DW_ATE_unsigned, DW_OP_stack_value), [[META16:![0-9]+]])
+; CHECK-NEXT: #dbg_value(!DIArgList(i1 false, i1 [[CMP_NOT]]), [[META17:![0-9]+]], !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_not, DW_OP_or, DW_OP_LLVM_convert, 1, DW_ATE_unsigned, DW_OP_LLVM_convert, 8, DW_ATE_unsigned, DW_OP_stack_value), [[META16]])
; CHECK-NEXT: [[TMP0:%.*]] = and i32 [[Y]], 1
; CHECK-NEXT: [[AND:%.*]] = select i1 [[CMP_NOT]], i32 0, i32 [[TMP0]]
; CHECK-NEXT: ret i32 [[AND]]
@@ -17,6 +18,7 @@ entry:
%cmp = icmp ne i32 %x, 0
%conv = zext i1 %cmp to i32
#dbg_value(i32 %conv, !15, !DIExpression(), !16)
+ #dbg_value(!DIArgList(i1 false, i1 %cmp), !17, !DIExpression(DW_OP_LLVM_arg, 0, DW_OP_LLVM_arg, 1, DW_OP_or, DW_OP_LLVM_convert, 1, DW_ATE_unsigned, DW_OP_LLVM_convert, 8, DW_ATE_unsigned, DW_OP_stack_value), !18)
%and = and i32 %conv, %y
ret i32 %and
}
@@ -42,9 +44,11 @@ entry:
!14 = !{!15}
!15 = !DILocalVariable(name: "z", scope: !10, file: !1, line: 2, type: !13)
!16 = !DILocation(line: 0, scope: !10)
+!17 = !DILocalVariable(name: "w", scope: !10, file: !1, line: 3, type: !13)
+!18 = !DILocation(line: 0, scope: !10)
;.
; CHECK: [[META0:![0-9]+]] = distinct !DICompileUnit(language: DW_LANG_C11, file: [[META1:![0-9]+]], producer: "{{.*}}clang version {{.*}}", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
-; CHECK: [[META1]] = !DIFile(filename: "test.c", directory: {{.*}})
+; CHECK: [[META1]] = !DIFile(filename: "{{.*}}test.c", directory: {{.*}})
; CHECK: [[DBG10]] = distinct !DISubprogram(name: "test", scope: [[META1]], file: [[META1]], line: 1, type: [[META11:![0-9]+]], scopeLine: 1, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: [[META0]], retainedNodes: [[META14:![0-9]+]])
; CHECK: [[META11]] = !DISubroutineType(types: [[META12:![0-9]+]])
; CHECK: [[META12]] = !{[[META13:![0-9]+]], [[META13]], [[META13]]}
@@ -52,4 +56,5 @@ entry:
; CHECK: [[META14]] = !{[[META15]]}
; CHECK: [[META15]] = !DILocalVariable(name: "z", scope: [[DBG10]], file: [[META1]], line: 2, type: [[META13]])
; CHECK: [[META16]] = !DILocation(line: 0, scope: [[DBG10]])
+; CHECK: [[META17]] = !DILocalVariable(name: "w", scope: [[DBG10]], file: [[META1]], line: 3, type: [[META13]])
;.
More information about the llvm-commits
mailing list