Skip to content

Commit a572e79

Browse files
committed
[InstCombine] Handle !DIArgList
1 parent 20070fb commit a572e79

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,12 +1402,20 @@ void InstCombinerImpl::freelyInvertAllUsersOf(Value *I, Value *IgnoredUser) {
14021402
SmallVector<DbgVariableRecord *, 4> DbgVariableRecords;
14031403
llvm::findDbgValues(DbgValues, I, &DbgVariableRecords);
14041404

1405-
SmallVector<uint64_t, 1> Ops = {dwarf::DW_OP_not};
1406-
for (auto *DVI : DbgValues)
1407-
DVI->setExpression(DIExpression::prependOpcodes(DVI->getExpression(), Ops));
1405+
auto InvertDbgValueUse = [&](auto *DbgVal) {
1406+
SmallVector<uint64_t, 1> Ops = {dwarf::DW_OP_not};
1407+
for (unsigned Idx = 0, End = DbgVal->getNumVariableLocationOps();
1408+
Idx != End; ++Idx)
1409+
if (DbgVal->getVariableLocationOp(Idx) == I)
1410+
DbgVal->setExpression(
1411+
DIExpression::appendOpsToArg(DbgVal->getExpression(), Ops, Idx));
1412+
};
1413+
1414+
for (DbgValueInst *DVI : DbgValues)
1415+
InvertDbgValueUse(DVI);
14081416

14091417
for (DbgVariableRecord *DVR : DbgVariableRecords)
1410-
DVR->setExpression(DIExpression::prependOpcodes(DVR->getExpression(), Ops));
1418+
InvertDbgValueUse(DVR);
14111419
}
14121420

14131421
/// Given a 'sub' instruction, return the RHS of the instruction if the LHS is a

llvm/test/Transforms/InstCombine/debuginfo-invert.ll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ define i32 @test(i32 noundef %x, i32 noundef %y) !dbg !10 {
99
; CHECK-NEXT: [[ENTRY:.*:]]
1010
; CHECK-NEXT: [[CMP_NOT:%.*]] = icmp eq i32 [[X]], 0
1111
; 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]+]])
12+
; 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]])
1213
; CHECK-NEXT: [[TMP0:%.*]] = and i32 [[Y]], 1
1314
; CHECK-NEXT: [[AND:%.*]] = select i1 [[CMP_NOT]], i32 0, i32 [[TMP0]]
1415
; CHECK-NEXT: ret i32 [[AND]]
@@ -17,6 +18,7 @@ entry:
1718
%cmp = icmp ne i32 %x, 0
1819
%conv = zext i1 %cmp to i32
1920
#dbg_value(i32 %conv, !15, !DIExpression(), !16)
21+
#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)
2022
%and = and i32 %conv, %y
2123
ret i32 %and
2224
}
@@ -42,14 +44,17 @@ entry:
4244
!14 = !{!15}
4345
!15 = !DILocalVariable(name: "z", scope: !10, file: !1, line: 2, type: !13)
4446
!16 = !DILocation(line: 0, scope: !10)
47+
!17 = !DILocalVariable(name: "w", scope: !10, file: !1, line: 3, type: !13)
48+
!18 = !DILocation(line: 0, scope: !10)
4549
;.
4650
; 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)
47-
; CHECK: [[META1]] = !DIFile(filename: "test.c", directory: {{.*}})
51+
; CHECK: [[META1]] = !DIFile(filename: "{{.*}}test.c", directory: {{.*}})
4852
; 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]+]])
4953
; CHECK: [[META11]] = !DISubroutineType(types: [[META12:![0-9]+]])
5054
; CHECK: [[META12]] = !{[[META13:![0-9]+]], [[META13]], [[META13]]}
5155
; CHECK: [[META13]] = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
5256
; CHECK: [[META14]] = !{[[META15]]}
5357
; CHECK: [[META15]] = !DILocalVariable(name: "z", scope: [[DBG10]], file: [[META1]], line: 2, type: [[META13]])
5458
; CHECK: [[META16]] = !DILocation(line: 0, scope: [[DBG10]])
59+
; CHECK: [[META17]] = !DILocalVariable(name: "w", scope: [[DBG10]], file: [[META1]], line: 3, type: [[META13]])
5560
;.

0 commit comments

Comments
 (0)