From 508c39393a29d4524d113293bcab0a1c74a2328a Mon Sep 17 00:00:00 2001 From: Oliver Stannard Date: Mon, 20 Oct 2014 11:00:18 +0000 Subject: [PATCH] [Thumb] Fix crash in Thumb1RegisterInfo::rewriteFrameIndex This function can, for some offsets from the SP, split one instruction into two. Since it re-uses the original instruction as the first instruction of the result, we need ensure its result register is not marked as dead before we use it in the second instruction. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@220194 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Target/ARM/Thumb1RegisterInfo.cpp | 1 + test/CodeGen/Thumb/large-stack.ll | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/lib/Target/ARM/Thumb1RegisterInfo.cpp b/lib/Target/ARM/Thumb1RegisterInfo.cpp index d0626311dd1..291e97b0708 100644 --- a/lib/Target/ARM/Thumb1RegisterInfo.cpp +++ b/lib/Target/ARM/Thumb1RegisterInfo.cpp @@ -418,6 +418,7 @@ rewriteFrameIndex(MachineBasicBlock::iterator II, unsigned FrameRegIdx, } Offset = (Offset - Mask * Scale); MachineBasicBlock::iterator NII = std::next(II); + MI.getOperand(0).setIsDead(false); emitThumbRegPlusImmediate(MBB, NII, dl, DestReg, DestReg, Offset, TII, *this); } else { diff --git a/test/CodeGen/Thumb/large-stack.ll b/test/CodeGen/Thumb/large-stack.ll index fb6daa47865..c371ac62a90 100644 --- a/test/CodeGen/Thumb/large-stack.ll +++ b/test/CodeGen/Thumb/large-stack.ll @@ -33,3 +33,22 @@ define i32 @test3() { %tmp1 = load i32* %tmp ret i32 %tmp1 } + +; Here, the adds get optimized out because they are dead, but the calculation +; of the address of stack_a is dead but not optimized out. When the address +; calculation gets expanded to two instructions, we need to avoid reading a +; dead register. +; No CHECK lines (just test for crashes), as we hope this will be optimised +; better in future. +define i32 @test4() { +entry: + %stack_a = alloca i8, align 1 + %stack_b = alloca [256 x i32*], align 4 + %int = ptrtoint i8* %stack_a to i32 + %add = add i32 %int, 1 + br label %block2 + +block2: + %add2 = add i32 %add, 1 + ret i32 0 +} -- 2.34.1