Skip to content

Commit d7fb9eb

Browse files
authored
[DebugInfo][RemoveDIs] Handle DPValues in SelectOptimize (#79005)
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).
1 parent 7378fb3 commit d7fb9eb

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

llvm/lib/CodeGen/SelectOptimize.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,23 @@ void SelectOptimizeImpl::convertProfitableSIGroups(SelectGroups &ProfSIGroups) {
491491
DI->moveBeforePreserving(&*EndBlock->getFirstInsertionPt());
492492
}
493493

494+
// Duplicate implementation for DPValues, the non-instruction debug-info
495+
// record. Helper lambda for moving DPValues to the end block.
496+
auto TransferDPValues = [&](Instruction &I) {
497+
for (auto &DPValue : llvm::make_early_inc_range(I.getDbgValueRange())) {
498+
DPValue.removeFromParent();
499+
EndBlock->insertDPValueBefore(&DPValue,
500+
EndBlock->getFirstInsertionPt());
501+
}
502+
};
503+
504+
// Iterate over all instructions in between SI and LastSI, not including
505+
// SI itself. These are all the variable assignments that happen "in the
506+
// middle" of the select group.
507+
auto R = make_range(std::next(SI->getIterator()),
508+
std::next(LastSI->getIterator()));
509+
llvm::for_each(R, TransferDPValues);
510+
494511
// These are the new basic blocks for the conditional branch.
495512
// At least one will become an actual new basic block.
496513
BasicBlock *TrueBlock = nullptr, *FalseBlock = nullptr;

llvm/test/CodeGen/X86/select-optimize.ll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
; RUN: opt -mtriple=x86_64-unknown-unknown -select-optimize -S < %s | FileCheck %s
33
; RUN: opt -mtriple=x86_64-unknown-unknown -passes='require<profile-summary>,function(select-optimize)' -S < %s | FileCheck %s
44

5+
; RUN: opt -mtriple=x86_64-unknown-unknown -select-optimize -S < %s --try-experimental-debuginfo-iterators | FileCheck %s
6+
; RUN: opt -mtriple=x86_64-unknown-unknown -passes='require<profile-summary>,function(select-optimize)' -S < %s --try-experimental-debuginfo-iterators | FileCheck %s
7+
58
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
69
;; Test base heuristic 1:
710
;; highly-biased selects assumed to be highly predictable, converted to branches

0 commit comments

Comments
 (0)