[llvm] d7f3b23 - [DXILBitcodeWriter] Fix handling of an unspecified lower bound in DISubrange

Justin Bogner via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 21 14:31:06 PDT 2023


Author: Justin Bogner
Date: 2023-08-21T14:30:45-07:00
New Revision: d7f3b238fdc384bf542357d0922a31c80edd1ae5

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

LOG: [DXILBitcodeWriter] Fix handling of an unspecified lower bound in DISubrange

If the lower bound isn't specified it implies that it's zero.

Differential Revision: https://reviews.llvm.org/D158441

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

Modified: 
    llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp b/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
index 86ad8ee77cab96..e2d0aeee092e17 100644
--- a/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
+++ b/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp
@@ -1392,17 +1392,23 @@ static uint64_t rotateSign(APInt Val) {
   return I < 0 ? ~(U << 1) : U << 1;
 }
 
-static uint64_t rotateSign(DISubrange::BoundType Val) {
-  return rotateSign(Val.get<ConstantInt *>()->getValue());
-}
-
 void DXILBitcodeWriter::writeDISubrange(const DISubrange *N,
                                         SmallVectorImpl<uint64_t> &Record,
                                         unsigned Abbrev) {
   Record.push_back(N->isDistinct());
+
+  // TODO: Do we need to handle DIExpression here? What about cases where Count
+  // isn't specified but UpperBound and such are?
+  ConstantInt *Count = N->getCount().dyn_cast<ConstantInt *>();
+  assert(Count && "Count is missing or not ConstantInt");
+  Record.push_back(Count->getValue().getSExtValue());
+
+  // TODO: Similarly, DIExpression is allowed here now
+  DISubrange::BoundType LowerBound = N->getLowerBound();
+  assert((LowerBound.isNull() || LowerBound.is<ConstantInt *>()) &&
+         "Lower bound provided but not ConstantInt");
   Record.push_back(
-      N->getCount().get<ConstantInt *>()->getValue().getSExtValue());
-  Record.push_back(rotateSign(N->getLowerBound()));
+      LowerBound ? rotateSign(LowerBound.get<ConstantInt *>()->getValue()) : 0);
 
   Stream.EmitRecord(bitc::METADATA_SUBRANGE, Record, Abbrev);
   Record.clear();

diff  --git a/llvm/test/tools/dxil-dis/di-subrange.ll b/llvm/test/tools/dxil-dis/di-subrange.ll
new file mode 100644
index 00000000000000..f9527d18dab021
--- /dev/null
+++ b/llvm/test/tools/dxil-dis/di-subrange.ll
@@ -0,0 +1,28 @@
+; RUN: llc --filetype=obj %s -o - | dxil-dis -o - | FileCheck %s
+target triple = "dxil-unknown-shadermodel6.7-library"
+
+!llvm.module.flags = !{!0, !1}
+!llvm.dbg.cu = !{!2}
+
+!0 = !{i32 7, !"Dwarf Version", i32 2}
+!1 = !{i32 2, !"Debug Info Version", i32 3}
+!2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "xyz", isOptimized: true, runtimeVersion: 0, emissionKind: 1, retainedTypes: !4)
+!3 = !DIFile(filename: "input.hlsl", directory: "/some/path")
+!4 = !{!5}
+!5 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 128, flags: DIFlagVector, elements: !7)
+!6 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float)
+!7 = !{!8}
+!8 = !DISubrange(count: 3)
+
+; CHECK: !llvm.module.flags = !{!0, !1}
+; CHECK: !llvm.dbg.cu = !{!2}
+
+; CHECK: !0 = !{i32 7, !"Dwarf Version", i32 2}
+; CHECK: !1 = !{i32 2, !"Debug Info Version", i32 3}
+; CHECK: !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "xyz", isOptimized: true, runtimeVersion: 0, emissionKind: 1, retainedTypes: !4)
+; CHECK: !3 = !DIFile(filename: "input.hlsl", directory: "/some/path")
+; CHECK: !4 = !{!5}
+; CHECK: !5 = !DICompositeType(tag: DW_TAG_array_type, baseType: !6, size: 128, flags: DIFlagVector, elements: !7)
+; CHECK: !6 = !DIBasicType(name: "float", size: 32, encoding: DW_ATE_float)
+; CHECK: !7 = !{!8}
+; CHECK: !8 = !DISubrange(count: 3)


        


More information about the llvm-commits mailing list