8eaa99933ab9f6c10ffd12ced5d5999b8df70d04
[oota-llvm.git] / test / Transforms / GVN / non-local-offset.ll
1 ; RUN: opt -basicaa -gvn -S < %s | FileCheck %s
2
3 target datalayout = "e-p:64:64:64"
4
5 ; GVN should ignore the store to p[1] to see that the load from p[0] is
6 ; fully redundant.
7
8 ; CHECK: @yes
9 ; CHECK: if.then:
10 ; CHECK-NEXT: store i32 0, i32* %q
11 ; CHECK-NEXT: ret void
12
13 define void @yes(i1 %c, i32* %p, i32* %q) nounwind {
14 entry:
15   store i32 0, i32* %p
16   %p1 = getelementptr inbounds i32* %p, i64 1
17   store i32 1, i32* %p1
18   br i1 %c, label %if.else, label %if.then
19
20 if.then:
21   %t = load i32* %p
22   store i32 %t, i32* %q
23   ret void
24
25 if.else:
26   ret void
27 }
28
29 ; GVN should ignore the store to p[1] to see that the first load from p[0] is
30 ; fully redundant. However, the second load is larger, so it's not a simple
31 ; redundancy.
32
33 ; CHECK: @watch_out_for_size_change
34 ; CHECK: if.then:
35 ; CHECK-NEXT: store i32 0, i32* %q
36 ; CHECK-NEXT: ret void
37 ; CHECK: if.else:
38 ; CHECK: load i64* %pc
39 ; CHECK: store i64
40
41 define void @watch_out_for_size_change(i1 %c, i32* %p, i32* %q) nounwind {
42 entry:
43   store i32 0, i32* %p
44   %p1 = getelementptr inbounds i32* %p, i64 1
45   store i32 1, i32* %p1
46   br i1 %c, label %if.else, label %if.then
47
48 if.then:
49   %t = load i32* %p
50   store i32 %t, i32* %q
51   ret void
52
53 if.else:
54   %pc = bitcast i32* %p to i64*
55   %qc = bitcast i32* %q to i64*
56   %t64 = load i64* %pc
57   store i64 %t64, i64* %qc
58   ret void
59 }