[flang-commits] [PATCH] D116926: [flang] Fix overallocation by fir-to-llvm-ir pass

Eric Schweitz via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon Jan 10 12:18:44 PST 2022


schweitz added inline comments.


================
Comment at: flang/lib/Optimizer/CodeGen/CodeGen.cpp:376
       if (auto seqTy = allocEleTy.dyn_cast<fir::SequenceType>()) {
-        fir::SequenceType::Extent constSize = 1;
-        for (auto extent : seqTy.getShape())
-          if (extent != fir::SequenceType::getUnknownExtent())
-            constSize *= extent;
-        mlir::Value constVal{
-            genConstantIndex(loc, ity, rewriter, constSize).getResult()};
-        size = rewriter.create<mlir::LLVM::MulOp>(loc, ity, size, constVal);
+        if (!seqTy.hasConstantInterior()) {
+          fir::SequenceType::Extent constSize = 1;
----------------
This does not appear to be the correct.

```
   alloca !fir.array<*:i32>, %1, %2
```
has a constant sized interior (the element type i32 has a constant size), but it is clearly not valid to drop the array shape arguments.

This applies to a case like
```
   alloca !fir.array<5x6x?x?xf64>, %3, %4, %5
```
as well. In this second case, space of `%3 * %4 * %5 * 5 * 6 * sizeof(f64)` bytes are required to be allocated even though the type has a constant interior of `5 * 6 * sizeof(f64)`.



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116926/new/

https://reviews.llvm.org/D116926



More information about the flang-commits mailing list