• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -globalopt -S | FileCheck %s
2
3@c = global i8 42
4
5@i = internal global i8 42
6; CHECK: @ia = internal global i8 42
7@ia = internal alias i8, i8* @i
8
9@llvm.used = appending global [3 x i8*] [i8* bitcast (void ()* @fa to i8*), i8* bitcast (void ()* @f to i8*), i8* @ca], section "llvm.metadata"
10; CHECK-DAG: @llvm.used = appending global [3 x i8*] [i8* @ca, i8* bitcast (void ()* @f to i8*), i8* bitcast (void ()* @fa to i8*)], section "llvm.metadata"
11
12@llvm.compiler.used = appending global [4 x i8*] [i8* bitcast (void ()* @fa3 to i8*), i8* bitcast (void ()* @fa to i8*), i8* @ia, i8* @i], section "llvm.metadata"
13; CHECK-DAG: @llvm.compiler.used = appending global [2 x i8*] [i8* bitcast (void ()* @fa3 to i8*), i8* @ia], section "llvm.metadata"
14
15@sameAsUsed = global [3 x i8*] [i8* bitcast (void ()* @fa to i8*), i8* bitcast (void ()* @f to i8*), i8* @ca]
16; CHECK-DAG: @sameAsUsed = local_unnamed_addr global [3 x i8*] [i8* bitcast (void ()* @f to i8*), i8* bitcast (void ()* @f to i8*), i8* @c]
17
18@other = global i32* bitcast (void ()* @fa to i32*)
19; CHECK-DAG: @other = local_unnamed_addr global i32* bitcast (void ()* @f to i32*)
20
21@fa = internal alias void (), void ()* @f
22; CHECK: @fa = internal alias void (), void ()* @f
23
24@fa2 = internal alias void (), void ()* @f
25; CHECK-NOT: @fa2
26
27@fa3 = internal alias void (), void ()* @f
28; CHECK: @fa3
29
30@ca = internal alias i8, i8* @c
31; CHECK: @ca = internal alias i8, i8* @c
32
33define void @f() {
34  ret void
35}
36
37define i8* @g() {
38  ret i8* bitcast (void ()* @fa to i8*);
39}
40
41define i8* @g2() {
42  ret i8* bitcast (void ()* @fa2 to i8*);
43}
44
45define i8* @h() {
46  ret i8* @ca
47}
48
49; Check that GlobalOpt doesn't try to resolve aliases with GEP operands.
50
51%struct.S = type { i32, i32, i32 }
52@s = global %struct.S { i32 1, i32 2, i32 3 }, align 4
53
54@alias1 = alias i32, i32* getelementptr inbounds (%struct.S, %struct.S* @s, i64 0, i32 1)
55@alias2 = alias i32, i32* getelementptr inbounds (%struct.S, %struct.S* @s, i64 0, i32 2)
56
57; CHECK: load i32, i32* @alias1, align 4
58; CHECK: load i32, i32* @alias2, align 4
59
60define i32 @foo1() {
61entry:
62  %0 = load i32, i32* @alias1, align 4
63  %1 = load i32, i32* @alias2, align 4
64  %add = add nsw i32 %1, %0
65  ret i32 %add
66}
67