Chris Lattner | c6b3b25 | 2009-10-27 05:39:41 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -inline -scalarrepl -S | FileCheck %s |
Kenneth Uildriks | 90fedc6 | 2009-11-03 15:29:06 +0000 | [diff] [blame] | 2 | target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128" |
Chris Lattner | e2d7896 | 2002-06-24 17:46:05 +0000 | [diff] [blame] | 3 | |
Chris Lattner | 58ee24c | 2009-10-27 05:35:35 +0000 | [diff] [blame] | 4 | define i32 @test1f(i32 %i) { |
Tanya Lattner | 5640bd1 | 2008-03-01 09:15:35 +0000 | [diff] [blame] | 5 | ret i32 %i |
Chris Lattner | e2d7896 | 2002-06-24 17:46:05 +0000 | [diff] [blame] | 6 | } |
| 7 | |
Chris Lattner | 58ee24c | 2009-10-27 05:35:35 +0000 | [diff] [blame] | 8 | define i32 @test1(i32 %W) { |
| 9 | %X = call i32 @test1f(i32 7) |
| 10 | %Y = add i32 %X, %W |
Tanya Lattner | 5640bd1 | 2008-03-01 09:15:35 +0000 | [diff] [blame] | 11 | ret i32 %Y |
Chris Lattner | 58ee24c | 2009-10-27 05:35:35 +0000 | [diff] [blame] | 12 | ; CHECK: @test1( |
| 13 | ; CHECK-NEXT: %Y = add i32 7, %W |
| 14 | ; CHECK-NEXT: ret i32 %Y |
Chris Lattner | e2d7896 | 2002-06-24 17:46:05 +0000 | [diff] [blame] | 15 | } |
Tanya Lattner | 5640bd1 | 2008-03-01 09:15:35 +0000 | [diff] [blame] | 16 | |
Chris Lattner | c6b3b25 | 2009-10-27 05:39:41 +0000 | [diff] [blame] | 17 | |
| 18 | |
| 19 | ; rdar://7339069 |
| 20 | |
| 21 | %T = type { i32, i32 } |
| 22 | |
| 23 | ; CHECK-NOT: @test2f |
| 24 | define internal %T* @test2f(i1 %cond, %T* %P) { |
| 25 | br i1 %cond, label %T, label %F |
| 26 | |
| 27 | T: |
| 28 | %A = getelementptr %T* %P, i32 0, i32 0 |
| 29 | store i32 42, i32* %A |
| 30 | ret %T* %P |
| 31 | |
| 32 | F: |
| 33 | ret %T* %P |
| 34 | } |
| 35 | |
| 36 | define i32 @test2(i1 %cond) { |
| 37 | %A = alloca %T |
| 38 | |
| 39 | %B = call %T* @test2f(i1 %cond, %T* %A) |
| 40 | %C = getelementptr %T* %B, i32 0, i32 0 |
| 41 | %D = load i32* %C |
| 42 | ret i32 %D |
| 43 | |
| 44 | ; CHECK: @test2( |
| 45 | ; CHECK-NOT: = alloca |
Chris Lattner | 5e0fef8 | 2011-01-14 07:46:33 +0000 | [diff] [blame] | 46 | ; CHECK: ret i32 |
Chris Lattner | c6b3b25 | 2009-10-27 05:39:41 +0000 | [diff] [blame] | 47 | } |
James Molloy | 4f6fb95 | 2012-12-20 16:04:27 +0000 | [diff] [blame^] | 48 | |
| 49 | declare void @barrier() noduplicate |
| 50 | |
| 51 | define internal i32 @f() { |
| 52 | call void @barrier() noduplicate |
| 53 | ret i32 1 |
| 54 | } |
| 55 | |
| 56 | define i32 @g() { |
| 57 | call void @barrier() noduplicate |
| 58 | ret i32 2 |
| 59 | } |
| 60 | |
| 61 | define internal i32 @h() { |
| 62 | call void @barrier() noduplicate |
| 63 | ret i32 3 |
| 64 | } |
| 65 | |
| 66 | define i32 @test3() { |
| 67 | %b = call i32 @f() |
| 68 | ret i32 %b |
| 69 | } |
| 70 | |
| 71 | ; The call to @f cannot be inlined as there is another callsite |
| 72 | ; calling @f, and @f contains a noduplicate call. |
| 73 | ; |
| 74 | ; The call to @g cannot be inlined as it has external linkage. |
| 75 | ; |
| 76 | ; The call to @h *can* be inlined. |
| 77 | |
| 78 | ; CHECK: @test |
| 79 | define i32 @test() { |
| 80 | ; CHECK: call i32 @f() |
| 81 | %a = call i32 @f() |
| 82 | ; CHECK: call i32 @g() |
| 83 | %b = call i32 @g() |
| 84 | ; CHECK-NOT: call i32 @h() |
| 85 | %c = call i32 @h() |
| 86 | |
| 87 | %d = add i32 %a, %b |
| 88 | %e = add i32 %d, %c |
| 89 | |
| 90 | ret i32 %e |
| 91 | ; CHECK: } |
| 92 | } |