Skip to content

[InstCombine][DebugInfo] Update debug value uses in freelyInvertAllUsersOf #137013

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[InstCombine] Update debug value uses in freelyInvertAllUsersOf
  • Loading branch information
dtcxzyw committed Apr 23, 2025
commit 0eb30b72b40df762e6e6ac1453efb135e22851c4
18 changes: 18 additions & 0 deletions llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/Transforms/InstCombine/debuginfo-invert.ll
Original file line number Diff line number Diff line change
Expand Up @@ -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]+]]
Expand Down
Loading