diff options
author | Jun Bum Lim <junbuml@codeaurora.org> | 2018-04-27 19:59:20 +0000 |
---|---|---|
committer | Jun Bum Lim <junbuml@codeaurora.org> | 2018-04-27 19:59:20 +0000 |
commit | 9e3e14b5f90580f1723fd6a3b1546534e21dd6bf (patch) | |
tree | e5daf9a3f6006f92ea0163d2bdc77b391f596656 | |
parent | 27fe8a50110a5249ac68469c9fc27fa75b42ac3c (diff) | |
download | bcm5719-llvm-9e3e14b5f90580f1723fd6a3b1546534e21dd6bf.tar.gz bcm5719-llvm-9e3e14b5f90580f1723fd6a3b1546534e21dd6bf.zip |
[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
-rw-r--r-- | llvm/lib/CodeGen/MachineSink.cpp | 22 | ||||
-rw-r--r-- | llvm/test/CodeGen/AArch64/post-ra-machine-sink.mir | 35 |
2 files changed, 46 insertions, 11 deletions
diff --git a/llvm/lib/CodeGen/MachineSink.cpp b/llvm/lib/CodeGen/MachineSink.cpp index f60484d42f6..835c55d8c7c 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<MachineBasicBlock *> SinkableBBs, unsigned Reg, - const TargetRegisterInfo *TRI) { + const SmallPtrSetImpl<MachineBasicBlock *> &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<MachineBasicBlock *> SinkableBBs, - ArrayRef<unsigned> DefedRegsInCopy, const TargetRegisterInfo *TRI) { +static MachineBasicBlock * +getSingleLiveInSuccBB(MachineBasicBlock &CurBB, + const SmallPtrSetImpl<MachineBasicBlock *> &SinkableBBs, + ArrayRef<unsigned> 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<MachineBasicBlock *, 2> SinkableBBs; + SmallPtrSet<MachineBasicBlock *, 2> 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 7014cddd277..ca9e9f6c1c6 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: |