1 ; RUN: opt -globalopt -S < %s | FileCheck %s
3 @G1 = internal global i32 5
4 @G2 = internal global i32 5
5 @G3 = internal global i32 5
6 @G4 = internal global i32 5
7 @G5 = internal global i32 5
10 define internal i32 @test1() norecurse {
13 %a = load i32, i32* @G1
18 ; The load comes before the store which makes @G2 live before the call.
20 define internal i32 @test2() norecurse {
22 %a = load i32, i32* @G2
28 ; This global is indexed by a GEP - this makes it partial alias and we bail out.
29 ; FIXME: We don't actually have to bail out in this case.
32 define internal i32 @test3() norecurse {
34 %x = getelementptr i32,i32* @G3, i32 0
35 %a = load i32, i32* %x
41 ; The global is casted away to a larger type then loaded. The store only partially
42 ; covers the load, so we must not demote.
45 define internal i32 @test4() norecurse {
48 %x = bitcast i32* @G4 to i64*
49 %a = load i64, i64* %x
50 %b = trunc i64 %a to i32
55 ; The global is casted away to a smaller type then loaded. This one is fine.
58 define internal i32 @test5() norecurse {
61 %x = bitcast i32* @G5 to i16*
62 %a = load i16, i16* %x
63 %b = zext i16 %a to i32
68 define i32 @main() norecurse {
69 %a = call i32 @test1()
70 %b = call i32 @test2()
71 %c = call i32 @test3()
72 %d = call i32 @test4()
73 %e = call i32 @test5()