[flang-commits] [flang] [flang] Inline scalar-to-scalar TRANSFER for same-size trivial types (PR #191589)

Zhen Wang via flang-commits flang-commits at lists.llvm.org
Thu Apr 16 12:03:53 PDT 2026


================
@@ -8680,6 +8680,38 @@ IntrinsicLibrary::genTransfer(mlir::Type resultType,
 
   assert(args.size() >= 2); // args.size() == 2 when size argument is omitted.
 
+  bool absentSize = (args.size() == 2);
+
+  // Inline scalar-to-scalar transfers when the result is a trivial type
+  // (integer, real, etc.) and both source and result have the same storage
+  // size.
+  if (absentSize && fir::isa_trivial(resultType)) {
+    mlir::Value sourceBase = fir::getBase(args[0]);
+    mlir::Type sourceType = fir::unwrapRefType(sourceBase.getType());
+    mlir::Type moldType = fir::unwrapRefType(fir::getBase(args[1]).getType());
+    if (fir::isa_ref_type(sourceBase.getType()) &&
+        !mlir::isa<fir::SequenceType>(sourceType) &&
+        !mlir::isa<fir::SequenceType>(moldType)) {
----------------
wangzpgi wrote:

Good point, switched to positive checks. For the mold I use fir::isa_trivial(moldType). For the source I also allow fir::RecordType since that's needed for the c_ptr/c_devptr → integer case (the fir.convert + load path).

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


More information about the flang-commits mailing list