Skip to content

Commit

Permalink
[DebugInfo][RemoveDIs] Handle DPValues in SelectOptimize (#79005)
Browse files Browse the repository at this point in the history
When there are debug intrinsics in-between groups of select
instructions, select-optimise sinks them into the "end" block. This
needs to be replicated for DPValues, the non-instruction variable
assignment object. Implement that and add a RUN line to a test that was
sensitive to this to ensure it gets tested.

(The exact range of instructions being transformed here is a little
fiddly, hence I've gone with a helper lambda).
  • Loading branch information
jmorse authored Jan 22, 2024
1 parent 7378fb3 commit d7fb9eb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions llvm/lib/CodeGen/SelectOptimize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,23 @@ void SelectOptimizeImpl::convertProfitableSIGroups(SelectGroups &ProfSIGroups) {
DI->moveBeforePreserving(&*EndBlock->getFirstInsertionPt());
}

// Duplicate implementation for DPValues, the non-instruction debug-info
// record. Helper lambda for moving DPValues to the end block.
auto TransferDPValues = [&](Instruction &I) {
for (auto &DPValue : llvm::make_early_inc_range(I.getDbgValueRange())) {
DPValue.removeFromParent();
EndBlock->insertDPValueBefore(&DPValue,
EndBlock->getFirstInsertionPt());
}
};

// Iterate over all instructions in between SI and LastSI, not including
// SI itself. These are all the variable assignments that happen "in the
// middle" of the select group.
auto R = make_range(std::next(SI->getIterator()),
std::next(LastSI->getIterator()));
llvm::for_each(R, TransferDPValues);

// These are the new basic blocks for the conditional branch.
// At least one will become an actual new basic block.
BasicBlock *TrueBlock = nullptr, *FalseBlock = nullptr;
Expand Down
3 changes: 3 additions & 0 deletions llvm/test/CodeGen/X86/select-optimize.ll
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
; RUN: opt -mtriple=x86_64-unknown-unknown -select-optimize -S < %s | FileCheck %s
; RUN: opt -mtriple=x86_64-unknown-unknown -passes='require<profile-summary>,function(select-optimize)' -S < %s | FileCheck %s

; RUN: opt -mtriple=x86_64-unknown-unknown -select-optimize -S < %s --try-experimental-debuginfo-iterators | FileCheck %s
; RUN: opt -mtriple=x86_64-unknown-unknown -passes='require<profile-summary>,function(select-optimize)' -S < %s --try-experimental-debuginfo-iterators | FileCheck %s

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Test base heuristic 1:
;; highly-biased selects assumed to be highly predictable, converted to branches
Expand Down

0 comments on commit d7fb9eb

Please sign in to comment.