]> granicus.if.org Git - llvm/commitdiff
[JumpThreading] Prevent non-deterministic use lists
authorPablo Barrio <pablo.barrio@arm.com>
Mon, 14 Nov 2016 10:24:26 +0000 (10:24 +0000)
committerPablo Barrio <pablo.barrio@arm.com>
Mon, 14 Nov 2016 10:24:26 +0000 (10:24 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@286807 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/JumpThreading.cpp

index 05ac11fc376adfef2bfe3c3f160ee66e66d50cdc..c37659b01f723885af535744a22998331a2315b4 100644 (file)
@@ -2042,19 +2042,18 @@ bool JumpThreadingPass::TryToUnfoldSelectInCurrBB(BasicBlock *BB) {
       // 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);
     }
   }