llvm.org GIT mirror llvm / 3d06cf4
Fix one more Thumb eliminateFrameIndex bug. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@34990 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 13 years ago
1 changed file(s) with 23 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
397397 Bytes -= ThisVal;
398398 NumMIs++;
399399 NumBits = 8;
400 Scale = 1;
400 Scale = 1; // Followed by a number of tADDi8.
401401 Chunk = ((1 << NumBits) - 1) * Scale;
402402 }
403403
684684 const TargetInstrDescriptor &Desc = TII.get(Opcode);
685685 unsigned AddrMode = (Desc.TSFlags & ARMII::AddrModeMask);
686686 bool isSub = false;
687
687
688688 if (Opcode == ARM::ADDri) {
689689 Offset += MI.getOperand(i+1).getImm();
690690 if (Offset == 0) {
723723 MI.getOperand(i+1).ChangeToImmediate(ThisSOImmVal);
724724 } else if (Opcode == ARM::tADDrSPi) {
725725 Offset += MI.getOperand(i+1).getImm();
726 assert((Offset & 3) == 0 &&
727 "Thumb add/sub sp, #imm immediate must be multiple of 4!");
726
727 // Can't use tADDrSPi if it's based off the frame pointer.
728 unsigned NumBits = 0;
729 unsigned Scale = 1;
730 if (FrameReg != ARM::SP) {
731 Opcode = ARM::tADDi3;
732 MI.setInstrDescriptor(TII.get(ARM::tADDi3));
733 NumBits = 3;
734 } else {
735 NumBits = 8;
736 Scale = 4;
737 assert((Offset & 3) == 0 &&
738 "Thumb add/sub sp, #imm immediate must be multiple of 4!");
739 }
740
728741 if (Offset == 0) {
729742 // Turn it into a move.
730743 MI.setInstrDescriptor(TII.get(ARM::tMOVrr));
734747 }
735748
736749 // Common case: small offset, fits into instruction.
737 if (((Offset >> 2) & ~255U) == 0) {
750 unsigned Mask = (1 << NumBits) - 1;
751 if (((Offset / Scale) & ~Mask) == 0) {
738752 // Replace the FrameIndex with sp / fp
739753 MI.getOperand(i).ChangeToRegister(FrameReg, false);
740 MI.getOperand(i+1).ChangeToImmediate(Offset >> 2);
754 MI.getOperand(i+1).ChangeToImmediate(Offset / Scale);
741755 return;
742756 }
743757
744758 unsigned DestReg = MI.getOperand(0).getReg();
745759 unsigned Bytes = (Offset > 0) ? Offset : -Offset;
746 unsigned NumMIs = calcNumMI(Opcode, 0, Bytes, 8, 1);
760 unsigned NumMIs = calcNumMI(Opcode, 0, Bytes, NumBits, Scale);
747761 // MI would expand into a large number of instructions. Don't try to
748762 // simplify the immediate.
749763 if (NumMIs > 2) {
757771 // r0 = add sp, 255*4
758772 // r0 = add r0, (imm - 255*4)
759773 MI.getOperand(i).ChangeToRegister(FrameReg, false);
760 MI.getOperand(i+1).ChangeToImmediate(255);
761 Offset = (Offset - 255 * 4);
774 MI.getOperand(i+1).ChangeToImmediate(Mask);
775 Offset = (Offset - Mask * Scale);
762776 MachineBasicBlock::iterator NII = next(II);
763777 emitThumbRegPlusImmediate(MBB, NII, DestReg, DestReg, Offset, TII);
764778 } else {