Skip to content

Commit fc712eb

Browse files
tmatheson-armpaulwalker-arm
authored andcommitted
[AArch64] Fix Copy Elemination for negative values
Redundant Copy Elimination was eliminating a MOVi32imm -1 when it determined that the value of the destination register is already -1. However, it didn't take into account that the MOVi32imm zeroes the upper 32 bits (which are FFFFFFFF) and therefore cannot be eliminated. Reviewed By: paulwalker-arm Differential Revision: https://reviews.llvm.org/D93100
1 parent c0bc169 commit fc712eb

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

llvm/lib/Target/AArch64/AArch64RedundantCopyElimination.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,11 @@ bool AArch64RedundantCopyElimination::optimizeBlock(MachineBasicBlock *MBB) {
408408
O.getReg() != CmpReg;
409409
}))
410410
continue;
411+
412+
// Don't remove a move immediate that implicitly defines the upper
413+
// bits as different.
414+
if (TRI->isSuperRegister(DefReg, KnownReg.Reg) && KnownReg.Imm < 0)
415+
continue;
411416
}
412417

413418
if (IsCopy)

llvm/test/CodeGen/AArch64/machine-copy-remove.mir

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,13 +536,13 @@ body: |
536536
bb.2:
537537
RET_ReallyLR
538538
...
539-
# Eliminate redundant MOVi32imm -1 in bb.1
539+
# Don't eliminate redundant MOVi32imm -1 in bb.1: the upper bits are nonzero.
540540
# Note: 64-bit compare/32-bit move imm
541541
# Kill marker should be removed from compare.
542542
# CHECK-LABEL: name: test21
543-
# CHECK: ADDSXri $x0, 1, 0, implicit-def $nzcv
543+
# CHECK: ADDSXri killed $x0, 1, 0, implicit-def $nzcv
544544
# CHECK: bb.1:
545-
# CHECK-NOT: MOVi32imm
545+
# CHECK: MOVi32imm
546546
name: test21
547547
tracksRegLiveness: true
548548
body: |

0 commit comments

Comments
 (0)