[flang-commits] [flang] [flang] Inline scalar-to-scalar TRANSFER for same-size trivial types (PR #191589)
via flang-commits
flang-commits at lists.llvm.org
Thu Apr 16 08:01:12 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)) {
----------------
jeanPerier wrote:
A positive checks with `fir::isa_trivial(sourceType) && fir::isa_trivial(moldType)` would be more restrictive and ensure the code is not relying on too many invariants about what `sourceBase` and the mold mlir types (just for the future sake, I do no think there is any bug with your code currently).
https://github.com/llvm/llvm-project/pull/191589
More information about the flang-commits
mailing list