Index: lib/Target/ARM/Thumb1FrameLowering.cpp =================================================================== --- lib/Target/ARM/Thumb1FrameLowering.cpp +++ lib/Target/ARM/Thumb1FrameLowering.cpp @@ -555,6 +555,21 @@ MBB.erase(MBBI); MBBI = MBB.end(); AddBx = true; + } else { + // Handle the case tPOP is followed by some other instruction. + int Index = -1; + auto Pop = MBBI; + while (Pop != MBB.begin()) { + if (Pop->getOpcode() == ARM::tPOP) { + Index = Pop->findRegisterDefOperandIdx(ARM::LR); + if (Index != -1) { + Pop->RemoveOperand(Index); + break; + } + } + --Pop; + } + assert(Index != -1 && "Did not find tPOP with LR operand"); } assert(PopReg && "Do not know how to get LR"); Index: test/CodeGen/Thumb/thumb-pop.ll =================================================================== --- /dev/null +++ test/CodeGen/Thumb/thumb-pop.ll @@ -0,0 +1,22 @@ +; RUN: llc < %s -mtriple=thumbv5e-none-linux-gnueabi-eabi -verify-machineinstrs -o - | FileCheck %s + +define i32 @test(i32 %value) { +; CHECK-LABEL: test: +; CHECK-NOT: pop {[[POP_REG:r[0-7]]], lr} +entry: + %cmp = icmp slt i32 %value, 50 + br i1 %cmp, label %if.then, label %if.else + +if.then: ; preds = %entry + %div = sdiv i32 5000, %value + br label %if.end + +if.else: ; preds = %entry + %mul = shl nsw i32 %value, 1 + %sub = sub nsw i32 200, %mul + br label %if.end + +if.end: ; preds = %if.else, %if.then + %value.addr.0 = phi i32 [ %div, %if.then ], [ %sub, %if.else ] + ret i32 %value.addr.0 +}