[flang-commits] [PATCH] D129481: [flang] Merge GEPs in substring fir.embox codegen

Jean Perier via Phabricator via flang-commits flang-commits at lists.llvm.org
Mon Jul 11 05:08:00 PDT 2022


jeanPerier created this revision.
jeanPerier added a reviewer: clementval.
jeanPerier added a project: Flang.
Herald added subscribers: mehdi_amini, jdoerfert.
Herald added a project: All.
jeanPerier requested review of this revision.

When computing the base addresses of an array slice to make a
descriptor, codegen generated two LLVM GEPs. The first to compute
the address of the base character element, and a second one to
compute the substring base inside that element.
The previous code did not care about getting the result of the first
GEP right: it used the base array LLVM type as the result type.
This used to work when opaque pointer were not enabled (the actual GEP
result type was probably applied in some later pass). But with opaque
pointers, the second GEP ends-up computing an offset of len*<LLVM array
type> instead of len*<character width>. A previous attempt to fix the
issue was done in D129079 <https://reviews.llvm.org/D129079>, but it does not cover the cases where the
array slice contains subcomponents before the substring
(e.g: array(:)%char_field(5:10)).

This patch fix the issue by computing the actual GEP result type in
codegen. There is also enough knowledge now so that a single GEP can be
generated instead of two.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D129481

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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D129481.443604.patch
Type: text/x-patch
Size: 18768 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20220711/cff15c0e/attachment-0001.bin>


More information about the flang-commits mailing list