[PATCH] D39947: [OpenMP] Stable sort Privates to remove non-deterministic ordering

Mandeep Singh Grang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 12 12:14:33 PST 2017


mgrang created this revision.
mgrang added a project: clang.

This fixes the following failures uncovered by https://reviews.llvm.org/D39245:

  Clang :: OpenMP/task_firstprivate_codegen.cpp
  Clang :: OpenMP/task_private_codegen.cpp
  Clang :: OpenMP/taskloop_firstprivate_codegen.cpp
  Clang :: OpenMP/taskloop_lastprivate_codegen.cpp
  Clang :: OpenMP/taskloop_private_codegen.cpp
  Clang :: OpenMP/taskloop_simd_firstprivate_codegen.cpp
  Clang :: OpenMP/taskloop_simd_lastprivate_codegen.cpp
  Clang :: OpenMP/taskloop_simd_private_codegen.cpp


https://reviews.llvm.org/D39947

Files:
  lib/CodeGen/CGOpenMPRuntime.cpp


Index: lib/CodeGen/CGOpenMPRuntime.cpp
===================================================================
--- lib/CodeGen/CGOpenMPRuntime.cpp
+++ lib/CodeGen/CGOpenMPRuntime.cpp
@@ -4048,9 +4048,9 @@
   return TaskPrivatesMap;
 }
 
-static int array_pod_sort_comparator(const PrivateDataTy *P1,
-                                     const PrivateDataTy *P2) {
-  return P1->first < P2->first ? 1 : (P2->first < P1->first ? -1 : 0);
+static bool stable_sort_comparator(const PrivateDataTy P1,
+                                   const PrivateDataTy P2) {
+  return P1.first < P2.first;
 }
 
 /// Emit initialization for private variables in task-based directives.
@@ -4278,8 +4278,7 @@
                          /*PrivateElemInit=*/nullptr)));
     ++I;
   }
-  llvm::array_pod_sort(Privates.begin(), Privates.end(),
-                       array_pod_sort_comparator);
+  std::stable_sort(Privates.begin(), Privates.end(), stable_sort_comparator);
   auto KmpInt32Ty = C.getIntTypeForBitwidth(/*DestWidth=*/32, /*Signed=*/1);
   // Build type kmp_routine_entry_t (if not built yet).
   emitKmpRoutineEntryT(KmpInt32Ty);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D39947.122604.patch
Type: text/x-patch
Size: 1120 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20171112/0bd068ee/attachment.bin>


More information about the cfe-commits mailing list