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