[flang-commits] [flang] [flang][fir] do not move alloca outside parallel regions in StackArrays (PR #218679)
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Tue Aug 25 08:14:19 PDT 2026
================
@@ -492,13 +492,48 @@ llvm::LogicalResult fir::AllocMemConversion::matchAndRewrite(
return mlir::success();
}
-static bool isInLoop(mlir::Block *block) {
- return mlir::LoopLikeOpInterface::blockIsInLoop(block);
+/// Return true if \p block can reach itself, i.e. it belongs to a control flow
+/// graph loop. This mirrors the control flow graph part of
+/// mlir::LoopLikeOpInterface::blockIsInLoop, which cannot be used here because
+/// it also walks the parent operations (see isInStackGrowingLoop).
+static bool isInCFGLoop(mlir::Block *block) {
+ llvm::DenseSet<mlir::Block *> visited;
+ llvm::SmallVector<mlir::Block *> stack{block};
+ while (!stack.empty()) {
+ mlir::Block *current = stack.pop_back_val();
+ auto [it, inserted] = visited.insert(current);
----------------
vzakhari wrote:
nit: I wonder if some compilers will warn `it` as unused variable.
https://github.com/llvm/llvm-project/pull/218679
More information about the flang-commits
mailing list