loadstore-metadata.ll 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. ; RUN: opt -instcombine -S < %s | FileCheck %s
  2. target datalayout = "e-m:e-p:64:64:64-i64:64-f80:128-n8:16:32:64-S128"
  3. define i32 @test_load_cast_combine_tbaa(float* %ptr) {
  4. ; Ensure (cast (load (...))) -> (load (cast (...))) preserves TBAA.
  5. ; CHECK-LABEL: @test_load_cast_combine_tbaa(
  6. ; CHECK: load i32, i32* %{{.*}}, !tbaa !0
  7. entry:
  8. %l = load float, float* %ptr, !tbaa !0
  9. %c = bitcast float %l to i32
  10. ret i32 %c
  11. }
  12. define i32 @test_load_cast_combine_noalias(float* %ptr) {
  13. ; Ensure (cast (load (...))) -> (load (cast (...))) preserves no-alias metadata.
  14. ; CHECK-LABEL: @test_load_cast_combine_noalias(
  15. ; CHECK: load i32, i32* %{{.*}}, !alias.scope !2, !noalias !1
  16. entry:
  17. %l = load float, float* %ptr, !alias.scope !2, !noalias !1
  18. %c = bitcast float %l to i32
  19. ret i32 %c
  20. }
  21. define float @test_load_cast_combine_range(i32* %ptr) {
  22. ; Ensure (cast (load (...))) -> (load (cast (...))) drops range metadata. It
  23. ; would be nice to preserve or update it somehow but this is hard when moving
  24. ; between types.
  25. ; CHECK-LABEL: @test_load_cast_combine_range(
  26. ; CHECK: load float, float* %{{.*}}
  27. ; CHECK-NOT: !range
  28. ; CHECK: ret float
  29. entry:
  30. %l = load i32, i32* %ptr, !range !5
  31. %c = bitcast i32 %l to float
  32. ret float %c
  33. }
  34. define i32 @test_load_cast_combine_invariant(float* %ptr) {
  35. ; Ensure (cast (load (...))) -> (load (cast (...))) preserves invariant metadata.
  36. ; CHECK-LABEL: @test_load_cast_combine_invariant(
  37. ; CHECK: load i32, i32* %{{.*}}, !invariant.load !3
  38. entry:
  39. %l = load float, float* %ptr, !invariant.load !3
  40. %c = bitcast float %l to i32
  41. ret i32 %c
  42. }
  43. define i32 @test_load_cast_combine_nontemporal(float* %ptr) {
  44. ; Ensure (cast (load (...))) -> (load (cast (...))) preserves nontemporal
  45. ; metadata.
  46. ; CHECK-LABEL: @test_load_cast_combine_nontemporal(
  47. ; CHECK: load i32, i32* %{{.*}}, !nontemporal !4
  48. entry:
  49. %l = load float, float* %ptr, !nontemporal !4
  50. %c = bitcast float %l to i32
  51. ret i32 %c
  52. }
  53. define void @test_load_cast_combine_loop(float* %src, i32* %dst, i32 %n) {
  54. ; Ensure (cast (load (...))) -> (load (cast (...))) preserves loop access
  55. ; metadata.
  56. ; CHECK-LABEL: @test_load_cast_combine_loop(
  57. ; CHECK: load i32, i32* %{{.*}}, !llvm.mem.parallel_loop_access !1
  58. entry:
  59. br label %loop
  60. loop:
  61. %i = phi i32 [ 0, %entry ], [ %i.next, %loop ]
  62. %src.gep = getelementptr inbounds float, float* %src, i32 %i
  63. %dst.gep = getelementptr inbounds i32, i32* %dst, i32 %i
  64. %l = load float, float* %src.gep, !llvm.mem.parallel_loop_access !1
  65. %c = bitcast float %l to i32
  66. store i32 %c, i32* %dst.gep
  67. %i.next = add i32 %i, 1
  68. %cmp = icmp slt i32 %i.next, %n
  69. br i1 %cmp, label %loop, label %exit, !llvm.loop !1
  70. exit:
  71. ret void
  72. }
  73. define void @test_load_cast_combine_nonnull(float** %ptr) {
  74. ; We can't preserve nonnull metadata when converting a load of a pointer to
  75. ; a load of an integer. Instead, we translate it to range metadata.
  76. ; FIXME: We should also transform range metadata back into nonnull metadata.
  77. ; FIXME: This test is very fragile. If any LABEL lines are added after
  78. ; this point, the test will fail, because this test depends on a metadata tuple,
  79. ; which is always emitted at the end of the file. At some point, we should
  80. ; consider an option to the IR printer to emit MD tuples after the function
  81. ; that first uses them--this will allow us to refer to them like this and not
  82. ; have the tests break. For now, this function must always come last in this
  83. ; file, and no LABEL lines are to be added after this point.
  84. ;
  85. ; CHECK-LABEL: @test_load_cast_combine_nonnull(
  86. ; CHECK: %[[V:.*]] = load i64, i64* %{{.*}}, !range ![[MD:[0-9]+]]
  87. ; CHECK-NOT: !nonnull
  88. ; CHECK: store i64 %[[V]], i64*
  89. entry:
  90. %p = load float*, float** %ptr, !nonnull !3
  91. %gep = getelementptr float*, float** %ptr, i32 42
  92. store float* %p, float** %gep
  93. ret void
  94. }
  95. ; This is the metadata tuple that we reference above:
  96. ; CHECK: ![[MD]] = !{i64 1, i64 0}
  97. !0 = !{ !1, !1, i64 0 }
  98. !1 = !{ !1 }
  99. !2 = !{ !2, !1 }
  100. !3 = !{ }
  101. !4 = !{ i32 1 }
  102. !5 = !{ i32 0, i32 42 }