[flang][hlfir] Do not reuse hlfir.expr mask when saving RHS.
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. Differential Revision: https://reviews.llvm.org/D153880
Loading
Please sign in to comment