vector_promote.ll 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. ; RUN: opt < %s -scalarrepl -S | FileCheck %s
  2. 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"
  3. target triple = "x86_64-apple-darwin10.0.0"
  4. define void @test1(<4 x float>* %F, float %f) {
  5. entry:
  6. %G = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
  7. %tmp = load <4 x float>, <4 x float>* %F ; <<4 x float>> [#uses=2]
  8. %tmp3 = fadd <4 x float> %tmp, %tmp ; <<4 x float>> [#uses=1]
  9. store <4 x float> %tmp3, <4 x float>* %G
  10. %G.upgrd.1 = getelementptr <4 x float>, <4 x float>* %G, i32 0, i32 0 ; <float*> [#uses=1]
  11. store float %f, float* %G.upgrd.1
  12. %tmp4 = load <4 x float>, <4 x float>* %G ; <<4 x float>> [#uses=2]
  13. %tmp6 = fadd <4 x float> %tmp4, %tmp4 ; <<4 x float>> [#uses=1]
  14. store <4 x float> %tmp6, <4 x float>* %F
  15. ret void
  16. ; CHECK-LABEL: @test1(
  17. ; CHECK-NOT: alloca
  18. ; CHECK: %tmp = load <4 x float>, <4 x float>* %F
  19. ; CHECK: fadd <4 x float> %tmp, %tmp
  20. ; CHECK-NEXT: insertelement <4 x float> %tmp3, float %f, i32 0
  21. }
  22. define void @test2(<4 x float>* %F, float %f) {
  23. entry:
  24. %G = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=3]
  25. %tmp = load <4 x float>, <4 x float>* %F ; <<4 x float>> [#uses=2]
  26. %tmp3 = fadd <4 x float> %tmp, %tmp ; <<4 x float>> [#uses=1]
  27. store <4 x float> %tmp3, <4 x float>* %G
  28. %tmp.upgrd.2 = getelementptr <4 x float>, <4 x float>* %G, i32 0, i32 2 ; <float*> [#uses=1]
  29. store float %f, float* %tmp.upgrd.2
  30. %tmp4 = load <4 x float>, <4 x float>* %G ; <<4 x float>> [#uses=2]
  31. %tmp6 = fadd <4 x float> %tmp4, %tmp4 ; <<4 x float>> [#uses=1]
  32. store <4 x float> %tmp6, <4 x float>* %F
  33. ret void
  34. ; CHECK-LABEL: @test2(
  35. ; CHECK-NOT: alloca
  36. ; CHECK: %tmp = load <4 x float>, <4 x float>* %F
  37. ; CHECK: fadd <4 x float> %tmp, %tmp
  38. ; CHECK-NEXT: insertelement <4 x float> %tmp3, float %f, i32 2
  39. }
  40. define void @test3(<4 x float>* %F, float* %f) {
  41. entry:
  42. %G = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
  43. %tmp = load <4 x float>, <4 x float>* %F ; <<4 x float>> [#uses=2]
  44. %tmp3 = fadd <4 x float> %tmp, %tmp ; <<4 x float>> [#uses=1]
  45. store <4 x float> %tmp3, <4 x float>* %G
  46. %tmp.upgrd.3 = getelementptr <4 x float>, <4 x float>* %G, i32 0, i32 2 ; <float*> [#uses=1]
  47. %tmp.upgrd.4 = load float, float* %tmp.upgrd.3 ; <float> [#uses=1]
  48. store float %tmp.upgrd.4, float* %f
  49. ret void
  50. ; CHECK-LABEL: @test3(
  51. ; CHECK-NOT: alloca
  52. ; CHECK: %tmp = load <4 x float>, <4 x float>* %F
  53. ; CHECK: fadd <4 x float> %tmp, %tmp
  54. ; CHECK-NEXT: extractelement <4 x float> %tmp3, i32 2
  55. }
  56. define void @test4(<4 x float>* %F, float* %f) {
  57. entry:
  58. %G = alloca <4 x float>, align 16 ; <<4 x float>*> [#uses=2]
  59. %tmp = load <4 x float>, <4 x float>* %F ; <<4 x float>> [#uses=2]
  60. %tmp3 = fadd <4 x float> %tmp, %tmp ; <<4 x float>> [#uses=1]
  61. store <4 x float> %tmp3, <4 x float>* %G
  62. %G.upgrd.5 = getelementptr <4 x float>, <4 x float>* %G, i32 0, i32 0 ; <float*> [#uses=1]
  63. %tmp.upgrd.6 = load float, float* %G.upgrd.5 ; <float> [#uses=1]
  64. store float %tmp.upgrd.6, float* %f
  65. ret void
  66. ; CHECK-LABEL: @test4(
  67. ; CHECK-NOT: alloca
  68. ; CHECK: %tmp = load <4 x float>, <4 x float>* %F
  69. ; CHECK: fadd <4 x float> %tmp, %tmp
  70. ; CHECK-NEXT: extractelement <4 x float> %tmp3, i32 0
  71. }
  72. define i32 @test5(float %X) { ;; should turn into bitcast.
  73. %X_addr = alloca [4 x float]
  74. %X1 = getelementptr [4 x float], [4 x float]* %X_addr, i32 0, i32 2
  75. store float %X, float* %X1
  76. %a = bitcast float* %X1 to i32*
  77. %tmp = load i32, i32* %a
  78. ret i32 %tmp
  79. ; CHECK-LABEL: @test5(
  80. ; CHECK-NEXT: bitcast float %X to i32
  81. ; CHECK-NEXT: ret i32
  82. }
  83. define i64 @test6(<2 x float> %X) {
  84. %X_addr = alloca <2 x float>
  85. store <2 x float> %X, <2 x float>* %X_addr
  86. %P = bitcast <2 x float>* %X_addr to i64*
  87. %tmp = load i64, i64* %P
  88. ret i64 %tmp
  89. ; CHECK-LABEL: @test6(
  90. ; CHECK: bitcast <2 x float> %X to i64
  91. ; CHECK: ret i64
  92. }
  93. %struct.test7 = type { [6 x i32] }
  94. define void @test7() {
  95. entry:
  96. %memtmp = alloca %struct.test7, align 16
  97. %0 = bitcast %struct.test7* %memtmp to <4 x i32>*
  98. store <4 x i32> zeroinitializer, <4 x i32>* %0, align 16
  99. %1 = getelementptr inbounds %struct.test7, %struct.test7* %memtmp, i64 0, i32 0, i64 5
  100. store i32 0, i32* %1, align 4
  101. ret void
  102. ; CHECK-LABEL: @test7(
  103. ; CHECK-NOT: alloca
  104. ; CHECK: and i192
  105. }
  106. ; When promoting an alloca to a 1-element vector type, instructions that
  107. ; produce that same vector type should not be changed to insert one element
  108. ; into a new vector. <rdar://problem/14249078>
  109. define <1 x i64> @test8(<1 x i64> %a) {
  110. entry:
  111. %a.addr = alloca <1 x i64>, align 8
  112. %__a = alloca <1 x i64>, align 8
  113. %tmp = alloca <1 x i64>, align 8
  114. store <1 x i64> %a, <1 x i64>* %a.addr, align 8
  115. %0 = load <1 x i64>, <1 x i64>* %a.addr, align 8
  116. store <1 x i64> %0, <1 x i64>* %__a, align 8
  117. %1 = load <1 x i64>, <1 x i64>* %__a, align 8
  118. %2 = bitcast <1 x i64> %1 to <8 x i8>
  119. %3 = bitcast <8 x i8> %2 to <1 x i64>
  120. %vshl_n = shl <1 x i64> %3, <i64 4>
  121. store <1 x i64> %vshl_n, <1 x i64>* %tmp
  122. %4 = load <1 x i64>, <1 x i64>* %tmp
  123. ret <1 x i64> %4
  124. ; CHECK-LABEL: @test8(
  125. ; CHECK-NOT: alloca
  126. ; CHECK-NOT: insertelement
  127. ; CHECK: ret <1 x i64>
  128. }