From: Davide Italiano Date: Wed, 11 Jan 2017 23:41:24 +0000 (+0000) Subject: [NewGVN] Fixup store count for the `initial` congruency class. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c082fcc6ffb65151090894f8af437245989298f9;p=llvm [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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@291725 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Transforms/Scalar/NewGVN.cpp b/lib/Transforms/Scalar/NewGVN.cpp index 06c3304afc8..e1b6741f31b 100644 --- a/lib/Transforms/Scalar/NewGVN.cpp +++ b/lib/Transforms/Scalar/NewGVN.cpp @@ -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(&I)) + if (isa(&I)) { MemoryAccessEquiv.insert( {MSSA->getMemoryAccess(&I), MSSA->getLiveOnEntryDef()}); + ++InitialClass->StoreCount; + assert(InitialClass->StoreCount > 0); + } } } InitialClass->Members.swap(InitialValues);