[Mlir-commits] [clang] [mlir] [CIR] Lower pointer const_array globals without insertvalue chains (PR #198427)

Erich Keane llvmlistbot at llvm.org
Wed May 20 07:35:49 PDT 2026


================
@@ -2510,6 +2509,25 @@ mlir::LogicalResult CIRToLLVMGlobalOpLowering::matchAndRewrite(
                          cir::ConstComplexAttr, cir::GlobalViewAttr,
                          cir::TypeInfoAttr, cir::UndefAttr, cir::PoisonAttr,
                          cir::VTableAttr, cir::ZeroAttr>(init.value())) {
+      if (auto constArr = mlir::dyn_cast<cir::ConstArrayAttr>(init.value())) {
+        if (!hasTrailingZeros(constArr)) {
+          mlir::Type elTy = constArr.getType();
+          while (auto arrTy = mlir::dyn_cast<cir::ArrayType>(elTy))
+            elTy = arrTy.getElementType();
+          if (mlir::isa<cir::PointerType>(elTy)) {
----------------
erichkeane wrote:

More I think about it, we can do this for basically any type that `lowerConstArrayAttr` can handle that doesn't require any sort of copying. 

As an 'inverse', we could probably just do something like `!mlir::isa<cir::RecordType>(elTy)` (to avoid any sort of copying issues).  But in the meantime,we should probably at least try `cir.bool`, `cir.int`, and the `FPInterfaceType`

https://github.com/llvm/llvm-project/pull/198427


More information about the Mlir-commits mailing list