store.ll 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. ; RUN: opt < %s -instcombine -S | FileCheck %s
  2. define void @test1(i32* %P) {
  3. store i32 undef, i32* %P
  4. store i32 123, i32* undef
  5. store i32 124, i32* null
  6. ret void
  7. ; CHECK-LABEL: @test1(
  8. ; CHECK-NEXT: store i32 123, i32* undef
  9. ; CHECK-NEXT: store i32 undef, i32* null
  10. ; CHECK-NEXT: ret void
  11. }
  12. define void @test2(i32* %P) {
  13. %X = load i32, i32* %P ; <i32> [#uses=1]
  14. %Y = add i32 %X, 0 ; <i32> [#uses=1]
  15. store i32 %Y, i32* %P
  16. ret void
  17. ; CHECK-LABEL: @test2(
  18. ; CHECK-NEXT: ret void
  19. }
  20. ;; Simple sinking tests
  21. ; "if then else"
  22. define i32 @test3(i1 %C) {
  23. %A = alloca i32
  24. br i1 %C, label %Cond, label %Cond2
  25. Cond:
  26. store i32 -987654321, i32* %A
  27. br label %Cont
  28. Cond2:
  29. store i32 47, i32* %A
  30. br label %Cont
  31. Cont:
  32. %V = load i32, i32* %A
  33. ret i32 %V
  34. ; CHECK-LABEL: @test3(
  35. ; CHECK-NOT: alloca
  36. ; CHECK: Cont:
  37. ; CHECK-NEXT: %storemerge = phi i32 [ -987654321, %Cond ], [ 47, %Cond2 ]
  38. ; CHECK-NEXT: ret i32 %storemerge
  39. }
  40. ; "if then"
  41. define i32 @test4(i1 %C) {
  42. %A = alloca i32
  43. store i32 47, i32* %A
  44. br i1 %C, label %Cond, label %Cont
  45. Cond:
  46. store i32 -987654321, i32* %A
  47. br label %Cont
  48. Cont:
  49. %V = load i32, i32* %A
  50. ret i32 %V
  51. ; CHECK-LABEL: @test4(
  52. ; CHECK-NOT: alloca
  53. ; CHECK: Cont:
  54. ; CHECK-NEXT: %storemerge = phi i32 [ -987654321, %Cond ], [ 47, %0 ]
  55. ; CHECK-NEXT: ret i32 %storemerge
  56. }
  57. ; "if then"
  58. define void @test5(i1 %C, i32* %P) {
  59. store i32 47, i32* %P, align 1
  60. br i1 %C, label %Cond, label %Cont
  61. Cond:
  62. store i32 -987654321, i32* %P, align 1
  63. br label %Cont
  64. Cont:
  65. ret void
  66. ; CHECK-LABEL: @test5(
  67. ; CHECK: Cont:
  68. ; CHECK-NEXT: %storemerge = phi i32
  69. ; CHECK-NEXT: store i32 %storemerge, i32* %P, align 1
  70. ; CHECK-NEXT: ret void
  71. }
  72. ; PR14753 - merging two stores should preserve the TBAA tag.
  73. define void @test6(i32 %n, float* %a, i32* %gi) nounwind uwtable ssp {
  74. entry:
  75. store i32 42, i32* %gi, align 4, !tbaa !0
  76. br label %for.cond
  77. for.cond: ; preds = %for.body, %entry
  78. %storemerge = phi i32 [ 0, %entry ], [ %inc, %for.body ]
  79. %0 = load i32, i32* %gi, align 4, !tbaa !0
  80. %cmp = icmp slt i32 %0, %n
  81. br i1 %cmp, label %for.body, label %for.end
  82. for.body: ; preds = %for.cond
  83. %idxprom = sext i32 %0 to i64
  84. %arrayidx = getelementptr inbounds float, float* %a, i64 %idxprom
  85. store float 0.000000e+00, float* %arrayidx, align 4, !tbaa !3
  86. %1 = load i32, i32* %gi, align 4, !tbaa !0
  87. %inc = add nsw i32 %1, 1
  88. store i32 %inc, i32* %gi, align 4, !tbaa !0
  89. br label %for.cond
  90. for.end: ; preds = %for.cond
  91. ret void
  92. ; CHECK-LABEL: @test6(
  93. ; CHECK: for.cond:
  94. ; CHECK-NEXT: phi i32 [ 42
  95. ; CHECK-NEXT: store i32 %storemerge, i32* %gi, align 4, !tbaa !0
  96. }
  97. !0 = !{!4, !4, i64 0}
  98. !1 = !{!"omnipotent char", !2}
  99. !2 = !{!"Simple C/C++ TBAA"}
  100. !3 = !{!"float", !1}
  101. !4 = !{!"int", !1}