This is an archive of the discontinued LLVM Phabricator instance.

[flang] Runs FIR SimplifyRegionLitePass pass after calling the inliner
ClosedPublic

Authored by jeanPerier on Jul 25 2022, 7:16 AM.

Details

Summary

In flang pipeline, the inliner calls createCanonicalizerPass with the region
simplification disabled. The inliner pass does canonicalization even if
no inlining happens. After canonicalization, FIR lite region simplification
must be called to get rid of unreachable regions.
This code exposes the need to run SimplifyRegionLitePass after the inliner is
called with FIR pipeline.

Diff Detail

Event Timeline

jeanPerier created this revision.Jul 25 2022, 7:16 AM
jeanPerier requested review of this revision.Jul 25 2022, 7:16 AM

In flang pipeline, the inliner calls createCanonicalizerPass with the region simplification disabled.

Why not enable region simplification instead? Just curious.

flang/test/Fir/simplify-region-lite-after-inliner.fir
1
This revision is now accepted and ready to land.Jul 25 2022, 7:47 AM
PeteSteinfeld accepted this revision.Jul 25 2022, 7:50 AM

All builds and tests correctly and looks good.

Just a drive-through comment. Feel free to ignore it.

We have a call to simplifyregions in the lowering code with a comment to move this to a pass. With this change can we remove that call in Bridge.cpp? Or alternatively call the simplifyregion pass early in the flow?
https://github.com/llvm/llvm-project/blob/883b0d5b7f873a7d6f8c8ee13c7f6174a2a79a50/flang/lib/Lower/Bridge.cpp#L2830

In flang pipeline, the inliner calls createCanonicalizerPass with the region simplification disabled.

Why not enable region simplification instead? Just curious.

The issue with the MLIR regions simplification is that it always does block merging, and block merging breaks some properties of high level FIR where some operand are expected to be compile time constants/parent operation are expected to be visible: see https://reviews.llvm.org/D109579#3052374 for a better explanation.

Just a drive-through comment. Feel free to ignore it.

We have a call to simplifyregions in the lowering code with a comment to move this to a pass. With this change can we remove that call in Bridge.cpp? Or alternatively call the simplify region pass early in the flow?
https://github.com/llvm/llvm-project/blob/883b0d5b7f873a7d6f8c8ee13c7f6174a2a79a50/flang/lib/Lower/Bridge.cpp#L2830

Thanks for the suggestion, the call to simplify region is required to produce valid CFGs after lowering (because we allow ourselves to produce unreachable blocks in lowering to simplify things), so this call does not allow removing it since many passes are called in between (in fact some regions createSimplifyRegionLitePass is already added a few line above in createDefaultFIROptimizerPassPipeline), it needs to be called every type a pass may create dead code.