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] Check if two ArrayConstructor's are Equal #121181

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Thirumalai-Shaktivel
Copy link
Member

This also includes comparing the two ImpliedDo

Details

  • For ArrayConstructor, check if x and y have the same
    elements and type
  • For ImpliedDo, check if x and y have the same lower,
    upper, stride and values

Fixes: #104526

This also includes comparing the two ImpliedDo

Details:
- For ArrayConstructor, check if x and y have the same
  elements and type
- For ImpliedDo, check if x and y have the same lower,
  upper, stride and values
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:fir-hlfir flang:openmp labels Dec 27, 2024
@llvmbot
Copy link
Member

llvmbot commented Dec 27, 2024

@llvm/pr-subscribers-flang-openmp

@llvm/pr-subscribers-flang-fir-hlfir

Author: Thirumalai Shaktivel (Thirumalai-Shaktivel)

Changes

This also includes comparing the two ImpliedDo

Details

  • For ArrayConstructor, check if x and y have the same
    elements and type
  • For ImpliedDo, check if x and y have the same lower,
    upper, stride and values

Fixes: #104526


Full diff: https://github.com/llvm/llvm-project/pull/121181.diff

2 Files Affected:

  • (modified) flang/include/flang/Lower/Support/Utils.h (+44-1)
  • (modified) flang/test/Lower/OpenMP/atomic-update.f90 (+15)
diff --git a/flang/include/flang/Lower/Support/Utils.h b/flang/include/flang/Lower/Support/Utils.h
index 1cc74521e22d88..b2f3673f9164cb 100644
--- a/flang/include/flang/Lower/Support/Utils.h
+++ b/flang/include/flang/Lower/Support/Utils.h
@@ -545,9 +545,52 @@ class IsEqualEvaluateExpr {
     return isEqual(x.proc(), y.proc()) && isEqual(x.arguments(), y.arguments());
   }
   template <typename A>
+  static bool isEqual(const Fortran::evaluate::ImpliedDo<A> &x,
+                      const Fortran::evaluate::ImpliedDo<A> &y) {
+    using Expr = Fortran::evaluate::Expr<A>;
+    for (const auto &[xValue, yValue] : llvm::zip(x.values(), y.values())) {
+      bool checkValue = Fortran::common::visit(
+          common::visitors{
+              [&](const Expr &v, const Expr &w) { return isEqual(v, w); },
+              [&](const auto &, const auto &) {
+                llvm::report_fatal_error("isEqual is not handled yet for "
+                    "the element type in ImpliedDo");
+                return false;
+
+              },
+          },
+          xValue.u, yValue.u);
+      if (!checkValue) {
+        return false;
+      }
+    }
+    return isEqual(x.lower(), y.lower()) && isEqual(x.upper(), y.upper()) &&
+           isEqual(x.stride(), y.stride());
+  }
+  template <typename A>
   static bool isEqual(const Fortran::evaluate::ArrayConstructor<A> &x,
                       const Fortran::evaluate::ArrayConstructor<A> &y) {
-    llvm::report_fatal_error("not implemented");
+    for (const auto &[xValue, yValue] : llvm::zip(x, y)) {
+      using Expr = Fortran::evaluate::Expr<A>;
+      using ImpliedDo = Fortran::evaluate::ImpliedDo<A>;
+      bool checkElement = Fortran::common::visit(
+          common::visitors{
+              [&](const Expr &v, const Expr &w) { return isEqual(v, w); },
+              [&](const ImpliedDo &v, const ImpliedDo &w) {
+                return isEqual(v, w);
+              },
+              [&](const auto &, const auto &) {
+                llvm::report_fatal_error("isEqual is not handled yet for "
+                    "the element type in ImpliedDo");
+                return false;
+              },
+          },
+          xValue.u, yValue.u);
+      if (!checkElement) {
+        return false;
+      }
+    }
+    return x.GetType() == y.GetType();
   }
   static bool isEqual(const Fortran::evaluate::ImpliedDoIndex &x,
                       const Fortran::evaluate::ImpliedDoIndex &y) {
diff --git a/flang/test/Lower/OpenMP/atomic-update.f90 b/flang/test/Lower/OpenMP/atomic-update.f90
index 16dae9d5f301c1..7d04745015faab 100644
--- a/flang/test/Lower/OpenMP/atomic-update.f90
+++ b/flang/test/Lower/OpenMP/atomic-update.f90
@@ -185,4 +185,19 @@ program OmpAtomicUpdate
   !$omp atomic update
     w = max(w,x,y,z)
 
+!CHECK:  %[[IMP_DO:.*]] = hlfir.elemental %{{.*}} unordered : (!fir.shape<1>) -> !hlfir.expr<?xi32> {
+!CHECK:  ^bb0(%{{.*}}: index):
+!          [...]
+!CHECK:    %[[ADD_I1:.*]] = arith.addi {{.*}} : i32
+!CHECK:    hlfir.yield_element %[[ADD_I1]] : i32
+!CHECK:  }
+!        [...]
+!CHECK:  %[[SUM:.*]] = hlfir.sum %[[IMP_DO]]
+!CHECK:  omp.atomic.update %[[VAL_X_DECLARE]]#1 : !fir.ref<i32> {
+!CHECK:  ^bb0(%[[ARG0:.*]]: i32):
+!CHECK:    %[[ADD_I2:.*]] = arith.addi %[[ARG0]], %[[SUM]] : i32
+!CHECK:    omp.yield(%[[ADD_I2]] : i32)
+!CHECK:  }
+  !$omp atomic update
+    x = x + sum([ (y+2, y=1, z) ])
 end program OmpAtomicUpdate

Copy link

github-actions bot commented Dec 27, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

@Thirumalai-Shaktivel Thirumalai-Shaktivel force-pushed the llvm/atomic_01 branch 3 times, most recently from 5588a93 to 06b6e83 Compare December 27, 2024 06:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:fir-hlfir flang:openmp flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Flang][OpenMP] ICE with "LLVM ERROR: not implemented" (omp atomic)
2 participants