Rafael Espindola | 7da1ea8 | 2014-10-17 21:25:48 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -basicaa -tailcallelim -inline -instcombine -dse -S | FileCheck %s |
Chandler Carruth | 625038d | 2016-12-27 07:18:43 +0000 | [diff] [blame] | 2 | ; RUN: opt < %s -aa-pipeline=basic-aa -passes='function(tailcallelim),cgscc(inline,function(instcombine,dse))' -S | FileCheck %s |
Reid Kleckner | 9b2cc64 | 2014-04-21 20:48:47 +0000 | [diff] [blame] | 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 | |
| 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" |
| 10 | |
| 11 | declare void @ext(i32*) |
| 12 | |
| 13 | define void @bar(i32* byval %x) { |
| 14 | call void @ext(i32* %x) |
| 15 | ret void |
| 16 | } |
| 17 | |
| 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) |
| 23 | ret void |
| 24 | } |
| 25 | |
| 26 | define internal void @qux(i32* byval %x) { |
| 27 | call void @ext(i32* %x) |
| 28 | tail call void @ext(i32* null) |
| 29 | ret void |
| 30 | } |
Saleem Abdulrasool | 7f52921 | 2014-10-16 03:27:30 +0000 | [diff] [blame] | 31 | |
Reid Kleckner | 9b2cc64 | 2014-04-21 20:48:47 +0000 | [diff] [blame] | 32 | define void @frob(i32* %x) { |
| 33 | ; CHECK-LABEL: define void @frob( |
Rafael Espindola | 7da1ea8 | 2014-10-17 21:25:48 +0000 | [diff] [blame] | 34 | ; CHECK: %[[POS:.*]] = alloca i32 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 35 | ; CHECK: %[[VAL:.*]] = load i32, i32* %x |
Rafael Espindola | 7da1ea8 | 2014-10-17 21:25:48 +0000 | [diff] [blame] | 36 | ; CHECK: store i32 %[[VAL]], i32* %[[POS]] |
Philip Reames | c25df11 | 2015-06-16 20:24:25 +0000 | [diff] [blame] | 37 | ; CHECK: {{^ *}}call void @ext(i32* nonnull %[[POS]] |
Reid Kleckner | dd3f3ed | 2014-11-04 02:02:14 +0000 | [diff] [blame] | 38 | ; CHECK: tail call void @ext(i32* null) |
Reid Kleckner | 9b2cc64 | 2014-04-21 20:48:47 +0000 | [diff] [blame] | 39 | ; CHECK: ret void |
| 40 | tail call void @qux(i32* byval %x) |
| 41 | ret void |
| 42 | } |
Robert Lougher | 0c93ea2 | 2018-10-08 18:03:40 +0000 | [diff] [blame] | 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 | |
| 47 | declare void @ext2(i32* byval) |
| 48 | |
| 49 | define void @bar2(i32* byval %x) { |
| 50 | call void @ext2(i32* byval %x) |
| 51 | ret void |
| 52 | } |
| 53 | |
| 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* byval nonnull %[[POS]] |
| 60 | ; CHECK: ret void |
| 61 | tail call void @bar2(i32* byval %x) |
| 62 | ret void |
| 63 | } |
| 64 | |
| 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* byval nonnull %[[POS]] |
| 71 | ; CHECK: ret void |
| 72 | %x = alloca i32 |
| 73 | tail call void @bar2(i32* byval %x) |
| 74 | ret void |
| 75 | } |