diff options
author | Daniel Berlin <dberlin@dberlin.org> | 2017-08-30 19:52:39 +0000 |
---|---|---|
committer | Daniel Berlin <dberlin@dberlin.org> | 2017-08-30 19:52:39 +0000 |
commit | 7ef26daba8bbf07934be6a49f0bf2c3338a48436 (patch) | |
tree | 35d51a08e95ff8802a2dacaf59d4d83b9dd10bd2 /llvm/lib/Transforms | |
parent | 5ec32d4f9655f207601bb9ccddb530ef79c8610d (diff) | |
download | bcm5719-llvm-7ef26daba8bbf07934be6a49f0bf2c3338a48436.tar.gz bcm5719-llvm-7ef26daba8bbf07934be6a49f0bf2c3338a48436.zip |
NewGVN: Allow simplification into variables
llvm-svn: 312161
Diffstat (limited to 'llvm/lib/Transforms')
-rw-r--r-- | llvm/lib/Transforms/Scalar/NewGVN.cpp | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/llvm/lib/Transforms/Scalar/NewGVN.cpp b/llvm/lib/Transforms/Scalar/NewGVN.cpp index 40e671fc108..ababf7f76e3 100644 --- a/llvm/lib/Transforms/Scalar/NewGVN.cpp +++ b/llvm/lib/Transforms/Scalar/NewGVN.cpp @@ -938,8 +938,6 @@ const Expression *NewGVN::createBinaryExpression(unsigned Opcode, Type *T, // 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 { @@ -963,22 +961,30 @@ const Expression *NewGVN::checkSimplificationResults(Expression *E, } 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; } @@ -998,13 +1004,6 @@ const Expression *NewGVN::createExpression(Instruction *I) const { } // 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. |