Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[flang][hlfir] Add hlfir.maxval intrinsic #65705

Merged
merged 1 commit into from
Sep 12, 2023

Conversation

yus3710-fj
Copy link
Contributor

@yus3710-fj yus3710-fj commented Sep 8, 2023

Adds a new HLFIR operation for the MAXVAL intrinsic according to the design set out in flang/docs/HighLevelFIR.md.

@yus3710-fj yus3710-fj added the flang Flang issues not falling into any other category label Sep 8, 2023
@yus3710-fj yus3710-fj requested a review from a team as a code owner September 8, 2023 02:38
@yus3710-fj
Copy link
Contributor Author

FYI: My colleague or I will implement hlfir.minval after this PR is accepted.

Copy link
Contributor

@tblah tblah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great. Thanks for adding it. Just one minor comment

@@ -404,6 +404,32 @@ def hlfir_CountOp : hlfir_Op<"count", [AttrSizedOperandSegments, DeclareOpInterf
let hasVerifier = 1;
}

def hlfir_MaxvalOp : hlfir_Op<"maxval", [AttrSizedOperandSegments,
DeclareOpInterfaceMethods<ArithFastMathInterface>]> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please could you add memory effects like I did in https://reviews.llvm.org/D158662. This is new since the previous intrinsics were added.

You will need to DeclareOpInterfaceMethods<MemoryEffectsOpInterface>, add an implementation of MaxValOp::getEffects which calls getIntrinsicEffects and add a test to memory-effects.fir

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your comment and information.
I fixed it.

Copy link
Contributor

@jeanPerier jeanPerier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

Comment on lines 234 to 238
auto argCharType = mlir::dyn_cast<fir::CharacterType>(
hlfir::getFortranElementType(argArray.getType()));
if (argCharType && argCharType.hasConstantLen())
resCharType = fir::CharacterType::get(
builder.getContext(), resCharType.getFKind(), argCharType.getLen());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a TODO comment to improve the front-end analysis here?

I see that it is not able to fold len(maxval(array(:, :)(:))) when array length is a compile time constant, and I think it should even though this is not technically a constant expression as per 10.1.2 since the len argument is not a variable.

I do not have an immediate idea of why this is not resolved by semantics currently. Some folding step may be missing.

It is likely fine to assume that all transformational operating on a character arrays return an object with the same length, but I would rather leave that up to semantics for the future sake.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your comment. It's very helpful for me.
After applying your patch #65771 to my branch, it seemed that my implementation for length information came to be unnecessary.
Should I remove this? If so, is the TODO comment still needed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review on this patch, I just merged it, so you should just be able to remove the part dealing with the constant length.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your reply.
I fixed it.

Copy link
Contributor

@tblah tblah left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@yus3710-fj
Copy link
Contributor Author

Now the check fails because this branch hasn't been rebased yet in order to keep changes easy to track.
The branch was rebased in my local and I checked that the test passed.

Copy link
Contributor

@jeanPerier jeanPerier left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

Adds a new HLFIR operation for the MAXVAL intrinsic according to
the design set out in flang/docs/HighLevelFIR.md.
@yus3710-fj yus3710-fj merged commit 2318bc8 into llvm:main Sep 12, 2023
1 of 2 checks passed
@yus3710-fj yus3710-fj deleted the feature/hlfir.maxval branch September 12, 2023 08:21
ZijunZhaoCCK pushed a commit to ZijunZhaoCCK/llvm-project that referenced this pull request Sep 19, 2023
Adds a new HLFIR operation for the MAXVAL intrinsic according to the
design set out in flang/docs/HighLevelFIR.md.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants