Skip to content

Commit 0918da8

Browse files
committed
[InstCombine][DebugInfo] Update debug info after inverting a boolean instruction
1 parent 0d238f1 commit 0918da8

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

llvm/lib/Transforms/InstCombine/InstructionCombining.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1187,6 +1187,13 @@ void InstCombinerImpl::freelyInvertAllUsersOf(Value *I, Value *IgnoredUser) {
11871187
"canFreelyInvertAllUsersOf() ?");
11881188
}
11891189
}
1190+
1191+
// Adapt all dbg users
1192+
if (auto *Inst = dyn_cast<Instruction>(I); Inst && Inst->isUsedByMetadata()) {
1193+
auto *Not = Builder.CreateNot(I);
1194+
auto *NotInst = dyn_cast<Instruction>(I);
1195+
replaceAllDbgUsesWith(*Inst, *Not, NotInst ? *NotInst : *Inst, DT);
1196+
}
11901197
}
11911198

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

llvm/test/DebugInfo/salvage-invert-bool.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ define i32 @test_invert_bool(i32 %call, i32 %a) {
66
; CHECK-SAME: i32 [[CALL:%.*]], i32 [[A:%.*]]) {
77
; CHECK-NEXT: entry:
88
; CHECK-NEXT: [[TOBOOL_NOT:%.*]] = icmp eq i32 [[CALL]], 0
9-
; CHECK-NEXT: call void @llvm.dbg.value(metadata i1 [[TOBOOL_NOT]], metadata [[META3:![0-9]+]], metadata !DIExpression(DW_OP_LLVM_convert, 1, DW_ATE_unsigned, DW_OP_LLVM_convert, 32, DW_ATE_unsigned, DW_OP_stack_value)), !dbg [[DBG8:![0-9]+]]
9+
; CHECK-NEXT: call void @llvm.dbg.value(metadata i1 [[TOBOOL_NOT]], metadata [[META3:![0-9]+]], metadata !DIExpression(DW_OP_constu, 18446744073709551615, DW_OP_xor, DW_OP_LLVM_convert, 1, DW_ATE_unsigned, DW_OP_LLVM_convert, 32, DW_ATE_unsigned, DW_OP_stack_value)), !dbg [[DBG8:![0-9]+]]
1010
; CHECK-NEXT: [[TMP0:%.*]] = and i32 [[A]], 1
1111
; CHECK-NEXT: [[AND:%.*]] = select i1 [[TOBOOL_NOT]], i32 0, i32 [[TMP0]]
1212
; CHECK-NEXT: ret i32 [[AND]]

0 commit comments

Comments
 (0)