[polly] [Polly] Restate array sizes and subscripts when the element type shrinks (PR #221496)

Timur Baidusenov via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 15 20:57:46 PDT 2026


================
@@ -295,6 +311,28 @@ void ScopArrayInfo::updateElementType(Type *NewElementType) {
     auto GCD = std::gcd((uint64_t)NewElementSize, (uint64_t)OldElementSize);
     ElementType = IntegerType::get(ElementType->getContext(), GCD);
   }
+
+  // The sizes recorded so far count elements of the type we just replaced, so
+  // they no longer describe the same memory. Restate them in the new element.
+  // Leaving them alone would shrink every row along with the element type and
+  // model in-bounds accesses as running past its end, which makes the inbounds
+  // assumption infeasible and drops the SCoP.
+  //
+  // The canonical type is an integer of the greatest common divisor of two
+  // sizes, and rounding that up to its allocation size can leave it not
+  // dividing the type it replaces. There is no whole number of new elements
+  // per old one to restate the sizes in, so leave them as they are.
+  uint64_t FinalElementSize = DL.getTypeAllocSizeInBits(ElementType);
+  if (FinalElementSize == 0 || (uint64_t)OldElementSize % FinalElementSize != 0)
+    return;
----------------
bai-tim wrote:

Addressed

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


More information about the llvm-commits mailing list