[Mlir-commits] [mlir] [OpenMP][MLIR] Fix llvm::sort comparator. (PR #91963)

Oleg Shyshkov llvmlistbot at llvm.org
Mon May 13 06:57:51 PDT 2024


https://github.com/olegshyshkov updated https://github.com/llvm/llvm-project/pull/91963

>From f5be1ff0a08e6bd1a3e8dad50db73bfa36fc5de4 Mon Sep 17 00:00:00 2001
From: Oleg Shyshkov <shyshkov.oleg at gmail.com>
Date: Mon, 13 May 2024 13:30:58 +0000
Subject: [PATCH 1/2] [OpenMP][MLIR] Fix llvm::sort comparator.

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.
---
 .../LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp   | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

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;

>From 8a1a806150d3a3be4a53af08635903be02cfb385 Mon Sep 17 00:00:00 2001
From: Oleg Shyshkov <shyshkov.oleg at gmail.com>
Date: Mon, 13 May 2024 13:37:21 +0000
Subject: [PATCH 2/2] Fix formatting.

---
 .../Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
index 2928900e40bd6..a7294632d6667 100644
--- a/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
+++ b/mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp
@@ -2155,7 +2155,8 @@ 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 == bIndex)
+            continue;
 
           if (aIndex != -1 && bIndex == -1)
             return false;



More information about the Mlir-commits mailing list