51 lines · plain
1; RUN: opt < %s -S -passes=globalopt | FileCheck %s2 3; This global is externally_initialized, so if we split it into scalars we4; should keep that flag set on all of the new globals. This will prevent the5; store to @a[0] from being constant propagated to the load in @foo, but will not6; prevent @a[1] from being removed since it is dead.7; CHECK: @a.0 = internal unnamed_addr externally_initialized global i32 undef8; CHECK-NOT: @a.19@a = internal externally_initialized global [2 x i32] undef, align 410; This is the same, but a struct rather than an array.11; CHECK: @b.0 = internal unnamed_addr externally_initialized global i32 undef12; CHECK-NOT: @b.113@b = internal externally_initialized global {i32, i32} undef, align 414 15define i32 @foo() {16; CHECK-LABEL: define i32 @foo17entry:18; This load uses the split global, but cannot be constant-propagated away.19; CHECK: %0 = load i32, ptr @a.020 %0 = load i32, ptr @a, align 421 ret i32 %022}23 24define i32 @bar() {25; CHECK-LABEL: define i32 @bar26entry:27; This load uses the split global, but cannot be constant-propagated away.28; CHECK: %0 = load i32, ptr @b.029 %0 = load i32, ptr @b, align 430 ret i32 %031}32 33define void @init() {34; CHECK-LABEL: define void @init35entry:36; This store uses the split global, but cannot be constant-propagated away.37; CHECK: store i32 1, ptr @a.038 store i32 1, ptr @a, align 439; This store can be removed, because the second element of @a is never read.40; CHECK-NOT: store i32 2, ptr @a.141 store i32 2, ptr getelementptr inbounds ([2 x i32], ptr @a, i32 0, i32 1), align 442 43; This store uses the split global, but cannot be constant-propagated away.44; CHECK: store i32 3, ptr @b.045 store i32 3, ptr @b, align 446; This store can be removed, because the second element of @b is never read.47; CHECK-NOT: store i32 4, ptr @b.148 store i32 4, ptr getelementptr inbounds ({i32, i32}, ptr @b, i32 0, i32 1), align 449 ret void50}51