-
Notifications
You must be signed in to change notification settings - Fork 12.3k
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
Thirumalai-Shaktivel
wants to merge
2
commits into
llvm:main
Choose a base branch
from
Thirumalai-Shaktivel:llvm/atomic_01
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[Flang] Check if two ArrayConstructor's are Equal #121181
Thirumalai-Shaktivel
wants to merge
2
commits into
llvm:main
from
Thirumalai-Shaktivel:llvm/atomic_01
+58
−1
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
added
flang
Flang issues not falling into any other category
flang:fir-hlfir
flang:openmp
labels
Dec 27, 2024
@llvm/pr-subscribers-flang-openmp @llvm/pr-subscribers-flang-fir-hlfir Author: Thirumalai Shaktivel (Thirumalai-Shaktivel) ChangesThis also includes comparing the two ImpliedDo Details
Fixes: #104526 Full diff: https://github.com/llvm/llvm-project/pull/121181.diff 2 Files Affected:
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
|
Thirumalai-Shaktivel
requested review from
tblah,
Leporacanthicus,
NimishMishra,
kiranktp and
kaviya2510
December 27, 2024 06:10
✅ With the latest revision this PR passed the C/C++ code formatter. |
Thirumalai-Shaktivel
force-pushed
the
llvm/atomic_01
branch
3 times, most recently
from
December 27, 2024 06:22
5588a93
to
06b6e83
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This also includes comparing the two ImpliedDo
Details
elements and type
upper, stride and values
Fixes: #104526