Home | History | Annotate | Download | only in DeadStoreElimination
      1 ; RUN: opt < %s -basicaa -dse -S | FileCheck %s
      2 
      3 declare noalias i8* @calloc(i64, i64)
      4 
      5 define i32* @test1() {
      6 ; CHECK-LABEL: test1
      7   %1 = tail call noalias i8* @calloc(i64 1, i64 4)
      8   %2 = bitcast i8* %1 to i32*
      9   ; This store is dead and should be removed
     10   store i32 0, i32* %2, align 4
     11 ; CHECK-NOT: store i32 0, i32* %2, align 4
     12   ret i32* %2
     13 }
     14 
     15 define i32* @test2() {
     16 ; CHECK-LABEL: test2
     17   %1 = tail call noalias i8* @calloc(i64 1, i64 4)
     18   %2 = bitcast i8* %1 to i32*
     19   %3 = getelementptr i32, i32* %2, i32 5
     20   store i32 0, i32* %3, align 4
     21 ; CHECK-NOT: store i32 0, i32* %2, align 4
     22   ret i32* %2
     23 }
     24 
     25 define i32* @test3(i32 *%arg) {
     26 ; CHECK-LABEL: test3
     27   store i32 0, i32* %arg, align 4
     28 ; CHECK: store i32 0, i32* %arg, align 4
     29   ret i32* %arg
     30 }
     31 
     32 declare void @clobber_memory(i8*)
     33 define i8* @test4() {
     34 ; CHECK-LABEL: test4
     35   %1 = tail call noalias i8* @calloc(i64 1, i64 4)
     36   call void @clobber_memory(i8* %1)
     37   store i8 0, i8* %1, align 4
     38 ; CHECK: store i8 0, i8* %1, align 4
     39   ret i8* %1
     40 }
     41 
     42 define i32* @test5() {
     43 ; CHECK-LABEL: test5
     44   %1 = tail call noalias i8* @calloc(i64 1, i64 4)
     45   %2 = bitcast i8* %1 to i32*
     46   store volatile i32 0, i32* %2, align 4
     47 ; CHECK: store volatile i32 0, i32* %2, align 4
     48   ret i32* %2
     49 }
     50 
     51 define i8* @test6() {
     52 ; CHECK-LABEL: test6
     53   %1 = tail call noalias i8* @calloc(i64 1, i64 4)
     54   store i8 5, i8* %1, align 4
     55 ; CHECK: store i8 5, i8* %1, align 4
     56   ret i8* %1
     57 }
     58 
     59 define i8* @test7(i8 %arg) {
     60 ; CHECK-LABEL: test7
     61   %1 = tail call noalias i8* @calloc(i64 1, i64 4)
     62   store i8 %arg, i8* %1, align 4
     63 ; CHECK: store i8 %arg, i8* %1, align 4
     64   ret i8* %1
     65 }
     66