================
@@ -735,31 +735,22 @@ void CIRGenFunction::emitCXXAggrConstructorCall(
// are probably legitimate places where we could assume that this
// doesn't happen, but it's not clear that it's worth it.
- auto arrayTy = mlir::cast<cir::ArrayType>(arrayBase.getElementType());
- mlir::Type elementType = arrayTy.getElementType();
-
- // This might be a multi-dimensional array. Find the innermost element type.
+ // Peel any array types wrapped in the address element type down to the CIR
+ // type of a single constructed object.
+ mlir::Type elementType = arrayBase.getElementType();
while (auto maybeArrayTy = mlir::dyn_cast<cir::ArrayType>(elementType))
elementType = maybeArrayTy.getElementType();
cir::PointerType ptrToElmType = builder.getPointerTo(elementType);
- // Optimize for a constant count.
- if (auto constantCount = numElements.getDefiningOp<cir::ConstantOp>()) {
- if (auto constIntAttr = constantCount.getValueAttr<cir::IntAttr>()) {
- // Just skip out if the constant count is zero.
- if (constIntAttr.getUInt() == 0)
- return;
-
- arrayTy = cir::ArrayType::get(elementType, constIntAttr.getUInt());
- // Otherwise, emit the check.
- }
-
- if (constantCount.use_empty())
- constantCount.erase();
- } else {
- // Otherwise, emit the check.
- cgm.errorNYI(e->getSourceRange(),
- "emitCXXAggrConstructorCall: dynamic-length array
expression");
+ bool useDynamicArrayCtor = true;
+ uint64_t constElementCount = 0;
+ if (auto constantOp = numElements.getDefiningOp<cir::ConstantOp>()) {
+ constElementCount = CIRGenFunction::getZExtIntValueFromConstOp(constantOp);
+ if (constElementCount == 0)
----------------
erichkeane wrote:
Yes, sure. This is the sort of thing that classic-codegen sometimes does with
his normal "constant-folder" thing, so its a shame to lose. We should at
least at one point think about an opt pass to figure this stuff out.
https://github.com/llvm/llvm-project/pull/190656
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits