• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -basic-aa -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
3; PR7272
4
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.
7
8target 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"
9target triple = "i386-pc-linux-gnu"
10
11declare void @ext(i32*)
12
13define void @bar(i32* byval(i32) %x) {
14  call void @ext(i32* %x)
15  ret void
16}
17
18define 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(i32) %x)
23  ret void
24}
25
26define internal void @qux(i32* byval(i32) %x) {
27  call void @ext(i32* %x)
28  tail call void @ext(i32* null)
29  ret void
30}
31
32define 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)
39; CHECK: ret void
40  tail call void @qux(i32* byval(i32) %x)
41  ret void
42}
43
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.
46
47declare void @ext2(i32* byval(i32))
48
49define void @bar2(i32* byval(i32) %x) {
50  call void @ext2(i32* byval(i32) %x)
51  ret void
52}
53
54define 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(i32) %[[POS]]
60; CHECK: ret void
61  tail call void @bar2(i32* byval(i32) %x)
62  ret void
63}
64
65define 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(i32) %[[POS]]
71; CHECK: ret void
72  %x = alloca i32
73  tail call void @bar2(i32* byval(i32) %x)
74  ret void
75}
76