[flang-commits] [flang] [flang][CodeGen] Fold partial insert_on_range on 1D arrays to a constant (PR #215836)

via flang-commits flang-commits at lists.llvm.org
Wed Aug 26 06:37:04 PDT 2026


jeanPerier wrote:

> I think both need handling for this to be generally applicable to partially initialized arrays in `COMMON` blocks, and it would be worth adding a test case for each shape. I wonder if this would be better addressed with a new helper that doesn't fold each `insert_on_range` individually from its `seq` operand, but instead walks the whole initializer region once — from `fir.has_value` back to the `fir.undefined` — filling a single element vector and emitting one `llvm.mlir.constant`.

I agree this would be best, but please make sure that is possible with all kind of global initializers, including the ones containing pointer initialization which implies dealing with symbols and derived types (descriptors components are also part of the reason we do not always emit attributes in lowering because we do not have attribute representation for descriptor values).

Last time I worked on similar problem, my understanding was that it was not possible to create llvm.mlir.constant / constant attributes for all kind of constants that LLVM can represents. This may not be true and it may be a much better idea to work on an attribute representation to hold any kind of constants that we need to represent so that we can always emit bodyless constants in lowering and do not spend time processing the related IR body in each module pass, so if you want to investigate this path, that would be great.



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


More information about the flang-commits mailing list