@@ -714,16 +714,15 @@ const Expression *NewGVN::performSymbolicStoreEvaluation(Instruction *I,
714
714
// Unlike loads, we never try to eliminate stores, so we do not check if they
715
715
// are simple and avoid value numbering them.
716
716
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.
720
717
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.
726
721
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);
727
726
CongruenceClass *CC = ExpressionToClass.lookup (OldStore);
728
727
if (CC && CC->DefiningExpr && isa<StoreExpression>(CC->DefiningExpr ) &&
729
728
CC->RepLeader == lookupOperandLeader (SI->getValueOperand (), SI, B))
@@ -1094,16 +1093,14 @@ void NewGVN::performCongruenceFinding(Value *V, const Expression *E) {
1094
1093
// If this is a MemoryDef, we need to update the equivalence table. If
1095
1094
// we determined the expression is congruent to a different memory
1096
1095
// 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
1099
1097
// 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 );
1107
1104
}
1108
1105
markMemoryUsersTouched (MA);
1109
1106
}
0 commit comments