From: Francis Visoiu Mistrih Date: Tue, 23 Apr 2019 21:57:43 +0000 (+0000) Subject: [X86] Add codegen prepare test exercising a bitcast + tail call X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7f2f10be2afc2766d6b9d701d67f0fbab6922424;p=llvm [X86] Add codegen prepare test exercising a bitcast + tail call In preparation of https://reviews.llvm.org/D60837, add this test where we don't perform a tail call because we don't look through a bitcast. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359040 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/CodeGen/X86/tailcall-cgp-dup.ll b/test/CodeGen/X86/tailcall-cgp-dup.ll index 26b43e7fe4d..cd1d15944cb 100644 --- a/test/CodeGen/X86/tailcall-cgp-dup.ll +++ b/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 +}