alloca-merge-align.ll 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. ; RUN: opt < %s -inline -S | FileCheck %s
  2. target datalayout = "E-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-f128:128:128-v128:128:128-n32:64"
  3. target triple = "powerpc64-unknown-linux-gnu"
  4. %struct.s = type { i32, i32 }
  5. define void @foo(%struct.s* byval nocapture readonly %a) {
  6. entry:
  7. %x = alloca [2 x i32], align 4
  8. %a1 = getelementptr inbounds %struct.s, %struct.s* %a, i64 0, i32 0
  9. %0 = load i32, i32* %a1, align 4
  10. %arrayidx = getelementptr inbounds [2 x i32], [2 x i32]* %x, i64 0, i64 0
  11. store i32 %0, i32* %arrayidx, align 4
  12. %b = getelementptr inbounds %struct.s, %struct.s* %a, i64 0, i32 1
  13. %1 = load i32, i32* %b, align 4
  14. %arrayidx2 = getelementptr inbounds [2 x i32], [2 x i32]* %x, i64 0, i64 1
  15. store i32 %1, i32* %arrayidx2, align 4
  16. call void @bar(i32* %arrayidx) #2
  17. ret void
  18. }
  19. define void @foo0(%struct.s* byval nocapture readonly %a) {
  20. entry:
  21. %x = alloca [2 x i32]
  22. %a1 = getelementptr inbounds %struct.s, %struct.s* %a, i64 0, i32 0
  23. %0 = load i32, i32* %a1, align 4
  24. %arrayidx = getelementptr inbounds [2 x i32], [2 x i32]* %x, i64 0, i64 0
  25. store i32 %0, i32* %arrayidx, align 4
  26. %b = getelementptr inbounds %struct.s, %struct.s* %a, i64 0, i32 1
  27. %1 = load i32, i32* %b, align 4
  28. %arrayidx2 = getelementptr inbounds [2 x i32], [2 x i32]* %x, i64 0, i64 1
  29. store i32 %1, i32* %arrayidx2, align 4
  30. call void @bar(i32* %arrayidx) #2
  31. ret void
  32. }
  33. define void @foo1(%struct.s* byval nocapture readonly %a) {
  34. entry:
  35. %x = alloca [2 x i32], align 1
  36. %a1 = getelementptr inbounds %struct.s, %struct.s* %a, i64 0, i32 0
  37. %0 = load i32, i32* %a1, align 4
  38. %arrayidx = getelementptr inbounds [2 x i32], [2 x i32]* %x, i64 0, i64 0
  39. store i32 %0, i32* %arrayidx, align 4
  40. %b = getelementptr inbounds %struct.s, %struct.s* %a, i64 0, i32 1
  41. %1 = load i32, i32* %b, align 4
  42. %arrayidx2 = getelementptr inbounds [2 x i32], [2 x i32]* %x, i64 0, i64 1
  43. store i32 %1, i32* %arrayidx2, align 4
  44. call void @bar(i32* %arrayidx) #2
  45. ret void
  46. }
  47. declare void @bar(i32*) #1
  48. define void @goo(%struct.s* byval nocapture readonly %a) {
  49. entry:
  50. %x = alloca [2 x i32], align 32
  51. %a1 = getelementptr inbounds %struct.s, %struct.s* %a, i64 0, i32 0
  52. %0 = load i32, i32* %a1, align 4
  53. %arrayidx = getelementptr inbounds [2 x i32], [2 x i32]* %x, i64 0, i64 0
  54. store i32 %0, i32* %arrayidx, align 32
  55. %b = getelementptr inbounds %struct.s, %struct.s* %a, i64 0, i32 1
  56. %1 = load i32, i32* %b, align 4
  57. %arrayidx2 = getelementptr inbounds [2 x i32], [2 x i32]* %x, i64 0, i64 1
  58. store i32 %1, i32* %arrayidx2, align 4
  59. call void @bar(i32* %arrayidx) #2
  60. ret void
  61. }
  62. ; CHECK-LABEL: @main
  63. ; CHECK: alloca [2 x i32], align 32
  64. ; CHECK-NOT: alloca [2 x i32]
  65. ; CHECK: ret i32 0
  66. define signext i32 @main() {
  67. entry:
  68. %a = alloca i64, align 8
  69. %tmpcast = bitcast i64* %a to %struct.s*
  70. store i64 0, i64* %a, align 8
  71. %a1 = bitcast i64* %a to i32*
  72. store i32 1, i32* %a1, align 8
  73. call void @foo(%struct.s* byval %tmpcast)
  74. store i32 2, i32* %a1, align 8
  75. call void @goo(%struct.s* byval %tmpcast)
  76. ret i32 0
  77. }
  78. ; CHECK-LABEL: @test0
  79. ; CHECK: alloca [2 x i32], align 32
  80. ; CHECK-NOT: alloca [2 x i32]
  81. ; CHECK: ret i32 0
  82. define signext i32 @test0() {
  83. entry:
  84. %a = alloca i64, align 8
  85. %tmpcast = bitcast i64* %a to %struct.s*
  86. store i64 0, i64* %a, align 8
  87. %a1 = bitcast i64* %a to i32*
  88. store i32 1, i32* %a1, align 8
  89. call void @foo0(%struct.s* byval %tmpcast)
  90. store i32 2, i32* %a1, align 8
  91. call void @goo(%struct.s* byval %tmpcast)
  92. ret i32 0
  93. }