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 3 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 9 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 12; to it. 13; CHECK: @b = internal unnamed_addr externally_initialized global i32 undef 14@b = internal externally_initialized global i32 undef 15 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 20 21define void @foo() { 22; CHECK-LABEL: foo 23entry: 24; CHECK: store i32 42, ptr @a 25 store i32 42, ptr @a 26 ret void 27} 28define i32 @bar() { 29; CHECK-LABEL: bar 30entry: 31; CHECK: %val = load i32, ptr @a 32 %val = load i32, ptr @a 33 ret i32 %val 34} 35 36define i32 @baz() { 37; CHECK-LABEL: baz 38entry: 39; CHECK: %val = load i32, ptr @b 40 %val = load i32, ptr @b 41 ret i32 %val 42} 43 44define i32 @bam() { 45; CHECK-CONSTANT-LABEL: bam 46entry: 47; CHECK-CONSTANT: %val = load i32, ptr @c 48 %val = load i32, ptr @c 49 ret i32 %val 50} 51