Skip to content

Commit d6c3347

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 3799ad8 commit d6c3347

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

llvm/lib/CodeGen/MachineCopyPropagation.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,7 +983,7 @@ static bool isBackwardPropagatableCopy(const DestSourcePair &CopyOperands,
983983
if (MRI.isReserved(Def) || MRI.isReserved(Src))
984984
return false;
985985

986-
return CopyOperands.Source->isRenamable() && CopyOperands.Source->isKill();
986+
return CopyOperands.Source->isKill();
987987
}
988988

989989
void MachineCopyPropagation::propagateDefs(MachineInstr &MI) {
@@ -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/test/CodeGen/RISCV/redundant-copy-from-tail-duplicate.ll

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 4
2-
; RUN: llc < %s -mtriple=riscv64 -mcpu=sifive-x280 | FileCheck %s
2+
; RUN: llc < %s -mtriple=riscv64 -mattr=+v | FileCheck %s
33

44

55
define signext i32 @sum(ptr %a, i32 signext %n, i1 %prof.min.iters.check, <vscale x 8 x i1> %0, <vscale x 8 x i1> %1) {
@@ -20,12 +20,11 @@ define signext i32 @sum(ptr %a, i32 signext %n, i1 %prof.min.iters.check, <vscal
2020
; CHECK-NEXT: ret
2121
; CHECK-NEXT: .LBB0_4: # %vector.ph
2222
; CHECK-NEXT: vsetvli a0, zero, e32, m4, ta, ma
23-
; CHECK-NEXT: vmv.v.i v8, 0
24-
; CHECK-NEXT: vmv.s.x v12, zero
23+
; CHECK-NEXT: vmv.s.x v8, zero
24+
; CHECK-NEXT: vmv.v.i v12, 0
2525
; CHECK-NEXT: vsetivli zero, 1, e32, m4, ta, ma
26-
; CHECK-NEXT: vredsum.vs v8, v8, v12, v0.t
27-
; CHECK-NEXT: vmv.x.s a2, v8
28-
; CHECK-NEXT: mv a0, a2
26+
; CHECK-NEXT: vredsum.vs v8, v12, v8, v0.t
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)