Skip to content
This repository was archived by the owner on Feb 5, 2019. It is now read-only.

Commit dc408e8

Browse files
committed
[FastISel][AArch64] Make use of the zero register when possible.
This change materializes now the value "0" from the zero register. The zero register can be folded by several instruction, so no materialization is need at all. Fixes <rdar://problem/17924413>. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@215591 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent eb1c51f commit dc408e8

File tree

5 files changed

+59
-16
lines changed

5 files changed

+59
-16
lines changed

lib/Target/AArch64/AArch64FastISel.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,19 @@ unsigned AArch64FastISel::TargetMaterializeAlloca(const AllocaInst *AI) {
217217
unsigned AArch64FastISel::AArch64MaterializeInt(const ConstantInt *CI, MVT VT) {
218218
if (VT > MVT::i64)
219219
return 0;
220-
return FastEmit_i(VT, VT, ISD::Constant, CI->getZExtValue());
220+
221+
if (!CI->isZero())
222+
return FastEmit_i(VT, VT, ISD::Constant, CI->getZExtValue());
223+
224+
// Create a copy from the zero register to materialize a "0" value.
225+
const TargetRegisterClass *RC = (VT == MVT::i64) ? &AArch64::GPR64RegClass
226+
: &AArch64::GPR32RegClass;
227+
unsigned ZeroReg = (VT == MVT::i64) ? AArch64::XZR : AArch64::WZR;
228+
unsigned ResultReg = createResultReg(RC);
229+
BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
230+
TII.get(TargetOpcode::COPY), ResultReg)
231+
.addReg(ZeroReg, getKillRegState(true));
232+
return ResultReg;
221233
}
222234

223235
unsigned AArch64FastISel::AArch64MaterializeFP(const ConstantFP *CFP, MVT VT) {

test/CodeGen/AArch64/arm64-fast-isel-call.ll

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ entry:
4242

4343
define i32 @sext_(i8 %a, i16 %b) nounwind {
4444
entry:
45-
; CHECK-LABEL: @sext_
45+
; CHECK-LABEL: sext_
4646
; CHECK: sxtb w0, w0
4747
; CHECK: sxth w1, w1
4848
; CHECK: bl _foo_sext_
@@ -54,7 +54,7 @@ declare void @foo_sext_(i8 %a, i16 %b)
5454

5555
define i32 @zext_(i8 %a, i16 %b) nounwind {
5656
entry:
57-
; CHECK-LABEL: @zext_
57+
; CHECK-LABEL: zext_
5858
; CHECK: uxtb w0, w0
5959
; CHECK: uxth w1, w1
6060
call void @foo_zext_(i8 zeroext %a, i16 zeroext %b)
@@ -78,17 +78,18 @@ declare i32 @bar(i8 zeroext, i8 zeroext, i8 zeroext, i8 zeroext, i8 zeroext, i8
7878
; Test materialization of integers. Target-independent selector handles this.
7979
define i32 @t2() {
8080
entry:
81-
; CHECK-LABEL: @t2
82-
; CHECK: movz x0, #0
81+
; CHECK-LABEL: t2
82+
; CHECK: mov [[REG1:x[0-9]+]], xzr
8383
; CHECK: orr w1, wzr, #0xfffffff8
84-
; CHECK: orr w[[REG:[0-9]+]], wzr, #0x3ff
85-
; CHECK: orr w[[REG2:[0-9]+]], wzr, #0x2
86-
; CHECK: movz w[[REG3:[0-9]+]], #0
87-
; CHECK: orr w[[REG4:[0-9]+]], wzr, #0x1
88-
; CHECK: uxth w2, w[[REG]]
89-
; CHECK: sxtb w3, w[[REG2]]
90-
; CHECK: and w4, w[[REG3]], #0x1
91-
; CHECK: and w5, w[[REG4]], #0x1
84+
; CHECK: orr [[REG2:w[0-9]+]], wzr, #0x3ff
85+
; CHECK: orr [[REG3:w[0-9]+]], wzr, #0x2
86+
; CHECK: mov [[REG4:w[0-9]+]], wzr
87+
; CHECK: orr [[REG5:w[0-9]+]], wzr, #0x1
88+
; CHECK: mov x0, [[REG1]]
89+
; CHECK: uxth w2, [[REG2]]
90+
; CHECK: sxtb w3, [[REG3]]
91+
; CHECK: and w4, [[REG4]], #0x1
92+
; CHECK: and w5, [[REG5]], #0x1
9293
; CHECK: bl _func2
9394
%call = call i32 @func2(i64 zeroext 0, i32 signext -8, i16 zeroext 1023, i8 signext -254, i1 zeroext 0, i1 zeroext 1)
9495
ret i32 0

test/CodeGen/AArch64/arm64-fast-isel-intrinsic.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ define void @t1() {
77
; ARM64-LABEL: t1
88
; ARM64: adrp x8, _message@PAGE
99
; ARM64: add x0, x8, _message@PAGEOFF
10-
; ARM64: movz w9, #0
10+
; ARM64: mov w9, wzr
1111
; ARM64: movz x2, #0x50
1212
; ARM64: uxtb w1, w9
1313
; ARM64: bl _memset
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
; RUN: llc -mtriple=aarch64-unknown-unknown < %s | FileCheck %s
2+
; RUN: llc -mtriple=aarch64-unknown-unknown -fast-isel -fast-isel-abort < %s | FileCheck %s
3+
4+
define void @store_i8(i8* %a) {
5+
; CHECK-LABEL: store_i8
6+
; CHECK: strb wzr, [x0]
7+
store i8 0, i8* %a
8+
ret void
9+
}
10+
11+
define void @store_i16(i16* %a) {
12+
; CHECK-LABEL: store_i16
13+
; CHECK: strh wzr, [x0]
14+
store i16 0, i16* %a
15+
ret void
16+
}
17+
18+
define void @store_i32(i32* %a) {
19+
; CHECK-LABEL: store_i32
20+
; CHECK: str wzr, [x0]
21+
store i32 0, i32* %a
22+
ret void
23+
}
24+
25+
define void @store_i64(i64* %a) {
26+
; CHECK-LABEL: store_i64
27+
; CHECK: str xzr, [x0]
28+
store i64 0, i64* %a
29+
ret void
30+
}

test/CodeGen/AArch64/arm64-fast-isel.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ entry:
6666
define void @t4(i32 *%ptr) nounwind {
6767
entry:
6868
; CHECK-LABEL: t4:
69-
; CHECK: movz w8, #0
69+
; CHECK: mov w8, wzr
7070
; CHECK: stur w8, [x0, #-4]
7171
; CHECK: ret
7272
%0 = getelementptr i32 *%ptr, i32 -1
@@ -77,7 +77,7 @@ entry:
7777
define void @t5(i32 *%ptr) nounwind {
7878
entry:
7979
; CHECK-LABEL: t5:
80-
; CHECK: movz w8, #0
80+
; CHECK: mov w8, wzr
8181
; CHECK: stur w8, [x0, #-256]
8282
; CHECK: ret
8383
%0 = getelementptr i32 *%ptr, i32 -64

0 commit comments

Comments
 (0)