From 0e9001131dcefdf516041e3d631f9b5e3248a1b5 Mon Sep 17 00:00:00 2001 From: Daniel Berlin Date: Fri, 24 Mar 2017 06:33:48 +0000 Subject: [PATCH] NewGVN: Small cleanup of useless expression deletion, and don't uselessly create two expressions in symbolic store evaluation. llvm-svn: 298691 --- llvm/lib/Transforms/Scalar/NewGVN.cpp | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp index 437f9d1..1a36664 100644 --- a/llvm/lib/Transforms/Scalar/NewGVN.cpp +++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp @@ -420,6 +420,7 @@ private: void verifyIterationSettled(Function &F); bool singleReachablePHIPath(const MemoryAccess *, const MemoryAccess *) const; BasicBlock *getBlockForValue(Value *V) const; + void deleteExpression(const Expression *E); // Debug counter info. When verifying, we have to reset the value numbering // debug counter to the same state it started in to get the same results. std::pair StartingVNCounter; @@ -471,6 +472,16 @@ BasicBlock *NewGVN::getBlockForValue(Value *V) const { return nullptr; } +// Delete a definitely dead expression, so it can be reused by the expression +// allocator. Some of these are not in creation functions, so we have to accept +// const versions. +void NewGVN::deleteExpression(const Expression *E) { + assert(isa(E)); + auto *BE = cast(E); + const_cast(BE)->deallocateOperands(ArgRecycler); + ExpressionAllocator.Deallocate(E); +} + PHIExpression *NewGVN::createPHIExpression(Instruction *I) { BasicBlock *PHIBlock = I->getParent(); auto *PN = cast(I); @@ -559,16 +570,13 @@ const Expression *NewGVN::checkSimplificationResults(Expression *E, NumGVNOpsSimplified++; assert(isa(E) && "We should always have had a basic expression here"); - - cast(E)->deallocateOperands(ArgRecycler); - ExpressionAllocator.Deallocate(E); + deleteExpression(E); return createConstantExpression(C); } else if (isa(V) || isa(V)) { if (I) DEBUG(dbgs() << "Simplified " << *I << " to " << " variable " << *V << "\n"); - cast(E)->deallocateOperands(ArgRecycler); - ExpressionAllocator.Deallocate(E); + deleteExpression(E); return createVariableExpression(V); } @@ -578,10 +586,7 @@ const Expression *NewGVN::checkSimplificationResults(Expression *E, DEBUG(dbgs() << "Simplified " << *I << " to " << " expression " << *V << "\n"); NumGVNOpsSimplified++; - assert(isa(E) && - "We should always have had a basic expression here"); - cast(E)->deallocateOperands(ArgRecycler); - ExpressionAllocator.Deallocate(E); + deleteExpression(E); return CC->DefiningExpr; } return nullptr; @@ -832,7 +837,8 @@ const Expression *NewGVN::performSymbolicStoreEvaluation(Instruction *I) { // The RepStoredValue gets nulled if all the stores disappear in a class, so // we don't need to check if the class contains a store besides us. if (CC && CC->RepStoredValue == lookupOperandLeader(SI->getValueOperand())) - return createStoreExpression(SI, StoreRHS); + return OldStore; + deleteExpression(OldStore); // Also check if our value operand is defined by a load of the same memory // location, and the memory state is the same as it was then // (otherwise, it could have been overwritten later. See test32 in @@ -1024,6 +1030,7 @@ bool NewGVN::setMemoryAccessEquivTo(MemoryAccess *From, CongruenceClass *To) { return Changed; } + // Evaluate PHI nodes symbolically, and create an expression result. const Expression *NewGVN::performSymbolicPHIEvaluation(Instruction *I) { auto *E = cast(createPHIExpression(I)); @@ -1045,8 +1052,7 @@ const Expression *NewGVN::performSymbolicPHIEvaluation(Instruction *I) { if (Filtered.begin() == Filtered.end()) { DEBUG(dbgs() << "Simplified PHI node " << *I << " to undef" << "\n"); - E->deallocateOperands(ArgRecycler); - ExpressionAllocator.Deallocate(E); + deleteExpression(E); return createConstantExpression(UndefValue::get(I->getType())); } Value *AllSameValue = *(Filtered.begin()); @@ -1074,8 +1080,7 @@ const Expression *NewGVN::performSymbolicPHIEvaluation(Instruction *I) { NumGVNPhisAllSame++; DEBUG(dbgs() << "Simplified PHI node " << *I << " to " << *AllSameValue << "\n"); - E->deallocateOperands(ArgRecycler); - ExpressionAllocator.Deallocate(E); + deleteExpression(E); return createVariableOrConstant(AllSameValue); } return E; -- 2.7.4