summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/CodeGenPrepare.cpp
diff options
context:
space:
mode:
authorMikael Holmen <mikael.holmen@ericsson.com>2019-03-15 13:51:05 +0000
committerMikael Holmen <mikael.holmen@ericsson.com>2019-03-15 13:51:05 +0000
commit339daae806b208cad060ce93f63e40f24a311812 (patch)
tree88913fda7bbcd695c853f0ee7d27d80bb74613bf /llvm/lib/CodeGen/CodeGenPrepare.cpp
parentf82d4ed771a0d85da4d3c779e58a9be9ded3968f (diff)
downloadbcm5719-llvm-339daae806b208cad060ce93f63e40f24a311812.tar.gz
bcm5719-llvm-339daae806b208cad060ce93f63e40f24a311812.zip
[CodeGenPrepare] avoid crashing from replacing a phi twice
Summary: This is a fix to bug 41052: https://bugs.llvm.org/show_bug.cgi?id=41052 While trying to optimize a memory instruction in a dead basic block, we end up registering the same phi for replacement twice. This patch avoids registering more than the first replacement candidate for a phi. Patch by: JesperAntonsson Reviewers: skatkov, aprantl Reviewed By: aprantl Subscribers: jdoerfert, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D59358 llvm-svn: 356260
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
-rw-r--r--llvm/lib/CodeGen/CodeGenPrepare.cpp8
1 files changed, 6 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp
index e8498eb375e..44f1709b6e9 100644
--- a/llvm/lib/CodeGen/CodeGenPrepare.cpp
+++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp
@@ -3282,6 +3282,8 @@ private:
PhiNodeSet &PhiNodesToMatch) {
SmallVector<PHIPair, 8> WorkList;
Matcher.insert({ PHI, Candidate });
+ SmallSet<PHINode *, 8> MatchedPHIs;
+ MatchedPHIs.insert(PHI);
WorkList.push_back({ PHI, Candidate });
SmallSet<PHIPair, 8> Visited;
while (!WorkList.empty()) {
@@ -3314,8 +3316,10 @@ private:
if (Matcher.count({ FirstPhi, SecondPhi }))
continue;
// So the values are different and does not match. So we need them to
- // match.
- Matcher.insert({ FirstPhi, SecondPhi });
+ // match. (But we register no more than one match per PHI node, so that
+ // we won't later try to replace them twice.)
+ if (!MatchedPHIs.insert(FirstPhi).second)
+ Matcher.insert({ FirstPhi, SecondPhi });
// But me must check it.
WorkList.push_back({ FirstPhi, SecondPhi });
}
OpenPOWER on IntegriCloud