[llvm] [DebugInfo][RemoveDIs] Use splice in Outliner rather than moveBefore (PR #79124)

Jeremy Morse via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 23 03:57:16 PST 2024


https://github.com/jmorse created https://github.com/llvm/llvm-project/pull/79124

This patch replaces a utility in the outliner that moves the contents of one basic block into another basic block, with a call to splice instead. I think it's NFC, however I'd like a second pair of eyes to look at it just in case.

The reason for doing this is an edge case in the handling of DPValue objects, the replacement for dbg.values. If there's a variable assignment "dangling" at the end of a block (which happens when we delete the terminator), inserting instructions at end() doesn't shift the DPValue up into the block. We could probably fix this; but it's much easier to use splice at the only call site that does this.

Patch adds --try-experimental-debuginfo-iterators to a test to exercise this code path.

>From 0cd8f2fd59702f32d34aeabdc87af0b681701ae1 Mon Sep 17 00:00:00 2001
From: Jeremy Morse <jeremy.morse at sony.com>
Date: Mon, 22 Jan 2024 15:49:53 +0000
Subject: [PATCH] [DebugInfo][RemoveDIs] Use splice in Outliner rather than
 moveBefore

This patch replaces a utility in the outliner that moves the contents of
one basic block into another basic block, with a call to splice instead. I
think it's NFC, however I'd like a second pair of eyes to look at it just
in case.

The reason for doing this is an edge case in the handling of DPValue
objects, the replacement for dbg.values. If there's a variable assignment
"dangling" at the end of a block (which happens when we delete the
terminator), inserting instructions at end() doesn't shift the DPValue up
into the block. We could probably fix this; but it's much easier to use
splice at the only call site that does this.

Patch adds --try-experimental-debuginfo-iterators to a test to exercise
this code path.
---
 llvm/lib/Transforms/IPO/IROutliner.cpp         | 3 +--
 llvm/test/Transforms/IROutliner/legal-debug.ll | 1 +
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/llvm/lib/Transforms/IPO/IROutliner.cpp b/llvm/lib/Transforms/IPO/IROutliner.cpp
index a6e19df7c5f1ff..8e6d0e814372d6 100644
--- a/llvm/lib/Transforms/IPO/IROutliner.cpp
+++ b/llvm/lib/Transforms/IPO/IROutliner.cpp
@@ -154,8 +154,7 @@ struct OutlinableGroup {
 /// \param SourceBB - the BasicBlock to pull Instructions from.
 /// \param TargetBB - the BasicBlock to put Instruction into.
 static void moveBBContents(BasicBlock &SourceBB, BasicBlock &TargetBB) {
-  for (Instruction &I : llvm::make_early_inc_range(SourceBB))
-    I.moveBeforePreserving(TargetBB, TargetBB.end());
+  TargetBB.splice(TargetBB.end(), &SourceBB);
 }
 
 /// A function to sort the keys of \p Map, which must be a mapping of constant
diff --git a/llvm/test/Transforms/IROutliner/legal-debug.ll b/llvm/test/Transforms/IROutliner/legal-debug.ll
index b7b472fa20b3e6..be1182b38fa2d8 100644
--- a/llvm/test/Transforms/IROutliner/legal-debug.ll
+++ b/llvm/test/Transforms/IROutliner/legal-debug.ll
@@ -1,5 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --include-generated-funcs
 ; RUN: opt -S -passes=verify,iroutliner -ir-outlining-no-cost < %s | FileCheck %s
+; RUN: opt -S -passes=verify,iroutliner -ir-outlining-no-cost < %s --try-experimental-debuginfo-iterators | FileCheck %s
 
 ; This test checks that debug info is recognized as able to be extracted along
 ; with the other instructions, but is not included in the consolidated function.



More information about the llvm-commits mailing list