[AArch64] Fix zero-register copying with zero-cycle moves (#154362)
Fix incorrect super-register lookup when copying from $wzr on subtargets that lack zero-cycle zeroing but support 64-bit zero-cycle moves. When copying from $wzr, we used the wrong register class to lookup the super-register, causing $w0 = COPY $wzr to get expanded as $x0 = ORRXrr $xzr, undef $noreg, implicit $wzr, rather than the correct $x0 = ORRXrr $xzr, undef $xzr, implicit $wzr.
This commit is contained in:
parent
23ea79de61
commit
0542355147
@ -5085,8 +5085,13 @@ void AArch64InstrInfo::copyPhysReg(MachineBasicBlock &MBB,
|
||||
// Cyclone recognizes "ORR Xd, XZR, Xm" as a zero-cycle register move.
|
||||
MCRegister DestRegX = TRI->getMatchingSuperReg(
|
||||
DestReg, AArch64::sub_32, &AArch64::GPR64spRegClass);
|
||||
MCRegister SrcRegX = TRI->getMatchingSuperReg(
|
||||
SrcReg, AArch64::sub_32, &AArch64::GPR64spRegClass);
|
||||
assert(DestRegX.isValid() && "Destination super-reg not valid");
|
||||
MCRegister SrcRegX =
|
||||
SrcReg == AArch64::WZR
|
||||
? AArch64::XZR
|
||||
: TRI->getMatchingSuperReg(SrcReg, AArch64::sub_32,
|
||||
&AArch64::GPR64spRegClass);
|
||||
assert(SrcRegX.isValid() && "Source super-reg not valid");
|
||||
// This instruction is reading and writing X registers. This may upset
|
||||
// the register scavenger and machine verifier, so we need to indicate
|
||||
// that we are reading an undefined value from SrcRegX, but a proper
|
||||
|
109
llvm/test/CodeGen/AArch64/arm64-copy-phys-zero-reg.mir
Normal file
109
llvm/test/CodeGen/AArch64/arm64-copy-phys-zero-reg.mir
Normal file
@ -0,0 +1,109 @@
|
||||
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5
|
||||
# RUN: llc -o - -mtriple=arm64-apple-ios -run-pass=postrapseudos -simplify-mir -verify-machineinstrs -mattr="-zcm-gpr32,-zcm-gpr64,-zcz" %s \
|
||||
# RUN: | FileCheck --check-prefix=CHECK-NO-ZCM-GPR32-NO-ZCM-GPR64-NO-ZCZ %s
|
||||
# RUN: llc -o - -mtriple=arm64-apple-ios -run-pass=postrapseudos -simplify-mir -verify-machineinstrs -mattr="+zcm-gpr32,-zcm-gpr64,-zcz" %s \
|
||||
# RUN: | FileCheck --check-prefix=CHECK-ZCM-GPR32-NO-ZCM-GPR64-NO-ZCZ %s
|
||||
# RUN: llc -o - -mtriple=arm64-apple-ios -run-pass=postrapseudos -simplify-mir -verify-machineinstrs -mattr="-zcm-gpr32,+zcm-gpr64,-zcz" %s \
|
||||
# RUN: | FileCheck --check-prefix=CHECK-NO-ZCM-GPR32-ZCM-GPR64-NO-ZCZ %s
|
||||
# RUN: llc -o - -mtriple=arm64-apple-ios -run-pass=postrapseudos -simplify-mir -verify-machineinstrs -mattr="+zcm-gpr32,+zcm-gpr64,-zcz" %s \
|
||||
# RUN: | FileCheck --check-prefix=CHECK-ZCM-GPR32-ZCM-GPR64-NO-ZCZ %s
|
||||
# RUN: llc -o - -mtriple=arm64-apple-ios -run-pass=postrapseudos -simplify-mir -verify-machineinstrs -mattr="-zcm-gpr32,-zcm-gpr64,+zcz" %s \
|
||||
# RUN: | FileCheck --check-prefix=CHECK-NO-ZCM-ZCZ %s
|
||||
# RUN: llc -o - -mtriple=arm64-apple-ios -run-pass=postrapseudos -simplify-mir -verify-machineinstrs -mattr="+zcm-gpr32,+zcm-gpr64,+zcz" %s \
|
||||
# RUN: | FileCheck --check-prefix=CHECK-ZCM-ZCZ %s
|
||||
|
||||
--- |
|
||||
define void @f0(i64 noundef %x) { ret void }
|
||||
define void @f1(i64 noundef %x) { ret void }
|
||||
define void @f2(i32 noundef) { ret void }
|
||||
...
|
||||
---
|
||||
name: f0
|
||||
liveins:
|
||||
- { reg: '$x0' }
|
||||
body: |
|
||||
bb.0:
|
||||
liveins: $x0, $lr
|
||||
; CHECK-NO-ZCM-GPR32-NO-ZCM-GPR64-NO-ZCZ-LABEL: name: f0
|
||||
; CHECK-NO-ZCM-GPR32-NO-ZCM-GPR64-NO-ZCZ: liveins: $x0, $lr
|
||||
; CHECK-NO-ZCM-GPR32-NO-ZCM-GPR64-NO-ZCZ-NEXT: {{ $}}
|
||||
; CHECK-NO-ZCM-GPR32-NO-ZCM-GPR64-NO-ZCZ-NEXT: $w0 = ORRWrr $wzr, $wzr
|
||||
; CHECK-NO-ZCM-GPR32-NO-ZCM-GPR64-NO-ZCZ-NEXT: BL @f2, csr_darwin_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $w0, implicit-def $sp, implicit-def $w0
|
||||
;
|
||||
; CHECK-ZCM-GPR32-NO-ZCM-GPR64-NO-ZCZ-LABEL: name: f0
|
||||
; CHECK-ZCM-GPR32-NO-ZCM-GPR64-NO-ZCZ: liveins: $x0, $lr
|
||||
; CHECK-ZCM-GPR32-NO-ZCM-GPR64-NO-ZCZ-NEXT: {{ $}}
|
||||
; CHECK-ZCM-GPR32-NO-ZCM-GPR64-NO-ZCZ-NEXT: $w0 = ORRWrr $wzr, $wzr
|
||||
; CHECK-ZCM-GPR32-NO-ZCM-GPR64-NO-ZCZ-NEXT: BL @f2, csr_darwin_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $w0, implicit-def $sp, implicit-def $w0
|
||||
;
|
||||
; CHECK-NO-ZCM-GPR32-ZCM-GPR64-NO-ZCZ-LABEL: name: f0
|
||||
; CHECK-NO-ZCM-GPR32-ZCM-GPR64-NO-ZCZ: liveins: $x0, $lr
|
||||
; CHECK-NO-ZCM-GPR32-ZCM-GPR64-NO-ZCZ-NEXT: {{ $}}
|
||||
; CHECK-NO-ZCM-GPR32-ZCM-GPR64-NO-ZCZ-NEXT: $x0 = ORRXrr $xzr, undef $xzr, implicit $wzr
|
||||
; CHECK-NO-ZCM-GPR32-ZCM-GPR64-NO-ZCZ-NEXT: BL @f2, csr_darwin_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $w0, implicit-def $sp, implicit-def $w0
|
||||
;
|
||||
; CHECK-ZCM-GPR32-ZCM-GPR64-NO-ZCZ-LABEL: name: f0
|
||||
; CHECK-ZCM-GPR32-ZCM-GPR64-NO-ZCZ: liveins: $x0, $lr
|
||||
; CHECK-ZCM-GPR32-ZCM-GPR64-NO-ZCZ-NEXT: {{ $}}
|
||||
; CHECK-ZCM-GPR32-ZCM-GPR64-NO-ZCZ-NEXT: $w0 = ORRWrr $wzr, $wzr
|
||||
; CHECK-ZCM-GPR32-ZCM-GPR64-NO-ZCZ-NEXT: BL @f2, csr_darwin_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $w0, implicit-def $sp, implicit-def $w0
|
||||
;
|
||||
; CHECK-NO-ZCM-ZCZ-LABEL: name: f0
|
||||
; CHECK-NO-ZCM-ZCZ: liveins: $x0, $lr
|
||||
; CHECK-NO-ZCM-ZCZ-NEXT: {{ $}}
|
||||
; CHECK-NO-ZCM-ZCZ-NEXT: $w0 = MOVZWi 0, 0
|
||||
; CHECK-NO-ZCM-ZCZ-NEXT: BL @f2, csr_darwin_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $w0, implicit-def $sp, implicit-def $w0
|
||||
;
|
||||
; CHECK-ZCM-ZCZ-LABEL: name: f0
|
||||
; CHECK-ZCM-ZCZ: liveins: $x0, $lr
|
||||
; CHECK-ZCM-ZCZ-NEXT: {{ $}}
|
||||
; CHECK-ZCM-ZCZ-NEXT: $w0 = MOVZWi 0, 0
|
||||
; CHECK-ZCM-ZCZ-NEXT: BL @f2, csr_darwin_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $w0, implicit-def $sp, implicit-def $w0
|
||||
$w0 = COPY $wzr
|
||||
BL @f2, csr_darwin_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $w0, implicit-def $sp, implicit-def $w0
|
||||
...
|
||||
---
|
||||
name: f1
|
||||
liveins:
|
||||
- { reg: '$x0' }
|
||||
body: |
|
||||
bb.0:
|
||||
liveins: $x0, $lr
|
||||
; CHECK-NO-ZCM-GPR32-NO-ZCM-GPR64-NO-ZCZ-LABEL: name: f1
|
||||
; CHECK-NO-ZCM-GPR32-NO-ZCM-GPR64-NO-ZCZ: liveins: $x0, $lr
|
||||
; CHECK-NO-ZCM-GPR32-NO-ZCM-GPR64-NO-ZCZ-NEXT: {{ $}}
|
||||
; CHECK-NO-ZCM-GPR32-NO-ZCM-GPR64-NO-ZCZ-NEXT: $x0 = ORRXrr $xzr, $xzr
|
||||
; CHECK-NO-ZCM-GPR32-NO-ZCM-GPR64-NO-ZCZ-NEXT: BL @f2, csr_darwin_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $w0, implicit-def $sp, implicit-def $w0
|
||||
;
|
||||
; CHECK-ZCM-GPR32-NO-ZCM-GPR64-NO-ZCZ-LABEL: name: f1
|
||||
; CHECK-ZCM-GPR32-NO-ZCM-GPR64-NO-ZCZ: liveins: $x0, $lr
|
||||
; CHECK-ZCM-GPR32-NO-ZCM-GPR64-NO-ZCZ-NEXT: {{ $}}
|
||||
; CHECK-ZCM-GPR32-NO-ZCM-GPR64-NO-ZCZ-NEXT: $x0 = ORRXrr $xzr, $xzr
|
||||
; CHECK-ZCM-GPR32-NO-ZCM-GPR64-NO-ZCZ-NEXT: BL @f2, csr_darwin_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $w0, implicit-def $sp, implicit-def $w0
|
||||
;
|
||||
; CHECK-NO-ZCM-GPR32-ZCM-GPR64-NO-ZCZ-LABEL: name: f1
|
||||
; CHECK-NO-ZCM-GPR32-ZCM-GPR64-NO-ZCZ: liveins: $x0, $lr
|
||||
; CHECK-NO-ZCM-GPR32-ZCM-GPR64-NO-ZCZ-NEXT: {{ $}}
|
||||
; CHECK-NO-ZCM-GPR32-ZCM-GPR64-NO-ZCZ-NEXT: $x0 = ORRXrr $xzr, $xzr
|
||||
; CHECK-NO-ZCM-GPR32-ZCM-GPR64-NO-ZCZ-NEXT: BL @f2, csr_darwin_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $w0, implicit-def $sp, implicit-def $w0
|
||||
;
|
||||
; CHECK-ZCM-GPR32-ZCM-GPR64-NO-ZCZ-LABEL: name: f1
|
||||
; CHECK-ZCM-GPR32-ZCM-GPR64-NO-ZCZ: liveins: $x0, $lr
|
||||
; CHECK-ZCM-GPR32-ZCM-GPR64-NO-ZCZ-NEXT: {{ $}}
|
||||
; CHECK-ZCM-GPR32-ZCM-GPR64-NO-ZCZ-NEXT: $x0 = ORRXrr $xzr, $xzr
|
||||
; CHECK-ZCM-GPR32-ZCM-GPR64-NO-ZCZ-NEXT: BL @f2, csr_darwin_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $w0, implicit-def $sp, implicit-def $w0
|
||||
;
|
||||
; CHECK-NO-ZCM-ZCZ-LABEL: name: f1
|
||||
; CHECK-NO-ZCM-ZCZ: liveins: $x0, $lr
|
||||
; CHECK-NO-ZCM-ZCZ-NEXT: {{ $}}
|
||||
; CHECK-NO-ZCM-ZCZ-NEXT: $x0 = MOVZXi 0, 0
|
||||
; CHECK-NO-ZCM-ZCZ-NEXT: BL @f2, csr_darwin_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $w0, implicit-def $sp, implicit-def $w0
|
||||
;
|
||||
; CHECK-ZCM-ZCZ-LABEL: name: f1
|
||||
; CHECK-ZCM-ZCZ: liveins: $x0, $lr
|
||||
; CHECK-ZCM-ZCZ-NEXT: {{ $}}
|
||||
; CHECK-ZCM-ZCZ-NEXT: $x0 = MOVZXi 0, 0
|
||||
; CHECK-ZCM-ZCZ-NEXT:BL @f2, csr_darwin_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $w0, implicit-def $sp, implicit-def $w0
|
||||
$x0 = COPY $xzr
|
||||
BL @f2, csr_darwin_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $w0, implicit-def $sp, implicit-def $w0
|
||||
...
|
Loading…
x
Reference in New Issue
Block a user