From b3a8d6d7ca4e38af90f65ef00492170a934d0267 Mon Sep 17 00:00:00 2001 From: YazZz1k Date: Wed, 31 Jan 2024 17:02:33 +0300 Subject: [PATCH] avoid emitting the redundant cir.const insts --- clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp b/clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp index 2d24abe46c15..eb20b551c132 100644 --- a/clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp +++ b/clang/lib/CIR/CodeGen/CIRGenExprAgg.cpp @@ -456,9 +456,6 @@ 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(), 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 @@ -466,8 +463,16 @@ void AggExprEmitter::buildArrayInit(Address DestPtr, mlir::cir::ArrayType AType, // 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(), 1); + // Advance to the next element. if (i > 0) { element = CGF.getBuilder().create(