memory-dereferenceable.ll 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. ; RUN: opt -print-memderefs -analyze -S <%s | FileCheck %s
  2. ; Uses the print-deref (+ analyze to print) pass to run
  3. ; isDereferenceablePointer() on many load instruction operands
  4. target datalayout = "e"
  5. declare zeroext i1 @return_i1()
  6. @globalstr = global [6 x i8] c"hello\00"
  7. @globali32ptr = external global i32*
  8. %struct.A = type { [8 x i8], [5 x i8] }
  9. @globalstruct = external global %struct.A
  10. define void @test(i32 addrspace(1)* dereferenceable(8) %dparam) gc "statepoint-example" {
  11. ; CHECK: The following are dereferenceable:
  12. ; CHECK: %globalptr
  13. ; CHECK: %alloca
  14. ; CHECK: %dparam
  15. ; CHECK: %relocate
  16. ; CHECK-NOT: %nparam
  17. ; CHECK-NOT: %nd_load
  18. ; CHECK: %d4_load
  19. ; CHECK-NOT: %d2_load
  20. ; CHECK-NOT: %d_or_null_load
  21. ; CHECK: %d_or_null_non_null_load
  22. ; CHECK: %within_allocation
  23. ; CHECK-NOT: %outside_allocation
  24. entry:
  25. %globalptr = getelementptr inbounds [6 x i8], [6 x i8]* @globalstr, i32 0, i32 0
  26. %load1 = load i8, i8* %globalptr
  27. %alloca = alloca i1
  28. %load2 = load i1, i1* %alloca
  29. %load3 = load i32, i32 addrspace(1)* %dparam
  30. %tok = tail call i32 (i64, i32, i1 ()*, i32, i32, ...) @llvm.experimental.gc.statepoint.p0f_i1f(i64 0, i32 0, i1 ()* @return_i1, i32 0, i32 0, i32 0, i32 0, i32 addrspace(1)* %dparam)
  31. %relocate = call i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32 %tok, i32 7, i32 7)
  32. %load4 = load i32, i32 addrspace(1)* %relocate
  33. %nparam = getelementptr i32, i32 addrspace(1)* %dparam, i32 5
  34. %load5 = load i32, i32 addrspace(1)* %nparam
  35. ; Load from a non-dereferenceable load
  36. %nd_load = load i32*, i32** @globali32ptr
  37. %load6 = load i32, i32* %nd_load
  38. ; Load from a dereferenceable load
  39. %d4_load = load i32*, i32** @globali32ptr, !dereferenceable !0
  40. %load7 = load i32, i32* %d4_load
  41. ; Load from an offset not covered by the dereferenceable portion
  42. %d2_load = load i32*, i32** @globali32ptr, !dereferenceable !1
  43. %load8 = load i32, i32* %d2_load
  44. ; Load from a potentially null pointer with dereferenceable_or_null
  45. %d_or_null_load = load i32*, i32** @globali32ptr, !dereferenceable_or_null !0
  46. %load9 = load i32, i32* %d_or_null_load
  47. ; Load from a non-null pointer with dereferenceable_or_null
  48. %d_or_null_non_null_load = load i32*, i32** @globali32ptr, !nonnull !2, !dereferenceable_or_null !0
  49. %load10 = load i32, i32* %d_or_null_non_null_load
  50. ; It's OK to overrun static array size as long as we stay within underlying object size
  51. %within_allocation = getelementptr inbounds %struct.A, %struct.A* @globalstruct, i64 0, i32 0, i64 10
  52. %load11 = load i8, i8* %within_allocation
  53. ; GEP is outside the underlying object size
  54. %outside_allocation = getelementptr inbounds %struct.A, %struct.A* @globalstruct, i64 0, i32 1, i64 10
  55. %load12 = load i8, i8* %outside_allocation
  56. ret void
  57. }
  58. declare i32 @llvm.experimental.gc.statepoint.p0f_i1f(i64, i32, i1 ()*, i32, i32, ...)
  59. declare i32 addrspace(1)* @llvm.experimental.gc.relocate.p1i32(i32, i32, i32)
  60. !0 = !{i64 4}
  61. !1 = !{i64 2}
  62. !2 = !{}