[llvm] r246801 - [RewriteStatepointsForGC] Workaround a lack of determinism in visit order

Philip Reames via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 3 13:24:29 PDT 2015


Author: reames
Date: Thu Sep  3 15:24:29 2015
New Revision: 246801

URL: http://llvm.org/viewvc/llvm-project?rev=246801&view=rev
Log:
[RewriteStatepointsForGC] Workaround a lack of determinism in visit order

The visit order being used in the base pointer inference algorithm is currently non-deterministic.  When working on http://reviews.llvm.org/D12583, I discovered that we were relying on a peephole optimization to get deterministic ordering in one of the test cases.  

This change is intented to let me test and land http://reviews.llvm.org/D12583.  The current code will not be long lived.  I'm starting to investigate a rewrite of the algorithm which will combine the post-process step into the initial algorithm and make the visit order determistic.  Before doing that, I wanted to make sure the existing code was complete and the test were stable.  Hopefully, patches should be up for review for the new algorithm this week or early next.


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

Modified: llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp?rev=246801&r1=246800&r2=246801&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/RewriteStatepointsForGC.cpp Thu Sep  3 15:24:29 2015
@@ -1026,14 +1026,19 @@ static Value *findBasePointer(Value *I,
   DenseMap<Value *, Value *> ReverseMap;
   SmallPtrSet<Instruction *, 16> NewInsts;
   SmallSetVector<AssertingVH<Instruction>, 16> Worklist;
-  for (auto Item : states) {
-    Value *V = Item.first;
-    Value *Base = Item.second.getBase();
+  // Note: We need to visit the states in a deterministic order.  We uses the
+  // Keys we sorted above for this purpose.  Note that we are papering over a
+  // bigger problem with the algorithm above - it's visit order is not
+  // deterministic.  A larger change is needed to fix this.
+  for (auto Key : Keys) {
+    Value *V = Key;
+    auto State = states[Key];
+    Value *Base = State.getBase();
     assert(V && Base);
     assert(!isKnownBaseResult(V) && "why did it get added?");
     assert(isKnownBaseResult(Base) &&
            "must be something we 'know' is a base pointer");
-    if (!Item.second.isConflict())
+    if (!State.isConflict())
       continue;
 
     ReverseMap[Base] = V;




More information about the llvm-commits mailing list