This is an archive of the discontinued LLVM Phabricator instance.

[flang] lower product intrinsic to hlfir.product operation
ClosedPublic

Authored by jacob-crawley on Apr 19 2023, 8:24 AM.

Details

Summary

Carries out the initial lowering of the product intrinsic into HLFIR
following a similar method to sum, the --use-hlfir-intrinsic-ops flag
in test/Lower/HLFIR/expr-box is set to false so that the tests will
pass until hlfir.product is lowered into fir.call

Diff Detail

Event Timeline

jacob-crawley created this revision.Apr 19 2023, 8:24 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 19 2023, 8:24 AM
jacob-crawley requested review of this revision.Apr 19 2023, 8:24 AM
tblah added a comment.EditedApr 19 2023, 8:52 AM

Thanks for working on this. Some comments

  • This patch needs a dependency on the previous hlfir.product patch, otherwise the CI builders will fail to build it. You can add that using either a Depends on: D1234 tag to the commit message/patch description. Alternately, you could press "Edit Related Revisions" on the right hand sidebar
  • --use-hlfir-intrinsic-ops=false will still be required after the patch lowering hlfir.product to fir.call because that test calls bbc -emit-fir -hlfir which emits the HLFIR after lowering and before passes run. Therefore the HLFIR intrinsics pass (where hlfir.product will be lowered to fir.call) will not be run.
  • Did you consider sharing the code in flang/lib/Lower/ConvertCall.cpp with hlfir.sum using a templated function as you did in the previous patch?

Nothing to add to Tom's comment. Thanks for working on this!
(adding --use-hlfir-intrinsic-ops=false in the test is fine, I should find another way to test genExprBox without using transformational intrinsics).

Thanks for the reviews

Following Tom's comments I have moved the shared code in
genHLFIRIntrinsicRefCore to a new lambda called buildOperation.

tblah added inline comments.Apr 24 2023, 7:52 AM
flang/lib/Lower/ConvertCall.cpp
1355

Please could you name this in a way that shows that it is only for hlfir.sum and hlfir.product. buildOperation sounds like it could build any operation. But this couldn't build hlfir.matmul or hlfir.transpose.

What about buildReductionIntrinsic?

Changed the name of the buildOperation function to buildReductionIntrinsic

jacob-crawley marked an inline comment as done.Apr 24 2023, 8:35 AM
tblah accepted this revision.Apr 24 2023, 8:40 AM

Looks good to me. Thanks for your work on this.

This revision is now accepted and ready to land.Apr 24 2023, 8:40 AM
jeanPerier accepted this revision.Apr 27 2023, 7:09 AM

Thanks! Two small nits, LGTM otherwise.

flang/lib/Lower/ConvertCall.cpp
1342

I think you probably need to pass "fir::FirOpBuilder" by reference here and below, otherwise, I am not sure what guarantee we have the the original builder insertion point will be moved properly when using a copy here.

Also nit: it seems the lambda is not capturing anything, you should rather use "[]" in this case to underline it (this helps identifying lamdas that can easily be moved as static function if desired).

Thanks! Two small nits, LGTM otherwise.

If they are that tiny, they cannot be methods of the builder?

addressing nit comments in review

Thanks for addressing the nits.

It looks like flang/lib/Lower/ConvertCall.cpp failed clang-format in CI. It also look like the FirOpBuilder is still passed by reference.

fixes to formatting and passing FirOpBuilder by reference in buildSumOperation/buildProductOperation

jacob-crawley marked an inline comment as done.May 2 2023, 2:38 AM
tblah accepted this revision.May 2 2023, 2:40 AM

Thanks for the fixes. LGTM!

jeanPerier accepted this revision.May 2 2023, 6:47 AM

LGTM, tanks