[all-commits] [llvm/llvm-project] 776d0e: [flang] Fix overallocation by fir-to-llvm-ir pass

Diana via All-commits all-commits at lists.llvm.org
Wed Jan 12 02:09:14 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 776d0ed632d96383ab4ecefd275d3d23389da37b
      https://github.com/llvm/llvm-project/commit/776d0ed632d96383ab4ecefd275d3d23389da37b
  Author: Diana Picus <diana.picus at linaro.org>
  Date:   2022-01-12 (Wed, 12 Jan 2022)

  Changed paths:
    M flang/lib/Optimizer/CodeGen/CodeGen.cpp
    M flang/test/Fir/convert-to-llvm.fir

  Log Message:
  -----------
  [flang] Fix overallocation by fir-to-llvm-ir pass

When converting a fir.alloca of an array to the LLVM dialect, we used to
multiply the allocated size by all the constant factors encoded in the
array type. This is fine when the array type is converted to the element
type for the purposes of the allocation, but if it's converted to an
array type, then we might be allocating too much space. For example, for
`%2 = fir.alloca !fir.array<8x16x32xf32>, %0, %1` we would allocate
%0 * %1 * 8 * 16 * 32 x llvm.array<32 x array<16 * array<8 x f32>>>. We
really only need to allocate %0 * %1 such arrays.

This patch fixes the issue by taking note of the array type that we're
trying to allocate. It tries to match the behaviour of
LLVMTypeConverter::convertPointerLike, which returns a pointer to the
element type only when the array type doesn't have a constant interior.
We consequently only multiply with the constant factors in the array
type if the array type doesn't have a constant interior.

This has the nice side effect that it gets rid of some redundant
multiplications with the constant 1 in some cases.

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




More information about the All-commits mailing list