bitcast.ll 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. ; RUN: opt < %s -instcombine -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-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
  3. target triple = "x86_64-apple-darwin10.0.0"
  4. ; Bitcasts between vectors and scalars are valid.
  5. ; PR4487
  6. define i32 @test1(i64 %a) {
  7. %t1 = bitcast i64 %a to <2 x i32>
  8. %t2 = bitcast i64 %a to <2 x i32>
  9. %t3 = xor <2 x i32> %t1, %t2
  10. %t4 = extractelement <2 x i32> %t3, i32 0
  11. ret i32 %t4
  12. ; CHECK-LABEL: @test1(
  13. ; CHECK: ret i32 0
  14. }
  15. ; Optimize bitcasts that are extracting low element of vector. This happens
  16. ; because of SRoA.
  17. ; rdar://7892780
  18. define float @test2(<2 x float> %A, <2 x i32> %B) {
  19. %tmp28 = bitcast <2 x float> %A to i64 ; <i64> [#uses=2]
  20. %tmp23 = trunc i64 %tmp28 to i32 ; <i32> [#uses=1]
  21. %tmp24 = bitcast i32 %tmp23 to float ; <float> [#uses=1]
  22. %tmp = bitcast <2 x i32> %B to i64
  23. %tmp2 = trunc i64 %tmp to i32 ; <i32> [#uses=1]
  24. %tmp4 = bitcast i32 %tmp2 to float ; <float> [#uses=1]
  25. %add = fadd float %tmp24, %tmp4
  26. ret float %add
  27. ; CHECK-LABEL: @test2(
  28. ; CHECK-NEXT: %tmp24 = extractelement <2 x float> %A, i32 0
  29. ; CHECK-NEXT: bitcast <2 x i32> %B to <2 x float>
  30. ; CHECK-NEXT: %tmp4 = extractelement <2 x float> {{.*}}, i32 0
  31. ; CHECK-NEXT: %add = fadd float %tmp24, %tmp4
  32. ; CHECK-NEXT: ret float %add
  33. }
  34. ; Optimize bitcasts that are extracting other elements of a vector. This
  35. ; happens because of SRoA.
  36. ; rdar://7892780
  37. define float @test3(<2 x float> %A, <2 x i64> %B) {
  38. %tmp28 = bitcast <2 x float> %A to i64
  39. %tmp29 = lshr i64 %tmp28, 32
  40. %tmp23 = trunc i64 %tmp29 to i32
  41. %tmp24 = bitcast i32 %tmp23 to float
  42. %tmp = bitcast <2 x i64> %B to i128
  43. %tmp1 = lshr i128 %tmp, 64
  44. %tmp2 = trunc i128 %tmp1 to i32
  45. %tmp4 = bitcast i32 %tmp2 to float
  46. %add = fadd float %tmp24, %tmp4
  47. ret float %add
  48. ; CHECK-LABEL: @test3(
  49. ; CHECK-NEXT: %tmp24 = extractelement <2 x float> %A, i32 1
  50. ; CHECK-NEXT: bitcast <2 x i64> %B to <4 x float>
  51. ; CHECK-NEXT: %tmp4 = extractelement <4 x float> {{.*}}, i32 2
  52. ; CHECK-NEXT: %add = fadd float %tmp24, %tmp4
  53. ; CHECK-NEXT: ret float %add
  54. }
  55. define <2 x i32> @test4(i32 %A, i32 %B){
  56. %tmp38 = zext i32 %A to i64
  57. %tmp32 = zext i32 %B to i64
  58. %tmp33 = shl i64 %tmp32, 32
  59. %ins35 = or i64 %tmp33, %tmp38
  60. %tmp43 = bitcast i64 %ins35 to <2 x i32>
  61. ret <2 x i32> %tmp43
  62. ; CHECK-LABEL: @test4(
  63. ; CHECK-NEXT: insertelement <2 x i32> undef, i32 %A, i32 0
  64. ; CHECK-NEXT: insertelement <2 x i32> {{.*}}, i32 %B, i32 1
  65. ; CHECK-NEXT: ret <2 x i32>
  66. }
  67. ; rdar://8360454
  68. define <2 x float> @test5(float %A, float %B) {
  69. %tmp37 = bitcast float %A to i32
  70. %tmp38 = zext i32 %tmp37 to i64
  71. %tmp31 = bitcast float %B to i32
  72. %tmp32 = zext i32 %tmp31 to i64
  73. %tmp33 = shl i64 %tmp32, 32
  74. %ins35 = or i64 %tmp33, %tmp38
  75. %tmp43 = bitcast i64 %ins35 to <2 x float>
  76. ret <2 x float> %tmp43
  77. ; CHECK-LABEL: @test5(
  78. ; CHECK-NEXT: insertelement <2 x float> undef, float %A, i32 0
  79. ; CHECK-NEXT: insertelement <2 x float> {{.*}}, float %B, i32 1
  80. ; CHECK-NEXT: ret <2 x float>
  81. }
  82. define <2 x float> @test6(float %A){
  83. %tmp23 = bitcast float %A to i32 ; <i32> [#uses=1]
  84. %tmp24 = zext i32 %tmp23 to i64 ; <i64> [#uses=1]
  85. %tmp25 = shl i64 %tmp24, 32 ; <i64> [#uses=1]
  86. %mask20 = or i64 %tmp25, 1109917696 ; <i64> [#uses=1]
  87. %tmp35 = bitcast i64 %mask20 to <2 x float> ; <<2 x float>> [#uses=1]
  88. ret <2 x float> %tmp35
  89. ; CHECK-LABEL: @test6(
  90. ; CHECK-NEXT: insertelement <2 x float> <float 4.200000e+01, float undef>, float %A, i32 1
  91. ; CHECK: ret
  92. }
  93. define i64 @ISPC0(i64 %in) {
  94. %out = and i64 %in, xor (i64 bitcast (<4 x i16> <i16 -1, i16 -1, i16 -1, i16 -1> to i64), i64 -1)
  95. ret i64 %out
  96. ; CHECK-LABEL: @ISPC0(
  97. ; CHECK: ret i64 0
  98. }
  99. define i64 @Vec2(i64 %in) {
  100. %out = and i64 %in, xor (i64 bitcast (<4 x i16> <i16 0, i16 0, i16 0, i16 0> to i64), i64 0)
  101. ret i64 %out
  102. ; CHECK-LABEL: @Vec2(
  103. ; CHECK: ret i64 0
  104. }
  105. define i64 @All11(i64 %in) {
  106. %out = and i64 %in, xor (i64 bitcast (<2 x float> bitcast (i64 -1 to <2 x float>) to i64), i64 -1)
  107. ret i64 %out
  108. ; CHECK-LABEL: @All11(
  109. ; CHECK: ret i64 0
  110. }
  111. define i32 @All111(i32 %in) {
  112. %out = and i32 %in, xor (i32 bitcast (<1 x float> bitcast (i32 -1 to <1 x float>) to i32), i32 -1)
  113. ret i32 %out
  114. ; CHECK-LABEL: @All111(
  115. ; CHECK: ret i32 0
  116. }
  117. define <2 x i16> @BitcastInsert(i32 %a) {
  118. %v = insertelement <1 x i32> undef, i32 %a, i32 0
  119. %r = bitcast <1 x i32> %v to <2 x i16>
  120. ret <2 x i16> %r
  121. ; CHECK-LABEL: @BitcastInsert(
  122. ; CHECK: bitcast i32 %a to <2 x i16>
  123. }
  124. ; PR17293
  125. define <2 x i64> @test7(<2 x i8*>* %arg) nounwind {
  126. %cast = bitcast <2 x i8*>* %arg to <2 x i64>*
  127. %load = load <2 x i64>, <2 x i64>* %cast, align 16
  128. ret <2 x i64> %load
  129. ; CHECK: @test7
  130. ; CHECK: bitcast
  131. ; CHECK: load
  132. }