|
| 1 | +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir |
| 2 | +// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s |
| 3 | +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll |
| 4 | +// RUN: FileCheck --check-prefix=LLVM --input-file=%t-cir.ll %s |
| 5 | +// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll |
| 6 | +// RUN: FileCheck --check-prefix=OGCG --input-file=%t.ll %s |
| 7 | + |
| 8 | +struct S { |
| 9 | + int a, b, c; |
| 10 | +}; |
| 11 | + |
| 12 | +void init() { |
| 13 | + S s1 = {1, 2, 3}; |
| 14 | + S s2 = {4, 5}; |
| 15 | +} |
| 16 | + |
| 17 | +// CIR: cir.func{{.*}} @_Z4initv() |
| 18 | +// CIR: %[[S1:.*]] = cir.alloca !rec_S, !cir.ptr<!rec_S>, ["s1", init] |
| 19 | +// CIR: %[[S2:.*]] = cir.alloca !rec_S, !cir.ptr<!rec_S>, ["s2", init] |
| 20 | +// CIR: %[[S1_A:.*]] = cir.get_member %[[S1]][0] {name = "a"} |
| 21 | +// CIR: %[[ONE:.*]] = cir.const #cir.int<1> |
| 22 | +// CIR: cir.store{{.*}} %[[ONE]], %[[S1_A]] |
| 23 | +// CIR: %[[S1_B:.*]] = cir.get_member %[[S1]][1] {name = "b"} |
| 24 | +// CIR: %[[TWO:.*]] = cir.const #cir.int<2> |
| 25 | +// CIR: cir.store{{.*}} %[[TWO]], %[[S1_B]] |
| 26 | +// CIR: %[[S1_C:.*]] = cir.get_member %[[S1]][2] {name = "c"} |
| 27 | +// CIR: %[[THREE:.*]] = cir.const #cir.int<3> |
| 28 | +// CIR: cir.store{{.*}} %[[THREE]], %[[S1_C]] |
| 29 | +// CIR: %[[S2_A:.*]] = cir.get_member %[[S2]][0] {name = "a"} |
| 30 | +// CIR: %[[FOUR:.*]] = cir.const #cir.int<4> |
| 31 | +// CIR: cir.store{{.*}} %[[FOUR]], %[[S2_A]] |
| 32 | +// CIR: %[[S2_B:.*]] = cir.get_member %[[S2]][1] {name = "b"} |
| 33 | +// CIR: %[[FIVE:.*]] = cir.const #cir.int<5> |
| 34 | +// CIR: cir.store{{.*}} %[[FIVE]], %[[S2_B]] |
| 35 | +// CIR: %[[S2_C:.*]] = cir.get_member %[[S2]][2] {name = "c"} |
| 36 | +// CIR: %[[ZERO:.*]] = cir.const #cir.int<0> |
| 37 | +// CIR: cir.store{{.*}} %[[ZERO]], %[[S2_C]] |
| 38 | +// CIR: cir.return |
| 39 | + |
| 40 | +// LLVM: define{{.*}} void @_Z4initv() |
| 41 | +// LLVM: %[[S1:.*]] = alloca %struct.S |
| 42 | +// LLVM: %[[S2:.*]] = alloca %struct.S |
| 43 | +// LLVM: %[[S1_A:.*]] = getelementptr %struct.S, ptr %[[S1]], i32 0, i32 0 |
| 44 | +// LLVM: store i32 1, ptr %[[S1_A]] |
| 45 | +// LLVM: %[[S1_B:.*]] = getelementptr %struct.S, ptr %[[S1]], i32 0, i32 1 |
| 46 | +// LLVM: store i32 2, ptr %[[S1_B]] |
| 47 | +// LLVM: %[[S1_C:.*]] = getelementptr %struct.S, ptr %[[S1]], i32 0, i32 2 |
| 48 | +// LLVM: store i32 3, ptr %[[S1_C]] |
| 49 | +// LLVM: %[[S2_A:.*]] = getelementptr %struct.S, ptr %[[S2]], i32 0, i32 0 |
| 50 | +// LLVM: store i32 4, ptr %[[S2_A]] |
| 51 | +// LLVM: %[[S2_B:.*]] = getelementptr %struct.S, ptr %[[S2]], i32 0, i32 1 |
| 52 | +// LLVM: store i32 5, ptr %[[S2_B]] |
| 53 | +// LLVM: %[[S2_C:.*]] = getelementptr %struct.S, ptr %[[S2]], i32 0, i32 2 |
| 54 | +// LLVM: store i32 0, ptr %[[S2_C]] |
| 55 | + |
| 56 | +// OGCG: @__const._Z4initv.s1 = private unnamed_addr constant %struct.S { i32 1, i32 2, i32 3 } |
| 57 | +// OGCG: @__const._Z4initv.s2 = private unnamed_addr constant %struct.S { i32 4, i32 5, i32 0 } |
| 58 | + |
| 59 | +// OGCG: define{{.*}} void @_Z4initv() |
| 60 | +// OGCG: %[[S1:.*]] = alloca %struct.S |
| 61 | +// OGCG: %[[S2:.*]] = alloca %struct.S |
| 62 | +// OGCG: call void @llvm.memcpy.p0.p0.i64(ptr{{.*}} %[[S1]], ptr{{.*}} @__const._Z4initv.s1, i64 12, i1 false) |
| 63 | +// OGCG: call void @llvm.memcpy.p0.p0.i64(ptr{{.*}} %[[S2]], ptr{{.*}} @__const._Z4initv.s2, i64 12, i1 false) |
| 64 | + |
| 65 | +void init_var(int a, int b) { |
| 66 | + S s = {a, b}; |
| 67 | +} |
| 68 | + |
| 69 | +// CIR: cir.func{{.*}} @_Z8init_varii(%[[A_ARG:.*]]: !s32i {{.*}}, %[[B_ARG:.*]]: !s32i {{.*}}) |
| 70 | +// CIR: %[[A_PTR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["a", init] |
| 71 | +// CIR: %[[B_PTR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["b", init] |
| 72 | +// CIR: %[[S:.*]] = cir.alloca !rec_S, !cir.ptr<!rec_S>, ["s", init] |
| 73 | +// CIR: cir.store{{.*}} %[[A_ARG]], %[[A_PTR]] |
| 74 | +// CIR: cir.store{{.*}} %[[B_ARG]], %[[B_PTR]] |
| 75 | +// CIR: %[[S_A:.*]] = cir.get_member %[[S]][0] {name = "a"} |
| 76 | +// CIR: %[[A:.*]] = cir.load{{.*}} %[[A_PTR]] |
| 77 | +// CIR: cir.store{{.*}} %[[A]], %[[S_A]] |
| 78 | +// CIR: %[[S_B:.*]] = cir.get_member %[[S]][1] {name = "b"} |
| 79 | +// CIR: %[[B:.*]] = cir.load{{.*}} %[[B_PTR]] |
| 80 | +// CIR: cir.store{{.*}} %[[B]], %[[S_B]] |
| 81 | +// CIR: cir.return |
| 82 | + |
| 83 | +// LLVM: define{{.*}} void @_Z8init_varii(i32 %[[A_ARG:.*]], i32 %[[B_ARG:.*]]) |
| 84 | +// LLVM: %[[A_PTR:.*]] = alloca i32 |
| 85 | +// LLVM: %[[B_PTR:.*]] = alloca i32 |
| 86 | +// LLVM: %[[S:.*]] = alloca %struct.S |
| 87 | +// LLVM: store i32 %[[A_ARG]], ptr %[[A_PTR]] |
| 88 | +// LLVM: store i32 %[[B_ARG]], ptr %[[B_PTR]] |
| 89 | +// LLVM: %[[S_A:.*]] = getelementptr %struct.S, ptr %[[S]], i32 0, i32 0 |
| 90 | +// LLVM: %[[A:.*]] = load i32, ptr %[[A_PTR]] |
| 91 | +// LLVM: store i32 %[[A]], ptr %[[S_A]] |
| 92 | +// LLVM: %[[S_B:.*]] = getelementptr %struct.S, ptr %[[S]], i32 0, i32 1 |
| 93 | +// LLVM: %[[B:.*]] = load i32, ptr %[[B_PTR]] |
| 94 | +// LLVM: store i32 %[[B]], ptr %[[S_B]] |
| 95 | +// LLVM: ret void |
| 96 | + |
| 97 | +// OGCG: define{{.*}} void @_Z8init_varii(i32 {{.*}} %[[A_ARG:.*]], i32 {{.*}} %[[B_ARG:.*]]) |
| 98 | +// OGCG: %[[A_PTR:.*]] = alloca i32 |
| 99 | +// OGCG: %[[B_PTR:.*]] = alloca i32 |
| 100 | +// OGCG: %[[S:.*]] = alloca %struct.S |
| 101 | +// OGCG: store i32 %[[A_ARG]], ptr %[[A_PTR]] |
| 102 | +// OGCG: store i32 %[[B_ARG]], ptr %[[B_PTR]] |
| 103 | +// OGCG: %[[S_A:.*]] = getelementptr {{.*}} %struct.S, ptr %[[S]], i32 0, i32 0 |
| 104 | +// OGCG: %[[A:.*]] = load i32, ptr %[[A_PTR]] |
| 105 | +// OGCG: store i32 %[[A]], ptr %[[S_A]] |
| 106 | +// OGCG: %[[S_B:.*]] = getelementptr {{.*}} %struct.S, ptr %[[S]], i32 0, i32 1 |
| 107 | +// OGCG: %[[B:.*]] = load i32, ptr %[[B_PTR]] |
| 108 | +// OGCG: store i32 %[[B]], ptr %[[S_B]] |
| 109 | +// OGCG: %[[S_C:.*]] = getelementptr {{.*}} %struct.S, ptr %[[S]], i32 0, i32 2 |
| 110 | +// OGCG: store i32 0, ptr %[[S_C]] |
| 111 | +// OGCG: ret void |
| 112 | + |
| 113 | +void init_expr(int a, int b, int c) { |
| 114 | + S s = {a + 1, b + 2, c + 3}; |
| 115 | +} |
| 116 | + |
| 117 | +// CIR: cir.func{{.*}} @_Z9init_expriii(%[[A_ARG:.*]]: !s32i {{.*}}, %[[B_ARG:.*]]: !s32i {{.*}}, %[[C_ARG:.*]]: !s32i {{.*}}) |
| 118 | +// CIR: %[[A_PTR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["a", init] |
| 119 | +// CIR: %[[B_PTR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["b", init] |
| 120 | +// CIR: %[[C_PTR:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["c", init] |
| 121 | +// CIR: %[[S:.*]] = cir.alloca !rec_S, !cir.ptr<!rec_S>, ["s", init] |
| 122 | +// CIR: cir.store{{.*}} %[[A_ARG]], %[[A_PTR]] |
| 123 | +// CIR: cir.store{{.*}} %[[B_ARG]], %[[B_PTR]] |
| 124 | +// CIR: cir.store{{.*}} %[[C_ARG]], %[[C_PTR]] |
| 125 | +// CIR: %[[S_A:.*]] = cir.get_member %[[S]][0] {name = "a"} |
| 126 | +// CIR: %[[A:.*]] = cir.load{{.*}} %[[A_PTR]] |
| 127 | +// CIR: %[[ONE:.*]] = cir.const #cir.int<1> |
| 128 | +// CIR: %[[A_PLUS_ONE:.*]] = cir.binop(add, %[[A]], %[[ONE]]) |
| 129 | +// CIR: cir.store{{.*}} %[[A_PLUS_ONE]], %[[S_A]] |
| 130 | +// CIR: %[[S_B:.*]] = cir.get_member %[[S]][1] {name = "b"} |
| 131 | +// CIR: %[[B:.*]] = cir.load{{.*}} %[[B_PTR]] |
| 132 | +// CIR: %[[TWO:.*]] = cir.const #cir.int<2> |
| 133 | +// CIR: %[[B_PLUS_TWO:.*]] = cir.binop(add, %[[B]], %[[TWO]]) nsw : !s32i |
| 134 | +// CIR: cir.store{{.*}} %[[B_PLUS_TWO]], %[[S_B]] |
| 135 | +// CIR: %[[S_C:.*]] = cir.get_member %[[S]][2] {name = "c"} |
| 136 | +// CIR: %[[C:.*]] = cir.load{{.*}} %[[C_PTR]] |
| 137 | +// CIR: %[[THREE:.*]] = cir.const #cir.int<3> |
| 138 | +// CIR: %[[C_PLUS_THREE:.*]] = cir.binop(add, %[[C]], %[[THREE]]) nsw : !s32i |
| 139 | +// CIR: cir.store{{.*}} %[[C_PLUS_THREE]], %[[S_C]] |
| 140 | +// CIR: cir.return |
| 141 | + |
| 142 | +// LLVM: define{{.*}} void @_Z9init_expriii(i32 %[[A_ARG:.*]], i32 %[[B_ARG:.*]], i32 %[[C_ARG:.*]]) |
| 143 | +// LLVM: %[[A_PTR:.*]] = alloca i32 |
| 144 | +// LLVM: %[[B_PTR:.*]] = alloca i32 |
| 145 | +// LLVM: %[[C_PTR:.*]] = alloca i32 |
| 146 | +// LLVM: %[[S:.*]] = alloca %struct.S |
| 147 | +// LLVM: store i32 %[[A_ARG]], ptr %[[A_PTR]] |
| 148 | +// LLVM: store i32 %[[B_ARG]], ptr %[[B_PTR]] |
| 149 | +// LLVM: store i32 %[[C_ARG]], ptr %[[C_PTR]] |
| 150 | +// LLVM: %[[S_A:.*]] = getelementptr %struct.S, ptr %[[S]], i32 0, i32 0 |
| 151 | +// LLVM: %[[A:.*]] = load i32, ptr %[[A_PTR]] |
| 152 | +// LLVM: %[[A_PLUS_ONE:.*]] = add nsw i32 %[[A]], 1 |
| 153 | +// LLVM: store i32 %[[A_PLUS_ONE]], ptr %[[S_A]] |
| 154 | +// LLVM: %[[S_B:.*]] = getelementptr %struct.S, ptr %[[S]], i32 0, i32 1 |
| 155 | +// LLVM: %[[B:.*]] = load i32, ptr %[[B_PTR]] |
| 156 | +// LLVM: %[[B_PLUS_TWO:.*]] = add nsw i32 %[[B]], 2 |
| 157 | +// LLVM: store i32 %[[B_PLUS_TWO]], ptr %[[S_B]] |
| 158 | +// LLVM: %[[S_C:.*]] = getelementptr %struct.S, ptr %[[S]], i32 0, i32 2 |
| 159 | +// LLVM: %[[C:.*]] = load i32, ptr %[[C_PTR]] |
| 160 | +// LLVM: %[[C_PLUS_THREE:.*]] = add nsw i32 %[[C]], 3 |
| 161 | +// LLVM: store i32 %[[C_PLUS_THREE]], ptr %[[S_C]] |
| 162 | +// LLVM: ret void |
| 163 | + |
| 164 | +// OGCG: define{{.*}} void @_Z9init_expriii(i32 {{.*}} %[[A_ARG:.*]], i32 {{.*}} %[[B_ARG:.*]], i32 {{.*}} %[[C_ARG:.*]]) |
| 165 | +// OGCG: %[[A_PTR:.*]] = alloca i32 |
| 166 | +// OGCG: %[[B_PTR:.*]] = alloca i32 |
| 167 | +// OGCG: %[[C_PTR:.*]] = alloca i32 |
| 168 | +// OGCG: %[[S:.*]] = alloca %struct.S |
| 169 | +// OGCG: store i32 %[[A_ARG]], ptr %[[A_PTR]] |
| 170 | +// OGCG: store i32 %[[B_ARG]], ptr %[[B_PTR]] |
| 171 | +// OGCG: store i32 %[[C_ARG]], ptr %[[C_PTR]] |
| 172 | +// OGCG: %[[S_A:.*]] = getelementptr {{.*}} %struct.S, ptr %[[S]], i32 0, i32 0 |
| 173 | +// OGCG: %[[A:.*]] = load i32, ptr %[[A_PTR]] |
| 174 | +// OGCG: %[[A_PLUS_ONE:.*]] = add nsw i32 %[[A]], 1 |
| 175 | +// OGCG: store i32 %[[A_PLUS_ONE]], ptr %[[S_A]] |
| 176 | +// OGCG: %[[S_B:.*]] = getelementptr {{.*}} %struct.S, ptr %[[S]], i32 0, i32 1 |
| 177 | +// OGCG: %[[B:.*]] = load i32, ptr %[[B_PTR]] |
| 178 | +// OGCG: %[[B_PLUS_TWO:.*]] = add nsw i32 %[[B]], 2 |
| 179 | +// OGCG: store i32 %[[B_PLUS_TWO]], ptr %[[S_B]] |
| 180 | +// OGCG: %[[S_C:.*]] = getelementptr {{.*}} %struct.S, ptr %[[S]], i32 0, i32 2 |
| 181 | +// OGCG: %[[C:.*]] = load i32, ptr %[[C_PTR]] |
| 182 | +// OGCG: %[[C_PLUS_THREE:.*]] = add nsw i32 %[[C]], 3 |
| 183 | +// OGCG: store i32 %[[C_PLUS_THREE]], ptr %[[S_C]] |
| 184 | +// OGCG: ret void |
0 commit comments