This is an archive of the discontinued LLVM Phabricator instance.

[flang][hlfir] Use the HLFIR base of hlfir.declare if possible.
ClosedPublic

Authored by vzakhari on Aug 16 2023, 2:19 PM.

Details

Summary

This patch makes use of the HLFIR box produced for hlfir.declare
in place of the FIR box (the memref of hlfir.declare) when possible.

This makes the representation a little bit more clear, because
all accesses are made via a single box.
This reduces the life range of the original box, because the new
temporary box produced by embox/rebox is used from now.
Apparently, this works around some issues in the current HLFIR codegen,
for example, look at the LIT tests changes around fir.array_coor
produced by hlfir.designate codegen - using the FIR box for fir.array_coor
might result in using incorrect lbounds.
Apparently, this change enables more intrinsics simplifications
because the SimplifyIntrinsicsPass looks for explicit embox/rebox
in findBoxDef() to decide whether to apply the optimization.
This change also provides better association of the base addresses
referenced by OpenACC clauses with the corresponding boxes
that might be used explicitly in OpenACC regions (e.g. for reading
the lbounds).

Diff Detail

Event Timeline

vzakhari created this revision.Aug 16 2023, 2:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 16 2023, 2:19 PM
vzakhari requested review of this revision.Aug 16 2023, 2:19 PM

FYI, my local testing was clean except for one nag test failure. It is related to the intrinsics simplification pass that can now do better due to the explicit embox/rebox. Apparently, there is an issue with MAXVAL for f128 values - LLVM ends up using the fmaxl, which is a long double version. I am going to address this issue separately.

clementval accepted this revision.Aug 16 2023, 2:30 PM

Thanks Slava. LGTM

This revision is now accepted and ready to land.Aug 16 2023, 2:30 PM
razvanlupusoru accepted this revision.Aug 16 2023, 2:34 PM

Doing this way makes a lot of sense. Looks great to me.