Code that fuses with GHC-8 no longer fuses with GHC-9
Summary
See #19790 (closed) and #19861 (closed) for background. I updated the repo (https://github.com/composewell/streamly-ghc9-regression) with reproduction code for another regression. This time it is in the after_
operation, a bit more complicated repro code than the previous ones.
Steps to reproduce
You can pull the repo (after
branch which is also the same as master as of now) and use the following command to build it:
$ cabal build --with-compiler <compiler>
This will build the Main executable and also produce .dump-simpl files which can be found in the dist-newstyle directory tree. After doing this step you can also build it directly using ghc
but make sure that you are providing the same optimization options as in the cabal file. For example:
$ ghc --make -O2 -fspec-constr-recursive=16 -fmax-worker-args=16 -ddump-to-file -ddump-simpl Main.hs
The core generated by ghc-8 and ghc-9 are quite different.
Both of these cores do not fuse all the constructors. However, we use a compiler plugin which inserts a pass after the simplifier phase0. It simply marks some bindings of interest with an INLINE pragma and runs the simplifier pass after doing so. You can build the repo code with fusion-plugin like this:
$ cabal build --with-compiler <compiler> --flag fusion-plugin
Or with ghc directly:
$ ghc --make -O2 -fspec-constr-recursive=16 -fmax-worker-args=16 -ddump-to-file -ddump-simpl -fplugin Fusion.Plugin Main.hs
ghc core-to-core verbose dump can provide more details about what's happening in each pass.
Using GHC-8 with the plugin, the above code fuses completely and produces this core. However, with GHC-9 this code does not fuse even with the plugin, it produces this core.
Let me know if I can help in any further investigation.
Expected behavior
GHC-9 should produce code as efficient as GHC-8. The core produced by GHC-9 even without the fusion-plugin is quite different which can possibly provide some clue why it won't fuse even after everything of interest is inlined by the fusion-plugin.
Environment
- GHC version used: ghc-9.3+!5658 (closed)