[llvm] [DirectX] Bug fix for Data Scalarization crash (PR #118426)

Farzon Lotfi via llvm-commits llvm-commits at lists.llvm.org
Mon Dec 16 12:31:08 PST 2024


================
@@ -317,10 +330,22 @@ bool DXILFlattenArraysVisitor::visit(Function &F) {
 static void collectElements(Constant *Init,
                             SmallVectorImpl<Constant *> &Elements) {
   // Base case: If Init is not an array, add it directly to the vector.
-  if (!isa<ArrayType>(Init->getType())) {
+  auto *ArrayTy = dyn_cast<ArrayType>(Init->getType());
+  if (!ArrayTy) {
     Elements.push_back(Init);
     return;
   }
+  unsigned ArrSize = ArrayTy->getNumElements();
+  if (isa<ConstantAggregateZero>(Init)) {
+    for (unsigned I = 0; I < ArrSize; ++I)
+      Elements.push_back(Constant::getNullValue(ArrayTy->getElementType()));
+    return;
+  }
+  if (isa<UndefValue>(Init)) {
+    for (unsigned I = 0; I < ArrSize; ++I)
+      Elements.push_back(UndefValue::get(ArrayTy->getElementType()));
----------------
farzonl wrote:

Note to myself, we need to figure out what to do with undef for DXIL now that is deprecated.

https://github.com/llvm/llvm-project/pull/118426


More information about the llvm-commits mailing list