Fix PR24469 resulting from r245025 and re-enable dead store elimination across basicb...
[oota-llvm.git] / test / Transforms / DeadStoreElimination / cross_block_dse.ll
1 ; RUN: opt < %s -basicaa -dse -S | FileCheck %s
2 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
3
4 @x = common global i32 0
5 @y = common global i32 0
6 @a = external global i32
7 @b = external global i32
8
9 define void @test_01(i32 %N) {
10   %1 = alloca i32
11   store i32 %N, i32* %1
12   store i32 10, i32* @x
13   %2 = load i32, i32* %1
14   %3 = icmp ne i32 %2, 0
15   br i1 %3, label %4, label %5
16
17 ; <label>:4
18   store i32 5, i32* @x
19   br label %5
20
21 ; <label>:5
22   store i32 15, i32* @x
23   ret void
24 }
25 ; CHECK-LABEL: @test_01(
26 ; CHECK-NOT: store i32 10, i32* @x
27 ; CHECK-NOT: store i32 5, i32* @x
28 ; CHECK: store i32 15, i32* @x
29
30
31 define void @test_02(i32 %N) {
32   %1 = alloca i32
33   store i32 %N, i32* %1
34   store i32 10, i32* @x
35   %2 = load i32, i32* %1
36   %3 = icmp ne i32 %2, 0
37   br i1 %3, label %4, label %5
38
39 ; <label>:4
40   store i32 5, i32* @x
41   br label %7
42
43 ; <label>:5
44   %6 = load i32, i32* @x
45   store i32 %6, i32* @y
46   br label %7
47
48 ; <label>:7
49   store i32 15, i32* @x
50   ret void
51 }
52 ; CHECK-LABEL: @test_02(
53 ; CHECK: store i32 10, i32* @x
54 ; CHECK-NOT: store i32 5, i32* @x
55 ; CHECK: store i32 %6, i32* @y
56
57
58 define void @test_03(i32 %N) #0 {
59   %1 = alloca i32
60   store i32 %N, i32* %1
61   store i32 10, i32* @x
62   %2 = load i32, i32* %1
63   %3 = icmp ne i32 %2, 0
64   br i1 %3, label %4, label %6
65
66 ; <label>:4                                       ; preds = %0
67   %5 = load i32, i32* @x
68   store i32 %5, i32* @y
69   br label %6
70
71 ; <label>:6                                       ; preds = %4, %0
72   store i32 15, i32* @x
73   ret void
74 }
75 ; CHECK-LABEL: @test_03(
76 ; CHECK: store i32 10, i32* @x
77 ; CHECK: store i32 %5, i32* @y
78 ; CHECK: store i32 15, i32* @x
79
80
81
82 ; Check we safely delete store i32 %g.02, i32* @b below.(PR24469)
83 define void @test_04() {
84 entry:
85   br i1 false, label %for.body, label %for.end.9
86
87 for.cond.1.loopexit:                              ; preds = %for.body
88   store i32 0, i32* @b
89   %0 = load i32, i32* @a
90   br i1 false, label %for.body, label %for.end.9
91
92 for.body:                                         ; preds = %for.cond.1.loopexit, %entry
93   %g.02 = phi i32 [ undef, %entry ], [ %0, %for.cond.1.loopexit ]
94   store i32 %g.02, i32* @b
95   br label %for.cond.1.loopexit
96
97 for.end.9:                                        ; preds = %for.cond.1.loopexit, %entry
98   ret void
99 }
100
101 ; CHECK-LABEL: @test_04(
102 ; CHECK-NOT: store i32 %g.02, i32* @b
103 ; CHECK-NOT: %g.02 = phi i32 [ undef, %entry ], [ %0, %for.cond.1.loopexit ]
104 ; CHECK-NOT: %0 = load i32, i32* @a