From 4cafbb58e2c54138f05b9857db4a098a15e914ca Mon Sep 17 00:00:00 2001 From: Owen Anderson Date: Fri, 20 Feb 2009 10:02:23 +0000 Subject: [PATCH] Fix a crash in the pre-alloc splitter exposed by recent codegen changes. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@65121 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/PreAllocSplitting.cpp | 6 ++ .../X86/2009-02-20-PreAllocSplit-Crash.ll | 71 +++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 test/CodeGen/X86/2009-02-20-PreAllocSplit-Crash.ll diff --git a/lib/CodeGen/PreAllocSplitting.cpp b/lib/CodeGen/PreAllocSplitting.cpp index ef2cfdb9828..9e955bd6969 100644 --- a/lib/CodeGen/PreAllocSplitting.cpp +++ b/lib/CodeGen/PreAllocSplitting.cpp @@ -224,6 +224,9 @@ PreAllocSplitting::findSpillPoint(MachineBasicBlock *MBB, MachineInstr *MI, if (RefsInMBB.empty() && !DefMI) { MachineBasicBlock::iterator MII = MBB->begin(); MachineBasicBlock::iterator EndPt = MI; + + if (MII == EndPt) return Pt; + do { ++MII; unsigned Index = LIs->getInstructionIndex(MII); @@ -303,6 +306,9 @@ PreAllocSplitting::findRestorePoint(MachineBasicBlock *MBB, MachineInstr *MI, if (RefsInMBB.empty() && LastIdx >= EndIdx) { MachineBasicBlock::iterator MII = MBB->getFirstTerminator(); MachineBasicBlock::iterator EndPt = MI; + + if (MII == EndPt) return Pt; + --MII; do { unsigned Index = LIs->getInstructionIndex(MII); diff --git a/test/CodeGen/X86/2009-02-20-PreAllocSplit-Crash.ll b/test/CodeGen/X86/2009-02-20-PreAllocSplit-Crash.ll new file mode 100644 index 00000000000..54fcd430e98 --- /dev/null +++ b/test/CodeGen/X86/2009-02-20-PreAllocSplit-Crash.ll @@ -0,0 +1,71 @@ +; RUN: llvm-as < %s | llc -march=x86 -mtriple=i386-apple-darwin8 -pre-alloc-split + +define i32 @main() nounwind { +bb4.i.thread: + br label %bb5.i4 + +bb16: ; preds = %bb111.i + %phitmp = add i32 %indvar.reg2mem.4, 1 ; [#uses=2] + switch i32 %indvar.reg2mem.4, label %bb100.i [ + i32 0, label %bb5.i4 + i32 1, label %bb5.i4 + i32 2, label %bb5.i4 + i32 5, label %bb.i14.i + i32 6, label %bb.i14.i + i32 7, label %bb.i14.i + ] + +bb5.i4: ; preds = %bb16, %bb16, %bb16, %bb4.i.thread + br i1 false, label %bb102.i, label %bb103.i + +bb.i14.i: ; preds = %bb16, %bb16, %bb16 + %0 = malloc [600 x i32] ; <[600 x i32]*> [#uses=0] + %1 = icmp eq i32 %phitmp, 7 ; [#uses=1] + %tl.0.i = select i1 %1, float 1.000000e+02, float 1.000000e+00 ; [#uses=1] + %2 = icmp eq i32 %phitmp, 8 ; [#uses=1] + %tu.0.i = select i1 %2, float 1.000000e+02, float 1.000000e+00 ; [#uses=1] + br label %bb30.i + +bb30.i: ; preds = %bb36.i, %bb.i14.i + %i.1173.i = phi i32 [ 0, %bb.i14.i ], [ %indvar.next240.i, %bb36.i ] ; [#uses=3] + %3 = icmp eq i32 0, %i.1173.i ; [#uses=1] + br i1 %3, label %bb33.i, label %bb34.i + +bb33.i: ; preds = %bb30.i + store float %tl.0.i, float* null, align 4 + br label %bb36.i + +bb34.i: ; preds = %bb30.i + %4 = icmp eq i32 0, %i.1173.i ; [#uses=1] + br i1 %4, label %bb35.i, label %bb36.i + +bb35.i: ; preds = %bb34.i + store float %tu.0.i, float* null, align 4 + br label %bb36.i + +bb36.i: ; preds = %bb35.i, %bb34.i, %bb33.i + %indvar.next240.i = add i32 %i.1173.i, 1 ; [#uses=1] + br label %bb30.i + +bb100.i: ; preds = %bb16 + ret i32 0 + +bb102.i: ; preds = %bb5.i4 + br label %bb103.i + +bb103.i: ; preds = %bb102.i, %bb5.i4 + %indvar.reg2mem.4 = phi i32 [ 0, %bb5.i4 ], [ 0, %bb102.i ] ; [#uses=2] + %n.0.reg2mem.1.i = phi i32 [ 0, %bb102.i ], [ 0, %bb5.i4 ] ; [#uses=1] + %5 = icmp eq i32 0, 0 ; [#uses=1] + br i1 %5, label %bb111.i, label %bb108.i + +bb108.i: ; preds = %bb103.i + ret i32 0 + +bb111.i: ; preds = %bb103.i + %6 = icmp sgt i32 %n.0.reg2mem.1.i, 7 ; [#uses=1] + br i1 %6, label %bb16, label %bb112.i + +bb112.i: ; preds = %bb111.i + unreachable +} -- 2.34.1