Skip to content

Commit de43ef9

Browse files
committed
NewGVN: Clean up after removing possibility of null expressions.
llvm-svn: 290828
1 parent 65d533c commit de43ef9

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

llvm/lib/Transforms/Scalar/NewGVN.cpp

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -714,16 +714,15 @@ const Expression *NewGVN::performSymbolicStoreEvaluation(Instruction *I,
714714
// Unlike loads, we never try to eliminate stores, so we do not check if they
715715
// are simple and avoid value numbering them.
716716
auto *SI = cast<StoreInst>(I);
717-
// If this store's memorydef stores the same value as the last store, the
718-
// memory accesses are equivalent.
719-
// Get the expression, if any, for the RHS of the MemoryDef.
720717
MemoryAccess *StoreAccess = MSSA->getMemoryAccess(SI);
721-
MemoryAccess *StoreRHS = lookupMemoryAccessEquiv(
722-
cast<MemoryDef>(StoreAccess)->getDefiningAccess());
723-
const Expression *OldStore = createStoreExpression(SI, StoreRHS, B);
724-
// See if this store expression already has a value, and it's the same as our
725-
// current store. FIXME: Right now, we only do this for simple stores.
718+
// See if we are defined by a previous store expression, it already has a
719+
// value, and it's the same value as our current store. FIXME: Right now, we
720+
// only do this for simple stores, we should expand to cover memcpys, etc.
726721
if (SI->isSimple()) {
722+
// Get the expression, if any, for the RHS of the MemoryDef.
723+
MemoryAccess *StoreRHS = lookupMemoryAccessEquiv(
724+
cast<MemoryDef>(StoreAccess)->getDefiningAccess());
725+
const Expression *OldStore = createStoreExpression(SI, StoreRHS, B);
727726
CongruenceClass *CC = ExpressionToClass.lookup(OldStore);
728727
if (CC && CC->DefiningExpr && isa<StoreExpression>(CC->DefiningExpr) &&
729728
CC->RepLeader == lookupOperandLeader(SI->getValueOperand(), SI, B))
@@ -1094,16 +1093,14 @@ void NewGVN::performCongruenceFinding(Value *V, const Expression *E) {
10941093
// If this is a MemoryDef, we need to update the equivalence table. If
10951094
// we determined the expression is congruent to a different memory
10961095
// state, use that different memory state. If we determined it didn't,
1097-
// we update that as well.
1098-
// Right now, the only way they can be equivalent is for store
1096+
// we update that as well. Right now, we only support store
10991097
// expressions.
1100-
if (!isa<MemoryUse>(MA)) {
1101-
if (E && isa<StoreExpression>(E) && EClass->Members.size() != 1) {
1102-
auto *DefAccess = cast<StoreExpression>(E)->getDefiningAccess();
1103-
setMemoryAccessEquivTo(MA, DefAccess != MA ? DefAccess : nullptr);
1104-
} else {
1105-
setMemoryAccessEquivTo(MA, nullptr);
1106-
}
1098+
if (!isa<MemoryUse>(MA) && isa<StoreExpression>(E) &&
1099+
EClass->Members.size() != 1) {
1100+
auto *DefAccess = cast<StoreExpression>(E)->getDefiningAccess();
1101+
setMemoryAccessEquivTo(MA, DefAccess != MA ? DefAccess : nullptr);
1102+
} else {
1103+
setMemoryAccessEquivTo(MA, nullptr);
11071104
}
11081105
markMemoryUsersTouched(MA);
11091106
}

0 commit comments

Comments
 (0)