[flang-commits] [flang] [flang][hlfir] Add hlfir.maxval intrinsic (PR #65705)
via flang-commits
flang-commits at lists.llvm.org
Fri Sep 8 07:31:17 PDT 2023
================
@@ -227,6 +228,17 @@ HlfirTransformationalIntrinsic::computeResultType(mlir::Value argArray,
mlir::Type elementType = array.getEleTy();
return hlfir::ExprType::get(builder.getContext(), resultShape, elementType,
/*polymorphic=*/false);
+ } else if (auto resCharType =
+ mlir::dyn_cast<fir::CharacterType>(stmtResultType)) {
+ if (!resCharType.hasConstantLen()) {
+ 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());
----------------
jeanPerier wrote:
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.
https://github.com/llvm/llvm-project/pull/65705
More information about the flang-commits
mailing list