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

Diana Picus via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon Jan 10 03:50:31 PST 2022


rovka created this revision.
rovka added reviewers: jeanPerier, clementval, schweitz, kiranchandramohan, awarzynski.
rovka added a project: Flang.
Herald added subscribers: mehdi_amini, jdoerfert.
rovka requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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 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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116926

Files:
  flang/lib/Optimizer/CodeGen/CodeGen.cpp
  flang/test/Fir/convert-to-llvm.fir

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116926.398563.patch
Type: text/x-patch
Size: 6302 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220110/6c94bc19/attachment.bin>


More information about the flang-commits mailing list