[llvm] 740e52b - [DirectX] Drop debug labels (#197490)

via llvm-commits llvm-commits at lists.llvm.org
Wed May 27 18:13:12 PDT 2026


Author: Harald van Dijk
Date: 2026-05-28T03:13:07+02:00
New Revision: 740e52bc99696661f357d4feb975f0209082cea9

URL: https://github.com/llvm/llvm-project/commit/740e52bc99696661f357d4feb975f0209082cea9
DIFF: https://github.com/llvm/llvm-project/commit/740e52bc99696661f357d4feb975f0209082cea9.diff

LOG: [DirectX] Drop debug labels (#197490)

Debug labels did not exist in LLVM 3.7 and have no equivalent.

Added: 
    llvm/test/tools/dxil-dis/di-label.ll

Modified: 
    llvm/lib/Target/DirectX/DirectXIRPasses/DXILDebugInfo.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/DirectX/DirectXIRPasses/DXILDebugInfo.cpp b/llvm/lib/Target/DirectX/DirectXIRPasses/DXILDebugInfo.cpp
index 9e7adda98a996..0fa81186000f9 100644
--- a/llvm/lib/Target/DirectX/DirectXIRPasses/DXILDebugInfo.cpp
+++ b/llvm/lib/Target/DirectX/DirectXIRPasses/DXILDebugInfo.cpp
@@ -68,6 +68,31 @@ DXILDebugInfoMap DXILDebugInfoPass::run(Module &M) {
   DebugInfoFinder DIF;
   DIF.processModule(M);
 
+  for (auto &F : M) {
+    for (auto &BB : F) {
+      for (auto &I : make_early_inc_range(reverse(BB))) {
+        if (auto *DL = dyn_cast<DbgLabelInst>(&I)) {
+          DL->eraseFromParent();
+          continue;
+        }
+      }
+    }
+  }
+
+  for (DISubprogram *SP : DIF.subprograms()) {
+    if (MDTuple *RN = cast_or_null<MDTuple>(SP->getRawRetainedNodes())) {
+      SmallVector<Metadata *> MDs(RN->operands());
+      MDs.erase(std::remove_if(MDs.begin(), MDs.end(),
+                               [](Metadata *M) { return isa<DILabel>(M); }),
+                MDs.end());
+      SP->replaceRetainedNodes(MDTuple::get(M.getContext(), MDs));
+    }
+  }
+
+  // Re-scan the module to account for removed metadata.
+  DIF.reset();
+  DIF.processModule(M);
+
   // Replace llvm.dbg.value with equivalent DXIL intrinsics.
   replaceDbgValue(M, Res);
 

diff  --git a/llvm/test/tools/dxil-dis/di-label.ll b/llvm/test/tools/dxil-dis/di-label.ll
new file mode 100644
index 0000000000000..7b66ba8ec4893
--- /dev/null
+++ b/llvm/test/tools/dxil-dis/di-label.ll
@@ -0,0 +1,36 @@
+; RUN: llc --filetype=obj %s -o - | dxil-dis -o - | FileCheck %s
+
+target triple = "dxil-pc-shadermodel6.3-library"
+
+; The label gets removed, so just check that the function is still emitted,
+; and other debug info is still present.
+; CHECK: define void @foo(i32 %i) {
+; CHECK-NEXT: entry:
+; CHECK-NEXT:   tail call void @llvm.dbg.value
+
+define void @foo(i32 %i) !dbg !4 {
+entry:
+    #dbg_value(i32 %i, !9, !DIExpression(), !11)
+  br label %label
+
+label:
+    #dbg_label(!8, !12)
+  ret void
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug)
+!1 = !DIFile(filename: "label.c", directory: "")
+!2 = !{i32 7, !"Dwarf Version", i32 5}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !5, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !7)
+!5 = !DISubroutineType(types: !6)
+!6 = !{null}
+!7 = !{!8}
+!8 = !DILabel(scope: !4, name: "label", file: !1, line: 2, column: 1)
+!9 = !DILocalVariable(name: "i", arg: 1, scope: !4, file: !1, line: 4, type: !10)
+!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!11 = !DILocation(line: 1, column: 1, scope: !4)
+!12 = !DILocation(line: 2, column: 1, scope: !4)


        


More information about the llvm-commits mailing list