This is an archive of the discontinued LLVM Phabricator instance.

[flang][hlfir] Generate temporary storage in Forall/Where [1/2]
ClosedPublic

Authored by jeanPerier on May 23 2023, 1:03 PM.

Details

Summary

Generate temporary storage inline inside WHERE and FORALL when possible.
A following patch will use the runtime to cover the generic cases.

Diff Detail

Event Timeline

jeanPerier created this revision.May 23 2023, 1:03 PM
jeanPerier requested review of this revision.May 23 2023, 1:03 PM

Load logical/numerical scalars value before selecting the temporary storage kind
to avoid picking up the runtime startegy when the inlined startegy works.
Add related regerssion test.

jeanPerier planned changes to this revision.May 24 2023, 6:32 AM

I did not properly plug the fetching of saved value on WHERE/ELSEWHERE, my bad. Update coming soon.

Handle saving of where and elsewhere mask correctly:

  1. Elsewhere mask that are saved should be evaluated using the "pending control mask" (inside the else region of the fir.if for the previous where/elsewhere mask).
  2. When entering Where/Elsewhere, the saved value for the mask must be used if the mask was saved. The previous code bypassed that.

Add related regression tests.

vzakhari accepted this revision.May 24 2023, 12:38 PM

Thank you, Jean! It looks great!

flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp
200
384
403
568–569

Thanks!

flang/test/HLFIR/order_assignments/impure-where.fir
2 ↗(On Diff #525192)
This revision is now accepted and ready to land.May 24 2023, 12:38 PM
tblah accepted this revision.May 25 2023, 2:31 AM

Thanks for this. Looks good.

flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp
146
217
245
248
flang/test/HLFIR/order_assignments/impure-where.fir
37 ↗(On Diff #525192)

Why doesn't this need a size parameter to tell the allocation how many elements are needed?

This revision was automatically updated to reflect the committed changes.
jeanPerier marked 5 inline comments as done.
jeanPerier marked 5 inline comments as done.May 25 2023, 4:47 AM

Thanks for the review!
I fixed typos in the merge commit, but I merged before seeing @tblah review comment, sorry about that. I made a new patch to address your comments.

flang/test/HLFIR/order_assignments/impure-where.fir
37 ↗(On Diff #525192)

I trimmed the expected IR a bit too much, well spotted, the generated fir.allocmem indeed has a size parameter. I updated the expected output to include it in https://reviews.llvm.org/D151428.

flang/test/HLFIR/order_assignments/inlined-stack-temp.fir