Index: lib/Target/ARM/ARM.h =================================================================== --- lib/Target/ARM/ARM.h +++ lib/Target/ARM/ARM.h @@ -60,6 +60,7 @@ void initializeARMLoadStoreOptPass(PassRegistry &); void initializeARMPreAllocLoadStoreOptPass(PassRegistry &); void initializeARMConstantIslandsPass(PassRegistry &); +void initializeARMExpandPseudoPass(PassRegistry &); } // end namespace llvm Index: lib/Target/ARM/ARMExpandPseudoInsts.cpp =================================================================== --- lib/Target/ARM/ARMExpandPseudoInsts.cpp +++ lib/Target/ARM/ARMExpandPseudoInsts.cpp @@ -40,6 +40,8 @@ VerifyARMPseudo("verify-arm-pseudo-expand", cl::Hidden, cl::desc("Verify machine code after expanding ARM pseudos")); +#define ARM_EXPAND_PSEUDO_NAME "ARM pseudo instruction expansion pass" + namespace { class ARMExpandPseudo : public MachineFunctionPass { public: @@ -59,7 +61,7 @@ } StringRef getPassName() const override { - return "ARM pseudo instruction expansion pass"; + return ARM_EXPAND_PSEUDO_NAME; } private: @@ -88,6 +90,9 @@ char ARMExpandPseudo::ID = 0; } +INITIALIZE_PASS(ARMExpandPseudo, DEBUG_TYPE, ARM_EXPAND_PSEUDO_NAME, false, + false) + /// TransferImpOps - Transfer implicit operands on the pseudo instruction to /// the instructions created from the expansion. void ARMExpandPseudo::TransferImpOps(MachineInstr &OldMI, @@ -666,6 +671,12 @@ llvm_unreachable("unhandled machine operand type"); } +static MachineOperand makeImplicit(const MachineOperand &MO) { + MachineOperand NewMO = MO; + NewMO.setImplicit(); + return NewMO; +} + void ARMExpandPseudo::ExpandMOV32BitImm(MachineBasicBlock &MBB, MachineBasicBlock::iterator &MBBI) { MachineInstr &MI = *MBBI; @@ -700,6 +711,8 @@ HI16->setMemRefs(MI.memoperands_begin(), MI.memoperands_end()); LO16.addImm(Pred).addReg(PredReg).add(condCodeOp()); HI16.addImm(Pred).addReg(PredReg).add(condCodeOp()); + if (isCC) + LO16.add(makeImplicit(MI.getOperand(1))); TransferImpOps(MI, LO16, HI16); MI.eraseFromParent(); return; @@ -753,6 +766,8 @@ if (RequiresBundling) finalizeBundle(MBB, LO16->getIterator(), MBBI->getIterator()); + if (isCC) + LO16.add(makeImplicit(MI.getOperand(1))); TransferImpOps(MI, LO16, HI16); MI.eraseFromParent(); } @@ -1067,7 +1082,8 @@ MI.getOperand(1).getReg()) .add(MI.getOperand(2)) .addImm(MI.getOperand(3).getImm()) // 'pred' - .add(MI.getOperand(4)); + .add(MI.getOperand(4)) + .add(makeImplicit(MI.getOperand(1))); MI.eraseFromParent(); return true; @@ -1080,7 +1096,8 @@ .add(MI.getOperand(2)) .addImm(MI.getOperand(3).getImm()) // 'pred' .add(MI.getOperand(4)) - .add(condCodeOp()); // 's' bit + .add(condCodeOp()) // 's' bit + .add(makeImplicit(MI.getOperand(1))); MI.eraseFromParent(); return true; @@ -1092,7 +1109,8 @@ .addImm(MI.getOperand(3).getImm()) .addImm(MI.getOperand(4).getImm()) // 'pred' .add(MI.getOperand(5)) - .add(condCodeOp()); // 's' bit + .add(condCodeOp()) // 's' bit + .add(makeImplicit(MI.getOperand(1))); MI.eraseFromParent(); return true; @@ -1105,7 +1123,8 @@ .addImm(MI.getOperand(4).getImm()) .addImm(MI.getOperand(5).getImm()) // 'pred' .add(MI.getOperand(6)) - .add(condCodeOp()); // 's' bit + .add(condCodeOp()) // 's' bit + .add(makeImplicit(MI.getOperand(1))); MI.eraseFromParent(); return true; @@ -1117,7 +1136,8 @@ MI.getOperand(1).getReg()) .addImm(MI.getOperand(2).getImm()) .addImm(MI.getOperand(3).getImm()) // 'pred' - .add(MI.getOperand(4)); + .add(MI.getOperand(4)) + .add(makeImplicit(MI.getOperand(1))); MI.eraseFromParent(); return true; } @@ -1129,7 +1149,8 @@ .addImm(MI.getOperand(2).getImm()) .addImm(MI.getOperand(3).getImm()) // 'pred' .add(MI.getOperand(4)) - .add(condCodeOp()); // 's' bit + .add(condCodeOp()) // 's' bit + .add(makeImplicit(MI.getOperand(1))); MI.eraseFromParent(); return true; @@ -1142,7 +1163,8 @@ .addImm(MI.getOperand(2).getImm()) .addImm(MI.getOperand(3).getImm()) // 'pred' .add(MI.getOperand(4)) - .add(condCodeOp()); // 's' bit + .add(condCodeOp()) // 's' bit + .add(makeImplicit(MI.getOperand(1))); MI.eraseFromParent(); return true; @@ -1165,7 +1187,8 @@ .addImm(MI.getOperand(3).getImm()) .addImm(MI.getOperand(4).getImm()) // 'pred' .add(MI.getOperand(5)) - .add(condCodeOp()); // 's' bit + .add(condCodeOp()) // 's' bit + .add(makeImplicit(MI.getOperand(1))); MI.eraseFromParent(); return true; } Index: lib/Target/ARM/ARMTargetMachine.cpp =================================================================== --- lib/Target/ARM/ARMTargetMachine.cpp +++ lib/Target/ARM/ARMTargetMachine.cpp @@ -91,6 +91,7 @@ initializeARMPreAllocLoadStoreOptPass(Registry); initializeARMConstantIslandsPass(Registry); initializeARMExecutionDepsFixPass(Registry); + initializeARMExpandPseudoPass(Registry); } static std::unique_ptr createTLOF(const Triple &TT) { Index: test/CodeGen/ARM/expand-pseudos.mir =================================================================== --- /dev/null +++ test/CodeGen/ARM/expand-pseudos.mir @@ -0,0 +1,75 @@ +# RUN: llc -run-pass=arm-pseudo -verify-machineinstrs %s -o - | FileCheck %s +--- | + target triple = "armv7---gnueabi" + + define i32 @test1(i32 %x) { + entry: + unreachable + } + define i32 @test2(i32 %x) { + entry: + unreachable + } + define i32 @test3(i32 %x) { + entry: + unreachable + } +... +--- +name: test1 +alignment: 2 +tracksRegLiveness: true +liveins: + - { reg: '%r0', virtual-reg: '' } +body: | + bb.0.entry: + liveins: %r0 + + %r1 = MOVi 2, 14, _, _ + CMPri killed %r0, 0, 14, _, implicit-def %cpsr + %r1 = MOVCCi16 killed %r1, 500, 0, killed %cpsr + %r0 = MOVr killed %r1, 14, _, _ + BX_RET 14, _, implicit %r0 + +... +--- +name: test2 +alignment: 2 +tracksRegLiveness: true +liveins: + - { reg: '%r0', virtual-reg: '' } +body: | + bb.0.entry: + liveins: %r0 + + %r1 = MOVi 2, 14, _, _ + CMPri killed %r0, 0, 14, _, implicit-def %cpsr + %r1 = MOVCCi32imm killed %r1, 500500500, 0, killed %cpsr + %r0 = MOVr killed %r1, 14, _, _ + BX_RET 14, _, implicit %r0 + +... +--- +name: test3 +alignment: 2 +tracksRegLiveness: true +liveins: + - { reg: '%r0', virtual-reg: '' } + - { reg: '%r1', virtual-reg: '' } +body: | + bb.0.entry: + liveins: %r0, %r1 + + CMPri %r1, 500, 14, _, implicit-def %cpsr + %r0 = MOVCCr killed %r0, killed %r1, 12, killed %cpsr + BX_RET 14, _, implicit %r0 + +... + +# CHECK-LABEL: name: test1 +# CHECK: %r1 = MOVi16 500, 0, killed %cpsr, implicit killed %r1 +# CHECK-LABEL: name: test2 +# CHECK: %r1 = MOVi16 2068, 0, %cpsr, implicit killed %r1 +# CHECK: %r1 = MOVTi16 %r1, 7637, 0, %cpsr +# CHECK-LABEL: name: test3 +# CHECK: %r0 = MOVr killed %r1, 12, killed %cpsr, _, implicit killed %r0