1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals
2 ; RUN: opt -S -passes=globalopt < %s | FileCheck %s
4 @g1 = internal global ptr null
5 @g2 = internal global ptr null
6 @g3 = internal global ptr null
8 declare noalias ptr @malloc(i64) allockind("alloc,uninitialized") allocsize(0)
11 ; CHECK: @[[G1_BODY_0:[a-zA-Z0-9_$"\\.-]+]] = internal unnamed_addr global i64 undef
12 ; CHECK: @[[G2_BODY_0:[a-zA-Z0-9_$"\\.-]+]] = internal unnamed_addr global i32 undef
13 ; CHECK: @[[G2_BODY_1:[a-zA-Z0-9_$"\\.-]+]] = internal unnamed_addr global i32 undef
14 ; CHECK: @[[G2_BODY_2:[a-zA-Z0-9_$"\\.-]+]] = internal unnamed_addr global i32 undef
15 ; CHECK: @[[G3_BODY:[a-zA-Z0-9_$"\\.-]+]] = internal unnamed_addr global [8 x i8] undef
17 define void @test_store(i64 %a, i32 %b) {
18 ; CHECK-LABEL: @test_store(
19 ; CHECK-NEXT: store i64 [[A:%.*]], ptr @g1.body.0, align 8
20 ; CHECK-NEXT: store i32 [[B:%.*]], ptr @g2.body.0, align 4
21 ; CHECK-NEXT: store i32 [[B]], ptr @g2.body.1, align 4
22 ; CHECK-NEXT: store i32 [[B]], ptr @g2.body.2, align 4
23 ; CHECK-NEXT: store i64 [[A]], ptr @g3.body, align 4
24 ; CHECK-NEXT: store i32 [[B]], ptr @g3.body, align 4
25 ; CHECK-NEXT: ret void
27 %m1 = call ptr @malloc(i64 8)
28 store ptr %m1, ptr @g1
29 %a1 = load ptr, ptr @g1
31 %m2 = call ptr @malloc(i64 16)
32 store ptr %m2, ptr @g2
33 %a2 = load ptr, ptr @g2
35 %m3 = call ptr @malloc(i64 8)
36 store ptr %m3, ptr @g3
37 %a3 = load ptr, ptr @g3
41 ; Access types at different offsets.
43 %a2.4 = getelementptr i8, ptr %a2, i64 4
44 store i32 %b, ptr %a2.4
45 %a2.10 = getelementptr i8, ptr %a2, i64 10
46 store i32 %b, ptr %a2.10, align 2
48 ; Access two different types at the same offset.
55 define void @test_load() {
56 ; CHECK-LABEL: @test_load(
57 ; CHECK-NEXT: [[TMP1:%.*]] = load i64, ptr @g1.body.0, align 8
58 ; CHECK-NEXT: [[TMP2:%.*]] = load i32, ptr @g2.body.0, align 4
59 ; CHECK-NEXT: [[TMP3:%.*]] = load i32, ptr @g2.body.1, align 4
60 ; CHECK-NEXT: [[TMP4:%.*]] = load i32, ptr @g2.body.2, align 4
61 ; CHECK-NEXT: [[TMP5:%.*]] = load i64, ptr @g3.body, align 4
62 ; CHECK-NEXT: ret void
64 %a1 = load ptr, ptr @g1
67 %a2 = load ptr, ptr @g2
69 %a2.4 = getelementptr i8, ptr %a2, i64 4
71 %a2.10 = getelementptr i8, ptr %a2, i64 10
72 load i32, ptr %a2.10, align 2
74 %a3 = load ptr, ptr @g3