This is an archive of the discontinued LLVM Phabricator instance.

[Flang][OpenMP] Add support for logical and reduction in worksharing-loop
ClosedPublic

Authored by DylanFleming-arm on Aug 19 2022, 6:23 AM.

Details

Summary

Adds support for .and. reductions with logical types.

Because arith.addi doesn'to work with fir.logical<4> types
logical<4> must be converted to i1 prior to the operation.

This means that the pattern matched by integer reductions
(load -> op -> store) will not match logical reductions.
Instead, the pattern being searched for here is
load -> convert(logical<4> to i1) -> op -> convert(i1 to logical<4>) -> store

Diff Detail

Event Timeline

Herald added projects: Restricted Project, Restricted Project. · View Herald Transcript
DylanFleming-arm requested review of this revision.Aug 19 2022, 6:23 AM

rebased onto more recent base.

Some minor comments.

flang/include/flang/Lower/OpenMP.h
54–62

Nit:Group overloaded functions together.

flang/lib/Lower/OpenMP.cpp
1143–1144

May be checking for the logical type is better here.

1927
1947

Nit: Add newline

1971

Addressed Nits.

flang/lib/Lower/OpenMP.cpp
1885

The name of this function sounds like it is only getting something. Shall we move this deletion of the Op to a separate function or do it in the caller of this function?

1921

Can this be combined with the existing function by making an optional argument?

1922

Nit: You dont need any braces in this loop nest.

1952

Can this be combined into the existing updateReduction with an optional argument? Can you add comments for what this function does?

flang/test/Lower/OpenMP/wsloop-reduction-logical-and.f90
3

Remove one of the !.

25

Check that the name of the reduction matches the declaration.

25

I am a bit surprised that the reduction accumulator is a logical<4> but the combiners and initializers are i1s. Could you paste a dump of the llvm IR for the simple reduction?

Combined overloads for both updateReduction and getReductionInChain into two singlular functions with optional parameters

I found trying to seperate the storeOp erase out of getReductionInChain resulted in either duplicate or messy code, I've renamed the function to findReductionChain,
hopefully this removes the implication that's stricly just a getter. I'm happy to revist this if needed.

rebased onto main

kiranchandramohan accepted this revision.Sep 9 2022, 6:03 AM

LGTM.

A couple of Nits to fix before you submit. I think a few more cleanups are possible (how we deal with converts) but we can do this in a follow-up patch.

flang/lib/Lower/OpenMP.cpp
1874

Nit:Remove this auto.

1877

Nit:Remove this auto

1935

Nit: Remove auto.

1938

Nit: Remove auto.

flang/test/Lower/OpenMP/wsloop-reduction-logical-and.f90
25

Note: This can be a bit problematic as we have seen in the case of eqv. Ideally, we would want to use logical<4> in the reduction declare op. We can handle this in a separate patch.

This revision is now accepted and ready to land.Sep 9 2022, 6:03 AM
flang/lib/Lower/OpenMP.cpp