This is an archive of the discontinued LLVM Phabricator instance.

[flang] Merge GEPs in substring fir.embox codegen
ClosedPublic

Authored by jeanPerier on Jul 11 2022, 5:07 AM.

Details

Summary

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

Diff Detail

Event Timeline

jeanPerier created this revision.Jul 11 2022, 5:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptJul 11 2022, 5:07 AM
jeanPerier requested review of this revision.Jul 11 2022, 5:07 AM
clementval accepted this revision.Jul 11 2022, 5:43 AM

LGTM. Maybe one typo.

flang/lib/Optimizer/CodeGen/CodeGen.cpp
1403

typo?

This revision is now accepted and ready to land.Jul 11 2022, 5:43 AM
jeanPerier marked an inline comment as done.

Fix comment typo.

This revision was automatically updated to reflect the committed changes.