[all-commits] [llvm/llvm-project] a023fd: [Flang][CodeGen] Rematerialize pure ops with impur...
Tom Eccles via All-commits
all-commits at lists.llvm.org
Wed May 13 06:32:32 PDT 2026
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: a023fd290ec084663b4dc482dc0a1d77940628ea
https://github.com/llvm/llvm-project/commit/a023fd290ec084663b4dc482dc0a1d77940628ea
Author: Tom Eccles <tom.eccles at arm.com>
Date: 2026-05-13 (Wed, 13 May 2026)
Changed paths:
M flang/include/flang/Optimizer/CodeGen/CGPasses.td
M flang/include/flang/Optimizer/CodeGen/CodeGen.h
M flang/lib/Optimizer/CodeGen/CMakeLists.txt
A flang/lib/Optimizer/CodeGen/RematerializeFIRBoxOps.cpp
M flang/lib/Optimizer/Passes/Pipelines.cpp
M flang/test/Driver/mlir-debug-pass-pipeline.f90
M flang/test/Driver/mlir-pass-pipeline.f90
M flang/test/Fir/basic-program.fir
A flang/test/Fir/rematerialize-fir-box-ops-pipeline.fir
A flang/test/Fir/rematerialize-fir-box-ops.fir
Log Message:
-----------
[Flang][CodeGen] Rematerialize pure ops with impure implementation (#196352)
Some NoMemoryEffect FIR ops have an impure implementation in the LLVM
dialect which generates allocas.
Some OpenMP operations have bodies that will be outlined and may be run
on different threads. These OpenMP operations are not IsolatedFromAbove.
Values used directly inside of the regions of these operations are
implicitly shared between threads.
It is important that the allocas generated to implement NoMemoryEffect
FIR ops do not lead to accidental sharing between threads. This commit
adds a fir codegen pass which avoids this by rematerializing these FIR
operations inside of outlinable OpenMP regions.
The problem is not inherent to the OpenMP dialect: every time an MLIR
value is defined above an MLIR region where it is used, the use is
semantically a copy of the value into that region. Making this copy
explicit for all uses would not be practical. What this pass is doing is
to copy (by rematerializing) only these values where that is relevant.
Only operations implementing OutlinableOpenMPOpInterface are handled in
this pass because these were the operations which already had special
handling for alloca placement in flang codegen. The pass is designed to
be easy to extent to other operations containing region boundaries which
require this re-materialization.
Similarly, the pass should be easy to extend to other operations which
should be rematerialized at these region boundaries.
Some fir.embox/fir.rebox operations are not speculatable; these are not
susceptible to the original bug because CSE will not hoist them outside
of the outlinable regions. I chose to support these anyway for
completeness and because of the mlir copying semantics described above.
It is safe to speculate these operations here because the rematerialized
operations are rematerialized immediately before where the values would
be used. Furthermore, if a value is used in a nested outlinable region,
that value must always dominante that nested region by SSA construction.
RFC:
https://discourse.llvm.org/t/rfc-make-outlinable-openmp-operations-isolatedfromabove/90565
Fixes: #170781
Assisted-by: Codex
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