297 lines · plain
1; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py2; RUN: llc -mtriple=x86_64-apple-macosx -mcpu=core2 < %s | FileCheck %s3 4declare i64 @testi()5 6define i64 @test_trivial() {7; CHECK-LABEL: test_trivial:8; CHECK: ## %bb.0: ## %entry9; CHECK-NEXT: jmp _testi ## TAILCALL10entry:11 %A = tail call i64 @testi()12 ret i64 %A13}14 15define i64 @test_noop_bitcast() {16; CHECK-LABEL: test_noop_bitcast:17; CHECK: ## %bb.0: ## %entry18; CHECK-NEXT: jmp _testi ## TAILCALL19entry:20 %A = tail call i64 @testi()21 %B = bitcast i64 %A to i6422 ret i64 %B23}24 25; Tail call shouldn't be blocked by no-op inttoptr.26define ptr @test_inttoptr() {27; CHECK-LABEL: test_inttoptr:28; CHECK: ## %bb.0: ## %entry29; CHECK-NEXT: jmp _testi ## TAILCALL30entry:31 %A = tail call i64 @testi()32 %B = inttoptr i64 %A to ptr33 ret ptr %B34}35 36declare <4 x float> @testv()37 38define <4 x i32> @test_vectorbitcast() {39; CHECK-LABEL: test_vectorbitcast:40; CHECK: ## %bb.0: ## %entry41; CHECK-NEXT: jmp _testv ## TAILCALL42entry:43 %A = tail call <4 x float> @testv()44 %B = bitcast <4 x float> %A to <4 x i32>45 ret <4 x i32> %B46}47 48declare { i64, i64 } @testp()49 50define {i64, i64} @test_pair_trivial() {51; CHECK-LABEL: test_pair_trivial:52; CHECK: ## %bb.0: ## %entry53; CHECK-NEXT: jmp _testp ## TAILCALL54entry:55 %A = tail call { i64, i64} @testp()56 ret { i64, i64} %A57}58 59define {i64, i64} @test_pair_notail() {60; CHECK-LABEL: test_pair_notail:61; CHECK: ## %bb.0: ## %entry62; CHECK-NEXT: pushq %rax63; CHECK-NEXT: .cfi_def_cfa_offset 1664; CHECK-NEXT: callq _testi65; CHECK-NEXT: movq %rax, %rdx66; CHECK-NEXT: popq %rcx67; CHECK-NEXT: retq68entry:69 %A = tail call i64 @testi()70 71 %b = insertvalue {i64, i64} undef, i64 %A, 072 %c = insertvalue {i64, i64} %b, i64 %A, 173 74 ret { i64, i64} %c75}76 77define {i64, i64} @test_pair_extract_trivial() {78; CHECK-LABEL: test_pair_extract_trivial:79; CHECK: ## %bb.0: ## %entry80; CHECK-NEXT: jmp _testp ## TAILCALL81entry:82 %A = tail call { i64, i64} @testp()83 %x = extractvalue { i64, i64} %A, 084 %y = extractvalue { i64, i64} %A, 185 86 %b = insertvalue {i64, i64} undef, i64 %x, 087 %c = insertvalue {i64, i64} %b, i64 %y, 188 89 ret { i64, i64} %c90}91 92define {i64, i64} @test_pair_extract_notail() {93; CHECK-LABEL: test_pair_extract_notail:94; CHECK: ## %bb.0: ## %entry95; CHECK-NEXT: pushq %rax96; CHECK-NEXT: .cfi_def_cfa_offset 1697; CHECK-NEXT: callq _testp98; CHECK-NEXT: movq %rax, %rcx99; CHECK-NEXT: movq %rdx, %rax100; CHECK-NEXT: movq %rcx, %rdx101; CHECK-NEXT: popq %rcx102; CHECK-NEXT: retq103entry:104 %A = tail call { i64, i64} @testp()105 %x = extractvalue { i64, i64} %A, 0106 %y = extractvalue { i64, i64} %A, 1107 108 %b = insertvalue {i64, i64} undef, i64 %y, 0109 %c = insertvalue {i64, i64} %b, i64 %x, 1110 111 ret { i64, i64} %c112}113 114define {ptr, i64} @test_pair_extract_conv() {115; CHECK-LABEL: test_pair_extract_conv:116; CHECK: ## %bb.0: ## %entry117; CHECK-NEXT: jmp _testp ## TAILCALL118entry:119 %A = tail call { i64, i64} @testp()120 %x = extractvalue { i64, i64} %A, 0121 %y = extractvalue { i64, i64} %A, 1122 123 %x1 = inttoptr i64 %x to ptr124 125 %b = insertvalue {ptr, i64} undef, ptr %x1, 0126 %c = insertvalue {ptr, i64} %b, i64 %y, 1127 128 ret { ptr, i64} %c129}130 131define {i64, i64} @test_pair_extract_multiple() {132; CHECK-LABEL: test_pair_extract_multiple:133; CHECK: ## %bb.0: ## %entry134; CHECK-NEXT: jmp _testp ## TAILCALL135entry:136 %A = tail call { i64, i64} @testp()137 %x = extractvalue { i64, i64} %A, 0138 %y = extractvalue { i64, i64} %A, 1139 140 %b = insertvalue {i64, i64} undef, i64 %x, 0141 %c = insertvalue {i64, i64} %b, i64 %y, 1142 143 %x1 = extractvalue { i64, i64} %b, 0144 %y1 = extractvalue { i64, i64} %c, 1145 146 %d = insertvalue {i64, i64} undef, i64 %x1, 0147 %e = insertvalue {i64, i64} %b, i64 %y1, 1148 149 ret { i64, i64} %e150}151 152define {i64, i64} @test_pair_extract_undef() {153; CHECK-LABEL: test_pair_extract_undef:154; CHECK: ## %bb.0: ## %entry155; CHECK-NEXT: jmp _testp ## TAILCALL156entry:157 %A = tail call { i64, i64} @testp()158 %x = extractvalue { i64, i64} %A, 0159 160 %b = insertvalue {i64, i64} undef, i64 %x, 0161 162 ret { i64, i64} %b163}164 165declare { i64, { i32, i32 } } @testn()166 167define {i64, {i32, i32}} @test_nest() {168; CHECK-LABEL: test_nest:169; CHECK: ## %bb.0: ## %entry170; CHECK-NEXT: jmp _testn ## TAILCALL171entry:172 %A = tail call { i64, { i32, i32 } } @testn()173 %x = extractvalue { i64, { i32, i32}} %A, 0174 %y = extractvalue { i64, { i32, i32}} %A, 1175 %y1 = extractvalue { i32, i32} %y, 0176 %y2 = extractvalue { i32, i32} %y, 1177 178 %b = insertvalue {i64, {i32, i32}} undef, i64 %x, 0179 %c1 = insertvalue {i32, i32} undef, i32 %y1, 0180 %c2 = insertvalue {i32, i32} %c1, i32 %y2, 1181 %c = insertvalue {i64, {i32, i32}} %b, {i32, i32} %c2, 1182 183 ret { i64, { i32, i32}} %c184}185 186%struct.A = type { i32 }187%struct.B = type { %struct.A, i32 }188 189declare ptr @testu()190 191define ptr @test_upcast() {192; CHECK-LABEL: test_upcast:193; CHECK: ## %bb.0: ## %entry194; CHECK-NEXT: jmp _testu ## TAILCALL195entry:196 %A = tail call ptr @testu()197 ret ptr %A198}199 200; PR13006201define { i64, i64 } @crash(ptr %this) {202; CHECK-LABEL: crash:203; CHECK: ## %bb.0: ## %entry204; CHECK-NEXT: jmp _testp ## TAILCALL205entry:206 %c = tail call { i64, i64 } @testp()207 %mrv7 = insertvalue { i64, i64 } %c, i64 undef, 1208 ret { i64, i64 } %mrv7209}210 211%struct.funcs = type { ptr, ptr, ptr, ptr, i32 }212 213@func_table = external global [0 x %struct.funcs]214 215; Check that we can fold an indexed load into a tail call instruction.216define void @fold_indexed_load(ptr %mbstr, i64 %idxprom) nounwind uwtable ssp {217; CHECK-LABEL: fold_indexed_load:218; CHECK: ## %bb.0: ## %entry219; CHECK-NEXT: leaq (%rsi,%rsi,4), %rax220; CHECK-NEXT: movq _func_table@GOTPCREL(%rip), %rcx221; CHECK-NEXT: jmpq *16(%rcx,%rax,8) ## TAILCALL222entry:223 %dsplen = getelementptr inbounds [0 x %struct.funcs], ptr @func_table, i64 0, i64 %idxprom, i32 2224 %x1 = load ptr, ptr %dsplen, align 8225 %call = tail call i32 %x1(ptr %mbstr) nounwind226 ret void227}228 229@funcs = external constant [0 x ptr]230 231; <rdar://problem/12282281> Fold an indexed load into the tail call instruction.232; Calling a varargs function with 6 arguments requires 7 registers (%al is the233; vector count for varargs functions). This leaves %r11 as the only available234; scratch register.235;236; It is not possible to fold an indexed load into TCRETURNmi64 in that case.237;238; typedef int (*funcptr)(ptr, ...);239; extern const funcptr funcs[];240; int f(int n) {241; return funcs[n](0, 0, 0, 0, 0, 0);242; }243define i32 @rdar12282281(i32 %n) nounwind uwtable ssp {244; CHECK-LABEL: rdar12282281:245; CHECK: ## %bb.0: ## %entry246; CHECK-NEXT: movslq %edi, %rax247; CHECK-NEXT: movq _funcs@GOTPCREL(%rip), %rcx248; CHECK-NEXT: movq (%rcx,%rax,8), %r11249; CHECK-NEXT: xorl %edi, %edi250; CHECK-NEXT: xorl %esi, %esi251; CHECK-NEXT: xorl %edx, %edx252; CHECK-NEXT: xorl %ecx, %ecx253; CHECK-NEXT: xorl %r8d, %r8d254; CHECK-NEXT: xorl %r9d, %r9d255; CHECK-NEXT: xorl %eax, %eax256; CHECK-NEXT: jmpq *%r11 ## TAILCALL257entry:258 %idxprom = sext i32 %n to i64259 %arrayidx = getelementptr inbounds [0 x ptr], ptr @funcs, i64 0, i64 %idxprom260 %0 = load ptr, ptr %arrayidx, align 8261 %call = tail call i32 (ptr, ...) %0(ptr null, i32 0, i32 0, i32 0, i32 0, i32 0) nounwind262 ret i32 %call263}264 265declare x86_fp80 @fp80_callee(x86_fp80)266 267define x86_fp80 @fp80_call(x86_fp80 %x) nounwind {268; CHECK-LABEL: fp80_call:269; CHECK: ## %bb.0: ## %entry270; CHECK-NEXT: jmp _fp80_callee ## TAILCALL271entry:272 %call = tail call x86_fp80 @fp80_callee(x86_fp80 %x) nounwind273 ret x86_fp80 %call274}275 276declare double @trunc(double) nounwind readnone277 278; rdar://12229511 - Don't tail call trunc here.279define x86_fp80 @trunc_fp80(x86_fp80 %x) nounwind {280; CHECK-LABEL: trunc_fp80:281; CHECK: ## %bb.0: ## %entry282; CHECK-NEXT: subq $24, %rsp283; CHECK-NEXT: fldt {{[0-9]+}}(%rsp)284; CHECK-NEXT: fstpl {{[0-9]+}}(%rsp)285; CHECK-NEXT: movsd {{.*#+}} xmm0 = mem[0],zero286; CHECK-NEXT: callq _trunc287; CHECK-NEXT: movsd %xmm0, {{[0-9]+}}(%rsp)288; CHECK-NEXT: fldl {{[0-9]+}}(%rsp)289; CHECK-NEXT: addq $24, %rsp290; CHECK-NEXT: retq291entry:292 %conv = fptrunc x86_fp80 %x to double293 %call = tail call double @trunc(double %conv) nounwind readnone294 %conv1 = fpext double %call to x86_fp80295 ret x86_fp80 %conv1296}297