[flang-commits] [flang] [flang] Fold IS_CONTIGUOUS of component refs with non-contiguous base (PR #69327)

via flang-commits flang-commits at lists.llvm.org
Tue Oct 17 06:12:56 PDT 2023


https://github.com/jeanPerier created https://github.com/llvm/llvm-project/pull/69327

None

>From 2865c74850ec87566a9ba03122ac0f017ede0b6e Mon Sep 17 00:00:00 2001
From: Jean Perier <jperier at nvidia.com>
Date: Tue, 17 Oct 2023 06:06:22 -0700
Subject: [PATCH] [flang] Fold IS_CONTIGUOUS of component ref with
 non-contiguous base

---
 flang/lib/Evaluate/check-expression.cpp | 9 +++++++--
 flang/test/Evaluate/folding09.f90       | 9 +++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/flang/lib/Evaluate/check-expression.cpp b/flang/lib/Evaluate/check-expression.cpp
index 29bd6eaa466bbc2..531fc5ccc56c858 100644
--- a/flang/lib/Evaluate/check-expression.cpp
+++ b/flang/lib/Evaluate/check-expression.cpp
@@ -821,8 +821,13 @@ class IsContiguousHelper
     if (x.base().Rank() == 0) {
       return (*this)(x.GetLastSymbol());
     } else {
-      // TODO could be true if base contiguous and this is only component, or
-      // if base has only one element?
+      if (Result baseIsContiguous{(*this)(x.base())}) {
+        if (!*baseIsContiguous) {
+          return false;
+        }
+        // TODO could be true if base contiguous and this is only component, or
+        // if base has only one element?
+      }
       return std::nullopt;
     }
   }
diff --git a/flang/test/Evaluate/folding09.f90 b/flang/test/Evaluate/folding09.f90
index e796ed3d5169bab..863b5e873a1e5b0 100644
--- a/flang/test/Evaluate/folding09.f90
+++ b/flang/test/Evaluate/folding09.f90
@@ -56,4 +56,13 @@ subroutine test(arr1, arr2, arr3, mat, alloc)
       end block
     end associate
   end subroutine
+  subroutine test2(x, vec)
+    type t
+      integer :: i
+    end type
+    type(t) :: x(100)
+    integer(8) :: vec(10)
+    integer(kind=merge(1,-1, .not. is_contiguous(x(1:50:2)%i)))    t01
+    integer(kind=merge(1,-1, .not. is_contiguous(x(vec)%i)))       t02
+  end subroutine
 end module



More information about the flang-commits mailing list