From 21b3f31f8f7d77b9c3a35012139df92ba40e7c92 Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Wed, 27 Feb 2008 19:57:11 +0000 Subject: [PATCH] Fix a bug in dead spill slot elimination. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@47687 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/llvm/CodeGen/MachineFrameInfo.h | 4 ++ lib/CodeGen/VirtRegMap.cpp | 2 + .../CodeGen/X86/2008-02-27-DeadSlotElimBug.ll | 66 +++++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 test/CodeGen/X86/2008-02-27-DeadSlotElimBug.ll diff --git a/include/llvm/CodeGen/MachineFrameInfo.h b/include/llvm/CodeGen/MachineFrameInfo.h index 4be3bd474e0..3a0432510c8 100644 --- a/include/llvm/CodeGen/MachineFrameInfo.h +++ b/include/llvm/CodeGen/MachineFrameInfo.h @@ -216,6 +216,8 @@ public: int64_t getObjectOffset(int ObjectIdx) const { assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && "Invalid Object Idx!"); + assert(!isDeadObjectIndex(ObjectIdx) && + "Getting frame offset for a dead object?"); return Objects[ObjectIdx+NumFixedObjects].SPOffset; } @@ -225,6 +227,8 @@ public: void setObjectOffset(int ObjectIdx, int64_t SPOffset) { assert(unsigned(ObjectIdx+NumFixedObjects) < Objects.size() && "Invalid Object Idx!"); + assert(!isDeadObjectIndex(ObjectIdx) && + "Setting frame offset for a dead object?"); Objects[ObjectIdx+NumFixedObjects].SPOffset = SPOffset; } diff --git a/lib/CodeGen/VirtRegMap.cpp b/lib/CodeGen/VirtRegMap.cpp index d210d93835d..6cfbee9b7b7 100644 --- a/lib/CodeGen/VirtRegMap.cpp +++ b/lib/CodeGen/VirtRegMap.cpp @@ -914,6 +914,7 @@ bool LocalSpiller::PrepForUnfoldOpti(MachineBasicBlock &MBB, Ops.push_back(Idx); MachineInstr *FoldedMI = TII->foldMemoryOperand(MF, NewMI, Ops, SS); if (FoldedMI) { + VRM.addSpillSlotUse(SS, FoldedMI); if (!VRM.hasPhys(UnfoldVR)) VRM.assignVirt2Phys(UnfoldVR, UnfoldPR); VRM.virtFolded(VirtReg, FoldedMI, VirtRegMap::isRef); @@ -1414,6 +1415,7 @@ void LocalSpiller::RewriteMBB(MachineBasicBlock &MBB, VirtRegMap &VRM) { MBB.insert(MII, NewMIs[0]); NewStore = NewMIs[1]; MBB.insert(MII, NewStore); + VRM.addSpillSlotUse(SS, NewStore); VRM.RemoveMachineInstrFromMaps(&MI); MBB.erase(&MI); Erased = true; diff --git a/test/CodeGen/X86/2008-02-27-DeadSlotElimBug.ll b/test/CodeGen/X86/2008-02-27-DeadSlotElimBug.ll new file mode 100644 index 00000000000..96ac7a7608c --- /dev/null +++ b/test/CodeGen/X86/2008-02-27-DeadSlotElimBug.ll @@ -0,0 +1,66 @@ +; RUN: llvm-as < %s | llc -march=x86 + + %struct.CompAtom = type <{ %struct.Position, float, i32 }> + %struct.Lattice = type { %struct.Position, %struct.Position, %struct.Position, %struct.Position, %struct.Position, %struct.Position, %struct.Position, i32, i32, i32 } + %struct.Position = type { double, double, double } + +define fastcc %struct.CompAtom* @_ZNK7Lattice6createEP8CompAtomii(%struct.Lattice* %this, %struct.CompAtom* %d, i32 %n, i32 %i) { +entry: + %tmp18 = tail call i8* @_Znam( i32 0 ) ; [#uses=1] + %tmp1819 = bitcast i8* %tmp18 to %struct.CompAtom* ; <%struct.CompAtom*> [#uses=4] + %tmp3286 = icmp eq i32 %n, 0 ; [#uses=1] + br i1 %tmp3286, label %bb35, label %bb24 + +bb24: ; preds = %bb24, %entry + %tmp9.0.reg2mem.0.rec = phi i32 [ %indvar.next, %bb24 ], [ 0, %entry ] ; [#uses=3] + %tmp3.i.i = getelementptr %struct.CompAtom* %tmp1819, i32 %tmp9.0.reg2mem.0.rec, i32 0, i32 1 ; [#uses=0] + %tmp5.i.i = getelementptr %struct.CompAtom* %tmp1819, i32 %tmp9.0.reg2mem.0.rec, i32 0, i32 2 ; [#uses=1] + store double -9.999900e+04, double* %tmp5.i.i, align 4 + %indvar.next = add i32 %tmp9.0.reg2mem.0.rec, 1 ; [#uses=2] + %exitcond = icmp eq i32 %indvar.next, %n ; [#uses=1] + br i1 %exitcond, label %bb35, label %bb24 + +bb35: ; preds = %bb24, %entry + %tmp42 = sdiv i32 %i, 9 ; [#uses=1] + %tmp43 = add i32 %tmp42, -1 ; [#uses=1] + %tmp4344 = sitofp i32 %tmp43 to double ; [#uses=1] + %tmp17.i76 = mul double %tmp4344, 0.000000e+00 ; [#uses=1] + %tmp48 = sdiv i32 %i, 3 ; [#uses=1] + %tmp49 = srem i32 %tmp48, 3 ; [#uses=1] + %tmp50 = add i32 %tmp49, -1 ; [#uses=1] + %tmp5051 = sitofp i32 %tmp50 to double ; [#uses=1] + %tmp17.i63 = mul double %tmp5051, 0.000000e+00 ; [#uses=1] + %tmp55 = srem i32 %i, 3 ; [#uses=1] + %tmp56 = add i32 %tmp55, -1 ; [#uses=1] + %tmp5657 = sitofp i32 %tmp56 to double ; [#uses=1] + %tmp15.i49 = getelementptr %struct.Lattice* %this, i32 0, i32 0, i32 0 ; [#uses=1] + %tmp16.i50 = load double* %tmp15.i49, align 4 ; [#uses=1] + %tmp17.i = mul double %tmp5657, %tmp16.i50 ; [#uses=1] + %tmp20.i39 = add double %tmp17.i, %tmp17.i63 ; [#uses=1] + %tmp20.i23 = add double %tmp20.i39, %tmp17.i76 ; [#uses=1] + br i1 false, label %bb58.preheader, label %bb81 + +bb58.preheader: ; preds = %bb35 + %smax = select i1 false, i32 1, i32 %n ; [#uses=1] + br label %bb58 + +bb58: ; preds = %bb58, %bb58.preheader + %tmp20.i7 = getelementptr %struct.CompAtom* %d, i32 0, i32 2 ; [#uses=2] + %tmp25.i = getelementptr %struct.CompAtom* %tmp1819, i32 0, i32 2 ; [#uses=2] + %tmp74.i = load i32* %tmp20.i7, align 1 ; [#uses=1] + %tmp82.i = and i32 %tmp74.i, 134217728 ; [#uses=1] + %tmp85.i = or i32 0, %tmp82.i ; [#uses=1] + store i32 %tmp85.i, i32* %tmp25.i, align 1 + %tmp88.i = load i32* %tmp20.i7, align 1 ; [#uses=1] + %tmp95.i = and i32 %tmp88.i, -268435456 ; [#uses=1] + %tmp97.i = or i32 0, %tmp95.i ; [#uses=1] + store i32 %tmp97.i, i32* %tmp25.i, align 1 + %tmp6.i = add double 0.000000e+00, %tmp20.i23 ; [#uses=0] + %exitcond96 = icmp eq i32 0, %smax ; [#uses=1] + br i1 %exitcond96, label %bb81, label %bb58 + +bb81: ; preds = %bb58, %bb35 + ret %struct.CompAtom* %tmp1819 +} + +declare i8* @_Znam(i32) -- 2.34.1