6f54fbbe3e6114abe616a3f7c9c9e69e1bd934da
[oota-llvm.git] / test / Analysis / GlobalsModRef / nonescaping-noalias.ll
1 ; RUN: opt < %s -globalsmodref-aa -gvn -S | FileCheck %s
2 ;
3 ; This tests the safe no-alias conclusions of GMR -- when there is
4 ; a non-escaping global as one indentified underlying object and some pointer
5 ; that would inherently have escaped any other function as the other underlying
6 ; pointer of an alias query.
7
8 @g1 = internal global i32 0
9
10 define i32 @test1(i32* %param) {
11 ; Ensure that we can fold a store to a load of a global across a store to
12 ; a parameter when the global is non-escaping.
13 ;
14 ; CHECK-LABEL: @test1(
15 ; CHECK: store i32 42, i32* @g1
16 ; CHECK-NOT: load i32
17 ; CHECK: ret i32 42
18 entry:
19   store i32 42, i32* @g1
20   store i32 7, i32* %param
21   %v = load i32, i32* @g1
22   ret i32 %v
23 }
24
25 declare i32* @f()
26
27 define i32 @test2() {
28 ; Ensure that we can fold a store to a load of a global across a store to
29 ; the pointer returned by a function call. Since the global could not escape,
30 ; this function cannot be returning its address.
31 ;
32 ; CHECK-LABEL: @test2(
33 ; CHECK: store i32 42, i32* @g1
34 ; CHECK-NOT: load i32
35 ; CHECK: ret i32 42
36 entry:
37   %ptr = call i32* @f() readnone
38   store i32 42, i32* @g1
39   store i32 7, i32* %ptr
40   %v = load i32, i32* @g1
41   ret i32 %v
42 }
43
44 @g2 = external global i32*
45
46 define i32 @test3() {
47 ; Ensure that we can fold a store to a load of a global across a store to
48 ; the pointer loaded from that global. Because the global does not escape, it
49 ; cannot alias a pointer loaded out of a global.
50 ;
51 ; CHECK-LABEL: @test3(
52 ; CHECK: store i32 42, i32* @g1
53 ; CHECK: store i32 7, i32*
54 ; CHECK-NOT: load i32
55 ; CHECK: ret i32 42
56 entry:
57   store i32 42, i32* @g1
58   %ptr1 = load i32*, i32** @g2
59   store i32 7, i32* %ptr1
60   %v = load i32, i32* @g1
61   ret i32 %v
62 }