[all-commits] [llvm/llvm-project] f01637: [flang] Promote scalar slots reached through fir.c...

Vijay Kandiah via All-commits all-commits at lists.llvm.org
Mon Sep 14 10:07:04 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: f016371f8339c37c7e8f228324a56a15a66ac21b
      https://github.com/llvm/llvm-project/commit/f016371f8339c37c7e8f228324a56a15a66ac21b
  Author: Vijay Kandiah <vkandiah at nvidia.com>
  Date:   2026-09-14 (Mon, 14 Sep 2026)

  Changed paths:
    M flang/include/flang/Optimizer/Dialect/FIROps.td
    M flang/lib/Optimizer/Dialect/FIROps.cpp
    M flang/test/Fir/mem2reg.mlir

  Log Message:
  -----------
  [flang] Promote scalar slots reached through fir.convert and fir.declare (#219314)

Neither `fir.declare` nor `fir.convert` implements
`PromotableAliaserInterface`, so mem2reg does not see accesses made
through them as touching the slot behind. A cast anywhere in the chain
blocks promotion outright, even when it only changes the flavor of a
reference to the same scalar. So a scalar slot reached as `memref.alloca
-> fir.convert -> fir.declare -> fir.convert -> store/load` stays in
memory today.

This patch implements `PromotableAliaserInterface` for both operations.
mem2reg collects defining blocks from the alias map, so writes through a
`fir.declare` are now seen and the single-block restriction from
https://github.com/llvm/llvm-project/pull/182933 is no longer needed. An
operation reports an alias only when it carries the pointee through
unchanged, so that the default value projections of the interface apply;
for a `fir.convert` that limits it to a reference or a rank-0 memref of
a simple scalar with an identity layout and no memory space, and never
when either side is volatile.

A `fir.convert` additionally requires every read of the slot to be
preceded, in its own block, by a write. A read that no write reaches
takes the default value of the allocation, which is `fir.undefined` for
`fir.alloca` but poison for the memref allocations a cast can reach.
Without this requirement, promoting through a cast would change what
reading an uninitialized variable produces.



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