featuretest.ll 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. ; This testcase tests for various features the basicaa test should be able to
  2. ; determine, as noted in the comments.
  3. ; RUN: opt < %s -basicaa -gvn -instcombine -dce -S | FileCheck %s
  4. target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
  5. @Global = external global { i32 }
  6. declare void @external(i32*)
  7. ; Array test: Test that operations on one local array do not invalidate
  8. ; operations on another array. Important for scientific codes.
  9. ;
  10. define i32 @different_array_test(i64 %A, i64 %B) {
  11. %Array1 = alloca i32, i32 100
  12. %Array2 = alloca i32, i32 200
  13. call void @external(i32* %Array1)
  14. call void @external(i32* %Array2)
  15. %pointer = getelementptr i32, i32* %Array1, i64 %A
  16. %val = load i32, i32* %pointer
  17. %pointer2 = getelementptr i32, i32* %Array2, i64 %B
  18. store i32 7, i32* %pointer2
  19. %REMOVE = load i32, i32* %pointer ; redundant with above load
  20. %retval = sub i32 %REMOVE, %val
  21. ret i32 %retval
  22. ; CHECK: @different_array_test
  23. ; CHECK: ret i32 0
  24. }
  25. ; Constant index test: Constant indexes into the same array should not
  26. ; interfere with each other. Again, important for scientific codes.
  27. ;
  28. define i32 @constant_array_index_test() {
  29. %Array = alloca i32, i32 100
  30. call void @external(i32* %Array)
  31. %P1 = getelementptr i32, i32* %Array, i64 7
  32. %P2 = getelementptr i32, i32* %Array, i64 6
  33. %A = load i32, i32* %P1
  34. store i32 1, i32* %P2 ; Should not invalidate load
  35. %BREMOVE = load i32, i32* %P1
  36. %Val = sub i32 %A, %BREMOVE
  37. ret i32 %Val
  38. ; CHECK: @constant_array_index_test
  39. ; CHECK: ret i32 0
  40. }
  41. ; Test that if two pointers are spaced out by a constant getelementptr, that
  42. ; they cannot alias.
  43. define i32 @gep_distance_test(i32* %A) {
  44. %REMOVEu = load i32, i32* %A
  45. %B = getelementptr i32, i32* %A, i64 2 ; Cannot alias A
  46. store i32 7, i32* %B
  47. %REMOVEv = load i32, i32* %A
  48. %r = sub i32 %REMOVEu, %REMOVEv
  49. ret i32 %r
  50. ; CHECK: @gep_distance_test
  51. ; CHECK: ret i32 0
  52. }
  53. ; Test that if two pointers are spaced out by a constant offset, that they
  54. ; cannot alias, even if there is a variable offset between them...
  55. define i32 @gep_distance_test2({i32,i32}* %A, i64 %distance) {
  56. %A1 = getelementptr {i32,i32}, {i32,i32}* %A, i64 0, i32 0
  57. %REMOVEu = load i32, i32* %A1
  58. %B = getelementptr {i32,i32}, {i32,i32}* %A, i64 %distance, i32 1
  59. store i32 7, i32* %B ; B cannot alias A, it's at least 4 bytes away
  60. %REMOVEv = load i32, i32* %A1
  61. %r = sub i32 %REMOVEu, %REMOVEv
  62. ret i32 %r
  63. ; CHECK: @gep_distance_test2
  64. ; CHECK: ret i32 0
  65. }
  66. ; Test that we can do funny pointer things and that distance calc will still
  67. ; work.
  68. define i32 @gep_distance_test3(i32 * %A) {
  69. %X = load i32, i32* %A
  70. %B = bitcast i32* %A to i8*
  71. %C = getelementptr i8, i8* %B, i64 4
  72. store i8 42, i8* %C
  73. %Y = load i32, i32* %A
  74. %R = sub i32 %X, %Y
  75. ret i32 %R
  76. ; CHECK: @gep_distance_test3
  77. ; CHECK: ret i32 0
  78. }
  79. ; Test that we can disambiguate globals reached through constantexpr geps
  80. define i32 @constexpr_test() {
  81. %X = alloca i32
  82. call void @external(i32* %X)
  83. %Y = load i32, i32* %X
  84. store i32 5, i32* getelementptr ({ i32 }, { i32 }* @Global, i64 0, i32 0)
  85. %REMOVE = load i32, i32* %X
  86. %retval = sub i32 %Y, %REMOVE
  87. ret i32 %retval
  88. ; CHECK: @constexpr_test
  89. ; CHECK: ret i32 0
  90. }
  91. ; PR7589
  92. ; These two index expressions are different, this cannot be CSE'd.
  93. define i16 @zext_sext_confusion(i16* %row2col, i5 %j) nounwind{
  94. entry:
  95. %sum5.cast = zext i5 %j to i64 ; <i64> [#uses=1]
  96. %P1 = getelementptr i16, i16* %row2col, i64 %sum5.cast
  97. %row2col.load.1.2 = load i16, i16* %P1, align 1 ; <i16> [#uses=1]
  98. %sum13.cast31 = sext i5 %j to i6 ; <i6> [#uses=1]
  99. %sum13.cast = zext i6 %sum13.cast31 to i64 ; <i64> [#uses=1]
  100. %P2 = getelementptr i16, i16* %row2col, i64 %sum13.cast
  101. %row2col.load.1.6 = load i16, i16* %P2, align 1 ; <i16> [#uses=1]
  102. %.ret = sub i16 %row2col.load.1.6, %row2col.load.1.2 ; <i16> [#uses=1]
  103. ret i16 %.ret
  104. ; CHECK: @zext_sext_confusion
  105. ; CHECK: ret i16 %.ret
  106. }