Skip to content

Commit 4cd2c41

Browse files
committed
avoid emitting the redundant cir.const insts
1 parent a0cd980 commit 4cd2c41

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -455,18 +455,23 @@ void AggExprEmitter::buildArrayInit(Address DestPtr, mlir::cir::ArrayType AType,
455455
[[maybe_unused]] Address endOfInit = Address::invalid();
456456
assert(!CGF.needsEHCleanup(dtorKind) && "destructed types NIY");
457457

458-
auto one = CGF.getBuilder().getConstInt(
459-
loc, CGF.PtrDiffTy.cast<mlir::cir::IntType>(), 1);
460-
461458
// The 'current element to initialize'. The invariants on this
462459
// variable are complicated. Essentially, after each iteration of
463460
// the loop, it points to the last initialized element, except
464461
// that it points to the beginning of the array before any
465462
// elements have been initialized.
466463
mlir::Value element = begin;
467464

465+
// Don't build the 'one' before the cycle to avoid
466+
// emmiting the redundant cir.const(1) instrs.
467+
mlir::Value one;
468+
468469
// Emit the explicit initializers.
469470
for (uint64_t i = 0; i != NumInitElements; ++i) {
471+
if (i == 1)
472+
one = CGF.getBuilder().getConstInt(
473+
loc, CGF.PtrDiffTy.cast<mlir::cir::IntType>(), 1);
474+
470475
// Advance to the next element.
471476
if (i > 0) {
472477
element = CGF.getBuilder().create<mlir::cir::PtrStrideOp>(

0 commit comments

Comments
 (0)