[llvm-branch-commits] [llvm-branch] r68792 - in /llvm/branches/Apple/Dib: lib/CodeGen/MachineSink.cpp test/CodeGen/Generic/2009-04-10-SinkCrash.ll
Bill Wendling
isanbard at gmail.com
Fri Apr 10 10:21:39 PDT 2009
Author: void
Date: Fri Apr 10 12:21:39 2009
New Revision: 68792
URL: http://llvm.org/viewvc/llvm-project?rev=68792&view=rev
Log:
--- Merging (from foreign repository) r68787 into '.':
A test/CodeGen/Generic/2009-04-10-SinkCrash.ll
U lib/CodeGen/MachineSink.cpp
fix two problems with machine sinking:
1. Sinking would crash when the first instruction of a block was
sunk due to iterator problems.
2. Instructions could be sunk to their current block, causing an
infinite loop.
This fixes PR3968
Added:
llvm/branches/Apple/Dib/test/CodeGen/Generic/2009-04-10-SinkCrash.ll
Modified:
llvm/branches/Apple/Dib/lib/CodeGen/MachineSink.cpp
Modified: llvm/branches/Apple/Dib/lib/CodeGen/MachineSink.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/lib/CodeGen/MachineSink.cpp?rev=68792&r1=68791&r2=68792&view=diff
==============================================================================
--- llvm/branches/Apple/Dib/lib/CodeGen/MachineSink.cpp (original)
+++ llvm/branches/Apple/Dib/lib/CodeGen/MachineSink.cpp Fri Apr 10 12:21:39 2009
@@ -111,20 +111,29 @@
}
bool MachineSinking::ProcessBlock(MachineBasicBlock &MBB) {
- bool MadeChange = false;
-
// Can't sink anything out of a block that has less than two successors.
- if (MBB.succ_size() <= 1) return false;
-
+ if (MBB.succ_size() <= 1 || MBB.empty()) return false;
+
+ bool MadeChange = false;
+
// Walk the basic block bottom-up. Remember if we saw a store.
- bool SawStore = false;
- for (MachineBasicBlock::iterator I = MBB.end(); I != MBB.begin(); ){
- MachineBasicBlock::iterator LastIt = I;
- if (SinkInstruction(--I, SawStore)) {
- I = LastIt;
- ++NumSunk;
- }
- }
+ MachineBasicBlock::iterator I = MBB.end();
+ --I;
+ bool ProcessedBegin, SawStore = false;
+ do {
+ MachineInstr *MI = I; // The instruction to sink.
+
+ // Predecrement I (if it's not begin) so that it isn't invalidated by
+ // sinking.
+ ProcessedBegin = I == MBB.begin();
+ if (!ProcessedBegin)
+ --I;
+
+ if (SinkInstruction(MI, SawStore))
+ ++NumSunk, MadeChange = true;
+
+ // If we just processed the first instruction in the block, we're done.
+ } while (!ProcessedBegin);
return MadeChange;
}
@@ -218,6 +227,11 @@
if (SuccToSinkTo->isLandingPad())
return false;
+ // If is not possible to sink an instruction into its own block. This can
+ // happen with loops.
+ if (MI->getParent() == SuccToSinkTo)
+ return false;
+
DEBUG(cerr << "Sink instr " << *MI);
DEBUG(cerr << "to block " << *SuccToSinkTo);
Added: llvm/branches/Apple/Dib/test/CodeGen/Generic/2009-04-10-SinkCrash.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Dib/test/CodeGen/Generic/2009-04-10-SinkCrash.ll?rev=68792&view=auto
==============================================================================
--- llvm/branches/Apple/Dib/test/CodeGen/Generic/2009-04-10-SinkCrash.ll (added)
+++ llvm/branches/Apple/Dib/test/CodeGen/Generic/2009-04-10-SinkCrash.ll Fri Apr 10 12:21:39 2009
@@ -0,0 +1,16 @@
+; RUN: llvm-as < %s | llc
+
+define void @QRiterate(i32 %p.1, double %tmp.212) nounwind {
+entry:
+ br i1 false, label %shortcirc_next.1, label %exit.1.critedge
+
+shortcirc_next.1: ; preds = %shortcirc_next.1, %entry
+ %tmp.213 = fcmp une double %tmp.212, 0.000000e+00 ; <i1> [#uses=1]
+ br i1 %tmp.213, label %shortcirc_next.1, label %exit.1
+
+exit.1.critedge: ; preds = %entry
+ ret void
+
+exit.1: ; preds = %shortcirc_next.1
+ ret void
+}
More information about the llvm-branch-commits
mailing list