[llvm] 1670d39 - [DirectX] Handle undef the same way as null (#197507)
via llvm-commits
llvm-commits at lists.llvm.org
Wed May 27 16:51:10 PDT 2026
Author: Harald van Dijk
Date: 2026-05-28T01:51:06+02:00
New Revision: 1670d39972a1c6dd4a9e6f54d509a86a72dae1da
URL: https://github.com/llvm/llvm-project/commit/1670d39972a1c6dd4a9e6f54d509a86a72dae1da
DIFF: https://github.com/llvm/llvm-project/commit/1670d39972a1c6dd4a9e6f54d509a86a72dae1da.diff
LOG: [DirectX] Handle undef the same way as null (#197507)
Added:
llvm/test/tools/dxil-dis/dbg-declare-undef.ll
Modified:
llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
llvm/lib/Target/DirectX/DirectXIRPasses/PointerTypeAnalysis.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp b/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
index 7c158d45dd131..f3ac19227a5fd 100644
--- a/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
+++ b/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
@@ -529,21 +529,19 @@ unsigned DXILBitcodeWriter::getEncodedBinaryOpcode(unsigned Opcode) {
}
unsigned DXILBitcodeWriter::getTypeID(Type *T, const Value *V) {
- if (!T->isPointerTy() &&
- // For Constant, always check PointerMap to make sure OpaquePointer in
- // things like constant struct/array works.
- (!V || !isa<Constant>(V)))
+ // For Constant, always check PointerMap to make sure OpaquePointer in
+ // things like constant struct/array works.
+ if (!T->isPointerTy() && !isa_and_nonnull<Constant>(V))
return VE.getTypeID(T);
auto It = PointerMap.find(V);
if (It != PointerMap.end())
return VE.getTypeID(It->second);
- // For Constant, return T when cannot find in PointerMap.
- // FIXME: support ConstantPointerNull which could map to more than one
- // TypedPointerType.
+ // FIXME: support ConstantPointerNull and UndefValue which could map to more
+ // than one TypedPointerType.
// See https://github.com/llvm/llvm-project/issues/57942.
- if (V && isa<Constant>(V) && !isa<ConstantPointerNull>(V))
- return VE.getTypeID(T);
- return VE.getTypeID(I8PtrTy);
+ if (T->isPointerTy())
+ return VE.getTypeID(I8PtrTy);
+ return VE.getTypeID(T);
}
unsigned DXILBitcodeWriter::getGlobalObjectValueTypeID(Type *T,
diff --git a/llvm/lib/Target/DirectX/DirectXIRPasses/PointerTypeAnalysis.cpp b/llvm/lib/Target/DirectX/DirectXIRPasses/PointerTypeAnalysis.cpp
index dd2037277e460..c58af1560a6b7 100644
--- a/llvm/lib/Target/DirectX/DirectXIRPasses/PointerTypeAnalysis.cpp
+++ b/llvm/lib/Target/DirectX/DirectXIRPasses/PointerTypeAnalysis.cpp
@@ -139,10 +139,11 @@ Type *classifyFunctionType(const Function &F, PointerTypeMap &Map) {
static Type *classifyConstantWithOpaquePtr(const Constant *C,
PointerTypeMap &Map) {
- // FIXME: support ConstantPointerNull which could map to more than one
- // TypedPointerType.
- // See https://github.com/llvm/llvm-project/issues/57942.
- if (isa<ConstantPointerNull>(C))
+ // FIXME: support ConstantPointerNull and UndefValue which could map to more
+ // than one TypedPointerType. See
+ // https://github.com/llvm/llvm-project/issues/57942.
+ if (isa<ConstantPointerNull>(C) ||
+ (isa<UndefValue>(C) && C->getType()->isPointerTy()))
return TypedPointerType::get(Type::getInt8Ty(C->getContext()),
C->getType()->getPointerAddressSpace());
diff --git a/llvm/test/tools/dxil-dis/dbg-declare-undef.ll b/llvm/test/tools/dxil-dis/dbg-declare-undef.ll
new file mode 100644
index 0000000000000..fa599ea02d912
--- /dev/null
+++ b/llvm/test/tools/dxil-dis/dbg-declare-undef.ll
@@ -0,0 +1,33 @@
+; RUN: llc --filetype=obj %s -o - | dxil-dis -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 i8* undef,
+; 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)
More information about the llvm-commits
mailing list