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

Oleg Shyshkov llvmlistbot at llvm.org
Mon May 13 06:34:08 PDT 2024


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

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.

>From 6001cc2f556551381439e31582cbc0080c8ae553 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] [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;



More information about the Mlir-commits mailing list