multi-size-address-space-pointer.ll 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. ; RUN: opt -S -instcombine %s -o - | FileCheck %s
  2. target datalayout = "e-p:32:32:32-p1:64:64:64-p2:8:8:8-p3:16:16:16-p4:16:16:16-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:32"
  3. define i32 @test_as0(i32 addrspace(0)* %a) {
  4. ; CHECK-LABEL: @test_as0(
  5. ; CHECK: %arrayidx = getelementptr i32, i32* %a, i32 1
  6. %arrayidx = getelementptr i32, i32 addrspace(0)* %a, i64 1
  7. %y = load i32, i32 addrspace(0)* %arrayidx, align 4
  8. ret i32 %y
  9. }
  10. define i32 @test_as1(i32 addrspace(1)* %a) {
  11. ; CHECK-LABEL: @test_as1(
  12. ; CHECK: %arrayidx = getelementptr i32, i32 addrspace(1)* %a, i64 1
  13. %arrayidx = getelementptr i32, i32 addrspace(1)* %a, i32 1
  14. %y = load i32, i32 addrspace(1)* %arrayidx, align 4
  15. ret i32 %y
  16. }
  17. define i32 @test_as2(i32 addrspace(2)* %a) {
  18. ; CHECK-LABEL: @test_as2(
  19. ; CHECK: %arrayidx = getelementptr i32, i32 addrspace(2)* %a, i8 1
  20. %arrayidx = getelementptr i32, i32 addrspace(2)* %a, i32 1
  21. %y = load i32, i32 addrspace(2)* %arrayidx, align 4
  22. ret i32 %y
  23. }
  24. define i32 @test_as3(i32 addrspace(3)* %a) {
  25. ; CHECK-LABEL: @test_as3(
  26. ; CHECK: %arrayidx = getelementptr i32, i32 addrspace(3)* %a, i16 1
  27. %arrayidx = getelementptr i32, i32 addrspace(3)* %a, i32 1
  28. %y = load i32, i32 addrspace(3)* %arrayidx, align 4
  29. ret i32 %y
  30. }
  31. define i32 @test_combine_ptrtoint(i32 addrspace(2)* %a) {
  32. ; CHECK-LABEL: @test_combine_ptrtoint(
  33. ; CHECK-NEXT: %y = load i32, i32 addrspace(2)* %a
  34. ; CHECK-NEXT: ret i32 %y
  35. %cast = ptrtoint i32 addrspace(2)* %a to i8
  36. %castback = inttoptr i8 %cast to i32 addrspace(2)*
  37. %y = load i32, i32 addrspace(2)* %castback, align 4
  38. ret i32 %y
  39. }
  40. define i8 @test_combine_inttoptr(i8 %a) {
  41. ; CHECK-LABEL: @test_combine_inttoptr(
  42. ; CHECK-NEXT: ret i8 %a
  43. %cast = inttoptr i8 %a to i32 addrspace(2)*
  44. %castback = ptrtoint i32 addrspace(2)* %cast to i8
  45. ret i8 %castback
  46. }
  47. define i32 @test_combine_vector_ptrtoint(<2 x i32 addrspace(2)*> %a) {
  48. ; CHECK-LABEL: @test_combine_vector_ptrtoint(
  49. ; CHECK-NEXT: %p = extractelement <2 x i32 addrspace(2)*> %a, i32 0
  50. ; CHECK-NEXT: %y = load i32, i32 addrspace(2)* %p, align 4
  51. ; CHECK-NEXT: ret i32 %y
  52. %cast = ptrtoint <2 x i32 addrspace(2)*> %a to <2 x i8>
  53. %castback = inttoptr <2 x i8> %cast to <2 x i32 addrspace(2)*>
  54. %p = extractelement <2 x i32 addrspace(2)*> %castback, i32 0
  55. %y = load i32, i32 addrspace(2)* %p, align 4
  56. ret i32 %y
  57. }
  58. define <2 x i8> @test_combine_vector_inttoptr(<2 x i8> %a) {
  59. ; CHECK-LABEL: @test_combine_vector_inttoptr(
  60. ; CHECK-NEXT: ret <2 x i8> %a
  61. %cast = inttoptr <2 x i8> %a to <2 x i32 addrspace(2)*>
  62. %castback = ptrtoint <2 x i32 addrspace(2)*> %cast to <2 x i8>
  63. ret <2 x i8> %castback
  64. }
  65. ; Check that the GEP index is changed to the address space integer type (i64 -> i8)
  66. define i32 addrspace(2)* @shrink_gep_constant_index_64_as2(i32 addrspace(2)* %p) {
  67. ; CHECK-LABEL: @shrink_gep_constant_index_64_as2(
  68. ; CHECK-NEXT: getelementptr i32, i32 addrspace(2)* %p, i8 1
  69. %ret = getelementptr i32, i32 addrspace(2)* %p, i64 1
  70. ret i32 addrspace(2)* %ret
  71. }
  72. define i32 addrspace(2)* @shrink_gep_constant_index_32_as2(i32 addrspace(2)* %p) {
  73. ; CHECK-LABEL: @shrink_gep_constant_index_32_as2(
  74. ; CHECK-NEXT: getelementptr i32, i32 addrspace(2)* %p, i8 1
  75. %ret = getelementptr i32, i32 addrspace(2)* %p, i32 1
  76. ret i32 addrspace(2)* %ret
  77. }
  78. define i32 addrspace(3)* @shrink_gep_constant_index_64_as3(i32 addrspace(3)* %p) {
  79. ; CHECK-LABEL: @shrink_gep_constant_index_64_as3(
  80. ; CHECK-NEXT: getelementptr i32, i32 addrspace(3)* %p, i16 1
  81. %ret = getelementptr i32, i32 addrspace(3)* %p, i64 1
  82. ret i32 addrspace(3)* %ret
  83. }
  84. define i32 addrspace(2)* @shrink_gep_variable_index_64_as2(i32 addrspace(2)* %p, i64 %idx) {
  85. ; CHECK-LABEL: @shrink_gep_variable_index_64_as2(
  86. ; CHECK-NEXT: %1 = trunc i64 %idx to i8
  87. ; CHECK-NEXT: getelementptr i32, i32 addrspace(2)* %p, i8 %1
  88. %ret = getelementptr i32, i32 addrspace(2)* %p, i64 %idx
  89. ret i32 addrspace(2)* %ret
  90. }
  91. define i32 addrspace(1)* @grow_gep_variable_index_8_as1(i32 addrspace(1)* %p, i8 %idx) {
  92. ; CHECK-LABEL: @grow_gep_variable_index_8_as1(
  93. ; CHECK-NEXT: %1 = sext i8 %idx to i64
  94. ; CHECK-NEXT: getelementptr i32, i32 addrspace(1)* %p, i64 %1
  95. %ret = getelementptr i32, i32 addrspace(1)* %p, i8 %idx
  96. ret i32 addrspace(1)* %ret
  97. }