Skip to content

Commit 81f5098

Browse files
authored
[flang] Enable optimizeEmptyElementals for BufferizeHLFIR pass. (#124982)
Enable the option under opt-for-speed. Elementals with shapes like `(0, HUGE)` should run faster.
1 parent eb7e199 commit 81f5098

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

flang/lib/Optimizer/Passes/Pipelines.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,15 @@ void createHLFIRToFIRPassPipeline(mlir::PassManager &pm, bool enableOpenMP,
245245
}
246246
pm.addPass(hlfir::createLowerHLFIROrderedAssignments());
247247
pm.addPass(hlfir::createLowerHLFIRIntrinsics());
248-
pm.addPass(hlfir::createBufferizeHLFIR());
248+
249+
hlfir::BufferizeHLFIROptions bufferizeOptions;
250+
// For opt-for-speed, avoid running any of the loops resulting
251+
// from hlfir.elemental lowering, if the result is an empty array.
252+
// This helps to avoid long running loops for elementals with
253+
// shapes like (0, HUGE).
254+
if (optLevel.isOptimizingForSpeed())
255+
bufferizeOptions.optimizeEmptyElementals = true;
256+
pm.addPass(hlfir::createBufferizeHLFIR(bufferizeOptions));
249257
// Run hlfir.assign inlining again after BufferizeHLFIR,
250258
// because the latter may introduce new hlfir.assign operations,
251259
// e.g. for copying an array into a temporary due to

0 commit comments

Comments
 (0)