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

Kareem Ergawy via All-commits all-commits at lists.llvm.org
Fri Sep 11 02:03:17 PDT 2026


  Branch: refs/heads/users/ergawy/licm-dont-hoist-field-index
  Home:   https://github.com/llvm/llvm-project
  Commit: d63f522d22623a709f8a677cbb3193cb0a02eed3
      https://github.com/llvm/llvm-project/commit/d63f522d22623a709f8a677cbb3193cb0a02eed3
  Author: ergawy <kareem.ergawy at gmail.com>
  Date:   2026-09-11 (Fri, 11 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

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