[all-commits] [llvm/llvm-project] a70234: [flang] Propagate INTENT(IN) dummy arguments as re...

Sergey Shcherbinin via All-commits all-commits at lists.llvm.org
Mon Jul 13 21:50:36 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: a70234b00d12aaa7723eb2ae5e8efe3348aeeb37
      https://github.com/llvm/llvm-project/commit/a70234b00d12aaa7723eb2ae5e8efe3348aeeb37
  Author: Sergey Shcherbinin <sscherbinin at nvidia.com>
  Date:   2026-07-14 (Tue, 14 Jul 2026)

  Changed paths:
    M flang/include/flang/Optimizer/Dialect/FIROpsSupport.h
    M flang/include/flang/Optimizer/Transforms/Passes.td
    M flang/lib/Lower/CallInterface.cpp
    M flang/lib/Optimizer/Passes/Pipelines.cpp
    M flang/lib/Optimizer/Transforms/FunctionAttr.cpp
    A flang/test/Driver/function-attr-readonly.f90
    M flang/test/Lower/HLFIR/structure-constructor.f90
    M flang/test/Lower/Intrinsics/dconjg.f90
    M flang/test/Lower/Intrinsics/dimag.f90
    M flang/test/Lower/Intrinsics/dreal.f90
    M flang/test/Lower/OpenMP/optional-argument-map.f90
    M flang/test/Lower/OpenMP/wsloop-unstructured.f90
    M flang/test/Lower/achar.f90
    M flang/test/Lower/arguments.f90
    M flang/test/Lower/call-copy-in-out.f90
    M flang/test/Lower/dispatch.f90
    A flang/test/Lower/dummy-argument-readonly.f90
    M flang/test/Lower/polymorphic-temp.f90
    M flang/test/Lower/polymorphic.f90
    M flang/test/Lower/select-type.f90
    M flang/test/Lower/unsigned-ops.f90
    M flang/test/Lower/volatile1.f90
    A flang/test/Transforms/function-attrs-readonly.fir

  Log Message:
  -----------
  [flang] Propagate INTENT(IN) dummy arguments as readonly (#207732)

Mark eligible `INTENT(IN)` dummy data objects with a `fir.read_only`
argument attribute during lowering, and teach `FunctionAttr` to
translate the marker to LLVM `readonly` for reference arguments when
optimizing for speed.

LLVM FunctionAttrs can infer `readonly` later in the pipeline, but this
happens too late for IPSCCP function specialization.
`FunctionSpecializer::promoteConstantStackValues` requires
`onlyReadsMemory()` before promoting constant by-reference scalar
arguments. Providing `readonly` satisfies this check and allows these
arguments to be promoted, enabling function specialization, including in
non-LTO builds.

For direct-data arguments, restrict propagation to by-reference
non-character intrinsic scalars. Ordinary arrays and derived-type
arguments are excluded because compiler-generated copy-out may write
back through a forwarded dummy argument. LLVM `readonly` does not permit
such writes, even when the stored value is unchanged.

`INTENT(IN)` `POINTER` and `ALLOCATABLE` dummies are supported with
shallow descriptor semantics: `readonly` protects the descriptor
storage, but does not imply that data addressed by the descriptor is
read-only. In particular, a `POINTER` target may still be modified.

Keep `readonly` handling independent from `noalias` and `nocapture`.
`TARGET` arguments may receive `readonly`, but must not receive
`noalias` or `nocapture`. Apply `readonly` to `BIND(C)` definitions
while leaving external C declarations unannotated. `VALUE`,
`ASYNCHRONOUS`, and `VOLATILE` dummy arguments remain excluded.

In our measurements, the enabled function specialization gives a 1.5x
speedup on 548.exchange2 on NVIDIA Neoverse V2 in a non-LTO
configuration.

Update existing lowering tests to account for the new `fir.read_only`
argument attribute, and add focused coverage:

* `dummy-argument-readonly.f90` checks marker emission for supported
scalar and descriptor arguments, excluded cases, and shallow pointer
semantics.
* `function-attrs-readonly.fir` checks translation from `fir.read_only`
to LLVM `readonly`, including `TARGET`, `BIND(C)`, and descriptor
references.
* `function-attr-readonly.f90` checks the optimization-level pipeline
gate and verifies that `readonly` reaches final LLVM IR.
* `call-copy-in-out.f90` checks that ordinary array copy-out cases
remain unmarked and that pointer-target copy-out is compatible with
shallow descriptor `readonly`.



To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications


More information about the All-commits mailing list