load-cmp.ll 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. ; RUN: opt -instcombine -S -default-data-layout="p:32:32:32-p1:16:16:16-n8:16:32:64" < %s | FileCheck %s
  2. @G16 = internal constant [10 x i16] [i16 35, i16 82, i16 69, i16 81, i16 85,
  3. i16 73, i16 82, i16 69, i16 68, i16 0]
  4. @G16_as1 = internal addrspace(1) constant [10 x i16] [i16 35, i16 82, i16 69, i16 81, i16 85,
  5. i16 73, i16 82, i16 69, i16 68, i16 0]
  6. @GD = internal constant [6 x double]
  7. [double -10.0, double 1.0, double 4.0, double 2.0, double -20.0, double -40.0]
  8. %Foo = type { i32, i32, i32, i32 }
  9. @GS = internal constant %Foo { i32 1, i32 4, i32 9, i32 14 }
  10. @GStructArr = internal constant [4 x %Foo] [ %Foo { i32 1, i32 4, i32 9, i32 14 },
  11. %Foo { i32 5, i32 4, i32 6, i32 11 },
  12. %Foo { i32 6, i32 5, i32 9, i32 20 },
  13. %Foo { i32 12, i32 3, i32 9, i32 8 } ]
  14. define i1 @test1(i32 %X) {
  15. %P = getelementptr inbounds [10 x i16], [10 x i16]* @G16, i32 0, i32 %X
  16. %Q = load i16, i16* %P
  17. %R = icmp eq i16 %Q, 0
  18. ret i1 %R
  19. ; CHECK-LABEL: @test1(
  20. ; CHECK-NEXT: %R = icmp eq i32 %X, 9
  21. ; CHECK-NEXT: ret i1 %R
  22. }
  23. define i1 @test1_noinbounds(i32 %X) {
  24. %P = getelementptr [10 x i16], [10 x i16]* @G16, i32 0, i32 %X
  25. %Q = load i16, i16* %P
  26. %R = icmp eq i16 %Q, 0
  27. ret i1 %R
  28. ; CHECK-LABEL: @test1_noinbounds(
  29. ; CHECK-NEXT: %R = icmp eq i32 %X, 9
  30. ; CHECK-NEXT: ret i1 %R
  31. }
  32. define i1 @test1_noinbounds_i64(i64 %X) {
  33. %P = getelementptr [10 x i16], [10 x i16]* @G16, i64 0, i64 %X
  34. %Q = load i16, i16* %P
  35. %R = icmp eq i16 %Q, 0
  36. ret i1 %R
  37. ; CHECK-LABEL: @test1_noinbounds_i64(
  38. ; CHECK: %R = icmp eq i32 %1, 9
  39. ; CHECK-NEXT: ret i1 %R
  40. }
  41. define i1 @test1_noinbounds_as1(i32 %x) {
  42. %p = getelementptr [10 x i16], [10 x i16] addrspace(1)* @G16_as1, i16 0, i32 %x
  43. %q = load i16, i16 addrspace(1)* %p
  44. %r = icmp eq i16 %q, 0
  45. ret i1 %r
  46. ; CHECK-LABEL: @test1_noinbounds_as1(
  47. ; CHECK-NEXT: trunc i32 %x to i16
  48. ; CHECK-NEXT: %r = icmp eq i16 %1, 9
  49. ; CHECK-NEXT: ret i1 %r
  50. }
  51. define i1 @test2(i32 %X) {
  52. %P = getelementptr inbounds [10 x i16], [10 x i16]* @G16, i32 0, i32 %X
  53. %Q = load i16, i16* %P
  54. %R = icmp slt i16 %Q, 85
  55. ret i1 %R
  56. ; CHECK-LABEL: @test2(
  57. ; CHECK-NEXT: %R = icmp ne i32 %X, 4
  58. ; CHECK-NEXT: ret i1 %R
  59. }
  60. define i1 @test3(i32 %X) {
  61. %P = getelementptr inbounds [6 x double], [6 x double]* @GD, i32 0, i32 %X
  62. %Q = load double, double* %P
  63. %R = fcmp oeq double %Q, 1.0
  64. ret i1 %R
  65. ; CHECK-LABEL: @test3(
  66. ; CHECK-NEXT: %R = icmp eq i32 %X, 1
  67. ; CHECK-NEXT: ret i1 %R
  68. }
  69. define i1 @test4(i32 %X) {
  70. %P = getelementptr inbounds [10 x i16], [10 x i16]* @G16, i32 0, i32 %X
  71. %Q = load i16, i16* %P
  72. %R = icmp sle i16 %Q, 73
  73. ret i1 %R
  74. ; CHECK-LABEL: @test4(
  75. ; CHECK-NEXT: lshr i32 933, %X
  76. ; CHECK-NEXT: and i32 {{.*}}, 1
  77. ; CHECK-NEXT: %R = icmp ne i32 {{.*}}, 0
  78. ; CHECK-NEXT: ret i1 %R
  79. }
  80. define i1 @test4_i16(i16 %X) {
  81. %P = getelementptr inbounds [10 x i16], [10 x i16]* @G16, i32 0, i16 %X
  82. %Q = load i16, i16* %P
  83. %R = icmp sle i16 %Q, 73
  84. ret i1 %R
  85. ; CHECK-LABEL: @test4_i16(
  86. ; CHECK-NEXT: sext i16 %X to i32
  87. ; CHECK-NEXT: lshr i32 933, %1
  88. ; CHECK-NEXT: and i32 {{.*}}, 1
  89. ; CHECK-NEXT: %R = icmp ne i32 {{.*}}, 0
  90. ; CHECK-NEXT: ret i1 %R
  91. }
  92. define i1 @test5(i32 %X) {
  93. %P = getelementptr inbounds [10 x i16], [10 x i16]* @G16, i32 0, i32 %X
  94. %Q = load i16, i16* %P
  95. %R = icmp eq i16 %Q, 69
  96. ret i1 %R
  97. ; CHECK-LABEL: @test5(
  98. ; CHECK-NEXT: icmp eq i32 %X, 2
  99. ; CHECK-NEXT: icmp eq i32 %X, 7
  100. ; CHECK-NEXT: %R = or i1
  101. ; CHECK-NEXT: ret i1 %R
  102. }
  103. define i1 @test6(i32 %X) {
  104. %P = getelementptr inbounds [6 x double], [6 x double]* @GD, i32 0, i32 %X
  105. %Q = load double, double* %P
  106. %R = fcmp ogt double %Q, 0.0
  107. ret i1 %R
  108. ; CHECK-LABEL: @test6(
  109. ; CHECK-NEXT: add i32 %X, -1
  110. ; CHECK-NEXT: %R = icmp ult i32 {{.*}}, 3
  111. ; CHECK-NEXT: ret i1 %R
  112. }
  113. define i1 @test7(i32 %X) {
  114. %P = getelementptr inbounds [6 x double], [6 x double]* @GD, i32 0, i32 %X
  115. %Q = load double, double* %P
  116. %R = fcmp olt double %Q, 0.0
  117. ret i1 %R
  118. ; CHECK-LABEL: @test7(
  119. ; CHECK-NEXT: add i32 %X, -1
  120. ; CHECK-NEXT: %R = icmp ugt i32 {{.*}}, 2
  121. ; CHECK-NEXT: ret i1 %R
  122. }
  123. define i1 @test8(i32 %X) {
  124. %P = getelementptr inbounds [10 x i16], [10 x i16]* @G16, i32 0, i32 %X
  125. %Q = load i16, i16* %P
  126. %R = and i16 %Q, 3
  127. %S = icmp eq i16 %R, 0
  128. ret i1 %S
  129. ; CHECK-LABEL: @test8(
  130. ; CHECK-NEXT: and i32 %X, -2
  131. ; CHECK-NEXT: icmp eq i32 {{.*}}, 8
  132. ; CHECK-NEXT: ret i1
  133. }
  134. @GA = internal constant [4 x { i32, i32 } ] [
  135. { i32, i32 } { i32 1, i32 0 },
  136. { i32, i32 } { i32 2, i32 1 },
  137. { i32, i32 } { i32 3, i32 1 },
  138. { i32, i32 } { i32 4, i32 0 }
  139. ]
  140. define i1 @test9(i32 %X) {
  141. %P = getelementptr inbounds [4 x { i32, i32 } ], [4 x { i32, i32 } ]* @GA, i32 0, i32 %X, i32 1
  142. %Q = load i32, i32* %P
  143. %R = icmp eq i32 %Q, 1
  144. ret i1 %R
  145. ; CHECK-LABEL: @test9(
  146. ; CHECK-NEXT: add i32 %X, -1
  147. ; CHECK-NEXT: icmp ult i32 {{.*}}, 2
  148. ; CHECK-NEXT: ret i1
  149. }
  150. define i1 @test10_struct(i32 %x) {
  151. ; CHECK-LABEL: @test10_struct(
  152. ; CHECK: ret i1 false
  153. %p = getelementptr inbounds %Foo, %Foo* @GS, i32 %x, i32 0
  154. %q = load i32, i32* %p
  155. %r = icmp eq i32 %q, 9
  156. ret i1 %r
  157. }
  158. define i1 @test10_struct_noinbounds(i32 %x) {
  159. ; CHECK-LABEL: @test10_struct_noinbounds(
  160. ; CHECK: getelementptr %Foo, %Foo* @GS, i32 %x, i32 0
  161. %p = getelementptr %Foo, %Foo* @GS, i32 %x, i32 0
  162. %q = load i32, i32* %p
  163. %r = icmp eq i32 %q, 9
  164. ret i1 %r
  165. }
  166. ; Test that the GEP indices are converted before we ever get here
  167. ; Index < ptr size
  168. define i1 @test10_struct_i16(i16 %x){
  169. ; CHECK-LABEL: @test10_struct_i16(
  170. ; CHECK: ret i1 false
  171. %p = getelementptr inbounds %Foo, %Foo* @GS, i16 %x, i32 0
  172. %q = load i32, i32* %p
  173. %r = icmp eq i32 %q, 0
  174. ret i1 %r
  175. }
  176. ; Test that the GEP indices are converted before we ever get here
  177. ; Index > ptr size
  178. define i1 @test10_struct_i64(i64 %x){
  179. ; CHECK-LABEL: @test10_struct_i64(
  180. ; CHECK: ret i1 false
  181. %p = getelementptr inbounds %Foo, %Foo* @GS, i64 %x, i32 0
  182. %q = load i32, i32* %p
  183. %r = icmp eq i32 %q, 0
  184. ret i1 %r
  185. }
  186. define i1 @test10_struct_noinbounds_i16(i16 %x) {
  187. ; CHECK-LABEL: @test10_struct_noinbounds_i16(
  188. ; CHECK: %1 = sext i16 %x to i32
  189. ; CHECK: getelementptr %Foo, %Foo* @GS, i32 %1, i32 0
  190. %p = getelementptr %Foo, %Foo* @GS, i16 %x, i32 0
  191. %q = load i32, i32* %p
  192. %r = icmp eq i32 %q, 0
  193. ret i1 %r
  194. }
  195. define i1 @test10_struct_arr(i32 %x) {
  196. ; CHECK-LABEL: @test10_struct_arr(
  197. ; CHECK-NEXT: %r = icmp ne i32 %x, 1
  198. ; CHECK-NEXT: ret i1 %r
  199. %p = getelementptr inbounds [4 x %Foo], [4 x %Foo]* @GStructArr, i32 0, i32 %x, i32 2
  200. %q = load i32, i32* %p
  201. %r = icmp eq i32 %q, 9
  202. ret i1 %r
  203. }
  204. define i1 @test10_struct_arr_noinbounds(i32 %x) {
  205. ; CHECK-LABEL: @test10_struct_arr_noinbounds(
  206. ; CHECK-NEXT %p = getelementptr [4 x %Foo], [4 x %Foo]* @GStructArr, i32 0, i32 %x, i32 2
  207. %p = getelementptr [4 x %Foo], [4 x %Foo]* @GStructArr, i32 0, i32 %x, i32 2
  208. %q = load i32, i32* %p
  209. %r = icmp eq i32 %q, 9
  210. ret i1 %r
  211. }
  212. define i1 @test10_struct_arr_i16(i16 %x) {
  213. ; CHECK-LABEL: @test10_struct_arr_i16(
  214. ; CHECK-NEXT: %r = icmp ne i16 %x, 1
  215. ; CHECK-NEXT: ret i1 %r
  216. %p = getelementptr inbounds [4 x %Foo], [4 x %Foo]* @GStructArr, i16 0, i16 %x, i32 2
  217. %q = load i32, i32* %p
  218. %r = icmp eq i32 %q, 9
  219. ret i1 %r
  220. }
  221. define i1 @test10_struct_arr_i64(i64 %x) {
  222. ; CHECK-LABEL: @test10_struct_arr_i64(
  223. ; CHECK-NEXT: trunc i64 %x to i32
  224. ; CHECK-NEXT: %r = icmp ne i32 %1, 1
  225. ; CHECK-NEXT: ret i1 %r
  226. %p = getelementptr inbounds [4 x %Foo], [4 x %Foo]* @GStructArr, i64 0, i64 %x, i32 2
  227. %q = load i32, i32* %p
  228. %r = icmp eq i32 %q, 9
  229. ret i1 %r
  230. }
  231. define i1 @test10_struct_arr_noinbounds_i16(i16 %x) {
  232. ; CHECK-LABEL: @test10_struct_arr_noinbounds_i16(
  233. ; CHECK-NEXT: %r = icmp ne i16 %x, 1
  234. %p = getelementptr [4 x %Foo], [4 x %Foo]* @GStructArr, i32 0, i16 %x, i32 2
  235. %q = load i32, i32* %p
  236. %r = icmp eq i32 %q, 9
  237. ret i1 %r
  238. }
  239. define i1 @test10_struct_arr_noinbounds_i64(i64 %x) {
  240. ; CHECK-LABEL: @test10_struct_arr_noinbounds_i64(
  241. ; CHECK: %r = icmp ne i32 %1, 1
  242. ; CHECK-NEXT: ret i1 %r
  243. %p = getelementptr [4 x %Foo], [4 x %Foo]* @GStructArr, i32 0, i64 %x, i32 2
  244. %q = load i32, i32* %p
  245. %r = icmp eq i32 %q, 9
  246. ret i1 %r
  247. }