[all-commits] [llvm/llvm-project] b58741: [flang] Do not hoist fir.field_index out of loops ...

Kareem Ergawy via All-commits all-commits at lists.llvm.org
Fri Sep 11 15:19:20 PDT 2026


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: b5874129d921518823d257770c742da2a860b2cf
      https://github.com/llvm/llvm-project/commit/b5874129d921518823d257770c742da2a860b2cf
  Author: Kareem Ergawy <kergawy at nvidia.com>
  Date:   2026-09-12 (Sat, 12 Sep 2026)

  Changed paths:
    M flang/lib/Optimizer/Transforms/LoopInvariantCodeMotion.cpp
    M flang/test/Transforms/licm.fir

  Log Message:
  -----------
  [flang] Do not hoist fir.field_index out of loops (#222891)

Lowering a consumer of a !fir.field value inspects its defining
operation: for a record whose layout is known at compile time the field
becomes an LLVM GEP struct index, which must be a constant, and
otherwise the `field` attribute is read off the defining op. A field
value therefore may not be a block argument.

LICM broke that. fir.field_index is Pure and takes no operands, so it is
trivially loop-invariant and was hoisted out of the loop. Lowering emits
one inside each arm of a construct -- for example the CASEs of a SELECT
CASE that each pass a different component of the same derived type as an
actual argument -- so hoisting them left those arms as
otherwise-identical blocks differing only in that operand. Block merging
then merged them and threaded the field through a new block argument,
and codegen aborted with "must be a constant".

Leave producers of a !fir.field where they are. The arms then differ by
an operation rather than by an operand, so they are no longer merge
candidates. Consumers are unaffected and still hoist: fir.coordinate_of
uses the attribute form of the field, so it does not depend on the
fir.field_index value.

The check keys on the result type rather than on FieldIndexOp so that
any operation producing a !fir.field is covered, and sits in the
predicate shared by the direct-loop and nested-region hoisting paths.



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