Skip to content

[OpenMP][MLIR] Fix llvm::sort comparator. #91963

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

Merged
merged 2 commits into from
May 13, 2024
Merged

Conversation

olegshyshkov
Copy link
Contributor

The current comparator doesn't work correctly when two identical entries with -1 are compared. The comparator returns first is case when aIndex == -1 && bIndex == -1, but it should continue as those indexes are the same.

@llvmbot
Copy link
Member

llvmbot commented May 13, 2024

@llvm/pr-subscribers-mlir
@llvm/pr-subscribers-mlir-llvm
@llvm/pr-subscribers-mlir-openmp

@llvm/pr-subscribers-flang-openmp

Author: Oleg Shyshkov (olegshyshkov)

Changes

The current comparator doesn't work correctly when two identical entries with -1 are compared. The comparator returns first is case when aIndex == -1 && bIndex == -1, but it should continue as those indexes are the same.


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

1 Files Affected:

  • (modified) mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp (+2-6)
diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index 282e640d3aaad..2928900e40bd6 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -2155,18 +2155,14 @@ getFirstOrLastMappedMemberPtr(mlir::omp::MapInfoOp mapInfo, bool first) {
           int aIndex = indexValues[a * shape[1] + i];
           int bIndex = indexValues[b * shape[1] + i];
 
+          if (aIndex == bIndex) continue;
+
           if (aIndex != -1 && bIndex == -1)
             return false;
 
           if (aIndex == -1 && bIndex != -1)
             return true;
 
-          if (aIndex == -1)
-            return first;
-
-          if (bIndex == -1)
-            return !first;
-
           // A is earlier in the record type layout than B
           if (aIndex < bIndex)
             return first;

@olegshyshkov olegshyshkov requested a review from agozillon May 13, 2024 13:36
Copy link

github-actions bot commented May 13, 2024

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

Copy link
Contributor

@agozillon agozillon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

The current comparator doesn't work correctly when two identical entries with -1 are compared. The comparator returns `first` is case when `aIndex == -1 && bIndex == -1`, but it should continue as those indexes are the same.
@olegshyshkov olegshyshkov merged commit 4445ed4 into llvm:main May 13, 2024
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants