[flang-commits] [flang] [flang] Enable optimizeEmptyElementals for BufferizeHLFIR pass. (PR #124982)
Slava Zakharin via flang-commits
flang-commits at lists.llvm.org
Wed Jan 29 12:37:40 PST 2025
https://github.com/vzakhari created https://github.com/llvm/llvm-project/pull/124982
Enable the option under opt-for-speed. Elementals with shapes
like `(0, HUGE)` should run faster.
>From 825a4c2d62fcac72d420754b30572bdb8e6367b8 Mon Sep 17 00:00:00 2001
From: Slava Zakharin <szakharin at nvidia.com>
Date: Tue, 28 Jan 2025 17:21:03 -0800
Subject: [PATCH] [flang] Enable optimizeEmptyElementals for BufferizeHLFIR
pass.
Enable the option under opt-for-speed. Elementals with shapes
like `(0, HUGE)` should run faster.
---
flang/lib/Optimizer/Passes/Pipelines.cpp | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/flang/lib/Optimizer/Passes/Pipelines.cpp b/flang/lib/Optimizer/Passes/Pipelines.cpp
index 1cc3f0b81c20ad..d55ad9e603ffaf 100644
--- a/flang/lib/Optimizer/Passes/Pipelines.cpp
+++ b/flang/lib/Optimizer/Passes/Pipelines.cpp
@@ -245,7 +245,15 @@ void createHLFIRToFIRPassPipeline(mlir::PassManager &pm, bool enableOpenMP,
}
pm.addPass(hlfir::createLowerHLFIROrderedAssignments());
pm.addPass(hlfir::createLowerHLFIRIntrinsics());
- pm.addPass(hlfir::createBufferizeHLFIR());
+
+ hlfir::BufferizeHLFIROptions bufferizeOptions;
+ // For opt-for-speed, avoid running any of the loops resulting
+ // from hlfir.elemental lowering, if the result is an empty array.
+ // This helps to avoid long running loops for elementals with
+ // shapes like (0, HUGE).
+ if (optLevel.isOptimizingForSpeed())
+ bufferizeOptions.optimizeEmptyElementals = true;
+ pm.addPass(hlfir::createBufferizeHLFIR(bufferizeOptions));
// Run hlfir.assign inlining again after BufferizeHLFIR,
// because the latter may introduce new hlfir.assign operations,
// e.g. for copying an array into a temporary due to
More information about the flang-commits
mailing list