summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/CodeGenPrepare.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r--llvm/lib/CodeGen/CodeGenPrepare.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index 1b1bad1ac93..422a0a972fb 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -2946,8 +2946,20 @@ private:
Matched.clear();
}
if (IsMatched) {
- // Replace all matched values and erase them.
+ // If we matched phi node to different but identical phis then
+ // make a simplification here.
+ DenseMap<PHINode *, PHINode *> MatchedPHINodeMapping;
for (auto MV : Matched) {
+ auto AlreadyMatched = MatchedPHINodeMapping.find(MV.first);
+ if (AlreadyMatched != MatchedPHINodeMapping.end()) {
+ MV.second->replaceAllUsesWith(AlreadyMatched->second);
+ ST.Put(MV.second, AlreadyMatched->second);
+ MV.second->eraseFromParent();
+ } else
+ MatchedPHINodeMapping.insert({ MV.first, MV.second });
+ }
+ // Replace all matched values and erase them.
+ for (auto MV : MatchedPHINodeMapping) {
MV.first->replaceAllUsesWith(MV.second);
PhiNodesToMatch.erase(MV.first);
ST.Put(MV.first, MV.second);
OpenPOWER on IntegriCloud