[llvm] 2fc3aec - [DirectX] Add more CodeGen tests (#201714)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 8 05:25:43 PDT 2026
Author: Harald van Dijk
Date: 2026-06-08T13:25:37+01:00
New Revision: 2fc3aec9fbab95a537f3fef381ec44928d76cfc8
URL: https://github.com/llvm/llvm-project/commit/2fc3aec9fbab95a537f3fef381ec44928d76cfc8
DIFF: https://github.com/llvm/llvm-project/commit/2fc3aec9fbab95a537f3fef381ec44928d76cfc8.diff
LOG: [DirectX] Add more CodeGen tests (#201714)
These tests were left out of the initial PRs that added the covered
functionality because the llc printed output was not yet in the right
form. It is now, so add the tests.
Added:
llvm/test/CodeGen/DirectX/DebugInfo/dbg-declare-undef.ll
llvm/test/CodeGen/DirectX/DebugInfo/dbg-value.ll
llvm/test/CodeGen/DirectX/DebugInfo/debug-info.ll
llvm/test/CodeGen/DirectX/DebugInfo/di-compile-unit.ll
llvm/test/CodeGen/DirectX/DebugInfo/di-label.ll
llvm/test/CodeGen/DirectX/DebugInfo/di-subrangetype.ll
Modified:
Removed:
################################################################################
diff --git a/llvm/test/CodeGen/DirectX/DebugInfo/dbg-declare-undef.ll b/llvm/test/CodeGen/DirectX/DebugInfo/dbg-declare-undef.ll
new file mode 100644
index 0000000000000..11fb5adbd030e
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/DebugInfo/dbg-declare-undef.ll
@@ -0,0 +1,33 @@
+; RUN: llc %s -o - | FileCheck %s
+
+target triple = "dxil-pc-shadermodel6.3-library"
+
+; CHECK-LABEL: define void @foo() {
+; CHECK-NEXT: entry:
+; CHECK-NEXT: tail call void @llvm.dbg.declare(metadata ptr poison,
+; CHECK: ret void
+; CHECK-NEXT: }
+
+define void @foo() {
+entry:
+ %0 = alloca i32, align 4
+ #dbg_declare(ptr %0, !4, !DIExpression(), !10)
+ %1 = load i32, ptr %0
+ store i32 %1, ptr %0
+ ret void
+}
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!2, !3}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "undef.c", directory: "")
+!2 = !{i32 7, !"Dwarf Version", i32 5}
+!3 = !{i32 2, !"Debug Info Version", i32 3}
+!4 = !DILocalVariable(name: "i", scope: !5, file: !1, line: 2, type: !9)
+!5 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 1, type: !6, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !8)
+!6 = !DISubroutineType(types: !7)
+!7 = !{null}
+!8 = !{}
+!9 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!10 = !DILocation(line: 2, column: 7, scope: !5)
diff --git a/llvm/test/CodeGen/DirectX/DebugInfo/dbg-value.ll b/llvm/test/CodeGen/DirectX/DebugInfo/dbg-value.ll
new file mode 100644
index 0000000000000..12f8f5912742c
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/DebugInfo/dbg-value.ll
@@ -0,0 +1,49 @@
+; RUN: llc %s -o - | FileCheck %s
+
+target triple = "dxil-pc-shadermodel6.3-library"
+
+; CHECK: define i32 @main(i32 %argc, ptr %argv)
+; CHECK-NEXT: entry:
+; CHECK-NEXT: ; DXIL: to be replaced with: {{.*}} @llvm.dbg.value(metadata i32 %argc, i64 0, metadata ![[LV_ARGC:[0-9]+]], metadata !DIExpression()), !dbg ![[LOC_ARGC:[0-9]+]]
+; CHECK-NEXT: call void @llvm.dbg.value(metadata i32 %argc, metadata ![[LV_ARGC:[0-9]+]], metadata !DIExpression()), !dbg ![[LOC_ARGC:[0-9]+]]
+; CHECK-NEXT: ; DXIL: to be replaced with: {{.*}} @llvm.dbg.value(metadata ptr %argv, i64 0, metadata ![[LV_ARGV:[0-9]+]], metadata !DIExpression()), !dbg ![[LOC_ARGV:[0-9]+]]
+; CHECK-NEXT: call void @llvm.dbg.value(metadata ptr %argv, metadata ![[LV_ARGV:[0-9]+]], metadata !DIExpression()), !dbg ![[LOC_ARGV:[0-9]+]]
+; CHECK-NEXT: ret i32 0
+; CHECK-NEXT: }
+
+define i32 @main(i32 %argc, ptr %argv) !dbg !25 {
+entry:
+ call void @llvm.dbg.value(metadata i32 %argc, metadata !31, metadata !33), !dbg !34
+ call void @llvm.dbg.value(metadata ptr %argv, metadata !32, metadata !33), !dbg !35
+ ret i32 0
+}
+
+declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+; CHECK-DAG: ![[LV_ARGC]] = !DILocalVariable(name: "argc", arg: 1, scope: !{{.*}}, file: !{{.*}}, line: 4, type: !{{.*}})
+; CHECK-DAG: ![[LV_ARGV]] = !DILocalVariable(name: "argv", arg: 2, scope: !{{.*}}, file: !{{.*}}, line: 4, type: !{{.*}})
+; CHECK-DAG: ![[LOC_ARGC]] = !DILocation(line: 4, column: 14, scope: !{{.*}})
+; CHECK-DAG: ![[LOC_ARGV]] = !DILocation(line: 4, column: 27, scope: !{{.*}})
+
+!llvm.dbg.cu = !{!2}
+!llvm.module.flags = !{!15, !16}
+
+!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !4, globals: !5)
+!3 = !DIFile(filename: "test.c", directory: "/")
+!4 = !{}
+!5 = !{}
+!10 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+!12 = !DIBasicType(name: "char", size: 8, encoding: DW_ATE_signed_char)
+!15 = !{i32 2, !"Dwarf Version", i32 4}
+!16 = !{i32 2, !"Debug Info Version", i32 3}
+!25 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 4, type: !26, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: true, unit: !2, retainedNodes: !30)
+!26 = !DISubroutineType(types: !27)
+!27 = !{!10, !10, !28}
+!28 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !29, size: 64)
+!29 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64)
+!30 = !{!31, !32}
+!31 = !DILocalVariable(name: "argc", arg: 1, scope: !25, file: !3, line: 4, type: !10)
+!32 = !DILocalVariable(name: "argv", arg: 2, scope: !25, file: !3, line: 4, type: !28)
+!33 = !DIExpression()
+!34 = !DILocation(line: 4, column: 14, scope: !25)
+!35 = !DILocation(line: 4, column: 27, scope: !25)
diff --git a/llvm/test/CodeGen/DirectX/DebugInfo/debug-info.ll b/llvm/test/CodeGen/DirectX/DebugInfo/debug-info.ll
new file mode 100644
index 0000000000000..0241d23788239
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/DebugInfo/debug-info.ll
@@ -0,0 +1,64 @@
+; RUN: llc %s -o - | FileCheck %s
+
+target triple = "dxil-unknown-shadermodel6.7-library"
+target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
+
+; CHECK: define dso_local float @fma(float %0, float %1, float %2) local_unnamed_addr #0
+define dso_local float @fma(float %0, float %1, float %2) local_unnamed_addr #0 !dbg !6 {
+; CHECK-NEXT: ; DXIL: to be replaced with: {{.*}} @llvm.dbg.value(metadata float %0, i64 0, metadata [[VarX:[!][0-9]+]], metadata !DIExpression()), !dbg [[Line1:[!][0-9]+]]
+; CHECK-NEXT: call void @llvm.dbg.value(metadata float %0, metadata [[VarX]], metadata !DIExpression()), !dbg [[Line1]]
+; CHECK-NEXT: ; DXIL: to be replaced with: {{.*}} @llvm.dbg.value(metadata float %1, i64 0, metadata [[VarY:[!][0-9]+]], metadata !DIExpression()), !dbg [[Line1]]
+; CHECK-NEXT: call void @llvm.dbg.value(metadata float %1, metadata [[VarY]], metadata !DIExpression()), !dbg [[Line1]]
+; CHECK-NEXT: ; DXIL: to be replaced with: {{.*}} @llvm.dbg.value(metadata float %2, i64 0, metadata [[VarZ:[!][0-9]+]], metadata !DIExpression()), !dbg [[Line1]]
+; CHECK-NEXT: call void @llvm.dbg.value(metadata float %2, metadata [[VarZ]], metadata !DIExpression()), !dbg [[Line1]]
+ call void @llvm.dbg.value(metadata float %0, metadata !11, metadata !DIExpression()), !dbg !14
+ call void @llvm.dbg.value(metadata float %1, metadata !12, metadata !DIExpression()), !dbg !14
+ call void @llvm.dbg.value(metadata float %2, metadata !13, metadata !DIExpression()), !dbg !14
+; CHECK-NEXT: %4 = fmul float %0, %1, !dbg [[Line2:[!][0-9]+]]
+; CHECK-NEXT: %5 = fadd float %4, %2, !dbg [[Line3:[!][0-9]+]]
+ %4 = fmul float %0, %1, !dbg !15
+ %5 = fadd float %4, %2, !dbg !16
+ ret float %5, !dbg !17
+}
+
+attributes #0 = { norecurse nounwind readnone willreturn "hlsl.export" }
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4}
+!llvm.ident = !{!5}
+
+; Other tests verify that we come back with reasonable structure for the debug
+; info types, this test just needs to ensure they are there.
+; The patch this is paired with fixes a bug where function debug info wasn't
+; being emitted correctly even though other tests verified the MD would be
+; emitted if it was referenced as module metadata.
+
+; CHECK: !0 = distinct !DICompileUnit
+; CHECK-NEXT: !1 = !DIFile(filename:
+; CHECK: [[VarX]] = !DILocalVariable(
+; CHECK: [[VarY]] = !DILocalVariable(
+; CHECK: [[VarZ]] = !DILocalVariable(
+; CHECK: [[Line1]] = !DILocation(line:
+; CHECK: [[Line2]] = !DILocation(line:
+; CHECK: [[Line3]] = !DILocation(line:
+; CHECK: {{[!][0-9]+}} = !DILocation(line:
+; CHECK: [[Fn:[!][0-9]+]] = !DISubprogram(name: "fma",
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "in.c", directory: "dir")
+!2 = !{}
+!3 = !{i32 7, !"Dwarf Version", i32 2}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+!5 = !{!"Some Compiler"}
+!6 = distinct !DISubprogram(name: "fma", scope: !1, file: !1, line: 1, type: !7, scopeLine: 1, flags: DIFlagPrototyped, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !10)
+!7 = !DISubroutineType(types: !8)
+!8 = !{!9, !9, !9, !9}
+!9 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float)
+!10 = !{!11, !12, !13}
+!11 = !DILocalVariable(name: "x", arg: 1, scope: !6, file: !1, line: 1, type: !9)
+!12 = !DILocalVariable(name: "y", arg: 2, scope: !6, file: !1, line: 1, type: !9)
+!13 = !DILocalVariable(name: "z", arg: 3, scope: !6, file: !1, line: 1, type: !9)
+!14 = !DILocation(line: 0, scope: !6)
+!15 = !DILocation(line: 2, column: 12, scope: !6)
+!16 = !DILocation(line: 2, column: 16, scope: !6)
+!17 = !DILocation(line: 2, column: 3, scope: !6)
diff --git a/llvm/test/CodeGen/DirectX/DebugInfo/di-compile-unit.ll b/llvm/test/CodeGen/DirectX/DebugInfo/di-compile-unit.ll
new file mode 100644
index 0000000000000..820144bc1ef12
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/DebugInfo/di-compile-unit.ll
@@ -0,0 +1,17 @@
+; RUN: llc %s -o - | FileCheck %s
+target triple = "dxil-unknown-shadermodel6.7-library"
+
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!3, !4}
+
+!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "Some Compiler", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
+!1 = !DIFile(filename: "di-compile-unit.src", directory: "/some-path")
+!2 = !{}
+!3 = !{i32 7, !"Dwarf Version", i32 2}
+!4 = !{i32 2, !"Debug Info Version", i32 3}
+
+; CHECK: !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "Some Compiler", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, splitDebugInlining: false, nameTableKind: None)
+; CHECK: !1 = !DIFile(filename: "di-compile-unit.src", directory: "/some-path")
+; CHECK: !2 = !{}
+; CHECK: !{i32 2, !"Dwarf Version", i32 2}
+; CHECK: !{i32 2, !"Debug Info Version", i32 3}
diff --git a/llvm/test/CodeGen/DirectX/DebugInfo/di-label.ll b/llvm/test/CodeGen/DirectX/DebugInfo/di-label.ll
new file mode 100644
index 0000000000000..a5dfc3126e8f4
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/DebugInfo/di-label.ll
@@ -0,0 +1,37 @@
+; RUN: llc %s -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: ; DXIL: to be replaced with: {{.*}} @llvm.dbg.value
+; 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)
diff --git a/llvm/test/CodeGen/DirectX/DebugInfo/di-subrangetype.ll b/llvm/test/CodeGen/DirectX/DebugInfo/di-subrangetype.ll
new file mode 100644
index 0000000000000..c1bc812b05a29
--- /dev/null
+++ b/llvm/test/CodeGen/DirectX/DebugInfo/di-subrangetype.ll
@@ -0,0 +1,37 @@
+; RUN: llc %s -o - | FileCheck %s
+
+target triple = "dxil-pc-shadermodel6.3-library"
+
+define void @sr() !dbg !7 {
+ unreachable
+}
+
+; CHECK-DAG: !llvm.dbg.cu = !{[[CU:![0-9]+]]}
+!llvm.dbg.cu = !{!0}
+!llvm.module.flags = !{!5, !6}
+
+; CHECK-DAG: [[CU]] = distinct !DICompileUnit(language: DW_LANG_Ada95, file: [[F:![0-9]+]], producer: "GNAT/LLVM", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: [[TS:![0-9]+]])
+; CHECK-DAG: DXIL: [[CU]]: additional data: [[SPS:![0-9]+]]
+; CHECK-DAG: [[F]] = !DIFile(filename: "subrange_type.adb", directory: "/dir")
+; CHECK-DAG: [[TS]] = !{[[RT:![0-9]+]]}
+; CHECK-DAG: [[RT]] = !DISubrangeType(name: "sr__int_range", file: [[F]], line: 2, size: 32, align: 32, baseType: [[BT:![0-9]+]], lowerBound: i64 -7, upperBound: i64 23)
+; CHECK-DAG: [[BT]] = !DIBasicType(name: "sr__Tint_rangeB", size: 32, encoding: DW_ATE_signed)
+; CHECK-DAG: DXIL: [[RT]]: to be replaced by: [[BT]]
+; CHECK-DAG: [[SPS]] = !{[[SP:![0-9]+]]}
+; CHECK-DAG: [[SP]] = distinct !DISubprogram(name: "sr", scope: [[F]], file: [[F]], line: 1, type: [[ST:![0-9]+]], scopeLine: 1, spFlags: DISPFlagDefinition, unit: [[CU]], retainedNodes: [[VS:![0-9]+]])
+; CHECK-DAG: [[ST]] = !DISubroutineType
+; CHECK-DAG: [[VS]] = !{[[V:![0-9]+]]}
+; CHECK-DAG: [[V]] = !DILocalVariable(name: "x", scope: [[SP]], file: [[F]], line: 3, type: [[RT]], align: 32)
+
+!0 = distinct !DICompileUnit(language: DW_LANG_Ada95, file: !1, producer: "GNAT/LLVM", isOptimized: false, runtimeVersion: 0, emissionKind: FullDebug, retainedTypes: !2)
+!1 = !DIFile(filename: "subrange_type.adb", directory: "/dir")
+!2 = !{!3}
+!3 = !DISubrangeType(name: "sr__int_range", file: !1, line: 2, size: 32, align: 32, baseType: !4, lowerBound: i64 -7, upperBound: i64 23)
+!4 = !DIBasicType(name: "sr__Tint_rangeB", size: 32, encoding: DW_ATE_signed)
+!5 = !{i32 2, !"Debug Info Version", i32 3}
+!6 = !{i32 2, !"Dwarf Version", i32 4}
+!7 = distinct !DISubprogram(name: "sr", scope: !1, file: !1, line: 1, type: !8, scopeLine: 1, spFlags: DISPFlagDefinition, unit: !0, retainedNodes: !10)
+!8 = !DISubroutineType(types: !9)
+!9 = !{null}
+!10 = !{!11}
+!11 = !DILocalVariable(name: "x", scope: !7, file: !1, line: 3, type: !3, align: 32)
More information about the llvm-commits
mailing list