|
| 1 | +; NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 5 |
| 2 | +; RUN: llc < %s -mtriple arm64e-apple-darwin -verify-machineinstrs -stop-after=finalize-isel -global-isel=0 \ |
| 3 | +; RUN: | FileCheck %s --check-prefixes=DAGISEL |
| 4 | +; RUN: llc < %s -mtriple arm64e-apple-darwin -verify-machineinstrs -stop-after=finalize-isel -global-isel=1 -global-isel-abort=1 \ |
| 5 | +; RUN: | FileCheck %s --check-prefixes=GISEL |
| 6 | +; RUN: llc < %s -mtriple aarch64-linux-gnu -mattr=+pauth -verify-machineinstrs -stop-after=finalize-isel -global-isel=0 \ |
| 7 | +; RUN: | FileCheck %s --check-prefixes=DAGISEL |
| 8 | +; RUN: llc < %s -mtriple aarch64-linux-gnu -mattr=+pauth -verify-machineinstrs -stop-after=finalize-isel -global-isel=1 -global-isel-abort=1 \ |
| 9 | +; RUN: | FileCheck %s --check-prefixes=GISEL |
| 10 | + |
| 11 | +; Check MIR produced by the instruction selector to validate properties that |
| 12 | +; cannot be reliably tested by only inspecting the final asm output. |
| 13 | + |
| 14 | +@discvar = dso_local global i64 0 |
| 15 | + |
| 16 | +; Make sure the components of blend(addr, imm) are recognized and passed to |
| 17 | +; PAC pseudo via separate operands to prevent substitution of the immediate |
| 18 | +; modifier. |
| 19 | +; |
| 20 | +; MIR output of the instruction selector is inspected, as it is hard to reliably |
| 21 | +; distinguish MOVKXi immediately followed by a pseudo from a standalone pseudo |
| 22 | +; instruction carrying address and immediate modifiers in its separate operands |
| 23 | +; by only observing the final asm output. |
| 24 | + |
| 25 | +define i64 @small_imm_disc(i64 %addr) { |
| 26 | + ; DAGISEL-LABEL: name: small_imm_disc |
| 27 | + ; DAGISEL: bb.0.entry: |
| 28 | + ; DAGISEL-NEXT: liveins: $x0 |
| 29 | + ; DAGISEL-NEXT: {{ $}} |
| 30 | + ; DAGISEL-NEXT: [[COPY:%[0-9]+]]:gpr64 = COPY $x0 |
| 31 | + ; DAGISEL-NEXT: [[MOVi32imm:%[0-9]+]]:gpr32 = MOVi32imm 42 |
| 32 | + ; DAGISEL-NEXT: [[SUBREG_TO_REG:%[0-9]+]]:gpr64noip = SUBREG_TO_REG 0, killed [[MOVi32imm]], %subreg.sub_32 |
| 33 | + ; DAGISEL-NEXT: [[PAC:%[0-9]+]]:gpr64 = PAC [[COPY]], 2, 42, killed $xzr, implicit-def dead $x17 |
| 34 | + ; DAGISEL-NEXT: $x0 = COPY [[PAC]] |
| 35 | + ; DAGISEL-NEXT: RET_ReallyLR implicit $x0 |
| 36 | + ; |
| 37 | + ; GISEL-LABEL: name: small_imm_disc |
| 38 | + ; GISEL: bb.1.entry: |
| 39 | + ; GISEL-NEXT: liveins: $x0 |
| 40 | + ; GISEL-NEXT: {{ $}} |
| 41 | + ; GISEL-NEXT: [[COPY:%[0-9]+]]:gpr64 = COPY $x0 |
| 42 | + ; GISEL-NEXT: [[MOVi32imm:%[0-9]+]]:gpr32 = MOVi32imm 42 |
| 43 | + ; GISEL-NEXT: [[SUBREG_TO_REG:%[0-9]+]]:gpr64noip = SUBREG_TO_REG 0, [[MOVi32imm]], %subreg.sub_32 |
| 44 | + ; GISEL-NEXT: [[PAC:%[0-9]+]]:gpr64 = PAC [[COPY]], 2, 42, $xzr, implicit-def dead $x17 |
| 45 | + ; GISEL-NEXT: $x0 = COPY [[PAC]] |
| 46 | + ; GISEL-NEXT: RET_ReallyLR implicit $x0 |
| 47 | +entry: |
| 48 | + %signed = call i64 @llvm.ptrauth.sign(i64 %addr, i32 2, i64 42) |
| 49 | + ret i64 %signed |
| 50 | +} |
| 51 | + |
| 52 | +define i64 @large_imm_disc_wreg(i64 %addr) { |
| 53 | + ; DAGISEL-LABEL: name: large_imm_disc_wreg |
| 54 | + ; DAGISEL: bb.0.entry: |
| 55 | + ; DAGISEL-NEXT: liveins: $x0 |
| 56 | + ; DAGISEL-NEXT: {{ $}} |
| 57 | + ; DAGISEL-NEXT: [[COPY:%[0-9]+]]:gpr64 = COPY $x0 |
| 58 | + ; DAGISEL-NEXT: [[MOVi32imm:%[0-9]+]]:gpr32 = MOVi32imm 12345678 |
| 59 | + ; DAGISEL-NEXT: [[SUBREG_TO_REG:%[0-9]+]]:gpr64noip = SUBREG_TO_REG 0, killed [[MOVi32imm]], %subreg.sub_32 |
| 60 | + ; DAGISEL-NEXT: [[PAC:%[0-9]+]]:gpr64 = PAC [[COPY]], 2, 0, killed [[SUBREG_TO_REG]], implicit-def dead $x17 |
| 61 | + ; DAGISEL-NEXT: $x0 = COPY [[PAC]] |
| 62 | + ; DAGISEL-NEXT: RET_ReallyLR implicit $x0 |
| 63 | + ; |
| 64 | + ; GISEL-LABEL: name: large_imm_disc_wreg |
| 65 | + ; GISEL: bb.1.entry: |
| 66 | + ; GISEL-NEXT: liveins: $x0 |
| 67 | + ; GISEL-NEXT: {{ $}} |
| 68 | + ; GISEL-NEXT: [[COPY:%[0-9]+]]:gpr64 = COPY $x0 |
| 69 | + ; GISEL-NEXT: [[MOVi32imm:%[0-9]+]]:gpr32 = MOVi32imm 12345678 |
| 70 | + ; GISEL-NEXT: [[SUBREG_TO_REG:%[0-9]+]]:gpr64noip = SUBREG_TO_REG 0, [[MOVi32imm]], %subreg.sub_32 |
| 71 | + ; GISEL-NEXT: [[PAC:%[0-9]+]]:gpr64 = PAC [[COPY]], 2, 0, [[SUBREG_TO_REG]], implicit-def dead $x17 |
| 72 | + ; GISEL-NEXT: $x0 = COPY [[PAC]] |
| 73 | + ; GISEL-NEXT: RET_ReallyLR implicit $x0 |
| 74 | +entry: |
| 75 | + %signed = call i64 @llvm.ptrauth.sign(i64 %addr, i32 2, i64 12345678) |
| 76 | + ret i64 %signed |
| 77 | +} |
| 78 | + |
| 79 | +define i64 @large_imm_disc_xreg(i64 %addr) { |
| 80 | + ; DAGISEL-LABEL: name: large_imm_disc_xreg |
| 81 | + ; DAGISEL: bb.0.entry: |
| 82 | + ; DAGISEL-NEXT: liveins: $x0 |
| 83 | + ; DAGISEL-NEXT: {{ $}} |
| 84 | + ; DAGISEL-NEXT: [[COPY:%[0-9]+]]:gpr64 = COPY $x0 |
| 85 | + ; DAGISEL-NEXT: [[MOVi64imm:%[0-9]+]]:gpr64noip = MOVi64imm 123456789012345 |
| 86 | + ; DAGISEL-NEXT: [[PAC:%[0-9]+]]:gpr64 = PAC [[COPY]], 2, 0, killed [[MOVi64imm]], implicit-def dead $x17 |
| 87 | + ; DAGISEL-NEXT: $x0 = COPY [[PAC]] |
| 88 | + ; DAGISEL-NEXT: RET_ReallyLR implicit $x0 |
| 89 | + ; |
| 90 | + ; GISEL-LABEL: name: large_imm_disc_xreg |
| 91 | + ; GISEL: bb.1.entry: |
| 92 | + ; GISEL-NEXT: liveins: $x0 |
| 93 | + ; GISEL-NEXT: {{ $}} |
| 94 | + ; GISEL-NEXT: [[COPY:%[0-9]+]]:gpr64 = COPY $x0 |
| 95 | + ; GISEL-NEXT: [[MOVi64imm:%[0-9]+]]:gpr64noip = MOVi64imm 123456789012345 |
| 96 | + ; GISEL-NEXT: [[PAC:%[0-9]+]]:gpr64 = PAC [[COPY]], 2, 0, [[MOVi64imm]], implicit-def dead $x17 |
| 97 | + ; GISEL-NEXT: $x0 = COPY [[PAC]] |
| 98 | + ; GISEL-NEXT: RET_ReallyLR implicit $x0 |
| 99 | +entry: |
| 100 | + %signed = call i64 @llvm.ptrauth.sign(i64 %addr, i32 2, i64 123456789012345) |
| 101 | + ret i64 %signed |
| 102 | +} |
| 103 | + |
| 104 | +define i64 @blend_and_sign_same_bb(i64 %addr) { |
| 105 | + ; DAGISEL-LABEL: name: blend_and_sign_same_bb |
| 106 | + ; DAGISEL: bb.0.entry: |
| 107 | + ; DAGISEL-NEXT: liveins: $x0 |
| 108 | + ; DAGISEL-NEXT: {{ $}} |
| 109 | + ; DAGISEL-NEXT: [[COPY:%[0-9]+]]:gpr64 = COPY $x0 |
| 110 | + ; DAGISEL-NEXT: [[ADRP:%[0-9]+]]:gpr64common = ADRP target-flags(aarch64-page) @discvar |
| 111 | + ; DAGISEL-NEXT: [[LDRXui:%[0-9]+]]:gpr64 = LDRXui killed [[ADRP]], target-flags(aarch64-pageoff, aarch64-nc) @discvar :: (dereferenceable load (s64) from @discvar) |
| 112 | + ; DAGISEL-NEXT: [[MOVKXi:%[0-9]+]]:gpr64noip = MOVKXi [[LDRXui]], 42, 48 |
| 113 | + ; DAGISEL-NEXT: [[COPY1:%[0-9]+]]:gpr64noip = COPY [[LDRXui]] |
| 114 | + ; DAGISEL-NEXT: [[PAC:%[0-9]+]]:gpr64 = PAC [[COPY]], 2, 42, killed [[COPY1]], implicit-def dead $x17 |
| 115 | + ; DAGISEL-NEXT: $x0 = COPY [[PAC]] |
| 116 | + ; DAGISEL-NEXT: RET_ReallyLR implicit $x0 |
| 117 | + ; |
| 118 | + ; GISEL-LABEL: name: blend_and_sign_same_bb |
| 119 | + ; GISEL: bb.1.entry: |
| 120 | + ; GISEL-NEXT: liveins: $x0 |
| 121 | + ; GISEL-NEXT: {{ $}} |
| 122 | + ; GISEL-NEXT: [[COPY:%[0-9]+]]:gpr64 = COPY $x0 |
| 123 | + ; GISEL-NEXT: [[ADRP:%[0-9]+]]:gpr64common = ADRP target-flags(aarch64-page) @discvar |
| 124 | + ; GISEL-NEXT: [[LDRXui:%[0-9]+]]:gpr64 = LDRXui [[ADRP]], target-flags(aarch64-pageoff, aarch64-nc) @discvar :: (dereferenceable load (s64) from @discvar) |
| 125 | + ; GISEL-NEXT: [[MOVKXi:%[0-9]+]]:gpr64noip = MOVKXi [[LDRXui]], 42, 48 |
| 126 | + ; GISEL-NEXT: [[COPY1:%[0-9]+]]:gpr64noip = COPY [[LDRXui]] |
| 127 | + ; GISEL-NEXT: [[PAC:%[0-9]+]]:gpr64 = PAC [[COPY]], 2, 42, [[COPY1]], implicit-def dead $x17 |
| 128 | + ; GISEL-NEXT: $x0 = COPY [[PAC]] |
| 129 | + ; GISEL-NEXT: RET_ReallyLR implicit $x0 |
| 130 | +entry: |
| 131 | + %addrdisc = load i64, ptr @discvar |
| 132 | + %disc = call i64 @llvm.ptrauth.blend(i64 %addrdisc, i64 42) |
| 133 | + %signed = call i64 @llvm.ptrauth.sign(i64 %addr, i32 2, i64 %disc) |
| 134 | + ret i64 %signed |
| 135 | +} |
| 136 | + |
| 137 | +; In the below test cases both %addrdisc and %disc are computed (i.e. they are |
| 138 | +; neither global addresses, nor function arguments) in a different basic block, |
| 139 | +; making them harder to express via ISD::PtrAuthGlobalAddress. |
| 140 | + |
| 141 | +define i64 @blend_and_sign_different_bbs(i64 %addr, i64 %cond) { |
| 142 | + ; DAGISEL-LABEL: name: blend_and_sign_different_bbs |
| 143 | + ; DAGISEL: bb.0.entry: |
| 144 | + ; DAGISEL-NEXT: successors: %bb.1(0x50000000), %bb.2(0x30000000) |
| 145 | + ; DAGISEL-NEXT: liveins: $x0, $x1 |
| 146 | + ; DAGISEL-NEXT: {{ $}} |
| 147 | + ; DAGISEL-NEXT: [[COPY:%[0-9]+]]:gpr64 = COPY $x1 |
| 148 | + ; DAGISEL-NEXT: [[COPY1:%[0-9]+]]:gpr64 = COPY $x0 |
| 149 | + ; DAGISEL-NEXT: [[ADRP:%[0-9]+]]:gpr64common = ADRP target-flags(aarch64-page) @discvar |
| 150 | + ; DAGISEL-NEXT: [[LDRXui:%[0-9]+]]:gpr64 = LDRXui killed [[ADRP]], target-flags(aarch64-pageoff, aarch64-nc) @discvar :: (dereferenceable load (s64) from @discvar) |
| 151 | + ; DAGISEL-NEXT: [[MOVKXi:%[0-9]+]]:gpr64 = MOVKXi [[LDRXui]], 42, 48 |
| 152 | + ; DAGISEL-NEXT: [[COPY2:%[0-9]+]]:gpr64noip = COPY [[MOVKXi]] |
| 153 | + ; DAGISEL-NEXT: CBZX [[COPY]], %bb.2 |
| 154 | + ; DAGISEL-NEXT: B %bb.1 |
| 155 | + ; DAGISEL-NEXT: {{ $}} |
| 156 | + ; DAGISEL-NEXT: bb.1.next: |
| 157 | + ; DAGISEL-NEXT: successors: %bb.2(0x80000000) |
| 158 | + ; DAGISEL-NEXT: {{ $}} |
| 159 | + ; DAGISEL-NEXT: [[COPY3:%[0-9]+]]:gpr64common = COPY [[COPY2]] |
| 160 | + ; DAGISEL-NEXT: INLINEASM &nop, 1 /* sideeffect attdialect */, 3866633 /* reguse:GPR64common */, [[COPY3]] |
| 161 | + ; DAGISEL-NEXT: {{ $}} |
| 162 | + ; DAGISEL-NEXT: bb.2.exit: |
| 163 | + ; DAGISEL-NEXT: [[COPY4:%[0-9]+]]:gpr64noip = COPY [[LDRXui]] |
| 164 | + ; DAGISEL-NEXT: [[PAC:%[0-9]+]]:gpr64 = PAC [[COPY1]], 2, 42, [[COPY4]], implicit-def dead $x17 |
| 165 | + ; DAGISEL-NEXT: $x0 = COPY [[PAC]] |
| 166 | + ; DAGISEL-NEXT: RET_ReallyLR implicit $x0 |
| 167 | + ; |
| 168 | + ; GISEL-LABEL: name: blend_and_sign_different_bbs |
| 169 | + ; GISEL: bb.1.entry: |
| 170 | + ; GISEL-NEXT: successors: %bb.2(0x50000000), %bb.3(0x30000000) |
| 171 | + ; GISEL-NEXT: liveins: $x0, $x1 |
| 172 | + ; GISEL-NEXT: {{ $}} |
| 173 | + ; GISEL-NEXT: [[COPY:%[0-9]+]]:gpr64 = COPY $x0 |
| 174 | + ; GISEL-NEXT: [[COPY1:%[0-9]+]]:gpr64 = COPY $x1 |
| 175 | + ; GISEL-NEXT: [[ADRP:%[0-9]+]]:gpr64common = ADRP target-flags(aarch64-page) @discvar |
| 176 | + ; GISEL-NEXT: [[LDRXui:%[0-9]+]]:gpr64 = LDRXui [[ADRP]], target-flags(aarch64-pageoff, aarch64-nc) @discvar :: (dereferenceable load (s64) from @discvar) |
| 177 | + ; GISEL-NEXT: [[MOVKXi:%[0-9]+]]:gpr64noip = MOVKXi [[LDRXui]], 42, 48 |
| 178 | + ; GISEL-NEXT: CBZX [[COPY1]], %bb.3 |
| 179 | + ; GISEL-NEXT: B %bb.2 |
| 180 | + ; GISEL-NEXT: {{ $}} |
| 181 | + ; GISEL-NEXT: bb.2.next: |
| 182 | + ; GISEL-NEXT: successors: %bb.3(0x80000000) |
| 183 | + ; GISEL-NEXT: {{ $}} |
| 184 | + ; GISEL-NEXT: [[COPY2:%[0-9]+]]:gpr64common = COPY [[MOVKXi]] |
| 185 | + ; GISEL-NEXT: INLINEASM &nop, 1 /* sideeffect attdialect */, 3866633 /* reguse:GPR64common */, [[COPY2]] |
| 186 | + ; GISEL-NEXT: {{ $}} |
| 187 | + ; GISEL-NEXT: bb.3.exit: |
| 188 | + ; GISEL-NEXT: [[COPY3:%[0-9]+]]:gpr64noip = COPY [[LDRXui]] |
| 189 | + ; GISEL-NEXT: [[PAC:%[0-9]+]]:gpr64 = PAC [[COPY]], 2, 42, [[COPY3]], implicit-def dead $x17 |
| 190 | + ; GISEL-NEXT: $x0 = COPY [[PAC]] |
| 191 | + ; GISEL-NEXT: RET_ReallyLR implicit $x0 |
| 192 | +entry: |
| 193 | + %addrdisc = load i64, ptr @discvar |
| 194 | + %disc = call i64 @llvm.ptrauth.blend(i64 %addrdisc, i64 42) |
| 195 | + %cond.b = icmp ne i64 %cond, 0 |
| 196 | + br i1 %cond.b, label %next, label %exit |
| 197 | + |
| 198 | +next: |
| 199 | + call void asm sideeffect "nop", "r"(i64 %disc) |
| 200 | + br label %exit |
| 201 | + |
| 202 | +exit: |
| 203 | + %signed = call i64 @llvm.ptrauth.sign(i64 %addr, i32 2, i64 %disc) |
| 204 | + ret i64 %signed |
| 205 | +} |
0 commit comments