1 ; RUN: opt < %s -basicaa -tailcallelim -inline -instcombine -dse -S | FileCheck %s
2 ; RUN: opt < %s -aa-pipeline=basic-aa -passes='function(tailcallelim),cgscc(inline,function(instcombine,dse))' -S | FileCheck %s
5 ; Calls that capture byval parameters cannot be marked as tail calls. Other
6 ; tails that don't capture byval parameters can still be tail calls.
8 target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32-n8:16:32"
9 target triple = "i386-pc-linux-gnu"
11 declare void @ext(i32*)
13 define void @bar(i32* byval %x) {
14 call void @ext(i32* %x)
18 define void @foo(i32* %x) {
19 ; CHECK-LABEL: define void @foo(
20 ; CHECK: llvm.lifetime.start
21 ; CHECK: store i32 %2, i32* %x
22 call void @bar(i32* byval %x)
26 define internal void @qux(i32* byval %x) {
27 call void @ext(i32* %x)
28 tail call void @ext(i32* null)
32 define void @frob(i32* %x) {
33 ; CHECK-LABEL: define void @frob(
34 ; CHECK: %[[POS:.*]] = alloca i32
35 ; CHECK: %[[VAL:.*]] = load i32, i32* %x
36 ; CHECK: store i32 %[[VAL]], i32* %[[POS]]
37 ; CHECK: {{^ *}}call void @ext(i32* nonnull %[[POS]]
38 ; CHECK: tail call void @ext(i32* null)
40 tail call void @qux(i32* byval %x)
44 ; A byval parameter passed into a function which is passed out as byval does
45 ; not block the call from being marked as tail.
47 declare void @ext2(i32* byval)
49 define void @bar2(i32* byval %x) {
50 call void @ext2(i32* byval %x)
54 define void @foobar(i32* %x) {
55 ; CHECK-LABEL: define void @foobar(
56 ; CHECK: %[[POS:.*]] = alloca i32
57 ; CHECK: %[[VAL:.*]] = load i32, i32* %x
58 ; CHECK: store i32 %[[VAL]], i32* %[[POS]]
59 ; CHECK: tail call void @ext2(i32* nonnull byval %[[POS]]
61 tail call void @bar2(i32* byval %x)
65 define void @barfoo() {
66 ; CHECK-LABEL: define void @barfoo(
67 ; CHECK: %[[POS:.*]] = alloca i32
68 ; CHECK: %[[VAL:.*]] = load i32, i32* %x
69 ; CHECK: store i32 %[[VAL]], i32* %[[POS]]
70 ; CHECK: tail call void @ext2(i32* nonnull byval %[[POS]]
73 tail call void @bar2(i32* byval %x)