232 lines · plain
1; RUN: llc -verify-machineinstrs < %s -mtriple=aarch64-none-linux-gnu | FileCheck %s --check-prefixes=SDAG,COMMON2; RUN: llc -global-isel -global-isel-abort=1 -verify-machineinstrs < %s -mtriple=aarch64-none-linux-gnu | FileCheck %s --check-prefixes=GISEL,COMMON3 4declare tailcc void @callee_stack0()5declare tailcc void @callee_stack8([8 x i64], i64)6declare tailcc void @callee_stack16([8 x i64], i64, i64)7declare extern_weak tailcc void @callee_weak()8 9define tailcc void @caller_to0_from0() nounwind {10; COMMON-LABEL: caller_to0_from0:11; COMMON-NEXT: // %bb.12 13 tail call tailcc void @callee_stack0()14 ret void15 16; COMMON-NEXT: b callee_stack017}18 19define tailcc void @caller_to0_from8([8 x i64], i64) #0 {20; COMMON-LABEL: caller_to0_from8:21 22 tail call tailcc void @callee_stack0()23 ret void24 25; COMMON: add sp, sp, #1626; COMMON: .cfi_def_cfa_offset -1627; COMMON-NEXT: b callee_stack028}29 30define tailcc void @caller_to8_from0() "frame-pointer"="all" uwtable {31; COMMON-LABEL: caller_to8_from0:32 33; Key point is that the "42" should go #16 below incoming stack34; pointer (we didn't have arg space to reuse).35 tail call tailcc void @callee_stack8([8 x i64] undef, i64 42)36 ret void37 38; COMMON: str {{x[0-9]+}}, [x29, #16]39; COMMON: ldp x29, x30, [sp], #1640 ; If there is a sub here then the 42 will be briefly exposed to corruption41 ; from an interrupt if the kernel does not honour a red-zone, and a larger42 ; call could well overflow the red zone even if it is present.43; COMMON-NOT: sub sp,44; COMMON-NEXT: .cfi_def_cfa_offset 1645; COMMON-NEXT: .cfi_restore w3046; COMMON-NEXT: .cfi_restore w2947; COMMON-NEXT: b callee_stack848}49 50define tailcc void @caller_to8_from8([8 x i64], i64 %a) #0 {51; COMMON-LABEL: caller_to8_from8:52; COMMON-NOT: sub sp,53 54; Key point is that the "%a" should go where at SP on entry.55 tail call tailcc void @callee_stack8([8 x i64] undef, i64 42)56 ret void57 58; COMMON: str {{x[0-9]+}}, [sp]59; COMMON-NEXT: b callee_stack860}61 62define tailcc void @caller_to16_from8([8 x i64], i64 %a) #0 {63; COMMON-LABEL: caller_to16_from8:64; COMMON-NOT: sub sp,65 66; Important point is that the call reuses the "dead" argument space67; above %a on the stack. If it tries to go below incoming-SP then the68; callee will not deallocate the space, even in tailcc.69 tail call tailcc void @callee_stack16([8 x i64] undef, i64 42, i64 2)70 71; COMMON: stp {{x[0-9]+}}, {{x[0-9]+}}, [sp]72; COMMON-NEXT: b callee_stack1673 ret void74}75 76 77define tailcc void @caller_to8_from24([8 x i64], i64 %a, i64 %b, i64 %c) #0 {78; COMMON-LABEL: caller_to8_from24:79; COMMON-NOT: sub sp,80 81; Key point is that the "%a" should go where at #16 above SP on entry.82 tail call tailcc void @callee_stack8([8 x i64] undef, i64 42)83 ret void84 85; COMMON: str {{x[0-9]+}}, [sp, #16]!86; COMMON-NEXT: .cfi_def_cfa_offset -1687; COMMON-NEXT: b callee_stack888}89 90 91define tailcc void @caller_to16_from16([8 x i64], i64 %a, i64 %b) #0 {92; COMMON-LABEL: caller_to16_from16:93; COMMON-NOT: sub sp,94 95; Here we want to make sure that both loads happen before the stores:96; otherwise either %a or %b will be wrongly clobbered.97 tail call tailcc void @callee_stack16([8 x i64] undef, i64 %b, i64 %a)98 ret void99 100; COMMON: ldp {{x[0-9]+}}, {{x[0-9]+}}, [sp]101; COMMON: stp {{x[0-9]+}}, {{x[0-9]+}}, [sp]102; COMMON-NEXT: b callee_stack16103}104 105define tailcc void @disable_tail_calls() nounwind "disable-tail-calls"="true" {106; COMMON-LABEL: disable_tail_calls:107; COMMON-NEXT: // %bb.108 109 tail call tailcc void @callee_stack0()110 ret void111 112; COMMON: bl callee_stack0113; COMMON: ret114}115 116; Weakly-referenced extern functions cannot be tail-called, as AAELF does117; not define the behaviour of branch instructions to undefined weak symbols.118define tailcc void @caller_weak() #0 {119; COMMON-LABEL: caller_weak:120; COMMON: bl callee_weak121 tail call void @callee_weak()122 ret void123}124 125declare { [2 x float] } @get_vec2()126 127define { [3 x float] } @test_add_elem() #0 {128; SDAG-LABEL: test_add_elem:129; SDAG: bl get_vec2130; SDAG: fmov s2, #1.0131; SDAG: ret132; GISEL-LABEL: test_add_elem:133; GISEL: str x30, [sp, #-16]!134; GISEL: bl get_vec2135; GISEL: fmov s2, #1.0136; GISEL: ldr x30, [sp], #16137; GISEL: ret138 139 %call = tail call { [2 x float] } @get_vec2()140 %arr = extractvalue { [2 x float] } %call, 0141 %arr.0 = extractvalue [2 x float] %arr, 0142 %arr.1 = extractvalue [2 x float] %arr, 1143 144 %res.0 = insertvalue { [3 x float] } undef, float %arr.0, 0, 0145 %res.01 = insertvalue { [3 x float] } %res.0, float %arr.1, 0, 1146 %res.012 = insertvalue { [3 x float] } %res.01, float 1.000000e+00, 0, 2147 ret { [3 x float] } %res.012148}149 150declare double @get_double()151define { double, [2 x double] } @test_mismatched_insert() #0 {152; COMMON-LABEL: test_mismatched_insert:153; COMMON: bl get_double154; COMMON: bl get_double155; COMMON: bl get_double156; COMMON: ret157 158 %val0 = call double @get_double()159 %val1 = call double @get_double()160 %val2 = tail call double @get_double()161 162 %res.0 = insertvalue { double, [2 x double] } undef, double %val0, 0163 %res.01 = insertvalue { double, [2 x double] } %res.0, double %val1, 1, 0164 %res.012 = insertvalue { double, [2 x double] } %res.01, double %val2, 1, 1165 166 ret { double, [2 x double] } %res.012167}168 169define void @fromC_totail() #0 {170; COMMON-LABEL: fromC_totail:171; COMMON: sub sp, sp, #32172 173; COMMON-NOT: sub sp,174; COMMON: mov w[[TMP:[0-9]+]], #42175; COMMON: str x[[TMP]], [sp]176; COMMON: bl callee_stack8177 ; We must reset the stack to where it was before the call by undoing its extra stack pop.178; COMMON: str x[[TMP]], [sp, #-16]!179; COMMON: bl callee_stack8180; COMMON: sub sp, sp, #16181 182 call tailcc void @callee_stack8([8 x i64] undef, i64 42)183 call tailcc void @callee_stack8([8 x i64] undef, i64 42)184 ret void185}186 187define void @fromC_totail_noreservedframe(i32 %len) #0 {188; COMMON-LABEL: fromC_totail_noreservedframe:189; COMMON: stp x29, x30, [sp, #-32]!190 191; COMMON: mov w[[TMP:[0-9]+]], #42192 ; Note stack is subtracted here to allocate space for arg193; COMMON: str x[[TMP]], [sp, #-16]!194; COMMON: bl callee_stack8195 ; And here.196; COMMON: str x[[TMP]], [sp, #-16]!197; COMMON: bl callee_stack8198 ; But not restored here because callee_stack8 did that for us.199; COMMON-NOT: sub sp,200 201 ; Variable sized allocation prevents reserving frame at start of function so each call must allocate any stack space it needs.202 %var = alloca i32, i32 %len203 204 call tailcc void @callee_stack8([8 x i64] undef, i64 42)205 call tailcc void @callee_stack8([8 x i64] undef, i64 42)206 ret void207}208 209declare void @Ccallee_stack8([8 x i64], i64)210 211define tailcc void @fromtail_toC() #0 {212; COMMON-LABEL: fromtail_toC:213; COMMON: sub sp, sp, #32214 215; COMMON-NOT: sub sp,216; COMMON: mov w[[TMP:[0-9]+]], #42217; COMMON: str x[[TMP]], [sp]218; COMMON: bl Ccallee_stack8219 ; C callees will return with the stack exactly where we left it, so we mustn't try to fix anything.220; COMMON-NOT: add sp,221; COMMON-NOT: sub sp,222; COMMON: str x[[TMP]], [sp]{{$}}223; COMMON: bl Ccallee_stack8224; COMMON-NOT: sub sp,225 226 227 call void @Ccallee_stack8([8 x i64] undef, i64 42)228 call void @Ccallee_stack8([8 x i64] undef, i64 42)229 ret void230}231 232attributes #0 = { uwtable }