51 lines · plain
1; RUN: opt < %s -S -passes=globalopt | FileCheck %s2; RUN: opt < %s -passes=early-cse | opt -S -passes=globalopt | FileCheck %s --check-prefix=CHECK-CONSTANT3 4; This global is externally_initialized, which may modify the value between5; it's static initializer and any code in this module being run, so the only6; write to it cannot be merged into the static initialiser.7; CHECK: @a = internal unnamed_addr externally_initialized global i32 undef8@a = internal externally_initialized global i32 undef9 10; This global is stored to by the external initialization, so cannot be11; constant-propagated and removed, despite the fact that there are no writes12; to it.13; CHECK: @b = internal unnamed_addr externally_initialized global i32 undef14@b = internal externally_initialized global i32 undef15 16; This constant global is externally_initialized, which may modify the value17; between its static const initializer and any code in this module being run, so18; the read from it cannot be const propagated19@c = internal externally_initialized constant i32 4220 21define void @foo() {22; CHECK-LABEL: foo23entry:24; CHECK: store i32 42, ptr @a25 store i32 42, ptr @a26 ret void27}28define i32 @bar() {29; CHECK-LABEL: bar30entry:31; CHECK: %val = load i32, ptr @a32 %val = load i32, ptr @a33 ret i32 %val34}35 36define i32 @baz() {37; CHECK-LABEL: baz38entry:39; CHECK: %val = load i32, ptr @b40 %val = load i32, ptr @b41 ret i32 %val42}43 44define i32 @bam() {45; CHECK-CONSTANT-LABEL: bam46entry:47; CHECK-CONSTANT: %val = load i32, ptr @c48 %val = load i32, ptr @c49 ret i32 %val50}51