1; RUN: llc -fast-isel-sink-local-values -verify-machineinstrs -disable-fp-elim -enable-shrink-wrap=false < %s -mtriple=aarch64-apple-ios -disable-post-ra | FileCheck -allow-deprecated-dag-overlap --check-prefix=CHECK-APPLE %s 2; RUN: llc -fast-isel-sink-local-values -verify-machineinstrs -disable-fp-elim -O0 -fast-isel < %s -mtriple=aarch64-apple-ios -disable-post-ra | FileCheck -allow-deprecated-dag-overlap --check-prefix=CHECK-O0 %s 3 4declare i8* @malloc(i64) 5declare void @free(i8*) 6%swift_error = type {i64, i8} 7 8; This tests the basic usage of a swifterror parameter. "foo" is the function 9; that takes a swifterror parameter and "caller" is the caller of "foo". 10define float @foo(%swift_error** swifterror %error_ptr_ref) { 11; CHECK-APPLE-LABEL: foo: 12; CHECK-APPLE: orr w0, wzr, #0x10 13; CHECK-APPLE: malloc 14; CHECK-APPLE: orr [[ID:w[0-9]+]], wzr, #0x1 15; CHECK-APPLE: strb [[ID]], [x0, #8] 16; CHECK-APPLE: mov x21, x0 17; CHECK-APPLE-NOT: x21 18 19; CHECK-O0-LABEL: foo: 20; CHECK-O0: orr w{{.*}}, wzr, #0x10 21; CHECK-O0: malloc 22; CHECK-O0: mov x21, x0 23; CHECK-O0-NOT: x21 24; CHECK-O0: orr [[ID:w[0-9]+]], wzr, #0x1 25; CHECK-O0-NOT: x21 26; CHECK-O0: strb [[ID]], [x0, #8] 27; CHECK-O0-NOT: x21 28entry: 29 %call = call i8* @malloc(i64 16) 30 %call.0 = bitcast i8* %call to %swift_error* 31 store %swift_error* %call.0, %swift_error** %error_ptr_ref 32 %tmp = getelementptr inbounds i8, i8* %call, i64 8 33 store i8 1, i8* %tmp 34 ret float 1.0 35} 36 37; "caller" calls "foo" that takes a swifterror parameter. 38define float @caller(i8* %error_ref) { 39; CHECK-APPLE-LABEL: caller: 40; CHECK-APPLE: mov [[ID:x[0-9]+]], x0 41; CHECK-APPLE: mov x21, xzr 42; CHECK-APPLE: bl {{.*}}foo 43; CHECK-APPLE: mov x0, x21 44; CHECK-APPLE: cbnz x21 45; Access part of the error object and save it to error_ref 46; CHECK-APPLE: ldrb [[CODE:w[0-9]+]], [x0, #8] 47; CHECK-APPLE: strb [[CODE]], [{{.*}}[[ID]]] 48; CHECK-APPLE: bl {{.*}}free 49 50; CHECK-O0-LABEL: caller: 51; CHECK-O0: mov x21 52; CHECK-O0: bl {{.*}}foo 53; CHECK-O0: mov [[ID:x[0-9]+]], x21 54; CHECK-O0: cbnz x21 55entry: 56 %error_ptr_ref = alloca swifterror %swift_error* 57 store %swift_error* null, %swift_error** %error_ptr_ref 58 %call = call float @foo(%swift_error** swifterror %error_ptr_ref) 59 %error_from_foo = load %swift_error*, %swift_error** %error_ptr_ref 60 %had_error_from_foo = icmp ne %swift_error* %error_from_foo, null 61 %tmp = bitcast %swift_error* %error_from_foo to i8* 62 br i1 %had_error_from_foo, label %handler, label %cont 63cont: 64 %v1 = getelementptr inbounds %swift_error, %swift_error* %error_from_foo, i64 0, i32 1 65 %t = load i8, i8* %v1 66 store i8 %t, i8* %error_ref 67 br label %handler 68handler: 69 call void @free(i8* %tmp) 70 ret float 1.0 71} 72 73; "caller2" is the caller of "foo", it calls "foo" inside a loop. 74define float @caller2(i8* %error_ref) { 75; CHECK-APPLE-LABEL: caller2: 76; CHECK-APPLE: mov [[ID:x[0-9]+]], x0 77; CHECK-APPLE: fmov [[CMP:s[0-9]+]], #1.0 78; CHECK-APPLE: mov x21, xzr 79; CHECK-APPLE: bl {{.*}}foo 80; CHECK-APPLE: cbnz x21 81; CHECK-APPLE: fcmp s0, [[CMP]] 82; CHECK-APPLE: b.le 83; Access part of the error object and save it to error_ref 84; CHECK-APPLE: ldrb [[CODE:w[0-9]+]], [x21, #8] 85; CHECK-APPLE: strb [[CODE]], [{{.*}}[[ID]]] 86; CHECK-APPLE: mov x0, x21 87; CHECK-APPLE: bl {{.*}}free 88 89; CHECK-O0-LABEL: caller2: 90; CHECK-O0: mov x21 91; CHECK-O0: bl {{.*}}foo 92; CHECK-O0: mov [[ID:x[0-9]+]], x21 93; CHECK-O0: cbnz x21 94entry: 95 %error_ptr_ref = alloca swifterror %swift_error* 96 br label %bb_loop 97bb_loop: 98 store %swift_error* null, %swift_error** %error_ptr_ref 99 %call = call float @foo(%swift_error** swifterror %error_ptr_ref) 100 %error_from_foo = load %swift_error*, %swift_error** %error_ptr_ref 101 %had_error_from_foo = icmp ne %swift_error* %error_from_foo, null 102 %tmp = bitcast %swift_error* %error_from_foo to i8* 103 br i1 %had_error_from_foo, label %handler, label %cont 104cont: 105 %cmp = fcmp ogt float %call, 1.000000e+00 106 br i1 %cmp, label %bb_end, label %bb_loop 107bb_end: 108 %v1 = getelementptr inbounds %swift_error, %swift_error* %error_from_foo, i64 0, i32 1 109 %t = load i8, i8* %v1 110 store i8 %t, i8* %error_ref 111 br label %handler 112handler: 113 call void @free(i8* %tmp) 114 ret float 1.0 115} 116 117; "foo_if" is a function that takes a swifterror parameter, it sets swifterror 118; under a certain condition. 119define float @foo_if(%swift_error** swifterror %error_ptr_ref, i32 %cc) { 120; CHECK-APPLE-LABEL: foo_if: 121; CHECK-APPLE: cbz w0 122; CHECK-APPLE: orr w0, wzr, #0x10 123; CHECK-APPLE: malloc 124; CHECK-APPLE: orr [[ID:w[0-9]+]], wzr, #0x1 125; CHECK-APPLE: strb [[ID]], [x0, #8] 126; CHECK-APPLE: mov x21, x0 127; CHECK-APPLE-NOT: x21 128; CHECK-APPLE: ret 129 130; CHECK-O0-LABEL: foo_if: 131; spill x21 132; CHECK-O0: str x21, [sp, [[SLOT:#[0-9]+]]] 133; CHECK-O0: cbz w0 134; CHECK-O0: orr w{{.*}}, wzr, #0x10 135; CHECK-O0: malloc 136; CHECK-O0: mov [[ID:x[0-9]+]], x0 137; CHECK-O0: orr [[ID2:w[0-9]+]], wzr, #0x1 138; CHECK-O0: strb [[ID2]], [x0, #8] 139; CHECK-O0: mov x21, [[ID]] 140; CHECK-O0: ret 141; reload from stack 142; CHECK-O0: ldr [[ID3:x[0-9]+]], [sp, [[SLOT]]] 143; CHECK-O0: mov x21, [[ID3]] 144; CHECK-O0: ret 145entry: 146 %cond = icmp ne i32 %cc, 0 147 br i1 %cond, label %gen_error, label %normal 148 149gen_error: 150 %call = call i8* @malloc(i64 16) 151 %call.0 = bitcast i8* %call to %swift_error* 152 store %swift_error* %call.0, %swift_error** %error_ptr_ref 153 %tmp = getelementptr inbounds i8, i8* %call, i64 8 154 store i8 1, i8* %tmp 155 ret float 1.0 156 157normal: 158 ret float 0.0 159} 160 161; "foo_loop" is a function that takes a swifterror parameter, it sets swifterror 162; under a certain condition inside a loop. 163define float @foo_loop(%swift_error** swifterror %error_ptr_ref, i32 %cc, float %cc2) { 164; CHECK-APPLE-LABEL: foo_loop: 165; CHECK-APPLE: mov x0, x21 166; CHECK-APPLE: cbz 167; CHECK-APPLE: orr w0, wzr, #0x10 168; CHECK-APPLE: malloc 169; CHECK-APPLE: strb w{{.*}}, [x0, #8] 170; CHECK-APPLE: fcmp 171; CHECK-APPLE: b.le 172; CHECK-APPLE: mov x21, x0 173; CHECK-APPLE: ret 174 175; CHECK-O0-LABEL: foo_loop: 176; spill x21 177; CHECK-O0: str x21, [sp, [[SLOT:#[0-9]+]]] 178; CHECK-O0: b [[BB1:[A-Za-z0-9_]*]] 179; CHECK-O0: [[BB1]]: 180; CHECK-O0: ldr x0, [sp, [[SLOT]]] 181; CHECK-O0: str x0, [sp, [[SLOT2:#[0-9]+]]] 182; CHECK-O0: cbz {{.*}}, [[BB2:[A-Za-z0-9_]*]] 183; CHECK-O0: orr w{{.*}}, wzr, #0x10 184; CHECK-O0: malloc 185; CHECK-O0: mov [[ID:x[0-9]+]], x0 186; CHECK-O0: strb w{{.*}}, [{{.*}}[[ID]], #8] 187; spill x0 188; CHECK-O0: str x0, [sp, [[SLOT2]]] 189; CHECK-O0:[[BB2]]: 190; CHECK-O0: ldr x0, [sp, [[SLOT2]]] 191; CHECK-O0: fcmp 192; CHECK-O0: str x0, [sp, [[SLOT3:#[0-9]+]] 193; CHECK-O0: b.le [[BB1]] 194; reload from stack 195; CHECK-O0: ldr [[ID3:x[0-9]+]], [sp, [[SLOT3]]] 196; CHECK-O0: mov x21, [[ID3]] 197; CHECK-O0: ret 198entry: 199 br label %bb_loop 200 201bb_loop: 202 %cond = icmp ne i32 %cc, 0 203 br i1 %cond, label %gen_error, label %bb_cont 204 205gen_error: 206 %call = call i8* @malloc(i64 16) 207 %call.0 = bitcast i8* %call to %swift_error* 208 store %swift_error* %call.0, %swift_error** %error_ptr_ref 209 %tmp = getelementptr inbounds i8, i8* %call, i64 8 210 store i8 1, i8* %tmp 211 br label %bb_cont 212 213bb_cont: 214 %cmp = fcmp ogt float %cc2, 1.000000e+00 215 br i1 %cmp, label %bb_end, label %bb_loop 216bb_end: 217 ret float 0.0 218} 219 220%struct.S = type { i32, i32, i32, i32, i32, i32 } 221 222; "foo_sret" is a function that takes a swifterror parameter, it also has a sret 223; parameter. 224define void @foo_sret(%struct.S* sret %agg.result, i32 %val1, %swift_error** swifterror %error_ptr_ref) { 225; CHECK-APPLE-LABEL: foo_sret: 226; CHECK-APPLE: mov [[SRET:x[0-9]+]], x8 227; CHECK-APPLE: orr w0, wzr, #0x10 228; CHECK-APPLE: malloc 229; CHECK-APPLE: orr [[ID:w[0-9]+]], wzr, #0x1 230; CHECK-APPLE: strb [[ID]], [x0, #8] 231; CHECK-APPLE: str w{{.*}}, [{{.*}}[[SRET]], #4] 232; CHECK-APPLE: mov x21, x0 233; CHECK-APPLE-NOT: x21 234 235; CHECK-O0-LABEL: foo_sret: 236; CHECK-O0: orr w{{.*}}, wzr, #0x10 237; spill x8 238; CHECK-O0-DAG: str x8 239; spill x21 240; CHECK-O0-DAG: str x21 241; CHECK-O0: malloc 242; CHECK-O0: orr [[ID:w[0-9]+]], wzr, #0x1 243; CHECK-O0: strb [[ID]], [x0, #8] 244; reload from stack 245; CHECK-O0: ldr [[SRET:x[0-9]+]] 246; CHECK-O0: str w{{.*}}, [{{.*}}[[SRET]], #4] 247; CHECK-O0: mov x21 248; CHECK-O0-NOT: x21 249entry: 250 %call = call i8* @malloc(i64 16) 251 %call.0 = bitcast i8* %call to %swift_error* 252 store %swift_error* %call.0, %swift_error** %error_ptr_ref 253 %tmp = getelementptr inbounds i8, i8* %call, i64 8 254 store i8 1, i8* %tmp 255 %v2 = getelementptr inbounds %struct.S, %struct.S* %agg.result, i32 0, i32 1 256 store i32 %val1, i32* %v2 257 ret void 258} 259 260; "caller3" calls "foo_sret" that takes a swifterror parameter. 261define float @caller3(i8* %error_ref) { 262; CHECK-APPLE-LABEL: caller3: 263; CHECK-APPLE: mov [[ID:x[0-9]+]], x0 264; CHECK-APPLE: mov x21, xzr 265; CHECK-APPLE: bl {{.*}}foo_sret 266; CHECK-APPLE: mov x0, x21 267; CHECK-APPLE: cbnz x21 268; Access part of the error object and save it to error_ref 269; CHECK-APPLE: ldrb [[CODE:w[0-9]+]], [x0, #8] 270; CHECK-APPLE: strb [[CODE]], [{{.*}}[[ID]]] 271; CHECK-APPLE: bl {{.*}}free 272 273; CHECK-O0-LABEL: caller3: 274; spill x0 275; CHECK-O0: str x0 276; CHECK-O0: mov x21 277; CHECK-O0: bl {{.*}}foo_sret 278; CHECK-O0: mov [[ID2:x[0-9]+]], x21 279; CHECK-O0: cbnz x21 280; Access part of the error object and save it to error_ref 281; reload from stack 282; CHECK-O0: ldrb [[CODE:w[0-9]+]] 283; CHECK-O0: ldr [[ID:x[0-9]+]] 284; CHECK-O0: strb [[CODE]], [{{.*}}[[ID]]] 285; CHECK-O0: bl {{.*}}free 286entry: 287 %s = alloca %struct.S, align 8 288 %error_ptr_ref = alloca swifterror %swift_error* 289 store %swift_error* null, %swift_error** %error_ptr_ref 290 call void @foo_sret(%struct.S* sret %s, i32 1, %swift_error** swifterror %error_ptr_ref) 291 %error_from_foo = load %swift_error*, %swift_error** %error_ptr_ref 292 %had_error_from_foo = icmp ne %swift_error* %error_from_foo, null 293 %tmp = bitcast %swift_error* %error_from_foo to i8* 294 br i1 %had_error_from_foo, label %handler, label %cont 295cont: 296 %v1 = getelementptr inbounds %swift_error, %swift_error* %error_from_foo, i64 0, i32 1 297 %t = load i8, i8* %v1 298 store i8 %t, i8* %error_ref 299 br label %handler 300handler: 301 call void @free(i8* %tmp) 302 ret float 1.0 303} 304 305; "foo_vararg" is a function that takes a swifterror parameter, it also has 306; variable number of arguments. 307declare void @llvm.va_start(i8*) nounwind 308define float @foo_vararg(%swift_error** swifterror %error_ptr_ref, ...) { 309; CHECK-APPLE-LABEL: foo_vararg: 310; CHECK-APPLE: orr w0, wzr, #0x10 311; CHECK-APPLE: malloc 312; CHECK-APPLE-DAG: orr [[ID:w[0-9]+]], wzr, #0x1 313; CHECK-APPLE-DAG: add [[ARGS:x[0-9]+]], [[TMP:x[0-9]+]], #16 314; CHECK-APPLE-DAG: strb [[ID]], [x0, #8] 315 316; First vararg 317; CHECK-APPLE-DAG: orr {{x[0-9]+}}, [[ARGS]], #0x8 318; CHECK-APPLE-DAG: ldr {{w[0-9]+}}, [{{.*}}[[TMP]], #16] 319; Second vararg 320; CHECK-APPLE-DAG: ldr {{w[0-9]+}}, [{{x[0-9]+}}], #8 321; CHECK-APPLE-DAG: add {{x[0-9]+}}, {{x[0-9]+}}, #16 322; Third vararg 323; CHECK-APPLE: ldr {{w[0-9]+}}, [{{x[0-9]+}}], #8 324 325; CHECK-APPLE: mov x21, x0 326; CHECK-APPLE-NOT: x21 327entry: 328 %call = call i8* @malloc(i64 16) 329 %call.0 = bitcast i8* %call to %swift_error* 330 store %swift_error* %call.0, %swift_error** %error_ptr_ref 331 %tmp = getelementptr inbounds i8, i8* %call, i64 8 332 store i8 1, i8* %tmp 333 334 %args = alloca i8*, align 8 335 %a10 = alloca i32, align 4 336 %a11 = alloca i32, align 4 337 %a12 = alloca i32, align 4 338 %v10 = bitcast i8** %args to i8* 339 call void @llvm.va_start(i8* %v10) 340 %v11 = va_arg i8** %args, i32 341 store i32 %v11, i32* %a10, align 4 342 %v12 = va_arg i8** %args, i32 343 store i32 %v12, i32* %a11, align 4 344 %v13 = va_arg i8** %args, i32 345 store i32 %v13, i32* %a12, align 4 346 347 ret float 1.0 348} 349 350; "caller4" calls "foo_vararg" that takes a swifterror parameter. 351define float @caller4(i8* %error_ref) { 352; CHECK-APPLE-LABEL: caller4: 353 354; CHECK-APPLE: mov [[ID:x[0-9]+]], x0 355; CHECK-APPLE: stp {{x[0-9]+}}, {{x[0-9]+}}, [sp, #8] 356; CHECK-APPLE: str {{x[0-9]+}}, [sp] 357 358; CHECK-APPLE: mov x21, xzr 359; CHECK-APPLE: bl {{.*}}foo_vararg 360; CHECK-APPLE: mov x0, x21 361; CHECK-APPLE: cbnz x21 362; Access part of the error object and save it to error_ref 363; CHECK-APPLE: ldrb [[CODE:w[0-9]+]], [x0, #8] 364; CHECK-APPLE: strb [[CODE]], [{{.*}}[[ID]]] 365; CHECK-APPLE: bl {{.*}}free 366entry: 367 %error_ptr_ref = alloca swifterror %swift_error* 368 store %swift_error* null, %swift_error** %error_ptr_ref 369 370 %a10 = alloca i32, align 4 371 %a11 = alloca i32, align 4 372 %a12 = alloca i32, align 4 373 store i32 10, i32* %a10, align 4 374 store i32 11, i32* %a11, align 4 375 store i32 12, i32* %a12, align 4 376 %v10 = load i32, i32* %a10, align 4 377 %v11 = load i32, i32* %a11, align 4 378 %v12 = load i32, i32* %a12, align 4 379 380 %call = call float (%swift_error**, ...) @foo_vararg(%swift_error** swifterror %error_ptr_ref, i32 %v10, i32 %v11, i32 %v12) 381 %error_from_foo = load %swift_error*, %swift_error** %error_ptr_ref 382 %had_error_from_foo = icmp ne %swift_error* %error_from_foo, null 383 %tmp = bitcast %swift_error* %error_from_foo to i8* 384 br i1 %had_error_from_foo, label %handler, label %cont 385 386cont: 387 %v1 = getelementptr inbounds %swift_error, %swift_error* %error_from_foo, i64 0, i32 1 388 %t = load i8, i8* %v1 389 store i8 %t, i8* %error_ref 390 br label %handler 391handler: 392 call void @free(i8* %tmp) 393 ret float 1.0 394} 395 396; Check that we don't blow up on tail calling swifterror argument functions. 397define float @tailcallswifterror(%swift_error** swifterror %error_ptr_ref) { 398entry: 399 %0 = tail call float @tailcallswifterror(%swift_error** swifterror %error_ptr_ref) 400 ret float %0 401} 402define swiftcc float @tailcallswifterror_swiftcc(%swift_error** swifterror %error_ptr_ref) { 403entry: 404 %0 = tail call swiftcc float @tailcallswifterror_swiftcc(%swift_error** swifterror %error_ptr_ref) 405 ret float %0 406} 407 408; CHECK-APPLE-LABEL: swifterror_clobber 409; CHECK-APPLE: mov [[REG:x[0-9]+]], x21 410; CHECK-APPLE: nop 411; CHECK-APPLE: mov x21, [[REG]] 412define swiftcc void @swifterror_clobber(%swift_error** nocapture swifterror %err) { 413 call void asm sideeffect "nop", "~{x21}"() 414 ret void 415} 416 417; CHECK-APPLE-LABEL: swifterror_reg_clobber 418; CHECK-APPLE: stp {{.*}}x21 419; CHECK-APPLE: nop 420; CHECK-APPLE: ldp {{.*}}x21 421define swiftcc void @swifterror_reg_clobber(%swift_error** nocapture %err) { 422 call void asm sideeffect "nop", "~{x21}"() 423 ret void 424} 425; CHECK-APPLE-LABEL: params_in_reg 426; Save callee saved registers and swifterror since it will be clobbered by the first call to params_in_reg2. 427; CHECK-APPLE: stp x21, x28, [sp 428; CHECK-APPLE: stp x27, x26, [sp 429; CHECK-APPLE: stp x25, x24, [sp 430; CHECK-APPLE: stp x23, x22, [sp 431; CHECK-APPLE: stp x20, x19, [sp 432; CHECK-APPLE: stp x29, x30, [sp 433; CHECK-APPLE: str x20, [sp 434; Store argument registers. 435; CHECK-APPLE: mov x23, x7 436; CHECK-APPLE: mov x24, x6 437; CHECK-APPLE: mov x25, x5 438; CHECK-APPLE: mov x26, x4 439; CHECK-APPLE: mov x27, x3 440; CHECK-APPLE: mov x28, x2 441; CHECK-APPLE: mov x19, x1 442; CHECK-APPLE: mov x22, x0 443; Setup call. 444; CHECK-APPLE: orr w0, wzr, #0x1 445; CHECK-APPLE: orr w1, wzr, #0x2 446; CHECK-APPLE: orr w2, wzr, #0x3 447; CHECK-APPLE: orr w3, wzr, #0x4 448; CHECK-APPLE: mov w4, #5 449; CHECK-APPLE: orr w5, wzr, #0x6 450; CHECK-APPLE: orr w6, wzr, #0x7 451; CHECK-APPLE: orr w7, wzr, #0x8 452; CHECK-APPLE: mov x20, xzr 453; CHECK-APPLE: mov x21, xzr 454; CHECK-APPLE: bl _params_in_reg2 455; Restore original arguments for next call. 456; CHECK-APPLE: mov x0, x22 457; CHECK-APPLE: mov x1, x19 458; CHECK-APPLE: mov x2, x28 459; CHECK-APPLE: mov x3, x27 460; CHECK-APPLE: mov x4, x26 461; CHECK-APPLE: mov x5, x25 462; CHECK-APPLE: mov x6, x24 463; CHECK-APPLE: mov x7, x23 464; Restore original swiftself argument and swifterror %err. 465; CHECK-APPLE: ldp x20, x21, [sp 466; CHECK-APPLE: bl _params_in_reg2 467; Restore calle save registers but don't clober swifterror x21. 468; CHECK-APPLE-NOT: x21 469; CHECK-APPLE: ldp x29, x30, [sp 470; CHECK-APPLE-NOT: x21 471; CHECK-APPLE: ldp x20, x19, [sp 472; CHECK-APPLE-NOT: x21 473; CHECK-APPLE: ldp x23, x22, [sp 474; CHECK-APPLE-NOT: x21 475; CHECK-APPLE: ldp x25, x24, [sp 476; CHECK-APPLE-NOT: x21 477; CHECK-APPLE: ldp x27, x26, [sp 478; CHECK-APPLE-NOT: x21 479; CHECK-APPLE: ldr x28, [sp 480; CHECK-APPLE-NOT: x21 481; CHECK-APPLE: ret 482define swiftcc void @params_in_reg(i64, i64, i64, i64, i64, i64, i64, i64, i8* swiftself, %swift_error** nocapture swifterror %err) { 483 %error_ptr_ref = alloca swifterror %swift_error*, align 8 484 store %swift_error* null, %swift_error** %error_ptr_ref 485 call swiftcc void @params_in_reg2(i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7, i64 8, i8* swiftself null, %swift_error** nocapture swifterror %error_ptr_ref) 486 call swiftcc void @params_in_reg2(i64 %0, i64 %1, i64 %2, i64 %3, i64 %4, i64 %5, i64 %6, i64 %7, i8* swiftself %8, %swift_error** nocapture swifterror %err) 487 ret void 488} 489declare swiftcc void @params_in_reg2(i64, i64, i64, i64, i64, i64, i64, i64, i8* swiftself, %swift_error** nocapture swifterror %err) 490 491; CHECK-APPLE-LABEL: params_and_return_in_reg 492; Store callee saved registers. 493; CHECK-APPLE: stp x20, x28, [sp, #24 494; CHECK-APPLE: stp x27, x26, [sp 495; CHECK-APPLE: stp x25, x24, [sp 496; CHECK-APPLE: stp x23, x22, [sp 497; CHECK-APPLE: stp x20, x19, [sp 498; CHECK-APPLE: stp x29, x30, [sp 499; Save original arguments. 500; CHECK-APPLE: mov x23, x21 501; CHECK-APPLE: str x7, [sp, #16] 502; CHECK-APPLE: mov x24, x6 503; CHECK-APPLE: mov x25, x5 504; CHECK-APPLE: mov x26, x4 505; CHECK-APPLE: mov x27, x3 506; CHECK-APPLE: mov x28, x2 507; CHECK-APPLE: mov x19, x1 508; CHECK-APPLE: mov x22, x0 509; Setup call arguments. 510; CHECK-APPLE: orr w0, wzr, #0x1 511; CHECK-APPLE: orr w1, wzr, #0x2 512; CHECK-APPLE: orr w2, wzr, #0x3 513; CHECK-APPLE: orr w3, wzr, #0x4 514; CHECK-APPLE: mov w4, #5 515; CHECK-APPLE: orr w5, wzr, #0x6 516; CHECK-APPLE: orr w6, wzr, #0x7 517; CHECK-APPLE: orr w7, wzr, #0x8 518; CHECK-APPLE: mov x20, xzr 519; CHECK-APPLE: mov x21, xzr 520; CHECK-APPLE: bl _params_in_reg2 521; Store swifterror %error_ptr_ref. 522; CHECK-APPLE: str x21, [sp, #8] 523; Setup call arguments from original arguments. 524; CHECK-APPLE: mov x0, x22 525; CHECK-APPLE: mov x1, x19 526; CHECK-APPLE: mov x2, x28 527; CHECK-APPLE: mov x3, x27 528; CHECK-APPLE: mov x4, x26 529; CHECK-APPLE: mov x5, x25 530; CHECK-APPLE: mov x6, x24 531; CHECK-APPLE: ldp x7, x20, [sp, #16] 532; CHECK-APPLE: mov x21, x23 533; CHECK-APPLE: bl _params_and_return_in_reg2 534; Store return values. 535; CHECK-APPLE: mov x19, x0 536; CHECK-APPLE: mov x22, x1 537; CHECK-APPLE: mov x24, x2 538; CHECK-APPLE: mov x25, x3 539; CHECK-APPLE: mov x26, x4 540; CHECK-APPLE: mov x27, x5 541; CHECK-APPLE: mov x28, x6 542; CHECK-APPLE: mov x23, x7 543; Save swifterror %err. 544; CHECK-APPLE: str x21, [sp, #24] 545; Setup call. 546; CHECK-APPLE: orr w0, wzr, #0x1 547; CHECK-APPLE: orr w1, wzr, #0x2 548; CHECK-APPLE: orr w2, wzr, #0x3 549; CHECK-APPLE: orr w3, wzr, #0x4 550; CHECK-APPLE: mov w4, #5 551; CHECK-APPLE: orr w5, wzr, #0x6 552; CHECK-APPLE: orr w6, wzr, #0x7 553; CHECK-APPLE: orr w7, wzr, #0x8 554; CHECK-APPLE: mov x20, xzr 555; ... setup call with swiferror %error_ptr_ref. 556; CHECK-APPLE: ldr x21, [sp, #8] 557; CHECK-APPLE: bl _params_in_reg2 558; Restore return values for return from this function. 559; CHECK-APPLE: mov x0, x19 560; CHECK-APPLE: mov x1, x22 561; CHECK-APPLE: mov x2, x24 562; CHECK-APPLE: mov x3, x25 563; CHECK-APPLE: mov x4, x26 564; CHECK-APPLE: mov x5, x27 565; CHECK-APPLE: mov x6, x28 566; CHECK-APPLE: mov x7, x23 567; Restore swifterror %err and callee save registers. 568; CHECK-APPLE: ldp x21, x28, [sp, #24 569; CHECK-APPLE: ldp x29, x30, [sp 570; CHECK-APPLE: ldp x20, x19, [sp 571; CHECK-APPLE: ldp x23, x22, [sp 572; CHECK-APPLE: ldp x25, x24, [sp 573; CHECK-APPLE: ldp x27, x26, [sp 574; CHECK-APPLE: ret 575define swiftcc { i64, i64, i64, i64, i64, i64, i64, i64 } @params_and_return_in_reg(i64, i64, i64, i64, i64, i64, i64, i64, i8* swiftself, %swift_error** nocapture swifterror %err) { 576 %error_ptr_ref = alloca swifterror %swift_error*, align 8 577 store %swift_error* null, %swift_error** %error_ptr_ref 578 call swiftcc void @params_in_reg2(i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7, i64 8, i8* swiftself null, %swift_error** nocapture swifterror %error_ptr_ref) 579 %val = call swiftcc { i64, i64, i64, i64, i64, i64, i64, i64 } @params_and_return_in_reg2(i64 %0, i64 %1, i64 %2, i64 %3, i64 %4, i64 %5, i64 %6, i64 %7, i8* swiftself %8, %swift_error** nocapture swifterror %err) 580 call swiftcc void @params_in_reg2(i64 1, i64 2, i64 3, i64 4, i64 5, i64 6, i64 7, i64 8, i8* swiftself null, %swift_error** nocapture swifterror %error_ptr_ref) 581 ret { i64, i64, i64, i64, i64, i64, i64, i64 } %val 582} 583 584declare swiftcc { i64, i64, i64, i64, i64, i64, i64, i64 } @params_and_return_in_reg2(i64, i64, i64, i64, i64, i64, i64, i64, i8* swiftself, %swift_error** nocapture swifterror %err) 585 586declare void @acallee(i8*) 587 588; Make sure we don't tail call if the caller returns a swifterror value. We 589; would have to move into the swifterror register before the tail call. 590; CHECK-APPLE: tailcall_from_swifterror: 591; CHECK-APPLE-NOT: b _acallee 592; CHECK-APPLE: bl _acallee 593 594define swiftcc void @tailcall_from_swifterror(%swift_error** swifterror %error_ptr_ref) { 595entry: 596 tail call void @acallee(i8* null) 597 ret void 598} 599 600declare swiftcc void @foo2(%swift_error** swifterror) 601 602; Make sure we properly assign registers during fast-isel. 603; CHECK-O0-LABEL: testAssign 604; CHECK-O0: mov [[TMP:x.*]], xzr 605; CHECK-O0: mov x21, [[TMP]] 606; CHECK-O0: bl _foo2 607; CHECK-O0: str x21, [s[[STK:.*]]] 608; CHECK-O0: ldr x0, [s[[STK]]] 609 610; CHECK-APPLE-LABEL: testAssign 611; CHECK-APPLE: mov x21, xzr 612; CHECK-APPLE: bl _foo2 613; CHECK-APPLE: mov x0, x21 614 615define swiftcc %swift_error* @testAssign(i8* %error_ref) { 616entry: 617 %error_ptr = alloca swifterror %swift_error* 618 store %swift_error* null, %swift_error** %error_ptr 619 call swiftcc void @foo2(%swift_error** swifterror %error_ptr) 620 br label %a 621 622a: 623 %error = load %swift_error*, %swift_error** %error_ptr 624 ret %swift_error* %error 625} 626