From 76bb4139dc67e205f139f536c10fd98582367f83 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Fri, 16 Dec 2016 23:55:43 +0000 Subject: [PATCH] AArch64: Enable post-ra liveness updates Differential Revision: https://reviews.llvm.org/D27559 llvm-svn: 290014 --- llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp | 7 ++++++- llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp | 3 +++ llvm/lib/Target/AArch64/AArch64RegisterInfo.h | 4 ++++ llvm/test/CodeGen/AArch64/ldst-opt-dbg-limit.mir | 10 +++++----- llvm/test/CodeGen/AArch64/movimm-wzr.mir | 2 +- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp b/llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp index 94b208a..fe1c0be 100644 --- a/llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp +++ b/llvm/lib/Target/AArch64/AArch64ExpandPseudoInsts.cpp @@ -897,9 +897,14 @@ bool AArch64ExpandPseudo::expandMI(MachineBasicBlock &MBB, case AArch64::MOVi64imm: return expandMOVImm(MBB, MBBI, 64); case AArch64::RET_ReallyLR: { + // Hiding the LR use with RET_ReallyLR may lead to extra kills in the + // function and missing live-ins. We are fine in practice because callee + // saved register handling ensures the register value is restored before + // RET, but we need the undef flag here to appease the MachineVerifier + // liveness checks. MachineInstrBuilder MIB = BuildMI(MBB, MBBI, MI.getDebugLoc(), TII->get(AArch64::RET)) - .addReg(AArch64::LR); + .addReg(AArch64::LR, RegState::Undef); transferImpOps(MI, MIB, MIB); MI.eraseFromParent(); return true; diff --git a/llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp b/llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp index 6e157638..dcb0560 100644 --- a/llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp +++ b/llvm/lib/Target/AArch64/AArch64LoadStoreOptimizer.cpp @@ -767,6 +767,7 @@ AArch64LoadStoreOpt::promoteLoadFromStore(MachineBasicBlock::iterator LoadI, // Remove the load, if the destination register of the loads is the same // register for stored value. if (StRt == LdRt && LoadSize == 8) { + StoreI->clearRegisterKills(StRt, TRI); DEBUG(dbgs() << "Remove load instruction:\n "); DEBUG(LoadI->print(dbgs())); DEBUG(dbgs() << "\n"); @@ -831,6 +832,8 @@ AArch64LoadStoreOpt::promoteLoadFromStore(MachineBasicBlock::iterator LoadI, .addImm(Imms); } } + StoreI->clearRegisterKills(StRt, TRI); + (void)BitExtMI; DEBUG(dbgs() << "Promoting load by replacing :\n "); diff --git a/llvm/lib/Target/AArch64/AArch64RegisterInfo.h b/llvm/lib/Target/AArch64/AArch64RegisterInfo.h index 098657f..8ce8935 100644 --- a/llvm/lib/Target/AArch64/AArch64RegisterInfo.h +++ b/llvm/lib/Target/AArch64/AArch64RegisterInfo.h @@ -95,6 +95,10 @@ public: unsigned getRegPressureLimit(const TargetRegisterClass *RC, MachineFunction &MF) const override; + + bool trackLivenessAfterRegAlloc(const MachineFunction&) const override { + return true; + } }; } // end namespace llvm diff --git a/llvm/test/CodeGen/AArch64/ldst-opt-dbg-limit.mir b/llvm/test/CodeGen/AArch64/ldst-opt-dbg-limit.mir index 88a4b2c..45542ca 100644 --- a/llvm/test/CodeGen/AArch64/ldst-opt-dbg-limit.mir +++ b/llvm/test/CodeGen/AArch64/ldst-opt-dbg-limit.mir @@ -28,7 +28,7 @@ name: promote-load-from-store alignment: 2 exposesReturnsTwice: false -tracksRegLiveness: false +tracksRegLiveness: true liveins: - { reg: '%x0' } - { reg: '%w1' } @@ -48,7 +48,7 @@ frameInfo: hasMustTailInVarArgFunc: false body: | bb.0 (%ir-block.0): - liveins: %w1, %x0 + liveins: %w1, %x0, %lr STRWui killed %w1, %x0, 0 :: (store 4 into %ir.dst) CFI_INSTRUCTION 0 @@ -76,13 +76,13 @@ body: | ... # CHECK-LABEL: name: promote-load-from-store -# CHECK: STRWui killed %w1 +# CHECK: STRWui %w1 # CHECK: UBFMWri %w1 --- name: store-pair alignment: 2 exposesReturnsTwice: false -tracksRegLiveness: false +tracksRegLiveness: true liveins: - { reg: '%x0' } - { reg: '%w1' } @@ -102,7 +102,7 @@ frameInfo: hasMustTailInVarArgFunc: false body: | bb.0 (%ir-block.0): - liveins: %w1, %x0 + liveins: %w1, %x0, %lr STRWui %w1, %x0, 0 :: (store 4 into %ir.dst01) CFI_INSTRUCTION 0 diff --git a/llvm/test/CodeGen/AArch64/movimm-wzr.mir b/llvm/test/CodeGen/AArch64/movimm-wzr.mir index c6bfcf1..093f85b 100644 --- a/llvm/test/CodeGen/AArch64/movimm-wzr.mir +++ b/llvm/test/CodeGen/AArch64/movimm-wzr.mir @@ -39,4 +39,4 @@ body: | ... # CHECK: bb.0 -# CHECK-NEXT: RET %lr +# CHECK-NEXT: RET undef %lr -- 2.7.4