compare-signs.ll 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. ; RUN: opt -instcombine -S < %s | FileCheck %s
  2. ; PR5438
  3. ; TODO: This should also optimize down.
  4. ;define i32 @test1(i32 %a, i32 %b) nounwind readnone {
  5. ;entry:
  6. ; %0 = icmp sgt i32 %a, -1 ; <i1> [#uses=1]
  7. ; %1 = icmp slt i32 %b, 0 ; <i1> [#uses=1]
  8. ; %2 = xor i1 %1, %0 ; <i1> [#uses=1]
  9. ; %3 = zext i1 %2 to i32 ; <i32> [#uses=1]
  10. ; ret i32 %3
  11. ;}
  12. ; TODO: This optimizes partially but not all the way.
  13. ;define i32 @test2(i32 %a, i32 %b) nounwind readnone {
  14. ;entry:
  15. ; %0 = and i32 %a, 8 ;<i32> [#uses=1]
  16. ; %1 = and i32 %b, 8 ;<i32> [#uses=1]
  17. ; %2 = icmp eq i32 %0, %1 ;<i1> [#uses=1]
  18. ; %3 = zext i1 %2 to i32 ;<i32> [#uses=1]
  19. ; ret i32 %3
  20. ;}
  21. define i32 @test3(i32 %a, i32 %b) nounwind readnone {
  22. ; CHECK-LABEL: @test3(
  23. entry:
  24. ; CHECK: [[XOR1:%.*]] = xor i32 %a, %b
  25. ; CHECK: [[SHIFT:%.*]] = lshr i32 [[XOR1]], 31
  26. ; CHECK: [[XOR2:%.*]] = xor i32 [[SHIFT]], 1
  27. %0 = lshr i32 %a, 31 ; <i32> [#uses=1]
  28. %1 = lshr i32 %b, 31 ; <i32> [#uses=1]
  29. %2 = icmp eq i32 %0, %1 ; <i1> [#uses=1]
  30. %3 = zext i1 %2 to i32 ; <i32> [#uses=1]
  31. ret i32 %3
  32. ; CHECK-NOT: icmp
  33. ; CHECK-NOT: zext
  34. ; CHECK: ret i32 [[XOR2]]
  35. }
  36. ; Variation on @test3: checking the 2nd bit in a situation where the 5th bit
  37. ; is one, not zero.
  38. define i32 @test3i(i32 %a, i32 %b) nounwind readnone {
  39. ; CHECK-LABEL: @test3i(
  40. entry:
  41. ; CHECK: xor i32 %a, %b
  42. ; CHECK: lshr i32 %0, 31
  43. ; CHECK: xor i32 %1, 1
  44. %0 = lshr i32 %a, 29 ; <i32> [#uses=1]
  45. %1 = lshr i32 %b, 29 ; <i32> [#uses=1]
  46. %2 = or i32 %0, 35
  47. %3 = or i32 %1, 35
  48. %4 = icmp eq i32 %2, %3 ; <i1> [#uses=1]
  49. %5 = zext i1 %4 to i32 ; <i32> [#uses=1]
  50. ret i32 %5
  51. ; CHECK-NOT: icmp
  52. ; CHECK-NOT: zext
  53. ; CHECK: ret i32 %2
  54. }