[llvm] r291725 - [NewGVN] Fixup store count for the `initial` congruency class.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 11 15:41:25 PST 2017


Author: davide
Date: Wed Jan 11 17:41:24 2017
New Revision: 291725

URL: http://llvm.org/viewvc/llvm-project?rev=291725&view=rev
Log:
[NewGVN] Fixup store count for the `initial` congruency class.

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.

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

Modified: llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp?rev=291725&r1=291724&r2=291725&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/NewGVN.cpp Wed Jan 11 17:41:24 2017
@@ -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::moveValueToNewCongruenceCla
     --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
       // 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);




More information about the llvm-commits mailing list