Fix PR24469 resulting from r245025 and re-enable dead store elimination across basicb...
[oota-llvm.git] / test / Transforms / DeadStoreElimination / cross_block_dse_loop.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 @A = common global [100 x i32] zeroinitializer, align 16
5 @x = common global i32 0
6
7 ; Negative Test case-
8 ;void foo(int N) {
9 ;  A[0] = N;
10 ;  for(int i=0;i<N;++i)
11 ;    A[i]+=i;
12 ;  A[0] = 10;
13 ;}
14 ;; Stores should not be optimized away.
15
16 define void @test_01(i32 %N) #0 {
17   %1 = alloca i32
18   %i = alloca i32
19   store i32 %N, i32* %1
20   %2 = load i32, i32* %1
21   store i32 %2, i32* getelementptr inbounds ([100 x i32], [100 x i32]* @A, i32 0, i64 0)
22   store i32 0, i32* %i
23   br label %3
24
25 ; <label>:3                                       ; preds = %14, %0
26   %4 = load i32, i32* %i
27   %5 = load i32, i32* %1
28   %6 = icmp slt i32 %4, %5
29   br i1 %6, label %7, label %17
30
31 ; <label>:7                                       ; preds = %3
32   %8 = load i32, i32* %i
33   %9 = load i32, i32* %i
34   %10 = sext i32 %9 to i64
35   %11 = getelementptr inbounds [100 x i32], [100 x i32]* @A, i32 0, i64 %10
36   %12 = load i32, i32* %11
37   %13 = add nsw i32 %12, %8
38   store i32 %13, i32* %11
39   br label %14
40
41 ; <label>:14                                      ; preds = %7
42   %15 = load i32, i32* %i
43   %16 = add nsw i32 %15, 1
44   store i32 %16, i32* %i
45   br label %3
46
47 ; <label>:17                                      ; preds = %3
48   store i32 10, i32* getelementptr inbounds ([100 x i32], [100 x i32]* @A, i32 0, i64 0)
49   ret void
50 }
51 ; CHECK-LABEL: @test_01(
52 ; CHECK: store i32 %2, i32* getelementptr inbounds ([100 x i32], [100 x i32]* @A, i32 0, i64 0)
53 ; CHECK: store i32 %13, i32* %11
54 ; CHECK: store i32 10, i32* getelementptr inbounds ([100 x i32], [100 x i32]* @A, i32 0, i64 0)
55
56
57 ; Postive Test case-
58 ;void foo(int N) {
59 ;  A[0] = N;
60 ;  for(int i=0;i<N;++i)
61 ;    A[i]=i;
62 ;  A[0] = 10;
63 ;}
64 ;; Stores should not be optimized away.
65 define void @test_02(i32 %N) #0 {
66   %1 = alloca i32
67   %i = alloca i32
68   store i32 %N, i32* %1
69   %2 = load i32, i32* %1
70   store i32 %2, i32* getelementptr inbounds ([100 x i32], [100 x i32]* @A, i32 0, i64 0)
71   store i32 0, i32* %i
72   br label %3
73
74 ; <label>:3                                       ; preds = %12, %0
75   %4 = load i32, i32* %i
76   %5 = load i32, i32* %1
77   %6 = icmp slt i32 %4, %5
78   br i1 %6, label %7, label %15
79
80 ; <label>:7                                       ; preds = %3
81   %8 = load i32, i32* %i
82   %9 = load i32, i32* %i
83   %10 = sext i32 %9 to i64
84   %11 = getelementptr inbounds [100 x i32], [100 x i32]* @A, i32 0, i64 %10
85   store i32 %8, i32* %11
86   br label %12
87
88 ; <label>:12                                      ; preds = %7
89   %13 = load i32, i32* %i
90   %14 = add nsw i32 %13, 1
91   store i32 %14, i32* %i
92   br label %3
93
94 ; <label>:15                                      ; preds = %3
95   store i32 10, i32* getelementptr inbounds ([100 x i32], [100 x i32]* @A, i32 0, i64 0)
96   ret void
97 }
98
99 ; CHECK-LABEL: @test_02(
100 ; CHECK-NOT: store i32 %2, i32* getelementptr inbounds ([100 x i32], [100 x i32]* @A, i32 0, i64 0)
101 ; CHECK: store i32 %7, i32* %10
102 ; CHECK: store i32 10, i32* getelementptr inbounds ([100 x i32], [100 x i32]* @A, i32 0, i64 0)
103
104