copy-aggregate.ll 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. ; RUN: opt < %s -scalarrepl -S | FileCheck %s
  2. ; PR3290
  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"
  4. ;; Store of integer to whole alloca struct.
  5. define i32 @test1(i64 %V) nounwind {
  6. ; CHECK: test1
  7. ; CHECK-NOT: alloca
  8. %X = alloca {{i32, i32}}
  9. %Y = bitcast {{i32,i32}}* %X to i64*
  10. store i64 %V, i64* %Y
  11. %A = getelementptr {{i32,i32}}, {{i32,i32}}* %X, i32 0, i32 0, i32 0
  12. %B = getelementptr {{i32,i32}}, {{i32,i32}}* %X, i32 0, i32 0, i32 1
  13. %a = load i32, i32* %A
  14. %b = load i32, i32* %B
  15. %c = add i32 %a, %b
  16. ret i32 %c
  17. }
  18. ;; Store of integer to whole struct/array alloca.
  19. define float @test2(i128 %V) nounwind {
  20. ; CHECK: test2
  21. ; CHECK-NOT: alloca
  22. %X = alloca {[4 x float]}
  23. %Y = bitcast {[4 x float]}* %X to i128*
  24. store i128 %V, i128* %Y
  25. %A = getelementptr {[4 x float]}, {[4 x float]}* %X, i32 0, i32 0, i32 0
  26. %B = getelementptr {[4 x float]}, {[4 x float]}* %X, i32 0, i32 0, i32 3
  27. %a = load float, float* %A
  28. %b = load float, float* %B
  29. %c = fadd float %a, %b
  30. ret float %c
  31. }
  32. ;; Load of whole alloca struct as integer
  33. define i64 @test3(i32 %a, i32 %b) nounwind {
  34. ; CHECK: test3
  35. ; CHECK-NOT: alloca
  36. %X = alloca {{i32, i32}}
  37. %A = getelementptr {{i32,i32}}, {{i32,i32}}* %X, i32 0, i32 0, i32 0
  38. %B = getelementptr {{i32,i32}}, {{i32,i32}}* %X, i32 0, i32 0, i32 1
  39. store i32 %a, i32* %A
  40. store i32 %b, i32* %B
  41. %Y = bitcast {{i32,i32}}* %X to i64*
  42. %Z = load i64, i64* %Y
  43. ret i64 %Z
  44. }
  45. ;; load of integer from whole struct/array alloca.
  46. define i128 @test4(float %a, float %b) nounwind {
  47. ; CHECK: test4
  48. ; CHECK-NOT: alloca
  49. %X = alloca {[4 x float]}
  50. %A = getelementptr {[4 x float]}, {[4 x float]}* %X, i32 0, i32 0, i32 0
  51. %B = getelementptr {[4 x float]}, {[4 x float]}* %X, i32 0, i32 0, i32 3
  52. store float %a, float* %A
  53. store float %b, float* %B
  54. %Y = bitcast {[4 x float]}* %X to i128*
  55. %V = load i128, i128* %Y
  56. ret i128 %V
  57. }
  58. ;; If the elements of a struct or array alloca contain padding, SROA can still
  59. ;; split up the alloca as long as there is no padding between the elements.
  60. %padded = type { i16, i8 }
  61. define void @test5([4 x %padded]* %p, [4 x %padded]* %q) {
  62. entry:
  63. ; CHECK: test5
  64. ; CHECK-NOT: i128
  65. %var = alloca [4 x %padded], align 4
  66. %vari8 = bitcast [4 x %padded]* %var to i8*
  67. %pi8 = bitcast [4 x %padded]* %p to i8*
  68. call void @llvm.memcpy.p0i8.p0i8.i32(i8* %vari8, i8* %pi8, i32 16, i32 4, i1 false)
  69. %qi8 = bitcast [4 x %padded]* %q to i8*
  70. call void @llvm.memcpy.p0i8.p0i8.i32(i8* %qi8, i8* %vari8, i32 16, i32 4, i1 false)
  71. ret void
  72. }
  73. ;; Check that an array alloca can be split up when it is also accessed with
  74. ;; a load or store as a homogeneous structure with the same element type and
  75. ;; number of elements as the array.
  76. %homogeneous = type { <8 x i16>, <8 x i16>, <8 x i16> }
  77. %wrapped_array = type { [3 x <8 x i16>] }
  78. define void @test6(i8* %p, %wrapped_array* %arr) {
  79. entry:
  80. ; CHECK: test6
  81. ; CHECK: store <8 x i16>
  82. ; CHECK: store <8 x i16>
  83. ; CHECK: store <8 x i16>
  84. %var = alloca %wrapped_array, align 16
  85. %res = call %homogeneous @test6callee(i8* %p)
  86. %varcast = bitcast %wrapped_array* %var to %homogeneous*
  87. store %homogeneous %res, %homogeneous* %varcast
  88. %tmp1 = bitcast %wrapped_array* %arr to i8*
  89. %tmp2 = bitcast %wrapped_array* %var to i8*
  90. call void @llvm.memcpy.p0i8.p0i8.i32(i8* %tmp1, i8* %tmp2, i32 48, i32 16, i1 false)
  91. ret void
  92. }
  93. declare %homogeneous @test6callee(i8* nocapture) nounwind
  94. declare void @llvm.memcpy.p0i8.p0i8.i32(i8* nocapture, i8* nocapture, i32, i32, i1) nounwind