Index: llvm/lib/Target/ARM/ARMLoadStoreOptimizer.cpp =================================================================== --- llvm/lib/Target/ARM/ARMLoadStoreOptimizer.cpp +++ llvm/lib/Target/ARM/ARMLoadStoreOptimizer.cpp @@ -587,7 +587,7 @@ } for (unsigned Reg : RegClassInfo.getOrder(&RegClass)) - if (!LiveRegs.contains(Reg)) + if (LiveRegs.available(MF->getRegInfo(), Reg)) return Reg; return 0; } Index: llvm/lib/Target/ARM/Thumb1FrameLowering.cpp =================================================================== --- llvm/lib/Target/ARM/Thumb1FrameLowering.cpp +++ llvm/lib/Target/ARM/Thumb1FrameLowering.cpp @@ -582,10 +582,10 @@ static void findTemporariesForLR(const BitVector &GPRsNoLRSP, const BitVector &PopFriendly, const LivePhysRegs &UsedRegs, unsigned &PopReg, - unsigned &TmpReg) { + unsigned &TmpReg, MachineRegisterInfo &MRI) { PopReg = TmpReg = 0; for (auto Reg : GPRsNoLRSP.set_bits()) { - if (!UsedRegs.contains(Reg)) { + if (UsedRegs.available(MRI, Reg)) { // Remember the first pop-friendly register and exit. if (PopFriendly.test(Reg)) { PopReg = Reg; @@ -693,7 +693,8 @@ GPRsNoLRSP.reset(ARM::LR); GPRsNoLRSP.reset(ARM::SP); GPRsNoLRSP.reset(ARM::PC); - findTemporariesForLR(GPRsNoLRSP, PopFriendly, UsedRegs, PopReg, TemporaryReg); + findTemporariesForLR(GPRsNoLRSP, PopFriendly, UsedRegs, PopReg, TemporaryReg, + MF.getRegInfo()); // If we couldn't find a pop-friendly register, try restoring LR before // popping the other callee-saved registers, so we could use one of them as a @@ -704,7 +705,8 @@ PrevMBBI--; if (PrevMBBI->getOpcode() == ARM::tPOP) { UsedRegs.stepBackward(*PrevMBBI); - findTemporariesForLR(GPRsNoLRSP, PopFriendly, UsedRegs, PopReg, TemporaryReg); + findTemporariesForLR(GPRsNoLRSP, PopFriendly, UsedRegs, PopReg, + TemporaryReg, MF.getRegInfo()); if (PopReg) { MBBI = PrevMBBI; UseLDRSP = true; Index: llvm/test/CodeGen/Thumb/PR35481.ll =================================================================== --- llvm/test/CodeGen/Thumb/PR35481.ll +++ llvm/test/CodeGen/Thumb/PR35481.ll @@ -18,10 +18,11 @@ ; CHECK-V4T-NEXT: movs r2, #3 ; CHECK-V4T-NEXT: movs r3, #4 ; CHECK-V4T-NEXT: bl g -; CHECK-V4T-NEXT: ldr r7, [sp, #4] -; CHECK-V4T-NEXT: mov lr, r7 ; CHECK-V4T-NEXT: pop {r7} -; CHECK-V4T-NEXT: add sp, #4 +; CHECK-V4T-NEXT: mov r12, r0 +; CHECK-V4T-NEXT: pop {r0} +; CHECK-V4T-NEXT: mov lr, r0 +; CHECK-V4T-NEXT: mov r0, r12 ; CHECK-V4T-NEXT: bx lr ; ; CHECK-V8M-LABEL: f: @@ -35,10 +36,11 @@ ; CHECK-V8M-NEXT: movs r1, #2 ; CHECK-V8M-NEXT: movs r2, #3 ; CHECK-V8M-NEXT: movs r3, #4 -; CHECK-V8M-NEXT: ldr r7, [sp, #4] -; CHECK-V8M-NEXT: mov lr, r7 ; CHECK-V8M-NEXT: pop {r7} -; CHECK-V8M-NEXT: add sp, #4 +; CHECK-V8M-NEXT: mov r12, r0 +; CHECK-V8M-NEXT: pop {r0} +; CHECK-V8M-NEXT: mov lr, r0 +; CHECK-V8M-NEXT: mov r0, r12 ; CHECK-V8M-NEXT: b g entry: %call = tail call i32 @h(i32 1)