pr17827.ll 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. ; RUN: opt < %s -instcombine -S | FileCheck %s
  2. ; With left shift, the comparison should not be modified.
  3. ; CHECK-LABEL: @test_shift_and_cmp_not_changed1(
  4. ; CHECK: icmp slt i8 %andp, 32
  5. define i1 @test_shift_and_cmp_not_changed1(i8 %p) #0 {
  6. entry:
  7. %shlp = shl i8 %p, 5
  8. %andp = and i8 %shlp, -64
  9. %cmp = icmp slt i8 %andp, 32
  10. ret i1 %cmp
  11. }
  12. ; With arithmetic right shift, the comparison should not be modified.
  13. ; CHECK-LABEL: @test_shift_and_cmp_not_changed2(
  14. ; CHECK: icmp slt i8 %andp, 32
  15. define i1 @test_shift_and_cmp_not_changed2(i8 %p) #0 {
  16. entry:
  17. %shlp = ashr i8 %p, 5
  18. %andp = and i8 %shlp, -64
  19. %cmp = icmp slt i8 %andp, 32
  20. ret i1 %cmp
  21. }
  22. ; This should simplify functionally to the left shift case.
  23. ; The extra input parameter should be optimized away.
  24. ; CHECK-LABEL: @test_shift_and_cmp_changed1(
  25. ; CHECK: %andp = shl i8 %p, 5
  26. ; CHECK-NEXT: %shl = and i8 %andp, -64
  27. ; CHECK-NEXT: %cmp = icmp slt i8 %shl, 32
  28. define i1 @test_shift_and_cmp_changed1(i8 %p, i8 %q) #0 {
  29. entry:
  30. %andp = and i8 %p, 6
  31. %andq = and i8 %q, 8
  32. %or = or i8 %andq, %andp
  33. %shl = shl i8 %or, 5
  34. %ashr = ashr i8 %shl, 5
  35. %cmp = icmp slt i8 %ashr, 1
  36. ret i1 %cmp
  37. }
  38. ; Unsigned compare allows a transformation to compare against 0.
  39. ; CHECK-LABEL: @test_shift_and_cmp_changed2(
  40. ; CHECK: icmp eq i8 %andp, 0
  41. define i1 @test_shift_and_cmp_changed2(i8 %p) #0 {
  42. entry:
  43. %shlp = shl i8 %p, 5
  44. %andp = and i8 %shlp, -64
  45. %cmp = icmp ult i8 %andp, 32
  46. ret i1 %cmp
  47. }
  48. ; nsw on the shift should not affect the comparison.
  49. ; CHECK-LABEL: @test_shift_and_cmp_changed3(
  50. ; CHECK: icmp slt i8 %andp, 32
  51. define i1 @test_shift_and_cmp_changed3(i8 %p) #0 {
  52. entry:
  53. %shlp = shl nsw i8 %p, 5
  54. %andp = and i8 %shlp, -64
  55. %cmp = icmp slt i8 %andp, 32
  56. ret i1 %cmp
  57. }
  58. ; Logical shift right allows a return true because the 'and' guarantees no bits are set.
  59. ; CHECK-LABEL: @test_shift_and_cmp_changed4(
  60. ; CHECK: ret i1 true
  61. define i1 @test_shift_and_cmp_changed4(i8 %p) #0 {
  62. entry:
  63. %shlp = lshr i8 %p, 5
  64. %andp = and i8 %shlp, -64
  65. %cmp = icmp slt i8 %andp, 32
  66. ret i1 %cmp
  67. }