[llvm] r359040 - [X86] Add codegen prepare test exercising a bitcast + tail call

Francis Visoiu Mistrih via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 23 14:57:43 PDT 2019


Author: thegameg
Date: Tue Apr 23 14:57:43 2019
New Revision: 359040

URL: http://llvm.org/viewvc/llvm-project?rev=359040&view=rev
Log:
[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.

Modified:
    llvm/trunk/test/CodeGen/X86/tailcall-cgp-dup.ll

Modified: llvm/trunk/test/CodeGen/X86/tailcall-cgp-dup.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/tailcall-cgp-dup.ll?rev=359040&r1=359039&r2=359040&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/tailcall-cgp-dup.ll (original)
+++ llvm/trunk/test/CodeGen/X86/tailcall-cgp-dup.ll Tue Apr 23 14:57:43 2019
@@ -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:
   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
+}




More information about the llvm-commits mailing list