1 # RUN: llc -mtriple=aarch64-apple-ios -run-pass=register-coalescer -verify-machineinstrs %s -o - | FileCheck %s
5 define void @func0() { ret void }
6 define void @func1() { ret void }
7 define void @func2() { ret void }
10 # Check coalescing of COPYs from reserved physregs.
11 # CHECK-LABEL: name: func0
15 ; We usually should not coalesce copies from allocatable physregs.
16 ; CHECK: %0:gpr32 = COPY $w7
17 ; CHECK: STRWui %0, $x1, 0
21 ; It is fine to coalesce copies from reserved physregs
23 ; CHECK: STRXui $fp, $x1, 0
27 ; It is not fine to coalesce copies from reserved physregs when they are
29 ; CHECK: %2:gpr64 = COPY $fp
30 ; CHECK: STRXui %2, $x1, 0
32 $fp = SUBXri $fp, 4, 0
35 ; Is is fine to coalesce copies from constant physregs even when they are
38 ; CHECK: STRWui $wzr, $x1
39 %3 : gpr32 = COPY $wzr
40 dead $wzr = SUBSWri $w1, 0, 0, implicit-def $nzcv
43 ; Is is fine to coalesce copies from constant physregs even when they are
46 ; CHECK: STRXui $xzr, $x1
47 %4 : gpr64 = COPY $xzr
48 dead $wzr = SUBSWri $w1, 0, 0, implicit-def $nzcv
51 ; Coalescing COPYs into constant physregs.
52 ; CHECK: $wzr = SUBSWri $w1, 0, 0
53 %5 : gpr32 = SUBSWri $w1, 0, 0, implicit-def $nzcv
56 ; Only coalesce when the source register is reserved as a whole (this is
57 ; a limitation of the current code which cannot update liveness information
58 ; of the non-reserved part).
59 ; CHECK: %6:xseqpairsclass = COPY $x28_fp
60 ; CHECK: HINT 0, implicit %6
61 %6 : xseqpairsclass = COPY $x28_fp
64 ; It is not fine to coalesce copies from reserved physregs when they are
65 ; clobbered by the regmask on a call.
66 ; CHECK: %7:gpr64 = COPY $x18
67 ; CHECK: BL @f2, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit-def $sp
68 ; CHECK: STRXui %7, $x1, 0
70 ; Need a def of x18 so that it's not deduced as "constant".
72 %7 : gpr64 = COPY $x18
73 BL @f2, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit-def $sp
76 ; This can be coalesced.
77 ; CHECK: $fp = SUBXri $fp, 4, 0
78 %8 : gpr64sp = SUBXri $fp, 4, 0
81 ; Cannot coalesce when there are reads of the physreg.
82 ; CHECK-NOT: $fp = SUBXri $fp, 8, 0
83 ; CHECK: %9:gpr64sp = SUBXri $fp, 8, 0
84 ; CHECK: STRXui $fp, $fp, 0
85 ; CHECK: $fp = COPY %9
86 %9 : gpr64sp = SUBXri $fp, 8, 0
91 # Check coalescing of COPYs from reserved physregs.
92 # CHECK-LABEL: name: func1
96 ; Cannot coalesce physreg because we have reads on other CFG paths (we
97 ; currently abort for any control flow)
98 ; CHECK-NOT: $fp = SUBXri
99 ; CHECK: %0:gpr64sp = SUBXri $fp, 12, 0
100 ; CHECK: CBZX undef $x0, %bb.1
102 %0 : gpr64sp = SUBXri $fp, 12, 0
103 CBZX undef $x0, %bb.1
115 # CHECK-LABEL: name: func2
119 ; We can coalesce copies from physreg to vreg across multiple blocks.
121 ; CHECK: CBZX undef $x0, %bb.1
122 ; CHECK-NEXT: B %bb.2
123 %0 : gpr64sp = COPY $fp
124 CBZX undef $x0, %bb.1
128 ; CHECK: STRXui undef $x0, $fp, 0
129 ; CHECK-NEXT: RET_ReallyLR
130 STRXui undef $x0, %0, 0