From e3b8a48d3285cdaf3593af9d4b658e15df037b9f Mon Sep 17 00:00:00 2001 From: Evan Cheng Date: Tue, 5 Aug 2008 21:51:46 +0000 Subject: [PATCH] Fix PR2596: out of bound reference. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@54375 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/VirtRegMap.cpp | 11 ++++-- test/CodeGen/X86/2008-08-06-RewriterBug.ll | 40 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 test/CodeGen/X86/2008-08-06-RewriterBug.ll diff --git a/lib/CodeGen/VirtRegMap.cpp b/lib/CodeGen/VirtRegMap.cpp index b9e96b11e29..c06ff71e6f4 100644 --- a/lib/CodeGen/VirtRegMap.cpp +++ b/lib/CodeGen/VirtRegMap.cpp @@ -560,8 +560,11 @@ static void InvalidateKills(MachineInstr &MI, BitVector &RegKills, if (!MO.isRegister() || !MO.isUse() || !MO.isKill()) continue; unsigned Reg = MO.getReg(); + if (TargetRegisterInfo::isVirtualRegister(Reg)) + continue; if (KillRegs) KillRegs->push_back(Reg); + assert(Reg < KillOps.size()); if (KillOps[Reg] == &MO) { RegKills.reset(Reg); KillOps[Reg] = NULL; @@ -943,9 +946,11 @@ bool LocalSpiller::PrepForUnfoldOpti(MachineBasicBlock &MBB, return false; continue; } - PhysReg = VRM.getPhys(VirtReg); - if (!TRI->regsOverlap(PhysReg, UnfoldPR)) - continue; + if (VRM.hasPhys(VirtReg)) { + PhysReg = VRM.getPhys(VirtReg); + if (!TRI->regsOverlap(PhysReg, UnfoldPR)) + continue; + } // Ok, we'll need to reload the value into a register which makes // it impossible to perform the store unfolding optimization later. diff --git a/test/CodeGen/X86/2008-08-06-RewriterBug.ll b/test/CodeGen/X86/2008-08-06-RewriterBug.ll new file mode 100644 index 00000000000..9371c2a6383 --- /dev/null +++ b/test/CodeGen/X86/2008-08-06-RewriterBug.ll @@ -0,0 +1,40 @@ +; RUN: llvm-as < %s | llc -march=x86 +; PR2596 + +@data = external global [400 x i64] ; <[400 x i64]*> [#uses=5] + +define void @foo(double* noalias, double* noalias) { + load i64* getelementptr ([400 x i64]* @data, i32 0, i64 200), align 4 ; :3 [#uses=1] + load i64* getelementptr ([400 x i64]* @data, i32 0, i64 199), align 4 ; :4 [#uses=1] + load i64* getelementptr ([400 x i64]* @data, i32 0, i64 198), align 4 ; :5 [#uses=2] + load i64* getelementptr ([400 x i64]* @data, i32 0, i64 197), align 4 ; :6 [#uses=1] + br i1 false, label %28, label %7 + +;