and2.ll 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. ; RUN: opt < %s -instcombine -S | FileCheck %s
  2. ; PR1738
  3. define i1 @test1(double %X, double %Y) {
  4. %tmp9 = fcmp ord double %X, 0.000000e+00
  5. %tmp13 = fcmp ord double %Y, 0.000000e+00
  6. %bothcond = and i1 %tmp13, %tmp9
  7. ret i1 %bothcond
  8. ; CHECK: fcmp ord double %Y, %X
  9. }
  10. define i1 @test2(i1 %X, i1 %Y) {
  11. %a = and i1 %X, %Y
  12. %b = and i1 %a, %X
  13. ret i1 %b
  14. ; CHECK-LABEL: @test2(
  15. ; CHECK-NEXT: and i1 %X, %Y
  16. ; CHECK-NEXT: ret
  17. }
  18. define i32 @test3(i32 %X, i32 %Y) {
  19. %a = and i32 %X, %Y
  20. %b = and i32 %Y, %a
  21. ret i32 %b
  22. ; CHECK-LABEL: @test3(
  23. ; CHECK-NEXT: and i32 %X, %Y
  24. ; CHECK-NEXT: ret
  25. }
  26. define i1 @test4(i32 %X) {
  27. %a = icmp ult i32 %X, 31
  28. %b = icmp slt i32 %X, 0
  29. %c = and i1 %a, %b
  30. ret i1 %c
  31. ; CHECK-LABEL: @test4(
  32. ; CHECK-NEXT: ret i1 false
  33. }
  34. ; Make sure we don't go into an infinite loop with this test
  35. define <4 x i32> @test5(<4 x i32> %A) {
  36. %1 = xor <4 x i32> %A, <i32 1, i32 2, i32 3, i32 4>
  37. %2 = and <4 x i32> <i32 1, i32 2, i32 3, i32 4>, %1
  38. ret <4 x i32> %2
  39. }
  40. ; Check that we combine "if x!=0 && x!=-1" into "if x+1u>1"
  41. define i32 @test6(i64 %x) nounwind {
  42. ; CHECK-LABEL: @test6(
  43. ; CHECK-NEXT: add i64 %x, 1
  44. ; CHECK-NEXT: icmp ugt i64 %x.off, 1
  45. %cmp1 = icmp ne i64 %x, -1
  46. %not.cmp = icmp ne i64 %x, 0
  47. %.cmp1 = and i1 %cmp1, %not.cmp
  48. %land.ext = zext i1 %.cmp1 to i32
  49. ret i32 %land.ext
  50. }
  51. define i1 @test7(i32 %i, i1 %b) {
  52. ; CHECK-LABEL: @test7(
  53. ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 %i, 0
  54. ; CHECK-NEXT: [[AND:%.*]] = and i1 [[CMP]], %b
  55. ; CHECK-NEXT: ret i1 [[AND]]
  56. %cmp1 = icmp slt i32 %i, 1
  57. %cmp2 = icmp sgt i32 %i, -1
  58. %and1 = and i1 %cmp1, %b
  59. %and2 = and i1 %and1, %cmp2
  60. ret i1 %and2
  61. }
  62. define i1 @test8(i32 %i) {
  63. ; CHECK-LABEL: @test8(
  64. ; CHECK-NEXT: [[DEC:%.*]] = add i32 %i, -1
  65. ; CHECK-NEXT: [[CMP:%.*]] = icmp ult i32 [[DEC]], 13
  66. ; CHECK-NEXT: ret i1 [[CMP]]
  67. %cmp1 = icmp ne i32 %i, 0
  68. %cmp2 = icmp ult i32 %i, 14
  69. %cond = and i1 %cmp1, %cmp2
  70. ret i1 %cond
  71. }