// Take a Value returned by simplification of Expression E/Instruction
// I, and see if it resulted in a simpler expression. If so, return
// that expression.
-// TODO: Once finished, this should not take an Instruction, we only
-// use it for printing.
const Expression *NewGVN::checkSimplificationResults(Expression *E,
Instruction *I,
Value *V) const {
}
CongruenceClass *CC = ValueToClass.lookup(V);
- if (CC && CC->getDefiningExpr()) {
- // If we simplified to something else, we need to communicate
- // that we're users of the value we simplified to.
- if (I != V) {
- // Don't add temporary instructions to the user lists.
- if (!AllTempInstructions.count(I))
- addAdditionalUsers(V, I);
+ if (CC) {
+ if (CC->getLeader() && CC->getLeader() != I) {
+ addAdditionalUsers(V, I);
+ return createVariableOrConstant(CC->getLeader());
}
- if (I)
- DEBUG(dbgs() << "Simplified " << *I << " to "
- << " expression " << *CC->getDefiningExpr() << "\n");
- NumGVNOpsSimplified++;
- deleteExpression(E);
- return CC->getDefiningExpr();
+ if (CC->getDefiningExpr()) {
+ // If we simplified to something else, we need to communicate
+ // that we're users of the value we simplified to.
+ if (I != V) {
+ // Don't add temporary instructions to the user lists.
+ if (!AllTempInstructions.count(I))
+ addAdditionalUsers(V, I);
+ }
+
+ if (I)
+ DEBUG(dbgs() << "Simplified " << *I << " to "
+ << " expression " << *CC->getDefiningExpr() << "\n");
+ NumGVNOpsSimplified++;
+ deleteExpression(E);
+ return CC->getDefiningExpr();
+ }
}
+
return nullptr;
}
}
// Perform simplification.
- // TODO: Right now we only check to see if we get a constant result.
- // We may get a less than constant, but still better, result for
- // some operations.
- // IE
- // add 0, x -> x
- // and x, x -> x
- // We should handle this by simply rewriting the expression.
if (auto *CI = dyn_cast<CmpInst>(I)) {
// Sort the operand value numbers so x<y and y>x get the same value
// number.