Skip to content

Commit 34f8fe4

Browse files
fangyi-zhoulanza
authored andcommitted
[CIR] Un-xfail some tests affected by GEP changes (llvm#1621)
This commit un-xfails some tests that were affected by upstream GEP changes. llvm#1497 The changes are likely introduced by inference of `inbounds` and `nuw` flags llvm@10f315d. It seems to allow LLVM to enable some constant foldings, whose effects include re-calculating the address using i8 and a single offset. (This change seems to arise from https://discourse.llvm.org/t/rfc-replacing-getelementptr-with-ptradd/68699/39)
1 parent 9818260 commit 34f8fe4

File tree

10 files changed

+48
-46
lines changed

10 files changed

+48
-46
lines changed

clang/test/CIR/CallConvLowering/AArch64/aarch64-cc-structs.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -fclangir -emit-cir-flat -fclangir-call-conv-lowering %s -o - | FileCheck %s
22
// RUN: %clang_cc1 -triple aarch64-unknown-linux-gnu -fclangir -emit-llvm -fclangir-call-conv-lowering %s -o -| FileCheck %s -check-prefix=LLVM
3-
// XFAIL: *
43

54
#include <stdint.h>
65

@@ -408,10 +407,11 @@ void qux(void) {
408407
// CHECK: %[[#V8:]] = cir.const #cir.int<6> : !u64i
409408
// CHECK: cir.libc.memcpy %[[#V8]] bytes from %[[#V7]]
410409

410+
// Note: GEP emitted by cir might not be the same as LLVM, due to constant folding.
411411
// LLVM: void @qux
412412
// LLVM: %[[#V1:]] = alloca ptr, i64 1, align 8
413413
// LLVM: %[[#V2:]] = alloca i64, i64 1, align 8
414-
// LLVM: store ptr getelementptr (%struct.PackedS2, ptr @g, i64 1), ptr %[[#V1]], align 8
414+
// LLVM: store ptr getelementptr inbounds nuw (i8, ptr @g, i64 6), ptr %[[#V1]], align 8
415415
// LLVM: %[[#V3:]] = load ptr, ptr %[[#V1]], align 8
416416
// LLVM: %[[#V4:]] = load %struct.PackedS2, ptr %[[#V3]], align 1
417417
// LLVM: call void @llvm.memcpy.p0.p0.i64(ptr %[[#V2]], ptr %[[#V3]], i64 6, i1 false)

clang/test/CIR/CodeGen/clear_cache.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// RUN: FileCheck --input-file=%t.cir -check-prefix=CIR %s
33
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu %s -fclangir -emit-llvm -o %t.ll
44
// RUN: FileCheck --input-file=%t.ll -check-prefix=LLVM %s
5-
// XFAIL: *
65

76
char buffer[32] = "This is a largely unused buffer";
87

@@ -21,7 +20,7 @@ char buffer[32] = "This is a largely unused buffer";
2120
// CIR: cir.clear_cache %[[VAL_3]] : !cir.ptr<!void>, %[[VAL_8]],
2221

2322
// LLVM-LABEL: main
24-
// LLVM: call void @llvm.clear_cache(ptr @buffer, ptr getelementptr (i8, ptr @buffer, i64 32))
23+
// LLVM: call void @llvm.clear_cache(ptr @buffer, ptr getelementptr inbounds nuw (i8, ptr @buffer, i64 32))
2524

2625
int main(void) {
2726
__builtin___clear_cache(buffer, buffer+32);

clang/test/CIR/CodeGen/complex.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -x c++ -fclangir -emit-cir -mmlir --mlir-print-ir-after=cir-canonicalize -o %t.cir %s 2>&1 | FileCheck --check-prefix=CHECK-AFTER %s
55
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm -o %t.ll %s
66
// RUN: FileCheck --input-file=%t.ll --check-prefixes=LLVM %s
7-
// XFAIL: *
87

98
double _Complex c, c2;
109
int _Complex ci, ci2;
@@ -302,9 +301,10 @@ void imag_ptr() {
302301
// CHECK-AFTER-NEXT: %{{.+}} = cir.complex.imag_ptr %[[#CI_PTR]] : !cir.ptr<!cir.complex<!s32i>> -> !cir.ptr<!s32i>
303302
// CHECK-AFTER: }
304303

304+
// Note: GEP emitted by cir might not be the same as LLVM, due to constant folding.
305305
// LLVM: define dso_local void @imag_ptr()
306-
// LLVM: store ptr getelementptr inbounds ({ double, double }, ptr @c, i32 0, i32 1), ptr %{{.+}}, align 8
307-
// LLVM: store ptr getelementptr inbounds ({ i32, i32 }, ptr @ci, i32 0, i32 1), ptr %{{.+}}, align 8
306+
// LLVM: store ptr getelementptr inbounds nuw (i8, ptr @c, i64 8), ptr %{{.+}}, align 8
307+
// LLVM: store ptr getelementptr inbounds nuw (i8, ptr @ci, i64 4), ptr %{{.+}}, align 8
308308
// LLVM: }
309309

310310
void extract_imag() {
@@ -330,7 +330,8 @@ void extract_imag() {
330330
// CHECK-AFTER-NEXT: %{{.+}} = cir.load %[[#IMAG_PTR]] : !cir.ptr<!s32i>, !s32i
331331
// CHECK-AFTER: }
332332

333+
// Note: GEP emitted by cir might not be the same as LLVM, due to constant folding.
333334
// LLVM: define dso_local void @extract_imag()
334-
// LLVM: %{{.+}} = load double, ptr getelementptr inbounds ({ double, double }, ptr @c, i32 0, i32 1), align 8
335-
// LLVM: %{{.+}} = load i32, ptr getelementptr inbounds ({ i32, i32 }, ptr @ci, i32 0, i32 1), align 4
335+
// LLVM: %{{.+}} = load double, ptr getelementptr inbounds nuw (i8, ptr @c, i64 8), align 8
336+
// LLVM: %{{.+}} = load i32, ptr getelementptr inbounds nuw (i8, ptr @ci, i64 4), align 4
336337
// LLVM: }

clang/test/CIR/CodeGen/globals-neg-index-array.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// RUN: FileCheck --input-file=%t.cir %s
77
// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll
88
// RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s
9-
// XFAIL: *
109

1110
struct __attribute__((packed)) PackedStruct {
1211
char a1;
@@ -18,4 +17,4 @@ char *packed_element = &(packed[-2].a3);
1817
// CHECK: cir.global external @packed = #cir.zero : !cir.array<!rec_PackedStruct x 10> {alignment = 16 : i64} loc(#loc5)
1918
// CHECK: cir.global external @packed_element = #cir.global_view<@packed, [-2 : i32, 2 : i32]>
2019
// LLVM: @packed = global [10 x %struct.PackedStruct] zeroinitializer
21-
// LLVM: @packed_element = global ptr getelementptr inbounds ([10 x %struct.PackedStruct], ptr @packed, i32 0, i32 -2, i32 2)
20+
// LLVM: @packed_element = global ptr getelementptr inbounds (i8, ptr @packed, i64 -4)

clang/test/CIR/CodeGen/multi-vtable.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
33
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -mconstructor-aliases -fclangir -emit-llvm -fno-clangir-call-conv-lowering %s -o %t.ll
44
// RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s
5-
// XFAIL: *
65

76
class Mother {
87
public:
@@ -40,22 +39,23 @@ int main() {
4039
// CIR: !rec_Child = !cir.record<class "Child" {!rec_Mother, !rec_Father} #cir.record.decl.ast>
4140

4241
// CIR: cir.func linkonce_odr @_ZN6MotherC2Ev(%arg0: !cir.ptr<!rec_Mother>
43-
// CIR: %{{[0-9]+}} = cir.vtable.address_point(@_ZTV6Mother, vtable_index = 0, address_point_index = 2) : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>
42+
// CIR: %{{[0-9]+}} = cir.vtable.address_point(@_ZTV6Mother, address_point = <index = 0, offset = 2>) : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>
4443
// CIR: %{{[0-9]+}} = cir.cast(bitcast, %{{[0-9]+}} : !cir.ptr<!rec_Mother>), !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
4544
// CIR: cir.store %2, %{{[0-9]+}} : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>, !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
4645
// CIR: cir.return
4746
// CIR: }
4847

48+
// Note: GEP emitted by cir might not be the same as LLVM, due to constant folding.
4949
// LLVM-DAG: define linkonce_odr void @_ZN6MotherC2Ev(ptr %0)
50-
// LLVM-DAG: store ptr getelementptr inbounds ({ [4 x ptr] }, ptr @_ZTV6Mother, i32 0, i32 0, i32 2), ptr %{{[0-9]+}}, align 8
50+
// LLVM-DAG: store ptr getelementptr inbounds nuw (i8, ptr @_ZTV6Mother, i64 16), ptr %{{[0-9]+}}, align 8
5151
// LLVM-DAG: ret void
5252
// LLVM-DAG: }
5353

5454
// CIR: cir.func linkonce_odr @_ZN5ChildC2Ev(%arg0: !cir.ptr<!rec_Child>
55-
// CIR: %{{[0-9]+}} = cir.vtable.address_point(@_ZTV5Child, vtable_index = 0, address_point_index = 2) : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>
55+
// CIR: %{{[0-9]+}} = cir.vtable.address_point(@_ZTV5Child, address_point = <index = 0, offset = 2>) : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>
5656
// CIR: %{{[0-9]+}} = cir.cast(bitcast, %{{[0-9]+}} : !cir.ptr<!rec_Child>), !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
5757
// CIR: cir.store %{{[0-9]+}}, %{{[0-9]+}} : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>, !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
58-
// CIR: %{{[0-9]+}} = cir.vtable.address_point(@_ZTV5Child, vtable_index = 1, address_point_index = 2) : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>
58+
// CIR: %{{[0-9]+}} = cir.vtable.address_point(@_ZTV5Child, address_point = <index = 1, offset = 2>) : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>
5959
// CIR: %7 = cir.base_class_addr(%1 : !cir.ptr<!rec_Child> nonnull) [8] -> !cir.ptr<!rec_Father>
6060
// CIR: %8 = cir.cast(bitcast, %7 : !cir.ptr<!rec_Father>), !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>> loc(#loc8)
6161
// CIR: cir.store %{{[0-9]+}}, %{{[0-9]+}} : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>, !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
@@ -66,18 +66,19 @@ int main() {
6666
// LLVM-DAG: $_ZTS5Child = comdat any
6767
// LLVM-DAG: $_ZTS6Father = comdat any
6868

69+
// Note: GEP emitted by cir might not be the same as LLVM, due to constant folding.
6970
// LLVM-DAG: define linkonce_odr void @_ZN5ChildC2Ev(ptr %0)
70-
// LLVM-DAG: store ptr getelementptr inbounds ({ [4 x ptr], [3 x ptr] }, ptr @_ZTV5Child, i32 0, i32 0, i32 2), ptr %{{[0-9]+}}, align 8
71+
// LLVM-DAG: store ptr getelementptr inbounds nuw (i8, ptr @_ZTV5Child, i64 16), ptr %{{[0-9]+}}, align 8
7172
// LLVM-DAG: %{{[0-9]+}} = getelementptr i8, ptr {{.*}}, i32 8
72-
// LLVM-DAG: store ptr getelementptr inbounds ({ [4 x ptr], [3 x ptr] }, ptr @_ZTV5Child, i32 0, i32 1, i32 2), ptr %{{[0-9]+}}, align 8
73+
// LLVM-DAG: store ptr getelementptr inbounds nuw (i8, ptr @_ZTV5Child, i64 48), ptr %{{[0-9]+}}, align 8
7374
// LLVM-DAG: ret void
7475
// }
7576

7677
// CIR: cir.func @main() -> !s32i extra(#fn_attr) {
7778

78-
// CIR: %{{[0-9]+}} = cir.vtable.address_point( %{{[0-9]+}} : !cir.ptr<!cir.ptr<!cir.func<(!cir.ptr<!rec_Mother>)>>>, vtable_index = 0, address_point_index = 0) : !cir.ptr<!cir.ptr<!cir.func<(!cir.ptr<!rec_Mother>)>>>
79+
// CIR: %{{[0-9]+}} = cir.vtable.address_point( %{{[0-9]+}} : !cir.ptr<!cir.ptr<!cir.func<(!cir.ptr<!rec_Mother>)>>>, address_point = <index = 0, offset = 0>) : !cir.ptr<!cir.ptr<!cir.func<(!cir.ptr<!rec_Mother>)>>>
7980

80-
// CIR: %{{[0-9]+}} = cir.vtable.address_point( %{{[0-9]+}} : !cir.ptr<!cir.ptr<!cir.func<(!cir.ptr<!rec_Child>)>>>, vtable_index = 0, address_point_index = 0) : !cir.ptr<!cir.ptr<!cir.func<(!cir.ptr<!rec_Child>)>>>
81+
// CIR: %{{[0-9]+}} = cir.vtable.address_point( %{{[0-9]+}} : !cir.ptr<!cir.ptr<!cir.func<(!cir.ptr<!rec_Child>)>>>, address_point = <index = 0, offset = 0>) : !cir.ptr<!cir.ptr<!cir.func<(!cir.ptr<!rec_Child>)>>>
8182

8283
// CIR: }
8384

@@ -94,8 +95,9 @@ int main() {
9495
// LLVM-DAG: @_ZTS6Mother = linkonce_odr global [7 x i8] c"6Mother", comdat
9596

9697
// typeinfo for Mother
98+
// Note: GEP emitted by cir might not be the same as LLVM, due to constant folding.
9799
// CIR: cir.global constant external @_ZTI6Mother = #cir.typeinfo<{#cir.global_view<@_ZTVN10__cxxabiv117__class_type_infoE, [2 : i32]> : !cir.ptr<!u8i>, #cir.global_view<@_ZTS6Mother> : !cir.ptr<!u8i>}> : ![[VTypeInfoA]] {alignment = 8 : i64}
98-
// LLVM-DAG: @_ZTI6Mother = constant { ptr, ptr } { ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv117__class_type_infoE, i32 2), ptr @_ZTS6Mother }
100+
// LLVM-DAG: @_ZTI6Mother = constant { ptr, ptr } { ptr getelementptr inbounds nuw (i8, ptr @_ZTVN10__cxxabiv117__class_type_infoE, i64 16), ptr @_ZTS6Mother }
99101

100102
// vtable for Father
101103
// CIR: cir.global linkonce_odr @_ZTV6Father = #cir.vtable<{#cir.const_array<[#cir.ptr<null> : !cir.ptr<!u8i>, #cir.global_view<@_ZTI6Father> : !cir.ptr<!u8i>, #cir.global_view<@_ZN6Father9FatherFooEv> : !cir.ptr<!u8i>]> : !cir.array<!cir.ptr<!u8i> x 3>}> : ![[VTableTypeFather]] {alignment = 8 : i64}
@@ -118,9 +120,11 @@ int main() {
118120
// LLVM-DAG: @_ZTS6Father = linkonce_odr global [7 x i8] c"6Father", comdat
119121

120122
// typeinfo for Father
123+
// Note: GEP emitted by cir might not be the same as LLVM, due to constant folding.
121124
// CIR: cir.global constant external @_ZTI6Father = #cir.typeinfo<{#cir.global_view<@_ZTVN10__cxxabiv117__class_type_infoE, [2 : i32]> : !cir.ptr<!u8i>, #cir.global_view<@_ZTS6Father> : !cir.ptr<!u8i>}> : !rec_anon_struct {alignment = 8 : i64}
122-
// LLVM-DAG: @_ZTI6Father = constant { ptr, ptr } { ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv117__class_type_infoE, i32 2), ptr @_ZTS6Father }
125+
// LLVM-DAG: @_ZTI6Father = constant { ptr, ptr } { ptr getelementptr inbounds nuw (i8, ptr @_ZTVN10__cxxabiv117__class_type_infoE, i64 16), ptr @_ZTS6Father }
123126

124127
// typeinfo for Child
128+
// Note: GEP emitted by cir might not be the same as LLVM, due to constant folding.
125129
// CIR: cir.global constant external @_ZTI5Child = #cir.typeinfo<{#cir.global_view<@_ZTVN10__cxxabiv121__vmi_class_type_infoE, [2 : i32]> : !cir.ptr<!u8i>, #cir.global_view<@_ZTS5Child> : !cir.ptr<!u8i>, #cir.int<0> : !u32i, #cir.int<2> : !u32i, #cir.global_view<@_ZTI6Mother> : !cir.ptr<!u8i>, #cir.int<2> : !s64i, #cir.global_view<@_ZTI6Father> : !cir.ptr<!u8i>, #cir.int<2050> : !s64i}> : ![[VTypeInfoB]] {alignment = 8 : i64}
126-
// LLVM-DAG: @_ZTI5Child = constant { ptr, ptr, i32, i32, ptr, i64, ptr, i64 } { ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv121__vmi_class_type_infoE, i32 2), ptr @_ZTS5Child, i32 0, i32 2, ptr @_ZTI6Mother, i64 2, ptr @_ZTI6Father, i64 2050 }
130+
// LLVM-DAG: @_ZTI5Child = constant { ptr, ptr, i32, i32, ptr, i64, ptr, i64 } { ptr getelementptr inbounds nuw (i8, ptr @_ZTVN10__cxxabiv121__vmi_class_type_infoE, i64 16), ptr @_ZTS5Child, i32 0, i32 2, ptr @_ZTI6Mother, i64 2, ptr @_ZTI6Father, i64 2050 }

clang/test/CIR/CodeGen/vbase.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// RUN: FileCheck --input-file=%t.cir %s --check-prefix=CIR
33
// RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t.ll
44
// RUN: FileCheck --input-file=%t.ll %s --check-prefix=LLVM
5-
// XFAIL: *
65

76
struct A {
87
int a;
@@ -40,11 +39,12 @@ void ppp() { B b; }
4039
// LLVM: $_ZTS1B = comdat any
4140
// LLVM: $_ZTS1A = comdat any
4241

42+
// Note: GEP emitted by cir might not be the same as LLVM, due to constant folding.
4343
// LLVM: @_ZTV1B = linkonce_odr global { [3 x ptr] } { [3 x ptr] [ptr inttoptr (i64 12 to ptr), ptr null, ptr @_ZTI1B] }
44-
// LLVM: @_ZTT1B = linkonce_odr global [1 x ptr] [ptr getelementptr inbounds ({ [3 x ptr] }, ptr @_ZTV1B, i32 0, i32 0, i32 3)]
44+
// LLVM: @_ZTT1B = linkonce_odr global [1 x ptr] [ptr getelementptr inbounds nuw (i8, ptr @_ZTV1B, i64 24)]
4545
// LLVM: @_ZTVN10__cxxabiv121__vmi_class_type_infoE = external global ptr
4646
// LLVM: @_ZTS1B = linkonce_odr global [2 x i8] c"1B", comdat
4747
// LLVM: @_ZTVN10__cxxabiv117__class_type_infoE = external global ptr
4848
// LLVM: @_ZTS1A = linkonce_odr global [2 x i8] c"1A", comdat
49-
// LLVM: @_ZTI1A = constant { ptr, ptr } { ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv117__class_type_infoE, i32 2), ptr @_ZTS1A }
50-
// LLVM: @_ZTI1B = constant { ptr, ptr, i32, i32, ptr, i64 } { ptr getelementptr inbounds (ptr, ptr @_ZTVN10__cxxabiv121__vmi_class_type_infoE, i32 2), ptr @_ZTS1B, i32 0, i32 1, ptr @_ZTI1A, i64 -6141 }
49+
// LLVM: @_ZTI1A = constant { ptr, ptr } { ptr getelementptr inbounds nuw (i8, ptr @_ZTVN10__cxxabiv117__class_type_infoE, i64 16), ptr @_ZTS1A }
50+
// LLVM: @_ZTI1B = constant { ptr, ptr, i32, i32, ptr, i64 } { ptr getelementptr inbounds nuw (i8, ptr @_ZTVN10__cxxabiv121__vmi_class_type_infoE, i64 16), ptr @_ZTS1B, i32 0, i32 1, ptr @_ZTI1A, i64 -6141 }

clang/test/CIR/CodeGen/vtable-emission.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm -o - %s \
44
// RUN: | opt -S -passes=instcombine,mem2reg,simplifycfg -o %t.ll
55
// RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s
6-
// XFAIL: *
76

87
struct S {
98
virtual void key();
@@ -20,11 +19,12 @@ void S::key() {}
2019
// LLVM: @_ZTV1S = global { [4 x ptr] } { [4 x ptr]
2120
// LLVM-SAME: [ptr null, ptr @_ZTI1S, ptr @_ZN1S3keyEv, ptr @_ZN1S6nonKeyEv] }, align 8
2221

22+
// Note: GEP emitted by cir might not be the same as LLVM, due to constant folding.
2323
// CHECK: cir.global external @sobj = #cir.const_record
2424
// CHECK-SAME: <{#cir.global_view<@_ZTV1S, [0 : i32, 2 : i32]> :
2525
// CHECK-SAME: !cir.ptr<!rec_anon_struct1>}> : !rec_anon_struct2 {alignment = 8 : i64}
26-
// LLVM: @sobj = global { ptr } { ptr getelementptr inbounds
27-
// LLVM-SAME: ({ [4 x ptr] }, ptr @_ZTV1S, i32 0, i32 0, i32 2) }, align 8
26+
// LLVM: @sobj = global { ptr } { ptr getelementptr inbounds nuw
27+
// LLVM-SAME: (i8, ptr @_ZTV1S, i64 16) }, align 8
2828

2929
// The reference from the vtable should result in nonKey being emitted.
3030
// CHECK: cir.func linkonce_odr @_ZN1S6nonKeyEv({{.*}} {

clang/test/CIR/CodeGen/vtt.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
33
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -mconstructor-aliases -fclangir -emit-llvm -fno-clangir-call-conv-lowering %s -o %t.ll
44
// RUN: FileCheck --check-prefix=LLVM --input-file=%t.ll %s
5-
// XFAIL: *
65

76
class A {
87
public:
@@ -39,7 +38,7 @@ int f() {
3938

4039
// Class A constructor
4140
// CIR: cir.func linkonce_odr @_ZN1AC2Ev(%arg0: !cir.ptr<!rec_A>
42-
// CIR: %{{[0-9]+}} = cir.vtable.address_point(@_ZTV1A, vtable_index = 0, address_point_index = 2) : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>
41+
// CIR: %{{[0-9]+}} = cir.vtable.address_point(@_ZTV1A, address_point = <index = 0, offset = 2>) : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>
4342
// CIR: %{{[0-9]+}} = cir.cast(bitcast, %{{[0-9]+}} : !cir.ptr<!rec_A>), !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
4443
// CIR: cir.store %{{[0-9]+}}, %{{[0-9]+}} : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>, !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
4544
// CIR: }
@@ -116,31 +115,32 @@ int f() {
116115
// CIR: %[[VTT_D_TO_C:.*]] = cir.vtt.address_point @_ZTT1D, offset = 3 -> !cir.ptr<!cir.ptr<!void>>
117116
// CIR: cir.call @_ZN1CC2Ev(%[[C_PTR]], %[[VTT_D_TO_C]]) : (!cir.ptr<!rec_C>, !cir.ptr<!cir.ptr<!void>>) -> ()
118117

119-
// CIR: %{{[0-9]+}} = cir.vtable.address_point(@_ZTV1D, vtable_index = 0, address_point_index = 3) : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>
118+
// CIR: %{{[0-9]+}} = cir.vtable.address_point(@_ZTV1D, address_point = <index = 0, offset = 3>) : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>
120119
// CIR: %{{[0-9]+}} = cir.cast(bitcast, %{{[0-9]+}} : !cir.ptr<!rec_D>), !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
121120
// CIR: cir.store %{{[0-9]+}}, %{{[0-9]+}} : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>, !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
122-
// CIR: %{{[0-9]+}} = cir.vtable.address_point(@_ZTV1D, vtable_index = 2, address_point_index = 3) : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>
121+
// CIR: %{{[0-9]+}} = cir.vtable.address_point(@_ZTV1D, address_point = <index = 2, offset = 3>) : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>
123122

124123
// CIR: %{{[0-9]+}} = cir.base_class_addr(%{{[0-9]+}} : !cir.ptr<!rec_D> nonnull) [40] -> !cir.ptr<!rec_A>
125124
// CIR: %{{[0-9]+}} = cir.cast(bitcast, %{{[0-9]+}} : !cir.ptr<!rec_A>), !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
126125
// CIR: cir.store %{{[0-9]+}}, %{{[0-9]+}} : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>, !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
127-
// CIR: %{{[0-9]+}} = cir.vtable.address_point(@_ZTV1D, vtable_index = 1, address_point_index = 3) : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>
126+
// CIR: %{{[0-9]+}} = cir.vtable.address_point(@_ZTV1D, address_point = <index = 1, offset = 3>) : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>
128127

129128
// CIR: cir.base_class_addr(%{{[0-9]+}} : !cir.ptr<!rec_D> nonnull) [16] -> !cir.ptr<!rec_C>
130129
// CIR: cir.cast(bitcast, %{{[0-9]+}} : !cir.ptr<!rec_C>), !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
131130
// CIR: cir.store %{{[0-9]+}}, %{{[0-9]+}} : !cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>, !cir.ptr<!cir.ptr<!cir.ptr<!cir.func<() -> !u32i>>>>
132131
// CIR: cir.return
133132
// CIR: }
134133

134+
// Note: GEP emitted by cir might not be the same as LLVM, due to constant folding.
135135
// LLVM-LABEL: @_ZN1DC1Ev
136136
// LLVM: %2 = alloca ptr, i64 1, align 8
137137
// LLVM: store ptr %0, ptr %2, align 8
138138
// LLVM: %[[THIS:.*]] = load ptr, ptr %2, align 8
139139
// LLVM: %[[BASE_A:.*]] = getelementptr i8, ptr %[[THIS]], i32 40
140140
// LLVM: call void @_ZN1AC2Ev(ptr %[[BASE_A]])
141-
// LLVM: call void @_ZN1BC2Ev(ptr %[[THIS]], ptr getelementptr inbounds ([7 x ptr], ptr @_ZTT1D, i32 0, i32 1))
141+
// LLVM: call void @_ZN1BC2Ev(ptr %[[THIS]], ptr getelementptr inbounds nuw (i8, ptr @_ZTT1D, i64 8))
142142
// LLVM: %[[BASE_C:.*]] = getelementptr i8, ptr %[[THIS]], i32 16
143-
// LLVM: call void @_ZN1CC2Ev(ptr %[[BASE_C]], ptr getelementptr inbounds ([7 x ptr], ptr @_ZTT1D, i32 0, i32 3))
143+
// LLVM: call void @_ZN1CC2Ev(ptr %[[BASE_C]], ptr getelementptr inbounds nuw (i8, ptr @_ZTT1D, i64 24))
144144
// LLVM: ret void
145145
// LLVM: }
146146

0 commit comments

Comments
 (0)