Skip to content

Commit 09fd96c

Browse files
committed
[MachineCopyPropagation] Remove logic to recognise and delete no-op moves produced after forwarded uses
As reported in <#166870>, some copies with src==reg are not no-ops, e.g. when self-assigning a w-reg on AArch64 which will zero-extend the corresponding x register. Revert in order to fix the issue. We may revisit whether the optimisation can be made safe at a later point. Reverts dffbc03.
1 parent 94a7006 commit 09fd96c

File tree

5 files changed

+14
-12
lines changed

5 files changed

+14
-12
lines changed

llvm/lib/CodeGen/MachineCopyPropagation.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -937,16 +937,6 @@ void MachineCopyPropagation::ForwardCopyPropagateBlock(MachineBasicBlock &MBB) {
937937
if (CopyOperands) {
938938
Register RegSrc = CopyOperands->Source->getReg();
939939
Register RegDef = CopyOperands->Destination->getReg();
940-
// It's possible that the previous transformations have resulted in a
941-
// no-op register move (i.e. one where source and destination registers
942-
// are the same and are not referring to a reserved register). If so,
943-
// delete it.
944-
if (RegSrc == RegDef && !MRI->isReserved(RegSrc)) {
945-
MI.eraseFromParent();
946-
NumDeletes++;
947-
Changed = true;
948-
continue;
949-
}
950940

951941
if (!TRI->regsOverlap(RegDef, RegSrc)) {
952942
// Copy is now a candidate for deletion.

llvm/test/CodeGen/RISCV/GlobalISel/constbarrier-rv32.ll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,12 @@ define void @constant_fold_barrier_i128(ptr %p) {
3232
; RV32-NEXT: mv a6, a1
3333
; RV32-NEXT: seqz a7, a1
3434
; RV32-NEXT: and a1, a7, a1
35+
; RV32-NEXT: mv a1, a1
3536
; RV32-NEXT: mv a7, a1
3637
; RV32-NEXT: seqz a3, a1
3738
; RV32-NEXT: and a1, a3, a1
39+
; RV32-NEXT: mv a1, a1
40+
; RV32-NEXT: mv a1, a1
3841
; RV32-NEXT: sw a2, 0(a0)
3942
; RV32-NEXT: sw a6, 4(a0)
4043
; RV32-NEXT: sw a7, 8(a0)

llvm/test/CodeGen/RISCV/GlobalISel/div-by-constant.ll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,15 +103,18 @@ define i64 @udiv64_constant_no_add(i64 %a) nounwind {
103103
; RV32-NEXT: mulhu a1, a1, a2
104104
; RV32-NEXT: add a5, a5, a6
105105
; RV32-NEXT: mv t0, t1
106+
; RV32-NEXT: mv a1, a1
106107
; RV32-NEXT: sltu a4, a5, a6
107108
; RV32-NEXT: add a5, a5, a7
108109
; RV32-NEXT: sltu a6, t1, t1
109110
; RV32-NEXT: sltiu t1, t1, 0
110111
; RV32-NEXT: add t0, t0, t2
112+
; RV32-NEXT: mv a1, a1
111113
; RV32-NEXT: sltu a2, a5, a7
112114
; RV32-NEXT: add a6, a6, t1
113115
; RV32-NEXT: sltu a5, t0, t2
114116
; RV32-NEXT: add t0, t0, a0
117+
; RV32-NEXT: mv a1, a1
115118
; RV32-NEXT: add a2, a4, a2
116119
; RV32-NEXT: add a5, a6, a5
117120
; RV32-NEXT: sltu a0, t0, a0
@@ -155,6 +158,7 @@ define i64 @udiv64_constant_add(i64 %a) nounwind {
155158
; RV32-NEXT: mulhu a7, a0, a2
156159
; RV32-NEXT: mulhu t2, a1, a3
157160
; RV32-NEXT: mv t1, t2
161+
; RV32-NEXT: mv t1, t1
158162
; RV32-NEXT: mul t2, a1, a3
159163
; RV32-NEXT: mulhu a2, a1, a2
160164
; RV32-NEXT: mulhu a3, a0, a3

llvm/test/CodeGen/RISCV/machine-copyprop-noop-removal.mir

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
22
# RUN: llc -o - %s -mtriple=riscv64 -run-pass=machine-cp -mcp-use-is-copy-instr | FileCheck %s
33

4-
## This test was added to capture a case where MachineCopyPropagation risks
5-
## leaving a no-op register move (add, x0, reg).
4+
## This test was added to capture a case where MachineCopyPropagation may
5+
## leave a no-op register move (add reg, x0, reg).
6+
## Due to the bug reported in
7+
## <https://github.com/llvm/llvm-project/issues/166870>, we are not currently
8+
## able to optimize this case.
69

710
---
811
name: ham
@@ -21,6 +24,7 @@ body: |
2124
; CHECK-NEXT: liveins: $x10
2225
; CHECK-NEXT: {{ $}}
2326
; CHECK-NEXT: $x11 = ADDI $x0, 0
27+
; CHECK-NEXT: renamable $x10 = ADDI killed renamable $x10, 0
2428
; CHECK-NEXT: BEQ renamable $x10, $x0, %bb.4
2529
; CHECK-NEXT: {{ $}}
2630
; CHECK-NEXT: bb.2:

llvm/test/CodeGen/RISCV/sextw-removal.ll

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1352,6 +1352,7 @@ define signext i32 @sextw_sh2add(i1 zeroext %0, ptr %1, i32 signext %2, i32 sign
13521352
; NOREMOVAL-LABEL: sextw_sh2add:
13531353
; NOREMOVAL: # %bb.0:
13541354
; NOREMOVAL-NEXT: sh2add a2, a2, a3
1355+
; NOREMOVAL-NEXT: mv a2, a2
13551356
; NOREMOVAL-NEXT: beqz a0, .LBB22_2
13561357
; NOREMOVAL-NEXT: # %bb.1:
13571358
; NOREMOVAL-NEXT: sw a2, 0(a1)

0 commit comments

Comments
 (0)