diff options
-rw-r--r-- | llvm/test/CodeGen/X86/tailcall-cgp-dup.ll | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/llvm/test/CodeGen/X86/tailcall-cgp-dup.ll b/llvm/test/CodeGen/X86/tailcall-cgp-dup.ll index 26b43e7fe4d..cd1d15944cb 100644 --- a/llvm/test/CodeGen/X86/tailcall-cgp-dup.ll +++ b/llvm/test/CodeGen/X86/tailcall-cgp-dup.ll @@ -1,4 +1,6 @@ +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py ; RUN: llc < %s -mtriple=x86_64-apple-darwin | FileCheck %s +; RUN: opt -S -codegenprepare %s -mtriple=x86_64-apple-darwin -o - | FileCheck %s --check-prefix OPT ; Teach CGP to dup returns to enable tail call optimization. ; rdar://9147433 @@ -105,3 +107,43 @@ land.end: ; preds = %entry, %land.rhs ret i1 %0 } +; We need to look through bitcasts when looking for tail calls in phi incoming +; values. +declare i32* @g_ret32() +define i8* @f_ret8(i8* %obj) nounwind { +; OPT-LABEL: @f_ret8( +; OPT-NEXT: entry: +; OPT-NEXT: [[CMP:%.*]] = icmp eq i8* [[OBJ:%.*]], null +; OPT-NEXT: br i1 [[CMP]], label [[RETURN:%.*]], label [[IF_THEN:%.*]] +; OPT: if.then: +; OPT-NEXT: [[PTR:%.*]] = tail call i32* @g_ret32() +; OPT-NEXT: [[CASTED:%.*]] = bitcast i32* [[PTR]] to i8* +; OPT-NEXT: br label [[RETURN]] +; OPT: return: +; OPT-NEXT: [[RETVAL:%.*]] = phi i8* [ [[CASTED]], [[IF_THEN]] ], [ [[OBJ]], [[ENTRY:%.*]] ] +; OPT-NEXT: ret i8* [[RETVAL]] +; +; CHECK-LABEL: f_ret8: +; CHECK: ## %bb.0: ## %entry +; CHECK-NEXT: movq %rdi, %rax +; CHECK-NEXT: testq %rdi, %rdi +; CHECK-NEXT: je LBB3_2 +; CHECK-NEXT: ## %bb.1: ## %if.then +; CHECK-NEXT: pushq %rax +; CHECK-NEXT: callq _g_ret32 +; CHECK-NEXT: addq $8, %rsp +; CHECK-NEXT: LBB3_2: ## %return +; CHECK-NEXT: retq +entry: + %cmp = icmp eq i8* %obj, null + br i1 %cmp, label %return, label %if.then + +if.then: + %ptr = tail call i32* @g_ret32() + %casted = bitcast i32* %ptr to i8* + br label %return + +return: + %retval = phi i8* [ %casted, %if.then ], [ %obj, %entry ] + ret i8* %retval +} |