Index: lib/Target/AMDGPU/SIISelLowering.cpp =================================================================== --- lib/Target/AMDGPU/SIISelLowering.cpp +++ lib/Target/AMDGPU/SIISelLowering.cpp @@ -3351,8 +3351,13 @@ case AMDGPU::ADJCALLSTACKDOWN: { const SIMachineFunctionInfo *Info = MF->getInfo(); MachineInstrBuilder MIB(*MF, &MI); + + // Add an implicit use of the frame offset reg to prevent the restore copy + // inserted after the call from being reorderd after stack operations in the + // the caller's frame. MIB.addReg(Info->getStackPtrOffsetReg(), RegState::ImplicitDefine) - .addReg(Info->getStackPtrOffsetReg(), RegState::Implicit); + .addReg(Info->getStackPtrOffsetReg(), RegState::Implicit) + .addReg(Info->getFrameOffsetReg(), RegState::Implicit); return BB; } case AMDGPU::SI_CALL_ISEL: Index: test/CodeGen/AMDGPU/call-preserved-registers.ll =================================================================== --- test/CodeGen/AMDGPU/call-preserved-registers.ll +++ test/CodeGen/AMDGPU/call-preserved-registers.ll @@ -34,9 +34,9 @@ ; GCN: s_mov_b32 s33, s5 ; GCN-NEXT: s_swappc_b64 ; GCN-NEXT: s_mov_b32 s5, s33 +; GCN-NEXT: s_mov_b32 s33, s5 ; GCN-NEXT: ;;#ASMSTART ; GCN-NEXT: ;;#ASMEND -; GCN-NEXT: s_mov_b32 s33, s5 ; GCN-NEXT: s_swappc_b64 ; GCN-NEXT: s_mov_b32 s5, s33 ; GCN: v_readlane_b32 s37, v32, 4