Skip to content

Commit

Permalink
avoid emitting the redundant cir.const insts
Browse files Browse the repository at this point in the history
  • Loading branch information
YazZz1k committed Jan 31, 2024
1 parent a0cd980 commit 4cd2c41
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -455,18 +455,23 @@ void AggExprEmitter::buildArrayInit(Address DestPtr, mlir::cir::ArrayType AType,
[[maybe_unused]] Address endOfInit = Address::invalid();
assert(!CGF.needsEHCleanup(dtorKind) && "destructed types NIY");

auto one = CGF.getBuilder().getConstInt(
loc, CGF.PtrDiffTy.cast<mlir::cir::IntType>(), 1);

// The 'current element to initialize'. The invariants on this
// variable are complicated. Essentially, after each iteration of
// the loop, it points to the last initialized element, except
// that it points to the beginning of the array before any
// elements have been initialized.
mlir::Value element = begin;

// Don't build the 'one' before the cycle to avoid
// emmiting the redundant cir.const(1) instrs.
mlir::Value one;

// Emit the explicit initializers.
for (uint64_t i = 0; i != NumInitElements; ++i) {
if (i == 1)
one = CGF.getBuilder().getConstInt(
loc, CGF.PtrDiffTy.cast<mlir::cir::IntType>(), 1);

// Advance to the next element.
if (i > 0) {
element = CGF.getBuilder().create<mlir::cir::PtrStrideOp>(
Expand Down

0 comments on commit 4cd2c41

Please sign in to comment.