[flang-commits] [PATCH] D153880: [flang][hlfir] Do not reuse hlfir.expr mask when saving RHS.

Jean Perier via Phabricator via flang-commits flang-commits at lists.llvm.org
Tue Jun 27 08:00:24 PDT 2023


jeanPerier created this revision.
jeanPerier added reviewers: vzakhari, tblah.
jeanPerier added a project: Flang.
Herald added subscribers: sunshaoce, mehdi_amini, jdoerfert.
Herald added a project: All.
jeanPerier requested review of this revision.

In WHERE and masked FORALL assignment, both the mask and the
RHS may need to be saved in some temporary storage before evaluating
the assignment.

The code was trying to "optimize" that case when evaluating the RHS
by not fetching the mask temporary that was just created, but in simple
cases of WHERE construct where the evaluated mask is an hlfir.expr,
this caused the hlfir.expr to be both used in an hlfir.associate and
later in an hlfir.apply to create the fir.if to mask the RHS evaluation.
This double usage prevents codegen from inlining the hlfir.expr at the
hlfir.apply, and from "moving" the hlfir.expr storage into the temp
during hlfir.associate bufferization. So this is pessimizing the code:
this would lead to created two mask array temporary storages

This was caught by the unexpectedly high number of "not yet implemented:
hlfir.associate of hlfir.expr with more than one use" that were firing.

Use the mask temporary instead (the hlfir.associate result) when possible.
Some temporary (the "inlined stack") do not support fetching and pushing
in the same run (a single counter is used to keep track of the fetching
and pushing position). Add a canBeFetchedAfterPush() for safety,
but this limitation is anyway not relevant for hlfir.expr since the
inlined stack is only used to save "trivial" scalars.

Also update the temporary storage name to only indicate "forall" if
the top level construct is a FORALL. This is not a very precise name,
but it should at least give a correct context to indicate in the IR
why some temporary array storage was created.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D153880

Files:
  flang/include/flang/Optimizer/Builder/TemporaryStorage.h
  flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp
  flang/test/HLFIR/order_assignments/impure-where.fir
  flang/test/HLFIR/order_assignments/inlined-stack-temp.fir
  flang/test/HLFIR/order_assignments/saving-mask-and-rhs.fir
  flang/test/HLFIR/order_assignments/user-defined-assignment.fir

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153880.534990.patch
Type: text/x-patch
Size: 16197 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/flang-commits/attachments/20230627/0177d887/attachment-0001.bin>


More information about the flang-commits mailing list