thread-loads.ll 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. ; RUN: opt < %s -jump-threading -S | FileCheck %s
  2. target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128"
  3. target triple = "i386-apple-darwin7"
  4. ; Test that we can thread through the block with the partially redundant load (%2).
  5. ; rdar://6402033
  6. define i32 @test1(i32* %P) nounwind {
  7. ; CHECK-LABEL: @test1(
  8. entry:
  9. %0 = tail call i32 (...) @f1() nounwind ; <i32> [#uses=1]
  10. %1 = icmp eq i32 %0, 0 ; <i1> [#uses=1]
  11. br i1 %1, label %bb1, label %bb
  12. bb: ; preds = %entry
  13. ; CHECK: bb1.thread:
  14. ; CHECK: store
  15. ; CHECK: br label %bb3
  16. store i32 42, i32* %P, align 4
  17. br label %bb1
  18. bb1: ; preds = %entry, %bb
  19. %res.0 = phi i32 [ 1, %bb ], [ 0, %entry ] ; <i32> [#uses=2]
  20. %2 = load i32, i32* %P, align 4 ; <i32> [#uses=1]
  21. %3 = icmp sgt i32 %2, 36 ; <i1> [#uses=1]
  22. br i1 %3, label %bb3, label %bb2
  23. bb2: ; preds = %bb1
  24. %4 = tail call i32 (...) @f2() nounwind ; <i32> [#uses=0]
  25. ret i32 %res.0
  26. bb3: ; preds = %bb1
  27. ; CHECK: bb3:
  28. ; CHECK: %res.01 = phi i32 [ 1, %bb1.thread ], [ 0, %bb1 ]
  29. ; CHECK: ret i32 %res.01
  30. ret i32 %res.0
  31. }
  32. declare i32 @f1(...)
  33. declare i32 @f2(...)
  34. ;; Check that we preserve TBAA information.
  35. ; rdar://11039258
  36. define i32 @test2(i32* %P) nounwind {
  37. ; CHECK-LABEL: @test2(
  38. entry:
  39. %0 = tail call i32 (...) @f1() nounwind ; <i32> [#uses=1]
  40. %1 = icmp eq i32 %0, 0 ; <i1> [#uses=1]
  41. br i1 %1, label %bb1, label %bb
  42. bb: ; preds = %entry
  43. ; CHECK: bb1.thread:
  44. ; CHECK: store{{.*}}, !tbaa !0
  45. ; CHECK: br label %bb3
  46. store i32 42, i32* %P, align 4, !tbaa !0
  47. br label %bb1
  48. bb1: ; preds = %entry, %bb
  49. %res.0 = phi i32 [ 1, %bb ], [ 0, %entry ]
  50. %2 = load i32, i32* %P, align 4, !tbaa !0
  51. %3 = icmp sgt i32 %2, 36
  52. br i1 %3, label %bb3, label %bb2
  53. bb2: ; preds = %bb1
  54. %4 = tail call i32 (...) @f2() nounwind
  55. ret i32 %res.0
  56. bb3: ; preds = %bb1
  57. ; CHECK: bb3:
  58. ; CHECK: %res.01 = phi i32 [ 1, %bb1.thread ], [ 0, %bb1 ]
  59. ; CHECK: ret i32 %res.01
  60. ret i32 %res.0
  61. }
  62. define i32 @test3(i8** %x, i1 %f) {
  63. ; Correctly thread loads of different (but compatible) types, placing bitcasts
  64. ; as necessary in the predecessors. This is especially tricky because the same
  65. ; predecessor ends up with two entries in the PHI node and they must share
  66. ; a single cast.
  67. ; CHECK-LABEL: @test3(
  68. entry:
  69. %0 = bitcast i8** %x to i32**
  70. %1 = load i32*, i32** %0, align 8
  71. br i1 %f, label %if.end57, label %if.then56
  72. ; CHECK: %[[LOAD:.*]] = load i32*, i32**
  73. ; CHECK: %[[CAST:.*]] = bitcast i32* %[[LOAD]] to i8*
  74. if.then56:
  75. br label %if.end57
  76. if.end57:
  77. %2 = load i8*, i8** %x, align 8
  78. %tobool59 = icmp eq i8* %2, null
  79. br i1 %tobool59, label %return, label %if.then60
  80. ; CHECK: %[[PHI:.*]] = phi i8* [ %[[CAST]], %[[PRED:[^ ]+]] ], [ %[[CAST]], %[[PRED]] ]
  81. ; CHECK-NEXT: %[[CMP:.*]] = icmp eq i8* %[[PHI]], null
  82. ; CHECK-NEXT: br i1 %[[CMP]]
  83. if.then60:
  84. ret i32 42
  85. return:
  86. ret i32 13
  87. }
  88. !0 = !{!3, !3, i64 0}
  89. !1 = !{!"omnipotent char", !2}
  90. !2 = !{!"Simple C/C++ TBAA", null}
  91. !3 = !{!"int", !1}