Skip to content

Commit 2a126d2

Browse files
authored
[CIR] Fix array init loop condition (#1758)
The LoweringPrepare pass was generating the wrong condition for loops when lowering the ArrayCtor op, causing only one element in an array of objects to be constructed. This fixes that problem.
1 parent 8f89224 commit 2a126d2

File tree

4 files changed

+4
-4
lines changed

4 files changed

+4
-4
lines changed

clang/lib/CIR/Dialect/Transforms/LoweringPrepare.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ static void lowerArrayDtorCtorIntoLoop(CIRBaseBuilderTy &builder,
13821382
[&](mlir::OpBuilder &b, mlir::Location loc) {
13831383
auto currentElement = b.create<cir::LoadOp>(loc, eltTy, tmpAddr);
13841384
mlir::Type boolTy = cir::BoolType::get(b.getContext());
1385-
auto cmp = builder.create<cir::CmpOp>(loc, boolTy, cir::CmpOpKind::eq,
1385+
auto cmp = builder.create<cir::CmpOp>(loc, boolTy, cir::CmpOpKind::ne,
13861386
currentElement, end);
13871387
builder.createCondition(cmp);
13881388
},

clang/test/CIR/CodeGen/array-init-destroy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ void x() {
5050
// AFTER: cir.yield
5151
// AFTER: } while {
5252
// AFTER: %[[ArrayElt:.*]] = cir.load %[[TmpIdx]] : !cir.ptr<!cir.ptr<!rec_xpto>>, !cir.ptr<!rec_xpto>
53-
// AFTER: %[[ExitCond:.*]] = cir.cmp(eq, %[[ArrayElt]], %[[ArrayPastEnd]]) : !cir.ptr<!rec_xpto>, !cir.bool
53+
// AFTER: %[[ExitCond:.*]] = cir.cmp(ne, %[[ArrayElt]], %[[ArrayPastEnd]]) : !cir.ptr<!rec_xpto>, !cir.bool
5454
// AFTER: cir.condition(%[[ExitCond]])
5555
// AFTER: }
5656

clang/test/CIR/CodeGen/array-new-init.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,6 @@ void t_new_constant_size_constructor() {
5555
// AFTER: cir.yield
5656
// AFTER: } while {
5757
// AFTER: %[[CUR_ELEM_PTR2:.*]] = cir.load %[[CUR_ELEM_ALLOCA]] : !cir.ptr<!cir.ptr<!rec_E>>, !cir.ptr<!rec_E>
58-
// AFTER: %[[END_TEST:.*]] = cir.cmp(eq, %[[CUR_ELEM_PTR2]], %[[END_PTR]]) : !cir.ptr<!rec_E>, !cir.bool
58+
// AFTER: %[[END_TEST:.*]] = cir.cmp(ne, %[[CUR_ELEM_PTR2]], %[[END_PTR]]) : !cir.ptr<!rec_E>, !cir.bool
5959
// AFTER: cir.condition(%[[END_TEST]])
6060
// AFTER: }

clang/test/CIR/Lowering/new.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ void t_new_constant_size_constructor() {
207207
// LLVM: br label %[[INIT_ELEM_BB:.*]]
208208
// LLVM: [[LOOP_INC_BB:.*]]:
209209
// LLVM: %[[NEXT_ELEM_PTR:.*]] = load ptr
210-
// LLVM: %[[END_TEST:.*]] = icmp eq ptr %[[NEXT_ELEM_PTR]], %[[END_PTR]]
210+
// LLVM: %[[END_TEST:.*]] = icmp ne ptr %[[NEXT_ELEM_PTR]], %[[END_PTR]]
211211
// LLVM: br i1 %[[END_TEST]], label %[[INIT_ELEM_BB]], label %[[EXIT_BB:.*]]
212212
// LLVM: [[INIT_ELEM_BB]]:
213213
// LLVM: %[[CUR_ELEM_PTR:.*]] = load ptr

0 commit comments

Comments
 (0)