[Attributor][FIX] Ensure stable iteration order
authorJohannes Doerfert <johannes@jdoerfert.de>
Thu, 17 Feb 2022 18:48:32 +0000 (12:48 -0600)
committerJohannes Doerfert <johannes@jdoerfert.de>
Thu, 17 Feb 2022 18:53:10 +0000 (12:53 -0600)
With
https://github.com/llvm/llvm-project/commit/668c5c688be7ab0af37739bbbe2d653be82d5c6f
we introduced an ordering issue revealed by the reverse iteration
buildbot. Depending on the order of the map that tracks the AAIsDead AAs
we ended up with slightly different attributes. This is not totally
unexpected and can happen. We should however be deterministic in our
orderings to avoid such issues.

llvm/lib/Transforms/IPO/AttributorAttributes.cpp

index 0ad64db..c94f386 100644 (file)
@@ -14,6 +14,7 @@
 #include "llvm/Transforms/IPO/Attributor.h"
 
 #include "llvm/ADT/APInt.h"
+#include "llvm/ADT/MapVector.h"
 #include "llvm/ADT/SCCIterator.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SetOperations.h"
@@ -270,7 +271,7 @@ static bool genericValueTraversal(
     const AAIsDead *LivenessAA = nullptr;
     bool AnyDead = false;
   };
-  DenseMap<const Function *, LivenessInfo> LivenessAAs;
+  SmallMapVector<const Function *, LivenessInfo, 4> LivenessAAs;
   auto GetLivenessInfo = [&](const Function &F) -> LivenessInfo & {
     LivenessInfo &LI = LivenessAAs[&F];
     if (!LI.LivenessAA)