[llvm] improve debug messages in delinearization and dependence analysis (PR #156339)

Sebastian Pop via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 2 06:54:12 PDT 2025


================
@@ -787,22 +805,38 @@ void printDelinearization(raw_ostream &O, Function *F, LoopInfo *LI,
                                 SE->getElementSize(&Inst));
     }
 
-      if (IsDelinearizationFailed()) {
-        O << "failed to delinearize\n";
-        continue;
-      }
+    if (IsDelinearizationFailed()) {
+      O << "failed to delinearize\n";
+      continue;
+    }
 
-      O << "Base offset: " << *BasePointer << "\n";
-      O << "ArrayDecl[UnknownSize]";
-      int Size = Subscripts.size();
-      for (int i = 0; i < Size - 1; i++)
+    O << "Base offset: " << *BasePointer << "\n";
+    O << "ArrayDecl";
+
+    // Print [Unknown] when the outermost dimension of the array is not known.
+    // Sizes[NumSizes - 1] is the array element size.
+    int NumSubscripts = Subscripts.size();
+    int NumSizes = Sizes.size();
+    if (NumSizes == NumSubscripts)
+      O << "[UnknownSize]";
+
+    // Handle different size relationships between Subscripts and Sizes.
+    if (NumSizes > 0) {
+      // Print array dimensions (all but the last size, which is element
+      // size).
+      for (int i = 0; i < NumSizes - 1; i++)
         O << "[" << *Sizes[i] << "]";
-      O << " with elements of " << *Sizes[Size - 1] << " bytes.\n";
 
-      O << "ArrayRef";
-      for (int i = 0; i < Size; i++)
-        O << "[" << *Subscripts[i] << "]";
-      O << "\n";
+      // Print element size (last element in Sizes array).
+      O << " with elements of " << *Sizes[NumSizes - 1] << " bytes.\n";
+    } else {
+      O << " unknown sizes.\n";
+    }
+
+    O << "ArrayRef";
+    for (int i = 0; i < NumSubscripts; i++)
+      O << "[" << *Subscripts[i] << "]";
+    O << "\n";
----------------
sebpop wrote:

The reason I split these changes off the other patches is to minimize the amount of output changes in the subsequent patches.
These changes can be reviewed quickly as there's no change in functionality.

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


More information about the llvm-commits mailing list