xref: /llvm-project/llvm/test/Transforms/GlobalOpt/store-struct-element.ll (revision d586bd5ca231a6022f439d4c6e43cfeeb53eb1d6)
18ebb3eacSBjorn Pettersson; RUN: opt < %s -passes=globalopt -S -o - | FileCheck %s
2d1431030SJon Roelofs
3d1431030SJon Roelofs%class.Class = type { i8, i8, i8, i8 }
4d1431030SJon Roelofs@A = local_unnamed_addr global %class.Class undef, align 4
5d1431030SJon Roelofs@B = local_unnamed_addr global %class.Class undef, align 4
6d1431030SJon Roelofs
7*d586bd5cSNikita Popov@llvm.global_ctors = appending global [2 x { i32, ptr, ptr }] [
8*d586bd5cSNikita Popov  { i32, ptr, ptr } { i32 65535, ptr @initA, ptr null },
9*d586bd5cSNikita Popov  { i32, ptr, ptr } { i32 65535, ptr @initB, ptr null }
10d1431030SJon Roelofs]
11d1431030SJon Roelofs
12d1431030SJon Roelofsdefine internal void @initA() section "__TEXT,__StaticInit,regular,pure_instructions" {
13d1431030SJon Roelofsentry:
14*d586bd5cSNikita Popov  store i32 -1, ptr @A, align 4
15d1431030SJon Roelofs  ret void
16d1431030SJon Roelofs}
17d1431030SJon Roelofs
18d1431030SJon Roelofsdefine internal void @initB() section "__TEXT,__StaticInit,regular,pure_instructions" {
19d1431030SJon Roelofsentry:
20*d586bd5cSNikita Popov  store i8 -1, ptr @B, align 4
21d1431030SJon Roelofs  ret void
22d1431030SJon Roelofs}
23d1431030SJon Roelofs
24d1431030SJon Roelofs; rdar://79503568
25d1431030SJon Roelofs; Check that we don't miscompile when the store covers the whole struct.
26d1431030SJon Roelofs; CHECK-NOT: @A = local_unnamed_addr global %class.Class { i8 -1, i8 undef, i8 undef, i8 undef }, align 4
27d1431030SJon Roelofs
28d1431030SJon Roelofs; FIXME: We could optimzie this as { i8 -1, i8 -1, i8 -1, i8 -1 } if constant folding were a little smarter.
29d1431030SJon Roelofs; CHECK: @A = local_unnamed_addr global %class.Class undef, align 4
30d1431030SJon Roelofs
31d1431030SJon Roelofs; Check that we still perform the transform when store is smaller than the width of the 0th element.
32d1431030SJon Roelofs; CHECK: @B = local_unnamed_addr global %class.Class { i8 -1, i8 undef, i8 undef, i8 undef }, align 4
33d1431030SJon Roelofs
34d1431030SJon Roelofs; CHECK: define internal void @initA()
35d1431030SJon Roelofs; CHECK-NOT: define internal void @initB()
36d1431030SJon Roelofs
37