Chris Lattner | 6f3ddbd | 2010-12-20 07:38:24 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -inline -S | FileCheck %s |
Chandler Carruth | 625038d | 2016-12-27 07:18:43 +0000 | [diff] [blame^] | 2 | ; RUN: opt < %s -passes='cgscc(inline)' -S | FileCheck %s |
Chris Lattner | 908117b | 2008-01-11 06:09:30 +0000 | [diff] [blame] | 3 | |
| 4 | ; Inlining a byval struct should cause an explicit copy into an alloca. |
| 5 | |
| 6 | %struct.ss = type { i32, i64 } |
| 7 | @.str = internal constant [10 x i8] c"%d, %lld\0A\00" ; <[10 x i8]*> [#uses=1] |
| 8 | |
| 9 | define internal void @f(%struct.ss* byval %b) nounwind { |
| 10 | entry: |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 11 | %tmp = getelementptr %struct.ss, %struct.ss* %b, i32 0, i32 0 ; <i32*> [#uses=2] |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 12 | %tmp1 = load i32, i32* %tmp, align 4 ; <i32> [#uses=1] |
Chris Lattner | 908117b | 2008-01-11 06:09:30 +0000 | [diff] [blame] | 13 | %tmp2 = add i32 %tmp1, 1 ; <i32> [#uses=1] |
| 14 | store i32 %tmp2, i32* %tmp, align 4 |
| 15 | ret void |
| 16 | } |
| 17 | |
| 18 | declare i32 @printf(i8*, ...) nounwind |
| 19 | |
Chris Lattner | a9a5c59 | 2010-12-20 07:39:57 +0000 | [diff] [blame] | 20 | define i32 @test1() nounwind { |
Chris Lattner | 908117b | 2008-01-11 06:09:30 +0000 | [diff] [blame] | 21 | entry: |
| 22 | %S = alloca %struct.ss ; <%struct.ss*> [#uses=4] |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 23 | %tmp1 = getelementptr %struct.ss, %struct.ss* %S, i32 0, i32 0 ; <i32*> [#uses=1] |
Chris Lattner | 908117b | 2008-01-11 06:09:30 +0000 | [diff] [blame] | 24 | store i32 1, i32* %tmp1, align 8 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 25 | %tmp4 = getelementptr %struct.ss, %struct.ss* %S, i32 0, i32 1 ; <i64*> [#uses=1] |
Chris Lattner | 908117b | 2008-01-11 06:09:30 +0000 | [diff] [blame] | 26 | store i64 2, i64* %tmp4, align 4 |
| 27 | call void @f( %struct.ss* byval %S ) nounwind |
| 28 | ret i32 0 |
David Majnemer | 120f4a0 | 2013-11-03 12:22:13 +0000 | [diff] [blame] | 29 | ; CHECK: @test1() |
Chris Lattner | 0099744 | 2010-12-20 07:57:41 +0000 | [diff] [blame] | 30 | ; CHECK: %S1 = alloca %struct.ss |
| 31 | ; CHECK: %S = alloca %struct.ss |
Chris Lattner | 6f3ddbd | 2010-12-20 07:38:24 +0000 | [diff] [blame] | 32 | ; CHECK: call void @llvm.memcpy |
Chris Lattner | a9a5c59 | 2010-12-20 07:39:57 +0000 | [diff] [blame] | 33 | ; CHECK: ret i32 0 |
| 34 | } |
| 35 | |
| 36 | ; Inlining a byval struct should NOT cause an explicit copy |
| 37 | ; into an alloca if the function is readonly |
| 38 | |
| 39 | define internal i32 @f2(%struct.ss* byval %b) nounwind readonly { |
| 40 | entry: |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 41 | %tmp = getelementptr %struct.ss, %struct.ss* %b, i32 0, i32 0 ; <i32*> [#uses=2] |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 42 | %tmp1 = load i32, i32* %tmp, align 4 ; <i32> [#uses=1] |
Chris Lattner | a9a5c59 | 2010-12-20 07:39:57 +0000 | [diff] [blame] | 43 | %tmp2 = add i32 %tmp1, 1 ; <i32> [#uses=1] |
| 44 | ret i32 %tmp2 |
| 45 | } |
| 46 | |
| 47 | define i32 @test2() nounwind { |
| 48 | entry: |
| 49 | %S = alloca %struct.ss ; <%struct.ss*> [#uses=4] |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 50 | %tmp1 = getelementptr %struct.ss, %struct.ss* %S, i32 0, i32 0 ; <i32*> [#uses=1] |
Chris Lattner | a9a5c59 | 2010-12-20 07:39:57 +0000 | [diff] [blame] | 51 | store i32 1, i32* %tmp1, align 8 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 52 | %tmp4 = getelementptr %struct.ss, %struct.ss* %S, i32 0, i32 1 ; <i64*> [#uses=1] |
Chris Lattner | a9a5c59 | 2010-12-20 07:39:57 +0000 | [diff] [blame] | 53 | store i64 2, i64* %tmp4, align 4 |
| 54 | %X = call i32 @f2( %struct.ss* byval %S ) nounwind |
| 55 | ret i32 %X |
David Majnemer | 120f4a0 | 2013-11-03 12:22:13 +0000 | [diff] [blame] | 56 | ; CHECK: @test2() |
Chris Lattner | a9a5c59 | 2010-12-20 07:39:57 +0000 | [diff] [blame] | 57 | ; CHECK: %S = alloca %struct.ss |
| 58 | ; CHECK-NOT: call void @llvm.memcpy |
| 59 | ; CHECK: ret i32 |
Chris Lattner | 908117b | 2008-01-11 06:09:30 +0000 | [diff] [blame] | 60 | } |
Chris Lattner | 7394680 | 2010-12-20 07:45:28 +0000 | [diff] [blame] | 61 | |
| 62 | |
| 63 | ; Inlining a byval with an explicit alignment needs to use *at least* that |
| 64 | ; alignment on the generated alloca. |
| 65 | ; PR8769 |
| 66 | declare void @g3(%struct.ss* %p) |
| 67 | |
| 68 | define internal void @f3(%struct.ss* byval align 64 %b) nounwind { |
| 69 | call void @g3(%struct.ss* %b) ;; Could make alignment assumptions! |
| 70 | ret void |
| 71 | } |
| 72 | |
| 73 | define void @test3() nounwind { |
| 74 | entry: |
| 75 | %S = alloca %struct.ss, align 1 ;; May not be aligned. |
| 76 | call void @f3( %struct.ss* byval align 64 %S) nounwind |
| 77 | ret void |
David Majnemer | 120f4a0 | 2013-11-03 12:22:13 +0000 | [diff] [blame] | 78 | ; CHECK: @test3() |
Chris Lattner | 0099744 | 2010-12-20 07:57:41 +0000 | [diff] [blame] | 79 | ; CHECK: %S1 = alloca %struct.ss, align 64 |
Chris Lattner | 7394680 | 2010-12-20 07:45:28 +0000 | [diff] [blame] | 80 | ; CHECK: %S = alloca %struct.ss |
| 81 | ; CHECK: call void @llvm.memcpy |
Chris Lattner | 0099744 | 2010-12-20 07:57:41 +0000 | [diff] [blame] | 82 | ; CHECK: call void @g3(%struct.ss* %S1) |
Chris Lattner | 7394680 | 2010-12-20 07:45:28 +0000 | [diff] [blame] | 83 | ; CHECK: ret void |
| 84 | } |
Chris Lattner | 0f11495 | 2010-12-20 08:10:40 +0000 | [diff] [blame] | 85 | |
| 86 | |
| 87 | ; Inlining a byval struct should NOT cause an explicit copy |
| 88 | ; into an alloca if the function is readonly, but should increase an alloca's |
| 89 | ; alignment to satisfy an explicit alignment request. |
| 90 | |
| 91 | define internal i32 @f4(%struct.ss* byval align 64 %b) nounwind readonly { |
| 92 | call void @g3(%struct.ss* %b) |
| 93 | ret i32 4 |
| 94 | } |
| 95 | |
| 96 | define i32 @test4() nounwind { |
| 97 | entry: |
| 98 | %S = alloca %struct.ss, align 2 ; <%struct.ss*> [#uses=4] |
| 99 | %X = call i32 @f4( %struct.ss* byval align 64 %S ) nounwind |
| 100 | ret i32 %X |
David Majnemer | 120f4a0 | 2013-11-03 12:22:13 +0000 | [diff] [blame] | 101 | ; CHECK: @test4() |
Chris Lattner | 0f11495 | 2010-12-20 08:10:40 +0000 | [diff] [blame] | 102 | ; CHECK: %S = alloca %struct.ss, align 64 |
| 103 | ; CHECK-NOT: call void @llvm.memcpy |
| 104 | ; CHECK: call void @g3 |
| 105 | ; CHECK: ret i32 4 |
| 106 | } |
| 107 | |
David Majnemer | 120f4a0 | 2013-11-03 12:22:13 +0000 | [diff] [blame] | 108 | %struct.S0 = type { i32 } |
Tom Stellard | bc7d87f | 2013-10-24 16:38:33 +0000 | [diff] [blame] | 109 | |
David Majnemer | 120f4a0 | 2013-11-03 12:22:13 +0000 | [diff] [blame] | 110 | @b = global %struct.S0 { i32 1 }, align 4 |
| 111 | @a = common global i32 0, align 4 |
| 112 | |
| 113 | define internal void @f5(%struct.S0* byval nocapture readonly align 4 %p) { |
Tom Stellard | bc7d87f | 2013-10-24 16:38:33 +0000 | [diff] [blame] | 114 | entry: |
David Blaikie | f72d05b | 2015-03-13 18:20:45 +0000 | [diff] [blame] | 115 | store i32 0, i32* getelementptr inbounds (%struct.S0, %struct.S0* @b, i64 0, i32 0), align 4 |
David Blaikie | 79e6c74 | 2015-02-27 19:29:02 +0000 | [diff] [blame] | 116 | %f2 = getelementptr inbounds %struct.S0, %struct.S0* %p, i64 0, i32 0 |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 117 | %0 = load i32, i32* %f2, align 4 |
David Majnemer | 120f4a0 | 2013-11-03 12:22:13 +0000 | [diff] [blame] | 118 | store i32 %0, i32* @a, align 4 |
| 119 | ret void |
Tom Stellard | bc7d87f | 2013-10-24 16:38:33 +0000 | [diff] [blame] | 120 | } |
| 121 | |
David Majnemer | 120f4a0 | 2013-11-03 12:22:13 +0000 | [diff] [blame] | 122 | define i32 @test5() { |
Tom Stellard | bc7d87f | 2013-10-24 16:38:33 +0000 | [diff] [blame] | 123 | entry: |
David Majnemer | 120f4a0 | 2013-11-03 12:22:13 +0000 | [diff] [blame] | 124 | tail call void @f5(%struct.S0* byval align 4 @b) |
David Blaikie | a79ac14 | 2015-02-27 21:17:42 +0000 | [diff] [blame] | 125 | %0 = load i32, i32* @a, align 4 |
David Majnemer | 120f4a0 | 2013-11-03 12:22:13 +0000 | [diff] [blame] | 126 | ret i32 %0 |
| 127 | ; CHECK: @test5() |
David Blaikie | f72d05b | 2015-03-13 18:20:45 +0000 | [diff] [blame] | 128 | ; CHECK: store i32 0, i32* getelementptr inbounds (%struct.S0, %struct.S0* @b, i64 0, i32 0), align 4 |
| 129 | ; CHECK-NOT: load i32, i32* getelementptr inbounds (%struct.S0, %struct.S0* @b, i64 0, i32 0), align 4 |
Tom Stellard | bc7d87f | 2013-10-24 16:38:33 +0000 | [diff] [blame] | 130 | } |