|
1 | 1 | // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fno-clangir-direct-lowering -emit-mlir %s -o %t.mlir
|
2 | 2 | // RUN: FileCheck --input-file=%t.mlir %s
|
3 | 3 |
|
| 4 | +// Check the MLIR lowering of struct and member accesses |
4 | 5 | struct s {
|
5 | 6 | int a;
|
6 | 7 | double b;
|
7 | 8 | char c;
|
| 9 | + float d[5]; |
8 | 10 | };
|
9 | 11 |
|
10 | 12 | int main() {
|
11 | 13 | s v;
|
12 |
| - // CHECK: %[[ALLOCA:.+]] = memref.alloca() {alignment = 8 : i64} : memref<!named_tuple.named_tuple<"s", [i32, f64, i8]>> |
| 14 | + // CHECK: %[[ALLOCA:.+]] = memref.alloca() {alignment = 8 : i64} : memref<!named_tuple.named_tuple<"s", [i32, f64, i8, memref<5xf32>]>> |
13 | 15 | v.a = 7;
|
14 | 16 | // CHECK: %[[C_7:.+]] = arith.constant 7 : i32
|
15 |
| - // CHECK: %[[I8_EQUIV_A:.+]] = named_tuple.cast %[[ALLOCA]] : memref<!named_tuple.named_tuple<"s", [i32, f64, i8]>> to memref<24xi8> |
| 17 | + // CHECK: %[[I8_EQUIV_A:.+]] = named_tuple.cast %[[ALLOCA]] : memref<!named_tuple.named_tuple<"s", [i32, f64, i8, memref<5xf32>]>> to memref<40xi8> |
16 | 18 | // CHECK: %[[OFFSET_A:.+]] = arith.constant 0 : index
|
17 |
| - // CHECK: %[[VIEW_A:.+]] = memref.view %[[I8_EQUIV_A]][%[[OFFSET_A]]][] : memref<24xi8> to memref<i32> |
| 19 | + // CHECK: %[[VIEW_A:.+]] = memref.view %[[I8_EQUIV_A]][%[[OFFSET_A]]][] : memref<40xi8> to memref<i32> |
18 | 20 | // CHECK: memref.store %[[C_7]], %[[VIEW_A]][] : memref<i32>
|
19 | 21 |
|
20 | 22 | v.b = 3.;
|
21 | 23 | // CHECK: %[[C_3:.+]] = arith.constant 3.000000e+00 : f64
|
22 |
| - // CHECK: %[[I8_EQUIV_B:.+]] = named_tuple.cast %[[ALLOCA]] : memref<!named_tuple.named_tuple<"s", [i32, f64, i8]>> to memref<24xi8> |
| 24 | + // CHECK: %[[I8_EQUIV_B:.+]] = named_tuple.cast %[[ALLOCA]] : memref<!named_tuple.named_tuple<"s", [i32, f64, i8, memref<5xf32>]>> to memref<40xi8> |
23 | 25 | // CHECK: %[[OFFSET_B:.+]] = arith.constant 8 : index
|
24 |
| - // CHECK: %[[VIEW_B:.+]] = memref.view %[[I8_EQUIV_B]][%[[OFFSET_B]]][] : memref<24xi8> to memref<f64> |
| 26 | + // CHECK: %[[VIEW_B:.+]] = memref.view %[[I8_EQUIV_B]][%[[OFFSET_B]]][] : memref<40xi8> to memref<f64> |
25 | 27 | // CHECK: memref.store %[[C_3]], %[[VIEW_B]][] : memref<f64>
|
26 | 28 |
|
27 | 29 | v.c = 'z';
|
28 |
| - // CHECK: %[[C_122:.+]] = arith.constant 122 : i8 |
29 |
| - // CHECK: %[[I8_EQUIV_C:.+]] = named_tuple.cast %[[ALLOCA]] : memref<!named_tuple.named_tuple<"s", [i32, f64, i8]>> to memref<24xi8> |
| 30 | + // CHECK: %[[C_122:.+]] = arith.constant 122 : i8 |
| 31 | + // CHECK: %[[I8_EQUIV_C:.+]] = named_tuple.cast %[[ALLOCA]] : memref<!named_tuple.named_tuple<"s", [i32, f64, i8, memref<5xf32>]>> to memref<40xi8> |
30 | 32 | // CHECK: %[[OFFSET_C:.+]] = arith.constant 16 : index
|
31 |
| - // CHECK: %[[VIEW_C:.+]] = memref.view %[[I8_EQUIV_C]][%[[OFFSET_C]]][] : memref<24xi8> to memref<i8> |
| 33 | + // CHECK: %[[VIEW_C:.+]] = memref.view %[[I8_EQUIV_C]][%[[OFFSET_C]]][] : memref<40xi8> to memref<i8> |
32 | 34 | // memref.store %[[C_122]], %[[VIEW_C]][] : memref<i8>
|
33 | 35 |
|
| 36 | + v.d[4] = 6.f; |
| 37 | + // CHECK: %[[C_6:.+]] = arith.constant 6.000000e+00 : f32 |
| 38 | + // CHECK: %[[I8_EQUIV_D:.+]] = named_tuple.cast %alloca_0 : memref<!named_tuple.named_tuple<"s", [i32, f64, i8, memref<5xf32>]>> to memref<40xi8> |
| 39 | + // CHECK: %[[OFFSET_D:.+]] = arith.constant 20 : index |
| 40 | + // Do not lower to a memref of memref |
| 41 | + // CHECK: %[[VIEW_D:.+]] = memref.view %3[%c20][] : memref<40xi8> to memref<5xf32> |
| 42 | + // CHECK: %[[C_4:.+]] = arith.constant 4 : i32 |
| 43 | + // CHECK: %[[I_D:.+]] = arith.index_cast %[[C_4]] : i32 to index |
| 44 | + // CHECK: memref.store %[[C_6]], %[[VIEW_D]][%[[I_D]]] : memref<5xf32> |
| 45 | + |
34 | 46 | return v.c;
|
35 |
| - // CHECK: %[[I8_EQUIV_C_1:.+]] = named_tuple.cast %[[ALLOCA]] : memref<!named_tuple.named_tuple<"s", [i32, f64, i8]>> to memref<24xi8> |
| 47 | + // CHECK: %[[I8_EQUIV_C_1:.+]] = named_tuple.cast %[[ALLOCA]] : memref<!named_tuple.named_tuple<"s", [i32, f64, i8, memref<5xf32>]>> to memref<40xi8> |
36 | 48 | // CHECK: %[[OFFSET_C_1:.+]] = arith.constant 16 : index
|
37 |
| - // CHECK: %[[VIEW_C_1:.+]] = memref.view %[[I8_EQUIV_C_1]][%[[OFFSET_C_1]]][] : memref<24xi8> to memref<i8> |
| 49 | + // CHECK: %[[VIEW_C_1:.+]] = memref.view %[[I8_EQUIV_C_1]][%[[OFFSET_C_1]]][] : memref<40xi8> to memref<i8> |
38 | 50 | // CHECK: %[[VALUE_C:.+]] = memref.load %[[VIEW_C_1]][] : memref<i8>
|
39 | 51 | // CHECK: %[[VALUE_RET:.+]] = arith.extsi %[[VALUE_C]] : i8 to i32
|
40 | 52 | }
|
0 commit comments