PartialStore.ll 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. ; RUN: opt < %s -basicaa -dse -S | FileCheck %s
  2. target datalayout = "E-p:64:64:64-a0:0:8-f32:32:32-f64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-v64:64:64-v128:128:128"
  3. ; Ensure that the dead store is deleted in this case. It is wholely
  4. ; overwritten by the second store.
  5. define void @test1(i32 *%V) {
  6. %V2 = bitcast i32* %V to i8* ; <i8*> [#uses=1]
  7. store i8 0, i8* %V2
  8. store i32 1234567, i32* %V
  9. ret void
  10. ; CHECK-LABEL: @test1(
  11. ; CHECK-NEXT: store i32 1234567
  12. }
  13. ; Note that we could do better by merging the two stores into one.
  14. define void @test2(i32* %P) {
  15. ; CHECK-LABEL: @test2(
  16. store i32 0, i32* %P
  17. ; CHECK: store i32
  18. %Q = bitcast i32* %P to i16*
  19. store i16 1, i16* %Q
  20. ; CHECK: store i16
  21. ret void
  22. }
  23. define i32 @test3(double %__x) {
  24. ; CHECK-LABEL: @test3(
  25. ; CHECK: store double
  26. %__u = alloca { [3 x i32] }
  27. %tmp.1 = bitcast { [3 x i32] }* %__u to double*
  28. store double %__x, double* %tmp.1
  29. %tmp.4 = getelementptr { [3 x i32] }, { [3 x i32] }* %__u, i32 0, i32 0, i32 1
  30. %tmp.5 = load i32, i32* %tmp.4
  31. %tmp.6 = icmp slt i32 %tmp.5, 0
  32. %tmp.7 = zext i1 %tmp.6 to i32
  33. ret i32 %tmp.7
  34. }
  35. ; PR6043
  36. define void @test4(i8* %P) {
  37. ; CHECK-LABEL: @test4(
  38. ; CHECK-NEXT: bitcast
  39. ; CHECK-NEXT: store double
  40. store i8 19, i8* %P ;; dead
  41. %A = getelementptr i8, i8* %P, i32 3
  42. store i8 42, i8* %A ;; dead
  43. %Q = bitcast i8* %P to double*
  44. store double 0.0, double* %Q
  45. ret void
  46. }
  47. ; PR8657
  48. declare void @test5a(i32*)
  49. define void @test5(i32 %i) nounwind ssp {
  50. %A = alloca i32
  51. %B = bitcast i32* %A to i8*
  52. %C = getelementptr i8, i8* %B, i32 %i
  53. store i8 10, i8* %C ;; Dead store to variable index.
  54. store i32 20, i32* %A
  55. call void @test5a(i32* %A)
  56. ret void
  57. ; CHECK-LABEL: @test5(
  58. ; CHECK-NEXT: alloca
  59. ; CHECK-NEXT: store i32 20
  60. ; CHECK-NEXT: call void @test5a
  61. }
  62. declare void @test5a_as1(i32*)
  63. define void @test5_addrspacecast(i32 %i) nounwind ssp {
  64. %A = alloca i32
  65. %B = addrspacecast i32* %A to i8 addrspace(1)*
  66. %C = getelementptr i8, i8 addrspace(1)* %B, i32 %i
  67. store i8 10, i8 addrspace(1)* %C ;; Dead store to variable index.
  68. store i32 20, i32* %A
  69. call void @test5a(i32* %A)
  70. ret void
  71. ; CHECK-LABEL: @test5_addrspacecast(
  72. ; CHECK-NEXT: alloca
  73. ; CHECK-NEXT: store i32 20
  74. ; CHECK-NEXT: call void @test5a
  75. }