Bob Wilson | 694a10e | 2011-01-13 17:45:08 +0000 | [diff] [blame^] | 1 | ; RUN: opt < %s -scalarrepl -S | FileCheck %s |
Chris Lattner | d2fa781 | 2009-01-07 08:11:13 +0000 | [diff] [blame] | 2 | ; PR3290 |
Kenneth Uildriks | b908f8a | 2009-11-03 15:29:06 +0000 | [diff] [blame] | 3 | target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64" |
Chris Lattner | d2fa781 | 2009-01-07 08:11:13 +0000 | [diff] [blame] | 4 | |
| 5 | ;; Store of integer to whole alloca struct. |
| 6 | define i32 @test1(i64 %V) nounwind { |
Bob Wilson | 694a10e | 2011-01-13 17:45:08 +0000 | [diff] [blame^] | 7 | ; CHECK: test1 |
| 8 | ; CHECK-NOT: alloca |
Chris Lattner | d2fa781 | 2009-01-07 08:11:13 +0000 | [diff] [blame] | 9 | %X = alloca {{i32, i32}} |
| 10 | %Y = bitcast {{i32,i32}}* %X to i64* |
| 11 | store i64 %V, i64* %Y |
| 12 | |
| 13 | %A = getelementptr {{i32,i32}}* %X, i32 0, i32 0, i32 0 |
| 14 | %B = getelementptr {{i32,i32}}* %X, i32 0, i32 0, i32 1 |
| 15 | %a = load i32* %A |
| 16 | %b = load i32* %B |
| 17 | %c = add i32 %a, %b |
| 18 | ret i32 %c |
| 19 | } |
| 20 | |
| 21 | ;; Store of integer to whole struct/array alloca. |
| 22 | define float @test2(i128 %V) nounwind { |
Bob Wilson | 694a10e | 2011-01-13 17:45:08 +0000 | [diff] [blame^] | 23 | ; CHECK: test2 |
| 24 | ; CHECK-NOT: alloca |
Chris Lattner | d2fa781 | 2009-01-07 08:11:13 +0000 | [diff] [blame] | 25 | %X = alloca {[4 x float]} |
| 26 | %Y = bitcast {[4 x float]}* %X to i128* |
| 27 | store i128 %V, i128* %Y |
| 28 | |
| 29 | %A = getelementptr {[4 x float]}* %X, i32 0, i32 0, i32 0 |
| 30 | %B = getelementptr {[4 x float]}* %X, i32 0, i32 0, i32 3 |
| 31 | %a = load float* %A |
| 32 | %b = load float* %B |
Dan Gohman | ae3a0be | 2009-06-04 22:49:04 +0000 | [diff] [blame] | 33 | %c = fadd float %a, %b |
Chris Lattner | d2fa781 | 2009-01-07 08:11:13 +0000 | [diff] [blame] | 34 | ret float %c |
| 35 | } |
| 36 | |
Chris Lattner | 5ffe6ac | 2009-01-08 05:42:05 +0000 | [diff] [blame] | 37 | ;; Load of whole alloca struct as integer |
| 38 | define i64 @test3(i32 %a, i32 %b) nounwind { |
Bob Wilson | 694a10e | 2011-01-13 17:45:08 +0000 | [diff] [blame^] | 39 | ; CHECK: test3 |
| 40 | ; CHECK-NOT: alloca |
Chris Lattner | 5ffe6ac | 2009-01-08 05:42:05 +0000 | [diff] [blame] | 41 | %X = alloca {{i32, i32}} |
| 42 | |
| 43 | %A = getelementptr {{i32,i32}}* %X, i32 0, i32 0, i32 0 |
| 44 | %B = getelementptr {{i32,i32}}* %X, i32 0, i32 0, i32 1 |
| 45 | store i32 %a, i32* %A |
| 46 | store i32 %b, i32* %B |
| 47 | |
| 48 | %Y = bitcast {{i32,i32}}* %X to i64* |
| 49 | %Z = load i64* %Y |
| 50 | ret i64 %Z |
| 51 | } |
| 52 | |
| 53 | ;; load of integer from whole struct/array alloca. |
| 54 | define i128 @test4(float %a, float %b) nounwind { |
Bob Wilson | 694a10e | 2011-01-13 17:45:08 +0000 | [diff] [blame^] | 55 | ; CHECK: test4 |
| 56 | ; CHECK-NOT: alloca |
Chris Lattner | 5ffe6ac | 2009-01-08 05:42:05 +0000 | [diff] [blame] | 57 | %X = alloca {[4 x float]} |
| 58 | %A = getelementptr {[4 x float]}* %X, i32 0, i32 0, i32 0 |
| 59 | %B = getelementptr {[4 x float]}* %X, i32 0, i32 0, i32 3 |
| 60 | store float %a, float* %A |
| 61 | store float %b, float* %B |
| 62 | |
| 63 | %Y = bitcast {[4 x float]}* %X to i128* |
| 64 | %V = load i128* %Y |
| 65 | ret i128 %V |
| 66 | } |
Bob Wilson | 694a10e | 2011-01-13 17:45:08 +0000 | [diff] [blame^] | 67 | |
| 68 | ;; If the elements of a struct or array alloca contain padding, SROA can still |
| 69 | ;; split up the alloca as long as there is no padding between the elements. |
| 70 | %padded = type { i16, i8 } |
| 71 | %arr = type [4 x %padded] |
| 72 | define void @test5(%arr* %p, %arr* %q) { |
| 73 | entry: |
| 74 | ; CHECK: test5 |
| 75 | ; CHECK-NOT: i128 |
| 76 | %var = alloca %arr, align 4 |
| 77 | %vari8 = bitcast %arr* %var to i8* |
| 78 | %pi8 = bitcast %arr* %p to i8* |
| 79 | call void @llvm.memcpy.i32(i8* %vari8, i8* %pi8, i32 16, i32 4) |
| 80 | %qi8 = bitcast %arr* %q to i8* |
| 81 | call void @llvm.memcpy.i32(i8* %qi8, i8* %vari8, i32 16, i32 4) |
| 82 | ret void |
| 83 | } |
| 84 | |
| 85 | declare void @llvm.memcpy.i32(i8* nocapture, i8* nocapture, i32, i32) nounwind |