Imported Upstream version 6.0.0.172

Former-commit-id: f3cc9b82f3e5bd8f0fd3ebc098f789556b44e9cd
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2019-04-12 14:10:50 +00:00
parent 8016999e4d
commit 64ac736ec5
32155 changed files with 3981439 additions and 75368 deletions

View File

@ -0,0 +1,20 @@
; RUN: opt < %s -tailcallelim -S | FileCheck %s
; PR7328
; PR7506
define i32 @foo(i32 %x) {
; CHECK-LABEL: define i32 @foo(
; CHECK: %accumulator.tr = phi i32 [ 1, %entry ], [ 0, %body ]
entry:
%cond = icmp ugt i32 %x, 0 ; <i1> [#uses=1]
br i1 %cond, label %return, label %body
body: ; preds = %entry
%y = add i32 %x, 1 ; <i32> [#uses=1]
%tmp = call i32 @foo(i32 %y) ; <i32> [#uses=0]
; CHECK-NOT: call
ret i32 0
; CHECK: ret i32 %accumulator.tr
return: ; preds = %entry
ret i32 1
}

View File

@ -0,0 +1,26 @@
; RUN: opt -tailcallelim -S < %s 2>&1 | FileCheck %s
; CHECK: add nsw i32
; CHECK-NEXT: br label
; CHECK: add nsw i32
; CHECK-NEXT: br label
; CHECK-NOT: Uses remain when a value is destroyed
define i32 @test(i32 %n) {
entry:
%cmp = icmp slt i32 %n, 2
br i1 %cmp, label %if.then, label %if.else
if.then: ; preds = %entry
%v1 = add nsw i32 %n, -2
%call1 = tail call i32 @test(i32 %v1)
br label %return
if.else: ; preds = %entry
%v2 = add nsw i32 %n, 4
%call2 = tail call i32 @test(i32 %v2)
br label %return
return: ; preds = %if.end, %if.else
%retval = phi i32 [ %call1, %if.then ], [ %call2, %if.else ]
ret i32 %retval
}

View File

@ -0,0 +1,75 @@
; RUN: opt < %s -tailcallelim -S | FileCheck %s
; RUN: opt < %s -passes=tailcallelim -S | FileCheck %s
define i32 @test1_factorial(i32 %x) {
entry:
%tmp.1 = icmp sgt i32 %x, 0 ; <i1> [#uses=1]
br i1 %tmp.1, label %then, label %else
then: ; preds = %entry
%tmp.6 = add i32 %x, -1 ; <i32> [#uses=1]
%tmp.4 = call i32 @test1_factorial( i32 %tmp.6 ) ; <i32> [#uses=1]
%tmp.7 = mul i32 %tmp.4, %x ; <i32> [#uses=1]
ret i32 %tmp.7
else: ; preds = %entry
ret i32 1
}
; CHECK-LABEL: define i32 @test1_factorial(
; CHECK: phi i32
; CHECK-NOT: call i32
; CHECK: else:
; This is a more aggressive form of accumulator recursion insertion, which
; requires noticing that X doesn't change as we perform the tailcall.
define i32 @test2_mul(i32 %x, i32 %y) {
entry:
%tmp.1 = icmp eq i32 %y, 0 ; <i1> [#uses=1]
br i1 %tmp.1, label %return, label %endif
endif: ; preds = %entry
%tmp.8 = add i32 %y, -1 ; <i32> [#uses=1]
%tmp.5 = call i32 @test2_mul( i32 %x, i32 %tmp.8 ) ; <i32> [#uses=1]
%tmp.9 = add i32 %tmp.5, %x ; <i32> [#uses=1]
ret i32 %tmp.9
return: ; preds = %entry
ret i32 %x
}
; CHECK-LABEL: define i32 @test2_mul(
; CHECK: phi i32
; CHECK-NOT: call i32
; CHECK: return:
define i64 @test3_fib(i64 %n) nounwind readnone {
; CHECK-LABEL: @test3_fib(
entry:
; CHECK: tailrecurse:
; CHECK: %accumulator.tr = phi i64 [ %n, %entry ], [ %3, %bb1 ]
; CHECK: %n.tr = phi i64 [ %n, %entry ], [ %2, %bb1 ]
switch i64 %n, label %bb1 [
; CHECK: switch i64 %n.tr, label %bb1 [
i64 0, label %bb2
i64 1, label %bb2
]
bb1:
; CHECK: bb1:
%0 = add i64 %n, -1
; CHECK: %0 = add i64 %n.tr, -1
%1 = tail call i64 @test3_fib(i64 %0) nounwind
; CHECK: %1 = tail call i64 @test3_fib(i64 %0)
%2 = add i64 %n, -2
; CHECK: %2 = add i64 %n.tr, -2
%3 = tail call i64 @test3_fib(i64 %2) nounwind
; CHECK-NOT: tail call i64 @test3_fib
%4 = add nsw i64 %3, %1
; CHECK: add nsw i64 %accumulator.tr, %1
ret i64 %4
; CHECK: br label %tailrecurse
bb2:
; CHECK: bb2:
ret i64 %n
; CHECK: ret i64 %accumulator.tr
}

View File

@ -0,0 +1,26 @@
; REQUIRES: asserts
; This function contains two tail calls, which should be eliminated
; RUN: opt < %s -tailcallelim -stats -disable-output 2>&1 | grep "2 tailcallelim"
define i32 @Ack(i32 %M.1, i32 %N.1) {
entry:
%tmp.1 = icmp eq i32 %M.1, 0 ; <i1> [#uses=1]
br i1 %tmp.1, label %then.0, label %endif.0
then.0: ; preds = %entry
%tmp.4 = add i32 %N.1, 1 ; <i32> [#uses=1]
ret i32 %tmp.4
endif.0: ; preds = %entry
%tmp.6 = icmp eq i32 %N.1, 0 ; <i1> [#uses=1]
br i1 %tmp.6, label %then.1, label %endif.1
then.1: ; preds = %endif.0
%tmp.10 = add i32 %M.1, -1 ; <i32> [#uses=1]
%tmp.8 = call i32 @Ack( i32 %tmp.10, i32 1 ) ; <i32> [#uses=1]
ret i32 %tmp.8
endif.1: ; preds = %endif.0
%tmp.13 = add i32 %M.1, -1 ; <i32> [#uses=1]
%tmp.17 = add i32 %N.1, -1 ; <i32> [#uses=1]
%tmp.14 = call i32 @Ack( i32 %M.1, i32 %tmp.17 ) ; <i32> [#uses=1]
%tmp.11 = call i32 @Ack( i32 %tmp.13, i32 %tmp.14 ) ; <i32> [#uses=1]
ret i32 %tmp.11
}

View File

@ -0,0 +1,200 @@
; RUN: opt < %s -tailcallelim -S | FileCheck %s
declare void @noarg()
declare void @use(i32*)
declare void @use_nocapture(i32* nocapture)
declare void @use2_nocapture(i32* nocapture, i32* nocapture)
; Trivial case. Mark @noarg with tail call.
define void @test0() {
; CHECK: tail call void @noarg()
call void @noarg()
ret void
}
; PR615. Make sure that we do not move the alloca so that it interferes with the tail call.
define i32 @test1() {
; CHECK: i32 @test1()
; CHECK-NEXT: alloca
%A = alloca i32 ; <i32*> [#uses=2]
store i32 5, i32* %A
call void @use(i32* %A)
; CHECK: tail call i32 @test1
%X = tail call i32 @test1() ; <i32> [#uses=1]
ret i32 %X
}
; This function contains intervening instructions which should be moved out of the way
define i32 @test2(i32 %X) {
; CHECK: i32 @test2
; CHECK-NOT: call
; CHECK: ret i32
entry:
%tmp.1 = icmp eq i32 %X, 0 ; <i1> [#uses=1]
br i1 %tmp.1, label %then.0, label %endif.0
then.0: ; preds = %entry
%tmp.4 = add i32 %X, 1 ; <i32> [#uses=1]
ret i32 %tmp.4
endif.0: ; preds = %entry
%tmp.10 = add i32 %X, -1 ; <i32> [#uses=1]
%tmp.8 = call i32 @test2(i32 %tmp.10) ; <i32> [#uses=1]
%DUMMY = add i32 %X, 1 ; <i32> [#uses=0]
ret i32 %tmp.8
}
; Though this case seems to be fairly unlikely to occur in the wild, someone
; plunked it into the demo script, so maybe they care about it.
define i32 @test3(i32 %c) {
; CHECK: i32 @test3
; CHECK-NOT: call
; CHECK: ret i32 0
entry:
%tmp.1 = icmp eq i32 %c, 0 ; <i1> [#uses=1]
br i1 %tmp.1, label %return, label %else
else: ; preds = %entry
%tmp.5 = add i32 %c, -1 ; <i32> [#uses=1]
%tmp.3 = call i32 @test3(i32 %tmp.5) ; <i32> [#uses=0]
ret i32 0
return: ; preds = %entry
ret i32 0
}
; Make sure that a nocapture pointer does not stop adding a tail call marker to
; an unrelated call and additionally that we do not mark the nocapture call with
; a tail call.
;
; rdar://14324281
define void @test4() {
; CHECK: void @test4
; CHECK-NOT: tail call void @use_nocapture
; CHECK: tail call void @noarg()
; CHECK: ret void
%a = alloca i32
call void @use_nocapture(i32* %a)
call void @noarg()
ret void
}
; Make sure that we do not perform TRE even with a nocapture use. This is due to
; bad codegen caused by PR962.
;
; rdar://14324281.
define i32* @test5(i32* nocapture %A, i1 %cond) {
; CHECK: i32* @test5
; CHECK-NOT: tailrecurse:
; CHECK: ret i32* null
%B = alloca i32
br i1 %cond, label %cond_true, label %cond_false
cond_true:
call i32* @test5(i32* %B, i1 false)
ret i32* null
cond_false:
call void @use2_nocapture(i32* %A, i32* %B)
call void @noarg()
ret i32* null
}
; PR14143: Make sure that we do not mark functions with nocapture allocas with tail.
;
; rdar://14324281.
define void @test6(i32* %a, i32* %b) {
; CHECK-LABEL: @test6(
; CHECK-NOT: tail call
; CHECK: ret void
%c = alloca [100 x i8], align 16
%tmp = bitcast [100 x i8]* %c to i32*
call void @use2_nocapture(i32* %b, i32* %tmp)
ret void
}
; PR14143: Make sure that we do not mark functions with nocapture allocas with tail.
;
; rdar://14324281
define void @test7(i32* %a, i32* %b) nounwind uwtable {
entry:
; CHECK-LABEL: @test7(
; CHECK-NOT: tail call
; CHECK: ret void
%c = alloca [100 x i8], align 16
%0 = bitcast [100 x i8]* %c to i32*
call void @use2_nocapture(i32* %0, i32* %a)
call void @use2_nocapture(i32* %b, i32* %0)
ret void
}
; If we have a mix of escaping captured/non-captured allocas, ensure that we do
; not do anything including marking callsites with the tail call marker.
;
; rdar://14324281.
define i32* @test8(i32* nocapture %A, i1 %cond) {
; CHECK: i32* @test8
; CHECK-NOT: tailrecurse:
; CHECK-NOT: tail call
; CHECK: ret i32* null
%B = alloca i32
%B2 = alloca i32
br i1 %cond, label %cond_true, label %cond_false
cond_true:
call void @use(i32* %B2)
call i32* @test8(i32* %B, i1 false)
ret i32* null
cond_false:
call void @use2_nocapture(i32* %A, i32* %B)
call void @noarg()
ret i32* null
}
; Don't tail call if a byval arg is captured.
define void @test9(i32* byval %a) {
; CHECK-LABEL: define void @test9(
; CHECK: {{^ *}}call void @use(
call void @use(i32* %a)
ret void
}
%struct.X = type { i8* }
declare void @ctor(%struct.X*)
define void @test10(%struct.X* noalias sret %agg.result, i1 zeroext %b) {
; CHECK-LABEL: @test10
entry:
%x = alloca %struct.X, align 8
br i1 %b, label %if.then, label %if.end
if.then: ; preds = %entry
call void @ctor(%struct.X* %agg.result)
; CHECK: tail call void @ctor
br label %return
if.end:
call void @ctor(%struct.X* %x)
; CHECK: call void @ctor
br label %return
return:
ret void
}
declare void @test11_helper1(i8** nocapture, i8*)
declare void @test11_helper2(i8*)
define void @test11() {
; CHECK-LABEL: @test11
; CHECK-NOT: tail
%a = alloca i8*
%b = alloca i8
call void @test11_helper1(i8** %a, i8* %b) ; a = &b
%c = load i8*, i8** %a
call void @test11_helper2(i8* %c)
; CHECK: call void @test11_helper2
ret void
}
; PR25928
define void @test12() {
entry:
; CHECK-LABEL: @test12
; CHECK: {{^ *}} call void undef(i8* undef) [ "foo"(i8* %e) ]
%e = alloca i8
call void undef(i8* undef) [ "foo"(i8* %e) ]
unreachable
}

View File

@ -0,0 +1,57 @@
; RUN: opt < %s -tailcallelim -S | FileCheck %s
define i32 @f_1(i32 %x) {
; CHECK-LABEL: @f_1(
wentry:
%cond = icmp ugt i32 %x, 0
br i1 %cond, label %return, label %body
body:
; CHECK: body:
; CHECK: call i32 @f_1(i32 %y) [ "deopt"() ]
%y = add i32 %x, 1
%tmp = call i32 @f_1(i32 %y) [ "deopt"() ]
ret i32 0
return:
ret i32 1
}
define i32 @f_2(i32 %x) {
; CHECK-LABEL: @f_2
entry:
%cond = icmp ugt i32 %x, 0
br i1 %cond, label %return, label %body
body:
; CHECK: body:
; CHECK: call i32 @f_2(i32 %y) [ "unknown"() ]
%y = add i32 %x, 1
%tmp = call i32 @f_2(i32 %y) [ "unknown"() ]
ret i32 0
return:
ret i32 1
}
declare void @func()
define void @f_3(i1 %B) personality i8 42 {
; CHECK-LABEL: @f_3(
entry:
invoke void @func()
to label %exit unwind label %merge
merge:
%cs1 = catchswitch within none [label %catch] unwind to caller
catch:
; CHECK: catch:
; CHECK: call void @f_3(i1 %B) [ "funclet"(token %cp) ]
%cp = catchpad within %cs1 []
call void @f_3(i1 %B) [ "funclet"(token %cp) ]
ret void
exit:
ret void
}

View File

@ -0,0 +1,82 @@
; RUN: opt < %s -tailcallelim -S | grep call | count 4
; PR4323
; Several cases where tail call elimination should not move the load above the
; call, and thus can't eliminate the tail recursion.
@extern_weak_global = extern_weak global i32 ; <i32*> [#uses=1]
; This load can't be safely moved above the call because the load is from an
; extern_weak global and may trap, but the call may unwind before that happens.
define fastcc i32 @no_tailrecelim_1(i32* %a_arg, i32 %a_len_arg, i32 %start_arg) readonly {
entry:
%tmp2 = icmp sge i32 %start_arg, %a_len_arg ; <i1> [#uses=1]
br i1 %tmp2, label %if, label %else
if: ; preds = %entry
ret i32 37
else: ; preds = %entry
%tmp7 = add i32 %start_arg, 1 ; <i32> [#uses=1]
%tmp8 = call fastcc i32 @no_tailrecelim_1(i32* %a_arg, i32 %a_len_arg, i32 %tmp7) ; <i32> [#uses=1]
%tmp9 = load i32, i32* @extern_weak_global ; <i32> [#uses=1]
%tmp10 = add i32 %tmp9, %tmp8 ; <i32> [#uses=1]
ret i32 %tmp10
}
; This load can't be safely moved above the call because function may write to the pointer.
define fastcc i32 @no_tailrecelim_2(i32* %a_arg, i32 %a_len_arg, i32 %start_arg) nounwind {
entry:
%tmp2 = icmp sge i32 %start_arg, %a_len_arg ; <i1> [#uses=1]
br i1 %tmp2, label %if, label %else
if: ; preds = %entry
store i32 1, i32* %a_arg
ret i32 0
else: ; preds = %entry
%tmp7 = add i32 %start_arg, 1 ; <i32> [#uses=1]
%tmp8 = call fastcc i32 @no_tailrecelim_2(i32* %a_arg, i32 %a_len_arg, i32 %tmp7) ; <i32> [#uses=1]
%tmp9 = load i32, i32* %a_arg ; <i32> [#uses=1]
%tmp10 = add i32 %tmp9, %tmp8 ; <i32> [#uses=1]
ret i32 %tmp10
}
; This load can't be safely moved above the call because that would change the
; order in which the load volatiles are performed.
define fastcc i32 @no_tailrecelim_3(i32* %a_arg, i32 %a_len_arg, i32 %start_arg) nounwind {
entry:
%tmp2 = icmp sge i32 %start_arg, %a_len_arg ; <i1> [#uses=1]
br i1 %tmp2, label %if, label %else
if: ; preds = %entry
ret i32 0
else: ; preds = %entry
%tmp7 = add i32 %start_arg, 1 ; <i32> [#uses=1]
%tmp8 = call fastcc i32 @no_tailrecelim_3(i32* %a_arg, i32 %a_len_arg, i32 %tmp7) ; <i32> [#uses=1]
%tmp9 = load volatile i32, i32* %a_arg ; <i32> [#uses=1]
%tmp10 = add i32 %tmp9, %tmp8 ; <i32> [#uses=1]
ret i32 %tmp10
}
; This load can NOT be moved above the call because the a_arg is not
; sufficiently dereferenceable.
define fastcc i32 @no_tailrecelim_4(i32* dereferenceable(2) %a_arg, i32 %a_len_arg, i32 %start_arg) readonly {
entry:
%tmp2 = icmp sge i32 %start_arg, %a_len_arg ; <i1> [#uses=1]
br i1 %tmp2, label %if, label %else
if: ; preds = %entry
ret i32 0
else: ; preds = %entry
%tmp7 = add i32 %start_arg, 1 ; <i32> [#uses=1]
%tmp8 = call fastcc i32 @no_tailrecelim_4(i32* %a_arg, i32 %a_len_arg, i32 %tmp7) ; <i32> [#uses=1]
%tmp9 = load i32, i32* %a_arg ; <i32> [#uses=1]
%tmp10 = add i32 %tmp9, %tmp8 ; <i32> [#uses=1]
ret i32 %tmp10
}

View File

@ -0,0 +1,26 @@
; REQUIRES: asserts
; Duplicate the return into if.end to enable TCE.
; RUN: opt -tailcallelim -stats -disable-output < %s 2>&1 | FileCheck %s
; CHECK: Number of return duplicated
define i32 @fib(i32 %n) nounwind ssp {
entry:
%cmp = icmp slt i32 %n, 2
br i1 %cmp, label %if.then, label %if.end
if.then: ; preds = %entry
br label %return
if.end: ; preds = %entry
%sub = add nsw i32 %n, -2
%call = call i32 @fib(i32 %sub)
%sub3 = add nsw i32 %n, -1
%call4 = call i32 @fib(i32 %sub3)
%add = add nsw i32 %call, %call4
br label %return
return: ; preds = %if.end, %if.then
%retval.0 = phi i32 [ 1, %if.then ], [ %add, %if.end ]
ret i32 %retval.0
}

View File

@ -0,0 +1,54 @@
; RUN: opt < %s -tailcallelim -S | FileCheck %s
; Don't turn this into an infinite loop, this is probably the implementation
; of fabs and we expect the codegen to lower fabs.
; CHECK: @fabs(double %f)
; CHECK: call
; CHECK: ret
define double @fabs(double %f) {
entry:
%tmp2 = call double @fabs( double %f ) ; <double> [#uses=1]
ret double %tmp2
}
; Do turn other calls into infinite loops though.
; CHECK-LABEL: define double @foo(
; CHECK-NOT: call
; CHECK: }
define double @foo(double %f) {
%t= call double @foo(double %f)
ret double %t
}
; CHECK-LABEL: define float @fabsf(
; CHECK-NOT: call
; CHECK: }
define float @fabsf(float %f) {
%t= call float @fabsf(float 2.0)
ret float %t
}
declare x86_fp80 @fabsl(x86_fp80 %f)
; Don't crash while transforming a function with infinite recursion.
define i32 @PR22704(i1 %bool) {
entry:
br i1 %bool, label %t, label %f
t:
%call1 = call i32 @PR22704(i1 1)
br label %return
f:
%call = call i32 @PR22704(i1 1)
br label %return
return:
ret i32 0
; CHECK-LABEL: @PR22704(
; CHECK: %bool.tr = phi i1 [ %bool, %entry ], [ true, %t ], [ true, %f ]
; CHECK: br i1 %bool.tr, label %t, label %f
}

View File

@ -0,0 +1,24 @@
; RUN: opt < %s -tailcallelim -S | FileCheck %s
; CHECK: tail call void @callee0()
; CHECK: notail call void @callee1()
define void @foo1(i32 %a) {
entry:
%tobool = icmp eq i32 %a, 0
br i1 %tobool, label %if.else, label %if.then
if.then:
call void @callee0()
br label %if.end
if.else:
notail call void @callee1()
br label %if.end
if.end:
ret void
}
declare void @callee0()
declare void @callee1()

View File

@ -0,0 +1,38 @@
; RUN: opt %s -tailcallelim -pass-remarks=tailcallelim -o /dev/null 2>&1 | FileCheck %s
; RUN: opt %s -o /dev/null -passes='require<opt-remark-emit>,tailcallelim' -pass-remarks=tailcallelim 2>&1 | FileCheck %s
; CHECK: /home/davide/pat.c:2:20: transforming tail recursion into loop
define i32 @fib(i32 %n) nounwind ssp {
entry:
%cmp = icmp slt i32 %n, 2
br i1 %cmp, label %if.then, label %if.end
if.then: ; preds = %entry
br label %return
if.end: ; preds = %entry
%sub = add nsw i32 %n, -2
%call = call i32 @fib(i32 %sub)
%sub3 = add nsw i32 %n, -1
%call4 = call i32 @fib(i32 %sub3), !dbg !8
%add = add nsw i32 %call, %call4
br label %return
return: ; preds = %if.end, %if.then
%retval.0 = phi i32 [ 1, %if.then ], [ %add, %if.end ]
ret i32 %retval.0
}
!llvm.dbg.cu = !{!0}
!llvm.module.flags = !{!3, !4}
!llvm.ident = !{!5}
!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 3.9.0 ", isOptimized: true, runtimeVersion: 0, emissionKind: NoDebug, enums: !2)
!1 = !DIFile(filename: "/home/davide/pat.c", directory: "/tmp")
!2 = !{}
!3 = !{i32 2, !"Debug Info Version", i32 3}
!4 = !{i32 1, !"PIC Level", i32 2}
!5 = !{!"clang version 3.9.0 "}
!6 = distinct !DISubprogram(name: "success", scope: !1, file: !1, line: 1, type: !7, isLocal: false, isDefinition: true, scopeLine: 1, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !2)
!7 = !DISubroutineType(types: !2)
!8 = !DILocation(line: 2, column: 20, scope: !6)

View File

@ -0,0 +1,174 @@
; RUN: opt < %s -tailcallelim -S | FileCheck %s
; PR4323
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
; Several cases where tail call elimination should move the load above the call,
; then eliminate the tail recursion.
@global = external global i32 ; <i32*> [#uses=1]
@extern_weak_global = extern_weak global i32 ; <i32*> [#uses=1]
; This load can be moved above the call because the function won't write to it
; and the call has no side effects.
define fastcc i32 @raise_load_1(i32* %a_arg, i32 %a_len_arg, i32 %start_arg) nounwind readonly {
; CHECK-LABEL: @raise_load_1(
; CHECK-NOT: call
; CHECK: load i32, i32*
; CHECK-NOT: call
; CHECK: }
entry:
%tmp2 = icmp sge i32 %start_arg, %a_len_arg ; <i1> [#uses=1]
br i1 %tmp2, label %if, label %else
if: ; preds = %entry
ret i32 0
else: ; preds = %entry
%tmp7 = add i32 %start_arg, 1 ; <i32> [#uses=1]
%tmp8 = call fastcc i32 @raise_load_1(i32* %a_arg, i32 %a_len_arg, i32 %tmp7) ; <i32> [#uses=1]
%tmp9 = load i32, i32* %a_arg ; <i32> [#uses=1]
%tmp10 = add i32 %tmp9, %tmp8 ; <i32> [#uses=1]
ret i32 %tmp10
}
; This load can be moved above the call because the function won't write to it
; and the load provably can't trap.
define fastcc i32 @raise_load_2(i32* %a_arg, i32 %a_len_arg, i32 %start_arg) readonly {
; CHECK-LABEL: @raise_load_2(
; CHECK-NOT: call
; CHECK: load i32, i32*
; CHECK-NOT: call
; CHECK: }
entry:
%tmp2 = icmp sge i32 %start_arg, %a_len_arg ; <i1> [#uses=1]
br i1 %tmp2, label %if, label %else
if: ; preds = %entry
ret i32 0
else: ; preds = %entry
%nullcheck = icmp eq i32* %a_arg, null ; <i1> [#uses=1]
br i1 %nullcheck, label %unwind, label %recurse
unwind: ; preds = %else
unreachable
recurse: ; preds = %else
%tmp7 = add i32 %start_arg, 1 ; <i32> [#uses=1]
%tmp8 = call fastcc i32 @raise_load_2(i32* %a_arg, i32 %a_len_arg, i32 %tmp7) ; <i32> [#uses=1]
%tmp9 = load i32, i32* @global ; <i32> [#uses=1]
%tmp10 = add i32 %tmp9, %tmp8 ; <i32> [#uses=1]
ret i32 %tmp10
}
; This load can be safely moved above the call (even though it's from an
; extern_weak global) because the call has no side effects.
define fastcc i32 @raise_load_3(i32* %a_arg, i32 %a_len_arg, i32 %start_arg) nounwind readonly {
; CHECK-LABEL: @raise_load_3(
; CHECK-NOT: call
; CHECK: load i32, i32*
; CHECK-NOT: call
; CHECK: }
entry:
%tmp2 = icmp sge i32 %start_arg, %a_len_arg ; <i1> [#uses=1]
br i1 %tmp2, label %if, label %else
if: ; preds = %entry
ret i32 0
else: ; preds = %entry
%tmp7 = add i32 %start_arg, 1 ; <i32> [#uses=1]
%tmp8 = call fastcc i32 @raise_load_3(i32* %a_arg, i32 %a_len_arg, i32 %tmp7) ; <i32> [#uses=1]
%tmp9 = load i32, i32* @extern_weak_global ; <i32> [#uses=1]
%tmp10 = add i32 %tmp9, %tmp8 ; <i32> [#uses=1]
ret i32 %tmp10
}
; The second load can be safely moved above the call even though it's from an
; unknown pointer (which normally means it might trap) because the first load
; proves it doesn't trap.
define fastcc i32 @raise_load_4(i32* %a_arg, i32 %a_len_arg, i32 %start_arg) readonly {
; CHECK-LABEL: @raise_load_4(
; CHECK-NOT: call
; CHECK: load i32, i32*
; CHECK-NEXT: load i32, i32*
; CHECK-NOT: call
; CHECK: }
entry:
%tmp2 = icmp sge i32 %start_arg, %a_len_arg ; <i1> [#uses=1]
br i1 %tmp2, label %if, label %else
if: ; preds = %entry
ret i32 0
else: ; preds = %entry
%nullcheck = icmp eq i32* %a_arg, null ; <i1> [#uses=1]
br i1 %nullcheck, label %unwind, label %recurse
unwind: ; preds = %else
unreachable
recurse: ; preds = %else
%tmp7 = add i32 %start_arg, 1 ; <i32> [#uses=1]
%first = load i32, i32* %a_arg ; <i32> [#uses=1]
%tmp8 = call fastcc i32 @raise_load_4(i32* %a_arg, i32 %first, i32 %tmp7) ; <i32> [#uses=1]
%second = load i32, i32* %a_arg ; <i32> [#uses=1]
%tmp10 = add i32 %second, %tmp8 ; <i32> [#uses=1]
ret i32 %tmp10
}
; This load can be moved above the call because the function won't write to it
; and the a_arg is dereferenceable.
define fastcc i32 @raise_load_5(i32* dereferenceable(4) %a_arg, i32 %a_len_arg, i32 %start_arg) readonly {
; CHECK-LABEL: @raise_load_5(
; CHECK-NOT: call
; CHECK: load i32, i32*
; CHECK-NOT: call
; CHECK: }
entry:
%tmp2 = icmp sge i32 %start_arg, %a_len_arg ; <i1> [#uses=1]
br i1 %tmp2, label %if, label %else
if: ; preds = %entry
ret i32 0
else: ; preds = %entry
%tmp7 = add i32 %start_arg, 1 ; <i32> [#uses=1]
%tmp8 = call fastcc i32 @raise_load_5(i32* %a_arg, i32 %a_len_arg, i32 %tmp7) ; <i32> [#uses=1]
%tmp9 = load i32, i32* %a_arg ; <i32> [#uses=1]
%tmp10 = add i32 %tmp9, %tmp8 ; <i32> [#uses=1]
ret i32 %tmp10
}
; This load can be moved above the call because the function call does not write to the memory the load
; is accessing and the load is safe to speculate.
define fastcc i32 @raise_load_6(i32* %a_arg, i32 %a_len_arg, i32 %start_arg) nounwind {
; CHECK-LABEL: @raise_load_6(
; CHECK-NOT: call
; CHECK: load i32, i32*
; CHECK-NOT: call
; CHECK: }
entry:
%s = alloca i32
store i32 4, i32* %s
%tmp2 = icmp sge i32 %start_arg, %a_len_arg ; <i1> [#uses=1]
br i1 %tmp2, label %if, label %else
if: ; preds = %entry
store i32 1, i32* %a_arg
ret i32 0
else: ; preds = %entry
%tmp7 = add i32 %start_arg, 1 ; <i32> [#uses=1]
%tmp8 = call fastcc i32 @raise_load_6(i32* %a_arg, i32 %a_len_arg, i32 %tmp7) ; <i32> [#uses=1]
%tmp9 = load i32, i32* %s ; <i32> [#uses=1]
%tmp10 = add i32 %tmp9, %tmp8 ; <i32> [#uses=1]
ret i32 %tmp10
}

View File

@ -0,0 +1,29 @@
; RUN: opt < %s -tailcallelim -S | FileCheck %s
; Test that we don't tail call in a functions that calls returns_twice
; functions.
declare void @bar()
; CHECK: foo1
; CHECK-NOT: tail call void @bar()
define void @foo1(i32* %x) {
bb:
%tmp75 = tail call i32 @setjmp(i32* %x)
call void @bar()
ret void
}
declare i32 @setjmp(i32*) returns_twice
; CHECK: foo2
; CHECK-NOT: tail call void @bar()
define void @foo2(i32* %x) {
bb:
%tmp75 = tail call i32 @zed2(i32* %x)
call void @bar()
ret void
}
declare i32 @zed2(i32*) returns_twice