[PATCH] D26450: [JumpThreading] Prevent non-deterministic use lists

Pablo Barrio via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 9 06:38:58 PST 2016


pbarrio created this revision.
pbarrio added a reviewer: efriedma.
pbarrio added a subscriber: llvm-commits.

Unfolding selects was previously done with the help of a vector
of pointers that was then sorted to be able to remove duplicates.
As this sorting depends on the memory addresses, it was
non-deterministic. A SetVector is used now so that duplicates are
removed without the need of sorting first.


https://reviews.llvm.org/D26450

Files:
  lib/Transforms/Scalar/JumpThreading.cpp


Index: lib/Transforms/Scalar/JumpThreading.cpp
===================================================================
--- lib/Transforms/Scalar/JumpThreading.cpp
+++ lib/Transforms/Scalar/JumpThreading.cpp
@@ -15,6 +15,7 @@
 #include "llvm/Transforms/Scalar.h"
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
+#include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/Statistic.h"
 #include "llvm/Analysis/GlobalsModRef.h"
@@ -2037,24 +2038,20 @@
 
     if (I.getType()->isIntegerTy(1)) {
 
-      SmallVector<SelectInst *, 4> Selects;
+      SmallSetVector<SelectInst *, 4> Selects;
 
       // Look for scalar booleans used in selects as conditions. If there are
       // several selects that use the same boolean, they are candidates for jump
       // threading and therefore we should unfold them.
       for (Value *U : I.users())
         if (auto *SI = dyn_cast<SelectInst>(U))
-          Selects.push_back(SI);
+          Selects.insert(SI);
       if (Selects.size() <= 1)
         continue;
 
-      // Remove duplicates
-      std::sort(Selects.begin(), Selects.end());
-      auto NewEnd = std::unique(Selects.begin(), Selects.end());
-
       Changed = true;
-      for (auto SI = Selects.begin(); SI != NewEnd; ++SI)
-        expandSelect(*SI);
+      for (auto SI : Selects)
+        expandSelect(SI);
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D26450.77342.patch
Type: text/x-patch
Size: 1373 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20161109/e8ba5154/attachment.bin>


More information about the llvm-commits mailing list