llvm.org GIT mirror llvm / a21335d
Another thumb large stack offset codegen bug. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@33795 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 13 years ago
1 changed file(s) with 13 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
624624 Offset += MI.getOperand(i+1).getImm();
625625 assert((Offset & 3) == 0 &&
626626 "Thumb add/sub sp, #imm immediate must be multiple of 4!");
627 Offset >>= 2;
628627 if (Offset == 0) {
629628 // Turn it into a move.
630629 MI.setInstrDescriptor(TII.get(ARM::tMOVrr));
634633 }
635634
636635 // Common case: small offset, fits into instruction.
637 if ((Offset & ~255U) == 0) {
636 if (((Offset >> 2) & ~255U) == 0) {
638637 // Replace the FrameIndex with sp / fp
639638 MI.getOperand(i).ChangeToRegister(FrameReg, false);
640 MI.getOperand(i+1).ChangeToImmediate(Offset);
639 MI.getOperand(i+1).ChangeToImmediate(Offset >> 2);
641640 return;
642641 }
643642
644643 unsigned DestReg = MI.getOperand(0).getReg();
644 unsigned Bytes = (Offset > 0) ? Offset : -Offset;
645 unsigned NumMIs = calcNumMI(Opcode, 0, Bytes, 8, 1);
646 // MI would expand into a large number of instructions. Don't try to
647 // simplify the immediate.
648 if (NumMIs > 2) {
649 emitThumbRegPlusImmediate(MBB, II, DestReg, ARM::SP, Offset, TII);
650 MBB.erase(II);
651 return;
652 }
653
645654 if (Offset > 0) {
646655 // Translate r0 = add sp, imm to
647656 // r0 = add sp, 255*4
648657 // r0 = add r0, (imm - 255*4)
649658 MI.getOperand(i).ChangeToRegister(FrameReg, false);
650659 MI.getOperand(i+1).ChangeToImmediate(255);
651 Offset = (Offset - 255) << 2;
660 Offset = (Offset - 255 * 4);
652661 MachineBasicBlock::iterator NII = next(II);
653662 emitThumbRegPlusImmediate(MBB, NII, DestReg, DestReg, Offset, TII);
654663 } else {
655664 // Translate r0 = add sp, -imm to
656665 // r0 = -imm (this is then translated into a series of instructons)
657666 // r0 = add r0, sp
658 Offset <<= 2;
659667 emitThumbConstant(MBB, II, DestReg, Offset, TII);
660668 MI.setInstrDescriptor(TII.get(ARM::tADDhirr));
661669 MI.getOperand(i).ChangeToRegister(DestReg, false);