Skip to content

Commit 64d1a8e

Browse files
committed
[AArch64] Widen GPR32 zero cycle zeroing
Given a GPR32 zeroing instruction, if the target supports zero cycle zeroing for GPR64 but not for GPR32, widen the zeroing instruction. It also aligns naming in the generic zeroing test.
1 parent 5ac616f commit 64d1a8e

File tree

3 files changed

+21
-10
lines changed

3 files changed

+21
-10
lines changed

llvm/lib/Target/AArch64/AArch64InstrInfo.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5116,7 +5116,15 @@ void AArch64InstrInfo::copyPhysReg(MachineBasicBlock &MBB,
51165116

51175117
// GPR32 zeroing
51185118
if (AArch64::GPR32spRegClass.contains(DestReg) && SrcReg == AArch64::WZR) {
5119-
if (Subtarget.hasZeroCycleZeroingGPR32()) {
5119+
if (Subtarget.hasZeroCycleZeroingGPR64() &&
5120+
!Subtarget.hasZeroCycleZeroingGPR32()) {
5121+
MCRegister DestRegX = RI.getMatchingSuperReg(
5122+
DestReg, AArch64::sub_32, &AArch64::GPR64spRegClass);
5123+
assert(DestRegX.isValid() && "Destination super-reg not valid");
5124+
BuildMI(MBB, I, DL, get(AArch64::MOVZXi), DestRegX)
5125+
.addImm(0)
5126+
.addImm(AArch64_AM::getShifterImm(AArch64_AM::LSL, 0));
5127+
} else if (Subtarget.hasZeroCycleZeroingGPR32()) {
51205128
BuildMI(MBB, I, DL, get(AArch64::MOVZWi), DestReg)
51215129
.addImm(0)
51225130
.addImm(AArch64_AM::getShifterImm(AArch64_AM::LSL, 0));

llvm/test/CodeGen/AArch64/arm64-copy-phys-zero-reg.mir

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ body: |
3535
; CHECK-NOZCZ-GPR32-ZCZ-GPR64-LABEL: name: f0
3636
; CHECK-NOZCZ-GPR32-ZCZ-GPR64: liveins: $x0, $lr
3737
; CHECK-NOZCZ-GPR32-ZCZ-GPR64-NEXT: {{ $}}
38-
; CHECK-NOZCZ-GPR32-ZCZ-GPR64-NEXT: $w0 = ORRWrr $wzr, $wzr
38+
; CHECK-NOZCZ-GPR32-ZCZ-GPR64-NEXT: $x0 = MOVZXi 0, 0
3939
; CHECK-NOZCZ-GPR32-ZCZ-GPR64-NEXT: BL @f2, csr_darwin_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit $w0, implicit-def $sp, implicit-def $w0
4040
;
4141
; CHECK-ZCZ-GPR32-ZCZ-GPR64-LABEL: name: f0
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,44 @@
1-
; RUN: llc < %s -mtriple=aarch64-linux-gnu | FileCheck %s -check-prefixes=ALL,NOZCZ-GPR
1+
; RUN: llc < %s -mtriple=aarch64-linux-gnu | FileCheck %s -check-prefixes=ALL,NOZCZ-GPR32-NOZCZ-GPR64
22
; RUN: llc < %s -mtriple=aarch64-linux-gnu -mattr=+zcz-gpr32 | FileCheck %s -check-prefixes=ALL,ZCZ-GPR32
3-
; RUN: llc < %s -mtriple=aarch64-linux-gnu -mattr=+zcz-gpr64 | FileCheck %s -check-prefixes=ALL,ZCZ-GPR64
4-
; RUN: llc < %s -mtriple=arm64-apple-macosx -mcpu=generic | FileCheck %s -check-prefixes=ALL,NOZCZ-GPR
3+
; RUN: llc < %s -mtriple=aarch64-linux-gnu -mattr=+zcz-gpr64 | FileCheck %s -check-prefixes=ALL,NOZCZ-GPR32-ZCZ-GPR64
4+
; RUN: llc < %s -mtriple=arm64-apple-macosx -mcpu=generic | FileCheck %s -check-prefixes=ALL,NOZCZ-GPR32-NOZCZ-GPR64
55
; RUN: llc < %s -mtriple=arm64-apple-ios -mcpu=cyclone | FileCheck %s -check-prefixes=ALL,ZCZ-GPR32,ZCZ-GPR64
66
; RUN: llc < %s -mtriple=arm64-apple-macosx -mcpu=apple-m1 | FileCheck %s -check-prefixes=ALL,ZCZ-GPR32,ZCZ-GPR64
7-
; RUN: llc < %s -mtriple=aarch64-linux-gnu -mcpu=exynos-m3 | FileCheck %s -check-prefixes=ALL,NOZCZ-GPR
7+
; RUN: llc < %s -mtriple=aarch64-linux-gnu -mcpu=exynos-m3 | FileCheck %s -check-prefixes=ALL,NOZCZ-GPR32-NOZCZ-GPR64
88
; RUN: llc < %s -mtriple=aarch64-linux-gnu -mcpu=kryo | FileCheck %s -check-prefixes=ALL,ZCZ-GPR32,ZCZ-GPR64
99
; RUN: llc < %s -mtriple=aarch64-linux-gnu -mcpu=falkor | FileCheck %s -check-prefixes=ALL,ZCZ-GPR32,ZCZ-GPR64
1010

1111
define i8 @ti8() {
1212
entry:
1313
; ALL-LABEL: ti8:
14-
; NOZCZ-GPR: mov w0, wzr
14+
; NOZCZ-GPR32-NOZCZ-GPR64: mov w0, wzr
1515
; ZCZ-GPR32: mov w0, #0
16+
; NOZCZ-GPR32-ZCZ-GPR64: mov x0, #0
1617
ret i8 0
1718
}
1819

1920
define i16 @ti16() {
2021
entry:
2122
; ALL-LABEL: ti16:
22-
; NOZCZ-GPR: mov w0, wzr
23+
; NOZCZ-GPR32-NOZCZ-GPR64: mov w0, wzr
2324
; ZCZ-GPR32: mov w0, #0
25+
; NOZCZ-GPR32-ZCZ-GPR64: mov x0, #0
2426
ret i16 0
2527
}
2628

2729
define i32 @ti32() {
2830
entry:
2931
; ALL-LABEL: ti32:
30-
; NOZCZ-GPR: mov w0, wzr
32+
; NOZCZ-GPR32-NOZCZ-GPR64: mov w0, wzr
3133
; ZCZ-GPR32: mov w0, #0
34+
; NOZCZ-GPR32-ZCZ-GPR64: mov x0, #0
3235
ret i32 0
3336
}
3437

3538
define i64 @ti64() {
3639
entry:
3740
; ALL-LABEL: ti64:
38-
; NOZCZ-GPR: mov x0, xzr
41+
; NOZCZ-GPR32-NOZCZ-GPR64 mov x0, xzr
3942
; ZCZ-GPR64: mov x0, #0
4043
ret i64 0
4144
}

0 commit comments

Comments
 (0)