1 ; RUN: opt < %s -tailcallelim -S | not grep call
4 ; Several cases where tail call elimination should move the load above the call,
5 ; then eliminate the tail recursion.
8 @global = external global i32 ; <i32*> [#uses=1]
9 @extern_weak_global = extern_weak global i32 ; <i32*> [#uses=1]
12 ; This load can be moved above the call because the function won't write to it
13 ; and the call has no side effects.
14 define fastcc i32 @raise_load_1(i32* %a_arg, i32 %a_len_arg, i32 %start_arg) nounwind readonly {
16 %tmp2 = icmp sge i32 %start_arg, %a_len_arg ; <i1> [#uses=1]
17 br i1 %tmp2, label %if, label %else
22 else: ; preds = %entry
23 %tmp7 = add i32 %start_arg, 1 ; <i32> [#uses=1]
24 %tmp8 = call fastcc i32 @raise_load_1(i32* %a_arg, i32 %a_len_arg, i32 %tmp7) ; <i32> [#uses=1]
25 %tmp9 = load i32* %a_arg ; <i32> [#uses=1]
26 %tmp10 = add i32 %tmp9, %tmp8 ; <i32> [#uses=1]
31 ; This load can be moved above the call because the function won't write to it
32 ; and the load provably can't trap.
33 define fastcc i32 @raise_load_2(i32* %a_arg, i32 %a_len_arg, i32 %start_arg) readonly {
35 %tmp2 = icmp sge i32 %start_arg, %a_len_arg ; <i1> [#uses=1]
36 br i1 %tmp2, label %if, label %else
41 else: ; preds = %entry
42 %nullcheck = icmp eq i32* %a_arg, null ; <i1> [#uses=1]
43 br i1 %nullcheck, label %unwind, label %recurse
45 unwind: ; preds = %else
48 recurse: ; preds = %else
49 %tmp7 = add i32 %start_arg, 1 ; <i32> [#uses=1]
50 %tmp8 = call fastcc i32 @raise_load_2(i32* %a_arg, i32 %a_len_arg, i32 %tmp7) ; <i32> [#uses=1]
51 %tmp9 = load i32* @global ; <i32> [#uses=1]
52 %tmp10 = add i32 %tmp9, %tmp8 ; <i32> [#uses=1]
57 ; This load can be safely moved above the call (even though it's from an
58 ; extern_weak global) because the call has no side effects.
59 define fastcc i32 @raise_load_3(i32* %a_arg, i32 %a_len_arg, i32 %start_arg) nounwind readonly {
61 %tmp2 = icmp sge i32 %start_arg, %a_len_arg ; <i1> [#uses=1]
62 br i1 %tmp2, label %if, label %else
67 else: ; preds = %entry
68 %tmp7 = add i32 %start_arg, 1 ; <i32> [#uses=1]
69 %tmp8 = call fastcc i32 @raise_load_3(i32* %a_arg, i32 %a_len_arg, i32 %tmp7) ; <i32> [#uses=1]
70 %tmp9 = load i32* @extern_weak_global ; <i32> [#uses=1]
71 %tmp10 = add i32 %tmp9, %tmp8 ; <i32> [#uses=1]
76 ; The second load can be safely moved above the call even though it's from an
77 ; unknown pointer (which normally means it might trap) because the first load
78 ; proves it doesn't trap.
79 define fastcc i32 @raise_load_4(i32* %a_arg, i32 %a_len_arg, i32 %start_arg) readonly {
81 %tmp2 = icmp sge i32 %start_arg, %a_len_arg ; <i1> [#uses=1]
82 br i1 %tmp2, label %if, label %else
87 else: ; preds = %entry
88 %nullcheck = icmp eq i32* %a_arg, null ; <i1> [#uses=1]
89 br i1 %nullcheck, label %unwind, label %recurse
91 unwind: ; preds = %else
94 recurse: ; preds = %else
95 %tmp7 = add i32 %start_arg, 1 ; <i32> [#uses=1]
96 %first = load i32* %a_arg ; <i32> [#uses=1]
97 %tmp8 = call fastcc i32 @raise_load_4(i32* %a_arg, i32 %first, i32 %tmp7) ; <i32> [#uses=1]
98 %second = load i32* %a_arg ; <i32> [#uses=1]
99 %tmp10 = add i32 %second, %tmp8 ; <i32> [#uses=1]