summaryrefslogtreecommitdiffstats
path: root/llvm/lib/CodeGen/PeepholeOptimizer.cpp
diff options
context:
space:
mode:
authorLang Hames <lhames@gmail.com>2014-04-03 05:03:20 +0000
committerLang Hames <lhames@gmail.com>2014-04-03 05:03:20 +0000
commit3c0dc2a99dff0ee979362264e93b0e4f2bd4a746 (patch)
tree7e774d63befd0fb51d3ea43f2da344ae6f5b1241 /llvm/lib/CodeGen/PeepholeOptimizer.cpp
parent27754f10f5c8455136b68be210266777f9ed5424 (diff)
downloadbcm5719-llvm-3c0dc2a99dff0ee979362264e93b0e4f2bd4a746.tar.gz
bcm5719-llvm-3c0dc2a99dff0ee979362264e93b0e4f2bd4a746.zip
[CodeGen] Fix peephole optimizer bug introduced in r205481. Fixes PR19318.
I should have read that comment a little more carefully. ;) Regression test in the works, committing in the mean time to un-break people. llvm-svn: 205511
Diffstat (limited to 'llvm/lib/CodeGen/PeepholeOptimizer.cpp')
-rw-r--r--llvm/lib/CodeGen/PeepholeOptimizer.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/llvm/lib/CodeGen/PeepholeOptimizer.cpp b/llvm/lib/CodeGen/PeepholeOptimizer.cpp
index ca8334bf477..e18d9635851 100644
--- a/llvm/lib/CodeGen/PeepholeOptimizer.cpp
+++ b/llvm/lib/CodeGen/PeepholeOptimizer.cpp
@@ -630,20 +630,22 @@ bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &MF) {
// earlier load into MI.
if (!isLoadFoldable(MI, FoldAsLoadDefCandidates) &&
!FoldAsLoadDefCandidates.empty()) {
- // We need to fold load after optimizeCmpInstr, since optimizeCmpInstr
- // can enable folding by converting SUB to CMP.
- // Save FoldAsLoadDefReg because optimizeLoadInstr() resets it and we
- // need it for markUsesInDebugValueAsUndef().
const MCInstrDesc &MIDesc = MI->getDesc();
for (unsigned i = MIDesc.getNumDefs(); i != MIDesc.getNumOperands();
++i) {
const MachineOperand &MOp = MI->getOperand(i);
if (!MOp.isReg())
continue;
- unsigned TryFoldReg = MOp.getReg();
- if (FoldAsLoadDefCandidates.count(TryFoldReg)) {
+ unsigned FoldAsLoadDefReg = MOp.getReg();
+ if (FoldAsLoadDefCandidates.count(FoldAsLoadDefReg)) {
+ // We need to fold load after optimizeCmpInstr, since
+ // optimizeCmpInstr can enable folding by converting SUB to CMP.
+ // Save FoldAsLoadDefReg because optimizeLoadInstr() resets it and
+ // we need it for markUsesInDebugValueAsUndef().
+ unsigned FoldedReg = FoldAsLoadDefReg;
MachineInstr *DefMI = 0;
- MachineInstr *FoldMI = TII->optimizeLoadInstr(MI, MRI, TryFoldReg,
+ MachineInstr *FoldMI = TII->optimizeLoadInstr(MI, MRI,
+ FoldAsLoadDefReg,
DefMI);
if (FoldMI) {
// Update LocalMIs since we replaced MI with FoldMI and deleted
@@ -655,8 +657,8 @@ bool PeepholeOptimizer::runOnMachineFunction(MachineFunction &MF) {
LocalMIs.insert(FoldMI);
MI->eraseFromParent();
DefMI->eraseFromParent();
- MRI->markUsesInDebugValueAsUndef(TryFoldReg);
- FoldAsLoadDefCandidates.erase(TryFoldReg);
+ MRI->markUsesInDebugValueAsUndef(FoldedReg);
+ FoldAsLoadDefCandidates.erase(FoldedReg);
++NumLoadFold;
// MI is replaced with FoldMI.
Changed = true;
OpenPOWER on IntegriCloud