[flang-commits] [flang] 8b13775 - [flang] Improve length information in character transformational (#65771)
via flang-commits
flang-commits at lists.llvm.org
Mon Sep 11 03:52:15 PDT 2023
Author: jeanPerier
Date: 2023-09-11T12:52:11+02:00
New Revision: 8b13775d6a7c2b2f070fd32d320676ed5b19cbb2
URL: https://github.com/llvm/llvm-project/commit/8b13775d6a7c2b2f070fd32d320676ed5b19cbb2
DIFF: https://github.com/llvm/llvm-project/commit/8b13775d6a7c2b2f070fd32d320676ed5b19cbb2.diff
LOG: [flang] Improve length information in character transformational (#65771)
Intrinsic resolution currently does not resolve constant length
information for character transformational (with "sameChar") where the
argument has constant length but is not a variable or a constant
expression.
It is not required to fold those expressions (only inquiry on constant
expression or variable with constant length is required to be a constant
expression).
But constant length information for character is valuable for lowering,
so I think this is a nice and easy to have.
Added:
Modified:
flang/lib/Evaluate/intrinsics.cpp
flang/test/Evaluate/fold-substr.f90
Removed:
################################################################################
diff --git a/flang/lib/Evaluate/intrinsics.cpp b/flang/lib/Evaluate/intrinsics.cpp
index fd549dd81655992..030e5b2fd2c6d9d 100644
--- a/flang/lib/Evaluate/intrinsics.cpp
+++ b/flang/lib/Evaluate/intrinsics.cpp
@@ -2093,7 +2093,15 @@ std::optional<SpecificCall> IntrinsicInterface::Match(
CHECK(sameArg);
if (std::optional<DynamicType> aType{sameArg->GetType()}) {
if (result.categorySet.test(aType->category())) {
- resultType = *aType;
+ if (const auto *sameChar{UnwrapExpr<Expr<SomeCharacter>>(*sameArg)}) {
+ if (auto len{ToInt64(Fold(context, sameChar->LEN()))}) {
+ resultType = DynamicType{aType->kind(), *len};
+ } else {
+ resultType = *aType;
+ }
+ } else {
+ resultType = *aType;
+ }
} else {
resultType = DynamicType{*category, aType->kind()};
}
diff --git a/flang/test/Evaluate/fold-substr.f90 b/flang/test/Evaluate/fold-substr.f90
index b36887e7f4dfd2b..daf62bd197ace60 100644
--- a/flang/test/Evaluate/fold-substr.f90
+++ b/flang/test/Evaluate/fold-substr.f90
@@ -20,3 +20,11 @@ module m
logical, parameter :: test_07d = ca(1)(5:) == ""
logical, parameter :: test_07e = ca(1)(:) == "abcd"
end module
+
+subroutine foo(x)
+ character(4) :: x(:, :)
+ logical, parameter :: test_01 = len(transpose(x(:, :)(:))) == 4
+ logical, parameter :: test_02 = len(transpose(x(:, :)(1:2))) == 2
+ logical, parameter :: test_03 = len(maxval(x(:, :)(:))) == 4
+ logical, parameter :: test_04 = len(maxval(x(:, :)(1:2))) == 2
+end subroutine
More information about the flang-commits
mailing list