distribute.ll 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. ; RUN: opt < %s -instcombine -S | FileCheck %s
  2. define i32 @factorize(i32 %x, i32 %y) {
  3. ; CHECK-LABEL: @factorize(
  4. ; (X | 1) & (X | 2) -> X | (1 & 2) -> X
  5. %l = or i32 %x, 1
  6. %r = or i32 %x, 2
  7. %z = and i32 %l, %r
  8. ret i32 %z
  9. ; CHECK: ret i32 %x
  10. }
  11. define i32 @factorize2(i32 %x) {
  12. ; CHECK-LABEL: @factorize2(
  13. ; 3*X - 2*X -> X
  14. %l = mul i32 3, %x
  15. %r = mul i32 2, %x
  16. %z = sub i32 %l, %r
  17. ret i32 %z
  18. ; CHECK: ret i32 %x
  19. }
  20. define i32 @factorize3(i32 %x, i32 %a, i32 %b) {
  21. ; CHECK-LABEL: @factorize3(
  22. ; (X | (A|B)) & (X | B) -> X | ((A|B) & B) -> X | B
  23. %aORb = or i32 %a, %b
  24. %l = or i32 %x, %aORb
  25. %r = or i32 %x, %b
  26. %z = and i32 %l, %r
  27. ret i32 %z
  28. ; CHECK: %z = or i32 %b, %x
  29. ; CHECK: ret i32 %z
  30. }
  31. define i32 @factorize4(i32 %x, i32 %y) {
  32. ; CHECK-LABEL: @factorize4(
  33. ; ((Y << 1) * X) - (X * Y) -> (X * (Y * 2 - Y)) -> (X * Y)
  34. %sh = shl i32 %y, 1
  35. %ml = mul i32 %sh, %x
  36. %mr = mul i32 %x, %y
  37. %s = sub i32 %ml, %mr
  38. ret i32 %s
  39. ; CHECK: %s = mul i32 %y, %x
  40. ; CHECK: ret i32 %s
  41. }
  42. define i32 @factorize5(i32 %x, i32 %y) {
  43. ; CHECK-LABEL: @factorize5(
  44. ; ((Y * 2) * X) - (X * Y) -> (X * Y)
  45. %sh = mul i32 %y, 2
  46. %ml = mul i32 %sh, %x
  47. %mr = mul i32 %x, %y
  48. %s = sub i32 %ml, %mr
  49. ret i32 %s
  50. ; CHECK: %s = mul i32 %y, %x
  51. ; CHECK: ret i32 %s
  52. }
  53. define i32 @expand(i32 %x) {
  54. ; CHECK-LABEL: @expand(
  55. ; ((X & 1) | 2) & 1 -> ((X & 1) & 1) | (2 & 1) -> (X & 1) | 0 -> X & 1
  56. %a = and i32 %x, 1
  57. %b = or i32 %a, 2
  58. %c = and i32 %b, 1
  59. ret i32 %c
  60. ; CHECK: %a = and i32 %x, 1
  61. ; CHECK: ret i32 %a
  62. }