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.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
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 |
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
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.
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.