Skip to content

Commit b8838e5

Browse files
committed
[RISCV] Remove redundant move from tail duplication
Tail duplication will generate the redundant move before return. It is because the MachineCopyPropogation can't recognize COPY after post-RA pseudoExpand. This patch 1. Keep renamable after post-RA pseudoExpand 2. Let MachineCopyPropogation recognize `%0 = ADDI %1, 0` as COPY
1 parent e005db7 commit b8838e5

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

llvm/lib/CodeGen/MachineCopyPropagation.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@ void MachineCopyPropagation::BackwardCopyPropagateBlock(
10531053
// Ignore non-trivial COPYs.
10541054
std::optional<DestSourcePair> CopyOperands =
10551055
isCopyInstr(MI, *TII, UseCopyInstr);
1056-
if (CopyOperands && MI.getNumOperands() == 2) {
1056+
if (CopyOperands) {
10571057
Register DefReg = CopyOperands->Destination->getReg();
10581058
Register SrcReg = CopyOperands->Source->getReg();
10591059

llvm/lib/Target/RISCV/RISCVInstrInfo.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -424,9 +424,11 @@ void RISCVInstrInfo::copyPhysReg(MachineBasicBlock &MBB,
424424
const TargetRegisterInfo *TRI = STI.getRegisterInfo();
425425

426426
if (RISCV::GPRRegClass.contains(DstReg, SrcReg)) {
427-
BuildMI(MBB, MBBI, DL, get(RISCV::ADDI), DstReg)
428-
.addReg(SrcReg, getKillRegState(KillSrc))
429-
.addImm(0);
427+
auto MI = BuildMI(MBB, MBBI, DL, get(RISCV::ADDI), DstReg)
428+
.addReg(SrcReg, getKillRegState(KillSrc))
429+
.addImm(0);
430+
MI->getOperand(0).setIsRenamable(MBBI->getOperand(0).isRenamable());
431+
MI->getOperand(1).setIsRenamable(MBBI->getOperand(1).isRenamable());
430432
return;
431433
}
432434

llvm/test/CodeGen/RISCV/redundant-copy-from-tail-duplicate.ll

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ define signext i32 @sum(ptr %a, i32 signext %n, i1 %prof.min.iters.check, <vscal
2424
; CHECK-NEXT: vmv.s.x v12, zero
2525
; CHECK-NEXT: vsetivli zero, 1, e32, m4, ta, ma
2626
; CHECK-NEXT: vredsum.vs v8, v8, v12, v0.t
27-
; CHECK-NEXT: vmv.x.s a2, v8
28-
; CHECK-NEXT: mv a0, a2
27+
; CHECK-NEXT: vmv.x.s a0, v8
2928
; CHECK-NEXT: ret
3029
entry:
3130
br i1 %prof.min.iters.check, label %for.body, label %vector.ph

0 commit comments

Comments
 (0)