aboutsummaryrefslogtreecommitdiff
path: root/lib/Transforms/Scalar/GVNSink.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Transforms/Scalar/GVNSink.cpp')
-rw-r--r--lib/Transforms/Scalar/GVNSink.cpp22
1 files changed, 14 insertions, 8 deletions
diff --git a/lib/Transforms/Scalar/GVNSink.cpp b/lib/Transforms/Scalar/GVNSink.cpp
index 1df5f5400c14..054025755c69 100644
--- a/lib/Transforms/Scalar/GVNSink.cpp
+++ b/lib/Transforms/Scalar/GVNSink.cpp
@@ -1,9 +1,8 @@
//===- GVNSink.cpp - sink expressions into successors ---------------------===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
@@ -442,6 +441,7 @@ public:
break;
case Instruction::Call:
case Instruction::Invoke:
+ case Instruction::FNeg:
case Instruction::Add:
case Instruction::FAdd:
case Instruction::Sub:
@@ -714,6 +714,15 @@ Optional<SinkingInstructionCandidate> GVNSink::analyzeInstructionForSinking(
// FIXME: If any of these fail, we should partition up the candidates to
// try and continue making progress.
Instruction *I0 = NewInsts[0];
+
+ // If all instructions that are going to participate don't have the same
+ // number of operands, we can't do any useful PHI analysis for all operands.
+ auto hasDifferentNumOperands = [&I0](Instruction *I) {
+ return I->getNumOperands() != I0->getNumOperands();
+ };
+ if (any_of(NewInsts, hasDifferentNumOperands))
+ return None;
+
for (unsigned OpNum = 0, E = I0->getNumOperands(); OpNum != E; ++OpNum) {
ModelledPHI PHI(NewInsts, OpNum, ActivePreds);
if (PHI.areAllIncomingValuesSame())
@@ -791,10 +800,7 @@ unsigned GVNSink::sinkBB(BasicBlock *BBEnd) {
--LRI;
}
- std::stable_sort(
- Candidates.begin(), Candidates.end(),
- [](const SinkingInstructionCandidate &A,
- const SinkingInstructionCandidate &B) { return A > B; });
+ llvm::stable_sort(Candidates, std::greater<SinkingInstructionCandidate>());
LLVM_DEBUG(dbgs() << " -- Sinking candidates:\n"; for (auto &C
: Candidates) dbgs()
<< " " << C << "\n";);