icmp-range.ll 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. ; RUN: opt < %s -instcombine -S | FileCheck %s
  2. ; These should be InstSimplify checks, but most of the code
  3. ; is currently only in InstCombine. TODO: move supporting code
  4. ; Definitely out of range
  5. define i1 @test_nonzero(i32* nocapture readonly %arg) {
  6. ; CHECK-LABEL:test_nonzero
  7. ; CHECK: ret i1 true
  8. %val = load i32, i32* %arg, !range !0
  9. %rval = icmp ne i32 %val, 0
  10. ret i1 %rval
  11. }
  12. define i1 @test_nonzero2(i32* nocapture readonly %arg) {
  13. ; CHECK-LABEL:test_nonzero2
  14. ; CHECK: ret i1 false
  15. %val = load i32, i32* %arg, !range !0
  16. %rval = icmp eq i32 %val, 0
  17. ret i1 %rval
  18. }
  19. ; Potentially in range
  20. define i1 @test_nonzero3(i32* nocapture readonly %arg) {
  21. ; CHECK-LABEL: test_nonzero3
  22. ; Check that this does not trigger - it wouldn't be legal
  23. ; CHECK: icmp
  24. %val = load i32, i32* %arg, !range !1
  25. %rval = icmp ne i32 %val, 0
  26. ret i1 %rval
  27. }
  28. ; Definitely in range
  29. define i1 @test_nonzero4(i8* nocapture readonly %arg) {
  30. ; CHECK-LABEL: test_nonzero4
  31. ; CHECK: ret i1 false
  32. %val = load i8, i8* %arg, !range !2
  33. %rval = icmp ne i8 %val, 0
  34. ret i1 %rval
  35. }
  36. define i1 @test_nonzero5(i8* nocapture readonly %arg) {
  37. ; CHECK-LABEL: test_nonzero5
  38. ; CHECK: ret i1 false
  39. %val = load i8, i8* %arg, !range !2
  40. %rval = icmp ugt i8 %val, 0
  41. ret i1 %rval
  42. }
  43. ; Cheaper checks (most values in range meet requirements)
  44. define i1 @test_nonzero6(i8* %argw) {
  45. ; CHECK-LABEL: test_nonzero6
  46. ; CHECK: icmp ne i8 %val, 0
  47. %val = load i8, i8* %argw, !range !3
  48. %rval = icmp sgt i8 %val, 0
  49. ret i1 %rval
  50. }
  51. !0 = !{i32 1, i32 6}
  52. !1 = !{i32 0, i32 6}
  53. !2 = !{i8 0, i8 1}
  54. !3 = !{i8 0, i8 6}