[clang] [CIR] Lower array globals with many trailing zeros as packed structs (PR #232835)
Konstantinos Parasyris via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 16 18:52:21 PDT 2026
================
@@ -929,6 +932,17 @@ mlir::Value CIRAttrToValue::visitCirAttr(cir::ConstArrayAttr attr) {
// Iteratively lower each constant element of the array.
if (auto arrayAttr = mlir::dyn_cast<mlir::ArrayAttr>(attr.getElts())) {
+ // Fewer struct members than elements: adjustGlobalTypeForInit grouped the
+ // elements of an array ending in many zeros into one leading array.
+ auto structTy = mlir::dyn_cast<mlir::LLVM::LLVMStructType>(llvmTy);
+ if (structTy && structTy.getBody().size() < arrayAttr.size()) {
+ auto arrayTy = mlir::cast<cir::ArrayType>(attr.getType());
+ auto prefix = cir::ConstArrayAttr::get(
+ cir::ArrayType::get(arrayTy.getElementType(), arrayAttr.size()),
+ arrayAttr);
+ return mlir::LLVM::InsertValueOp::create(rewriter, loc, result,
----------------
koparasy wrote:
Ran it: replayed all 6,672 TUs of a self-build. I have a python script that goes over compile_commands.json with -fclangir, with and without this PR, OG runs as noise floor.
Total CIR CPU 48,672s → 48,646s (0.999×); per-TU on/off distribution matches OG noise.
I added a fixme in the last commit. I will merge this in if no objections sometime next week.
https://github.com/llvm/llvm-project/pull/232835
More information about the cfe-commits
mailing list