1# RUN: llc -mtriple=aarch64-apple-ios -run-pass=simple-register-coalescing %s -o - | FileCheck %s 2--- | 3 declare void @f2() 4 5 define void @func0() { ret void } 6 define void @func1() { ret void } 7 define void @func2() { ret void } 8... 9--- 10# Check coalescing of COPYs from reserved physregs. 11# CHECK-LABEL: name: func0 12name: func0 13body: | 14 bb.0: 15 ; We usually should not coalesce copies from allocatable physregs. 16 ; CHECK: %0:gpr32 = COPY $w7 17 ; CHECK: STRWui %0, $x1, 0 18 %0 : gpr32 = COPY $w7 19 STRWui %0, $x1, 0 20 21 ; It is fine to coalesce copies from reserved physregs 22 ; CHECK-NOT: COPY 23 ; CHECK: STRXui $fp, $x1, 0 24 %1 : gpr64 = COPY $fp 25 STRXui %1, $x1, 0 26 27 ; It is not fine to coalesce copies from reserved physregs when they are 28 ; clobbered. 29 ; CHECK: %2:gpr64 = COPY $fp 30 ; CHECK: STRXui %2, $x1, 0 31 %2 : gpr64 = COPY $fp 32 $fp = SUBXri $fp, 4, 0 33 STRXui %2, $x1, 0 34 35 ; Is is fine to coalesce copies from constant physregs even when they are 36 ; clobbered. 37 ; CHECK-NOT: COPY 38 ; CHECK: STRWui $wzr, $x1 39 %3 : gpr32 = COPY $wzr 40 dead $wzr = SUBSWri $w1, 0, 0, implicit-def $nzcv 41 STRWui %3, $x1, 0 42 43 ; Is is fine to coalesce copies from constant physregs even when they are 44 ; clobbered. 45 ; CHECK-NOT: COPY 46 ; CHECK: STRXui $xzr, $x1 47 %4 : gpr64 = COPY $xzr 48 dead $wzr = SUBSWri $w1, 0, 0, implicit-def $nzcv 49 STRXui %4, $x1, 0 50 51 ; Coalescing COPYs into constant physregs. 52 ; CHECK: $wzr = SUBSWri $w1, 0, 0 53 %5 : gpr32 = SUBSWri $w1, 0, 0, implicit-def $nzcv 54 $wzr = COPY %5 55 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 62 HINT 0, implicit %6 63 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 69 70 ; Need a def of x18 so that it's not deduced as "constant". 71 $x18 = COPY $xzr 72 %7 : gpr64 = COPY $x18 73 BL @f2, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit-def $sp 74 STRXui %7, $x1, 0 75 76 ; This can be coalesced. 77 ; CHECK: $fp = SUBXri $fp, 4, 0 78 %8 : gpr64sp = SUBXri $fp, 4, 0 79 $fp = COPY %8 80 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 87 STRXui $fp, $fp, 0 88 $fp = COPY %9 89... 90--- 91# Check coalescing of COPYs from reserved physregs. 92# CHECK-LABEL: name: func1 93name: func1 94body: | 95 bb.0: 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 101 ; CHECK: B %bb.2 102 %0 : gpr64sp = SUBXri $fp, 12, 0 103 CBZX undef $x0, %bb.1 104 B %bb.2 105 106 bb.1: 107 $fp = COPY %0 108 RET_ReallyLR 109 110 bb.2: 111 STRXui $fp, $fp, 0 112 RET_ReallyLR 113... 114--- 115# CHECK-LABEL: name: func2 116name: func2 117body: | 118 bb.0: 119 ; We can coalesce copies from physreg to vreg across multiple blocks. 120 ; CHECK-NOT: COPY 121 ; CHECK: CBZX undef $x0, %bb.1 122 ; CHECK-NEXT: B %bb.2 123 %0 : gpr64sp = COPY $fp 124 CBZX undef $x0, %bb.1 125 B %bb.2 126 127 bb.1: 128 ; CHECK: STRXui undef $x0, $fp, 0 129 ; CHECK-NEXT: RET_ReallyLR 130 STRXui undef $x0, %0, 0 131 RET_ReallyLR 132 133 bb.2: 134 RET_ReallyLR 135... 136