[all-commits] [llvm/llvm-project] c7c566: [flang] Do not hoist all scalar sub-expressions fr...

jeanPerier via All-commits all-commits at lists.llvm.org
Tue May 14 04:35:07 PDT 2024


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: c7c5666aac543a49b485a133f4a94865e2613a43
      https://github.com/llvm/llvm-project/commit/c7c5666aac543a49b485a133f4a94865e2613a43
  Author: jeanPerier <jperier at nvidia.com>
  Date:   2024-05-14 (Tue, 14 May 2024)

  Changed paths:
    M flang/include/flang/Lower/StatementContext.h
    M flang/include/flang/Optimizer/HLFIR/HLFIROps.td
    M flang/lib/Lower/Bridge.cpp
    M flang/lib/Lower/ConvertCall.cpp
    M flang/lib/Optimizer/HLFIR/Transforms/LowerHLFIROrderedAssignments.cpp
    M flang/test/HLFIR/order_assignments/impure-where.fir
    M flang/test/HLFIR/order_assignments/inlined-stack-temp.fir
    M flang/test/HLFIR/order_assignments/user-defined-assignment-finalization.fir
    A flang/test/HLFIR/order_assignments/where-cleanup.f90
    M flang/test/HLFIR/order_assignments/where-codegen-no-conflict.fir
    A flang/test/HLFIR/order_assignments/where-hoisting.f90
    A flang/test/Lower/HLFIR/where-nonelemental.f90

  Log Message:
  -----------
  [flang] Do not hoist all scalar sub-expressions from WHERE constructs (#91395)

The HLFIR pass lowering WHERE (hlfir.where op) was too aggressive in its
hoisting of scalar sub-expressions from LHS/RHS/MASKS outside of the
loops generated for the WHERE construct.
This violated F'2023 10.2.3.2 point 10 that stipulated that elemental
operations must be evaluated only for elements corresponding to true
values, because scalar operations are still elemental, and hoisting them
is invalid if they could have side effects (e.g, division by zero) and
if the MASK is always false (i.e., the loop body is never evaluated).

The difficulty is that 10.2.3.2 point 9 mandates that nonelemental
function must be evaluated before the loops. So it is not possible to
simply stop hoisting non hlfir.elemental operations.
Marking calls with an elemental/nonelemental attribute would not allow
the pass to be correct if inlining is run before and drops this
information, beside, extracting the argument tree that may have been
CSE-ed with the rest of the expression evaluation would be a bit
combursome.

Instead, lower nonelemental calls into a new hlfir.exactly_once
operation that will allow retaining the information that the operations
contained inside its region must be hoisted. This allows inlining to
operate before if desired in order to improve alias analysis.

The LowerHLFIROrderedAssignments pass is updated to only hoist the
operations contained inside hlfir.exactly_once bodies.



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