[flang-commits] [flang] [flang][FIRToMemRef] [flang][fir-to-memref] Lower complex projected slices via memref<...x2xT> reinterpretation (PR #196123)

Susan Tan ス-ザン タン via flang-commits flang-commits at lists.llvm.org
Fri May 8 08:17:03 PDT 2026


================
@@ -171,6 +172,17 @@ class FIRToMemRef : public fir::impl::FIRToMemRefBase<FIRToMemRef> {
     return sliceOp && !sliceOp.getFields().empty();
   }
 
+  // Returns true for imaginary, false for real, nullopt if not a constant.
+  static std::optional<bool> sliceProjectionIsImaginary(fir::SliceOp sliceOp) {
+    auto fields = sliceOp.getFields();
+    if (fields.empty())
+      return std::nullopt;
+    if (auto cst = fields[0].getDefiningOp<arith::ConstantOp>())
+      if (auto attr = mlir::dyn_cast<IntegerAttr>(cst.getValueAttr()))
+        return attr.getInt() != 0;
----------------
SusanTan wrote:

hi Razvan, the path field for slice projection of a complex number can only be either 0 or 1. However there doesn't seem to be FIR-level guarantee that this is true (@jeanPerier correct me if this is not the case). I'll make this check to be more specific and bail out the conversion if we detect complex project to have other integers.

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


More information about the flang-commits mailing list