[PATCH] D119373: [flang] Make folding of LEN less aggressive
Eric Schweitz via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 9 16:50:40 PST 2022
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG391578950334: Folding in the front end was replacing calls to LEN and dropping (authored by schweitz).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D119373/new/
https://reviews.llvm.org/D119373
Files:
flang/lib/Evaluate/fold-integer.cpp
flang/test/Evaluate/rewrite01.f90
Index: flang/test/Evaluate/rewrite01.f90
===================================================================
--- flang/test/Evaluate/rewrite01.f90
+++ flang/test/Evaluate/rewrite01.f90
@@ -76,4 +76,44 @@
!CHECK: PRINT *, 1_4
print *, lbound(returns_array_3(), dim=1)
end subroutine
+
+!CHECK: len_test
+subroutine len_test(a,b, c, d, e, n, m)
+ character(*), intent(in) :: a
+ character(*) :: b
+ external b
+ character(10), intent(in) :: c
+ character(10) :: d
+ external d
+ integer, intent(in) :: n, m
+ character(n), intent(in) :: e
+
+ !CHECK: PRINT *, int(a%len,kind=4)
+ print *, len(a)
+ !CHECK: PRINT *, 5_4
+ print *, len(a(1:5))
+ !CHECK: PRINT *, len(b(a))
+ print *, len(b(a))
+ !CHECK: PRINT *, len(b(a)//a)
+ print *, len(b(a) // a)
+ !CHECK: PRINT *, 10_4
+ print *, len(c)
+ !CHECK: PRINT *, len(c(int(i,kind=8):int(j,kind=8)))
+ print *, len(c(i:j))
+ !CHECK: PRINT *, 5_4
+ print *, len(c(1:5))
+ !CHECK: PRINT *, 10_4
+ print *, len(d(c))
+ !CHECK: PRINT *, 20_4
+ print *, len(d(c) // c)
+ !CHECK: PRINT *, 0_4
+ print *, len(a(10:4))
+ !CHECK: PRINT *, int(max(0_8,int(m,kind=8)-int(n,kind=8)+1_8),kind=4)
+ print *, len(a(n:m))
+ !CHECK: PRINT *, len(b(a(int(n,kind=8):int(m,kind=8))))
+ print *, len(b(a(n:m)))
+ !CHECK: PRINT *, int(max(0_8,max(0_8,int(n,kind=8))-4_8+1_8),kind=4)
+ print *, len(e(4:))
+end subroutine len_test
+
end module
Index: flang/lib/Evaluate/fold-integer.cpp
===================================================================
--- flang/lib/Evaluate/fold-integer.cpp
+++ flang/lib/Evaluate/fold-integer.cpp
@@ -677,7 +677,11 @@
return std::visit(
[&](auto &kx) {
if (auto len{kx.LEN()}) {
- return Fold(context, ConvertToType<T>(*std::move(len)));
+ if (IsScopeInvariantExpr(*len)) {
+ return Fold(context, ConvertToType<T>(*std::move(len)));
+ } else {
+ return Expr<T>{std::move(funcRef)};
+ }
} else {
return Expr<T>{std::move(funcRef)};
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119373.407348.patch
Type: text/x-patch
Size: 2089 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220210/83900aa8/attachment.bin>
More information about the llvm-commits
mailing list