[llvm] r286807 - [JumpThreading] Prevent non-deterministic use lists

Pablo Barrio via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 14 02:24:27 PST 2016


Author: pabbar01
Date: Mon Nov 14 04:24:26 2016
New Revision: 286807

URL: http://llvm.org/viewvc/llvm-project?rev=286807&view=rev
Log:
[JumpThreading] Prevent non-deterministic use lists

Summary:
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.

Reviewers: mgrang, efriedma

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D26450

Modified:
    llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp?rev=286807&r1=286806&r2=286807&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp Mon Nov 14 04:24:26 2016
@@ -2042,19 +2042,18 @@ bool JumpThreadingPass::TryToUnfoldSelec
       // 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))
+      for (Use& U : I.uses()) {
+        auto *SI = dyn_cast<SelectInst>(U.getUser());
+        if (SI && U.getOperandNo() == 0)
           Selects.push_back(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);
     }
   }
 




More information about the llvm-commits mailing list