]> granicus.if.org Git - llvm/commitdiff
[NewGVN] Fixup store count for the `initial` congruency class.
authorDavide Italiano <davide@freebsd.org>
Wed, 11 Jan 2017 23:41:24 +0000 (23:41 +0000)
committerDavide Italiano <davide@freebsd.org>
Wed, 11 Jan 2017 23:41:24 +0000 (23:41 +0000)
It was always zero. When we move a store from `initial` to its
own congruency class, we end up with a negative store count, which
is obviously wrong.
Also, while here, change StoreCount to be signed so that the assertions
actually fire.

Ack'ed by Daniel Berlin.

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

lib/Transforms/Scalar/NewGVN.cpp

index 06c3304afc8cc06b07c19f84649c85594d82a3ef..e1b6741f31b42dec8cc2d1344d9300840e3640de 100644 (file)
@@ -137,7 +137,7 @@ struct CongruenceClass {
 
   // Number of stores in this congruence class.
   // This is used so we can detect store equivalence changes properly.
-  unsigned StoreCount = 0;
+  int StoreCount = 0;
 
   explicit CongruenceClass(unsigned ID) : ID(ID) {}
   CongruenceClass(unsigned ID, Value *Leader, const Expression *E)
@@ -1066,7 +1066,7 @@ void NewGVN::moveValueToNewCongruenceClass(Value *V, CongruenceClass *OldClass,
     --OldClass->StoreCount;
     assert(OldClass->StoreCount >= 0);
     ++NewClass->StoreCount;
-    assert(NewClass->StoreCount >= 0);
+    assert(NewClass->StoreCount > 0);
   }
 
   ValueToClass[V] = NewClass;
@@ -1337,9 +1337,12 @@ void NewGVN::initializeCongruenceClasses(Function &F) {
       // MemoryDef's for stores and all MemoryPhis to be equal.  Right now, no
       // other expression can generate a memory equivalence.  If we start
       // handling memcpy/etc, we can expand this.
-      if (isa<StoreInst>(&I))
+      if (isa<StoreInst>(&I)) {
         MemoryAccessEquiv.insert(
             {MSSA->getMemoryAccess(&I), MSSA->getLiveOnEntryDef()});
+        ++InitialClass->StoreCount;
+        assert(InitialClass->StoreCount > 0);
+      }
     }
   }
   InitialClass->Members.swap(InitialValues);