1 ; RUN: opt < %s -S -passes=globalopt | FileCheck %s
2 ; RUN: opt < %s -passes=early-cse | opt -S -passes=globalopt | FileCheck %s --check-prefix=CHECK-CONSTANT
4 ; This global is externally_initialized, which may modify the value between
5 ; it's static initializer and any code in this module being run, so the only
6 ; write to it cannot be merged into the static initialiser.
7 ; CHECK: @a = internal unnamed_addr externally_initialized global i32 undef
8 @a = internal externally_initialized global i32 undef
10 ; This global is stored to by the external initialization, so cannot be
11 ; constant-propagated and removed, despite the fact that there are no writes
13 ; CHECK: @b = internal unnamed_addr externally_initialized global i32 undef
14 @b = internal externally_initialized global i32 undef
16 ; This constant global is externally_initialized, which may modify the value
17 ; between its static const initializer and any code in this module being run, so
18 ; the read from it cannot be const propagated
19 @c = internal externally_initialized constant i32 42
24 ; CHECK: store i32 42, ptr @a
31 ; CHECK: %val = load i32, ptr @a
32 %val = load i32, ptr @a
39 ; CHECK: %val = load i32, ptr @b
40 %val = load i32, ptr @b
45 ; CHECK-CONSTANT-LABEL: bam
47 ; CHECK-CONSTANT: %val = load i32, ptr @c
48 %val = load i32, ptr @c