Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CodeGenCXX / init-invariant.cpp
blobfdd5753402ccba8cbcb7f2b4fbfa1837ecfbb8a2
1 // RUN: %clang_cc1 -triple i686-linux-gnu -std=c++20 -emit-llvm %s -disable-llvm-passes -o - | FileCheck %s --check-prefix=CHECK-O0
2 // RUN: %clang_cc1 -triple i686-linux-gnu -std=c++20 -emit-llvm %s -O1 -disable-llvm-passes -o - | FileCheck %s
4 // Check that we add an llvm.invariant.start.p0i8 to mark when a global becomes
5 // read-only. If globalopt can fold the initializer, it will then mark the
6 // variable as constant.
8 // Do not produce markers at -O0.
9 // CHECK-O0-NOT: llvm.invariant.start.p0i8
11 struct A {
12 A();
13 int n;
16 // CHECK: @a ={{.*}} global {{.*}} zeroinitializer
17 extern const A a = A();
19 struct A2 {
20 A2();
21 constexpr ~A2() {}
22 int n;
25 // CHECK: @a2 ={{.*}} global {{.*}} zeroinitializer
26 extern const A2 a2 = A2();
29 struct B {
30 B();
31 mutable int n;
34 // CHECK: @b ={{.*}} global {{.*}} zeroinitializer
35 extern const B b = B();
37 struct C {
38 C();
39 ~C();
40 int n;
43 // CHECK: @c ={{.*}} global {{.*}} zeroinitializer
44 extern const C c = C();
46 int f();
47 // CHECK: @d ={{.*}} global i32 0
48 extern const int d = f();
50 void e() {
51 static const A a = A();
54 // CHECK: call void @_ZN1AC1Ev(ptr noundef {{[^,]*}} @a)
55 // CHECK: call {{.*}}@llvm.invariant.start.p0(i64 4, ptr @a)
57 // CHECK: call void @_ZN2A2C1Ev(ptr noundef {{[^,]*}} @a2)
58 // CHECK: call {{.*}}@llvm.invariant.start.p0(i64 4, ptr @a2)
60 // CHECK: call void @_ZN1BC1Ev(ptr noundef {{[^,]*}} @b)
61 // CHECK-NOT: call {{.*}}@llvm.invariant.start.p0(i64 noundef 4, ptr @b)
63 // CHECK: call void @_ZN1CC1Ev(ptr noundef {{[^,]*}} @c)
64 // CHECK-NOT: call {{.*}}@llvm.invariant.start.p0(i64 noundef 4, ptr @c)
66 // CHECK: call noundef i32 @_Z1fv(
67 // CHECK: store {{.*}}, ptr @d
68 // CHECK: call {{.*}}@llvm.invariant.start.p0(i64 4, ptr @d)
70 // CHECK-LABEL: define{{.*}} void @_Z1ev(
71 // CHECK: call void @_ZN1AC1Ev(ptr noundef {{[^,]*}} @_ZZ1evE1a)
72 // CHECK: call {{.*}}@llvm.invariant.start.p0(i64 4, ptr {{.*}}@_ZZ1evE1a)
73 // CHECK-NOT: llvm.invariant.end