This is an archive of the discontinued LLVM Phabricator instance.

[flang] Fix MAXLOC/MINLOC when MASK is scalar .FALSE.
ClosedPublic

Authored by PeteSteinfeld on Apr 26 2022, 3:21 PM.

Details

Summary

When passing a scalar .FALSE. as the MASK argument to MAXLOC, we were getting
bad memory references. We were falling into the code intended when the MASK
argument was missing.

I fixed this by passing extra information to determine if the MASK argument is
missing versus a scalar value. I also added tests for MAXLOC and MINLOC with
scalar values of .TRUE. and .FALSE. for the MASK argument.

Along the way, I eliminated the unused "chars" argument from the constructor
for ExtremumLocAccumulator.

Diff Detail

Event Timeline

PeteSteinfeld created this revision.Apr 26 2022, 3:21 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptApr 26 2022, 3:21 PM
PeteSteinfeld requested review of this revision.Apr 26 2022, 3:21 PM
jeanPerier added inline comments.Apr 27 2022, 12:58 AM
flang/runtime/extrema.cpp
84

It is really not straightforward to me how you can assume that mask_ is a scalar false here when the if is only testing for the presence of a MASK.

I assume this may come from the way GetResult() is called in flang/runtime/reduction-templates.h, but that is a big assumption.

Have you tried fixing the issue on the reduction-templates side that is calling GetResult ?

Responding to Jean's comments. Rather than using the presence of a mask in
the ExtremumLocAccumulator object to determine if the MASK argument is a
scalar .FALSE. value, I added an argument to the GetResult function.

PeteSteinfeld added inline comments.Apr 27 2022, 7:19 AM
flang/runtime/extrema.cpp
84

Thanks, Jean. Your point is well taken.

I changed things to add an argument to GetResult to explicitly cover the situation where the MASK argument is a scalar .FALSE. value. Let me know if there's a better way to handle this.

When the mask is scalar .false. the result will be zero(es). Seems easier and clearer to check for that case up front than to run the reduction and then override the result.

Responding to Peter's comments. I restricted all changes to extrema.cpp where
I modified TypedPartialMaxOrMinLoc to test for the scalar .FALSE. value of MASK
and, in the case, create the result and set it to all zeroes.

Thanks @klausler. I'm tried to follow your suggestion. Please take another look.

klausler accepted this revision.Apr 27 2022, 1:41 PM
This revision is now accepted and ready to land.Apr 27 2022, 1:41 PM
klausler added inline comments.Apr 27 2022, 1:43 PM
flang/runtime/extrema.cpp
262

In the case where the mask is scalar and .TRUE., would it be best here to set mask = nullptr;?

Responding to Peter's latest suggestion.

This revision was landed with ongoing or failed builds.Apr 27 2022, 2:52 PM
This revision was automatically updated to reflect the committed changes.