From: Jun Bum Lim Date: Fri, 27 Apr 2018 19:59:20 +0000 (+0000) Subject: [PostRASink] extend the live-in check for all aliased registers X-Git-Tag: llvmorg-7.0.0-rc1~7198 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9e3e14b5f90580f1723fd6a3b1546534e21dd6bf;p=platform%2Fupstream%2Fllvm.git [PostRASink] extend the live-in check for all aliased registers Extend the live-in check for all aliased registers so that we can allow sinking Copy instructions when only implicit def is in successor's live-in. llvm-svn: 331072 --- diff --git a/llvm/lib/CodeGen/MachineSink.cpp b/llvm/lib/CodeGen/MachineSink.cpp index f60484d..835c55d 100644 --- a/llvm/lib/CodeGen/MachineSink.cpp +++ b/llvm/lib/CodeGen/MachineSink.cpp @@ -984,12 +984,12 @@ static bool aliasWithRegsInLiveIn(MachineBasicBlock &MBB, unsigned Reg, static MachineBasicBlock * getSingleLiveInSuccBB(MachineBasicBlock &CurBB, - ArrayRef SinkableBBs, unsigned Reg, - const TargetRegisterInfo *TRI) { + const SmallPtrSetImpl &SinkableBBs, + unsigned Reg, const TargetRegisterInfo *TRI) { // Try to find a single sinkable successor in which Reg is live-in. MachineBasicBlock *BB = nullptr; for (auto *SI : SinkableBBs) { - if (SI->isLiveIn(Reg)) { + if (aliasWithRegsInLiveIn(*SI, Reg, TRI)) { // If BB is set here, Reg is live-in to at least two sinkable successors, // so quit. if (BB) @@ -1003,17 +1003,17 @@ getSingleLiveInSuccBB(MachineBasicBlock &CurBB, // Check if any register aliased with Reg is live-in in other successors. for (auto *SI : CurBB.successors()) { - if (SI == BB) - continue; - if (aliasWithRegsInLiveIn(*SI, Reg, TRI)) + if (!SinkableBBs.count(SI) && aliasWithRegsInLiveIn(*SI, Reg, TRI)) return nullptr; } return BB; } -static MachineBasicBlock *getSingleLiveInSuccBB( - MachineBasicBlock &CurBB, ArrayRef SinkableBBs, - ArrayRef DefedRegsInCopy, const TargetRegisterInfo *TRI) { +static MachineBasicBlock * +getSingleLiveInSuccBB(MachineBasicBlock &CurBB, + const SmallPtrSetImpl &SinkableBBs, + ArrayRef DefedRegsInCopy, + const TargetRegisterInfo *TRI) { MachineBasicBlock *SingleBB = nullptr; for (auto DefReg : DefedRegsInCopy) { MachineBasicBlock *BB = @@ -1096,13 +1096,13 @@ bool PostRAMachineSinking::tryToSinkCopy(MachineBasicBlock &CurBB, MachineFunction &MF, const TargetRegisterInfo *TRI, const TargetInstrInfo *TII) { - SmallVector SinkableBBs; + SmallPtrSet SinkableBBs; // FIXME: For now, we sink only to a successor which has a single predecessor // so that we can directly sink COPY instructions to the successor without // adding any new block or branch instruction. for (MachineBasicBlock *SI : CurBB.successors()) if (!SI->livein_empty() && SI->pred_size() == 1) - SinkableBBs.push_back(SI); + SinkableBBs.insert(SI); if (SinkableBBs.empty()) return false; diff --git a/llvm/test/CodeGen/AArch64/post-ra-machine-sink.mir b/llvm/test/CodeGen/AArch64/post-ra-machine-sink.mir index 7014cdd..ca9e9f6 100644 --- a/llvm/test/CodeGen/AArch64/post-ra-machine-sink.mir +++ b/llvm/test/CodeGen/AArch64/post-ra-machine-sink.mir @@ -203,8 +203,43 @@ body: | liveins: $w0, $w19 $w0 = ADDWrr $w0, $w19 RET $x0 +... + --- +# Sink w19 to %bb.3 through %bb.2. +# CHECK-LABEL: name: sinkcopy8 +# CHECK-LABEL: bb.0: +# CHECK-NOT: renamable $w19 = COPY $w0, implicit-def $x19 +# CHECK-LABEL: bb.2: +# CHECK: $w1 = ADDWrr $w1, $w0, implicit $x0 +# CHECK-LABEL: bb.3: +# CHECK: liveins: $x1, $w0 +# CHECK: renamable $w19 = COPY killed $w0, implicit-def $x19 +name: sinkcopy8 +tracksRegLiveness: true +body: | + bb.0: + liveins: $w0, $x1 + $w1 = SUBSWri $w1, 1, 0, implicit-def $nzcv + renamable $w19 = COPY $w0, implicit-def $x19 + Bcc 11, %bb.2, implicit $nzcv + bb.1: + liveins: $x0 + $w19 = COPY $wzr + RET $x0 + + bb.2: + liveins: $w0, $x1, $x19 + $w1 = ADDWrr $w1, $w0, implicit killed $x0 + + bb.3: + liveins: $x1, $x19 + $x0 = ADDXrr $x1, $x19 + RET $x0 +... + +--- # Don't sink w19 as w0 is defined in bb.0. # CHECK-LABEL: name: donotsinkcopy1 # CHECK-LABEL: bb.0: