CorePrep: Eliminate EmptyCase and unsafeEqualityProof in CoreToStg instead
We eliminate EmptyCase by way of `coreToStg (Case e _ _ []) = coreToStg e` now. The main reason is that it plays far better in conjunction with eta expansion (as we aim to do for arguments in CorePrep, #23083), because we can discard any arguments, `(case e of {}) eta == case e of {}`, whereas in `(e |> co) eta` it's impossible to discard the argument. We do also give the same treatment to unsafeCoerce proofs and treat them as trivial iff their RHS is trivial. It is also both much simpler to describe than the previous mechanism of emitting an unsafe coercion and simpler to implement, removing quite a bit of commentary and `CorePrepProv`. In the ghc/alloc perf test `LargeRecord`, we introduce an additional Simplifier iteration due to #17910. E.g., FloatOut produces a binding ``` lvl_s6uK [Occ=Once1] :: GHC.Types.Int [LclId] lvl_s6uK = GHC.Types.I# 2# lvl_s6uL [Occ=Once1] :: GHC.Types.Any [LclId] lvl_s6uL = case Unsafe.Coerce.unsafeEqualityProof ... of { Unsafe.Coerce.UnsafeRefl v2_i6tr -> lvl_s6uK `cast` (... v2_i6tr ...) } ``` That occurs once and hence is pre-inlined unconditionally in the next Simplifier pass. It's non-trivial to find a way around that, but not really harmful otherwise. Hence we accept a 1.2% increase on some architectures. Metric Increase: LargeRecord
Showing
- compiler/GHC/Core.hs 7 additions, 3 deletionscompiler/GHC/Core.hs
- compiler/GHC/Core/Coercion.hs 0 additions, 4 deletionscompiler/GHC/Core/Coercion.hs
- compiler/GHC/Core/Coercion/Opt.hs 0 additions, 1 deletioncompiler/GHC/Core/Coercion/Opt.hs
- compiler/GHC/Core/FVs.hs 0 additions, 2 deletionscompiler/GHC/Core/FVs.hs
- compiler/GHC/Core/Lint.hs 1 addition, 12 deletionscompiler/GHC/Core/Lint.hs
- compiler/GHC/Core/Opt/SetLevels.hs 17 additions, 10 deletionscompiler/GHC/Core/Opt/SetLevels.hs
- compiler/GHC/Core/Opt/Simplify/Utils.hs 12 additions, 0 deletionscompiler/GHC/Core/Opt/Simplify/Utils.hs
- compiler/GHC/Core/TyCo/FVs.hs 1 addition, 8 deletionscompiler/GHC/Core/TyCo/FVs.hs
- compiler/GHC/Core/TyCo/Rep.hs 0 additions, 7 deletionscompiler/GHC/Core/TyCo/Rep.hs
- compiler/GHC/Core/TyCo/Subst.hs 0 additions, 1 deletioncompiler/GHC/Core/TyCo/Subst.hs
- compiler/GHC/Core/TyCo/Tidy.hs 0 additions, 1 deletioncompiler/GHC/Core/TyCo/Tidy.hs
- compiler/GHC/Core/Type.hs 0 additions, 2 deletionscompiler/GHC/Core/Type.hs
- compiler/GHC/Core/Unfold.hs 9 additions, 4 deletionscompiler/GHC/Core/Unfold.hs
- compiler/GHC/Core/Utils.hs 25 additions, 9 deletionscompiler/GHC/Core/Utils.hs
- compiler/GHC/CoreToIface.hs 0 additions, 1 deletioncompiler/GHC/CoreToIface.hs
- compiler/GHC/CoreToStg.hs 55 additions, 56 deletionscompiler/GHC/CoreToStg.hs
- compiler/GHC/CoreToStg/Prep.hs 42 additions, 214 deletionscompiler/GHC/CoreToStg/Prep.hs
- compiler/GHC/Iface/Syntax.hs 0 additions, 1 deletioncompiler/GHC/Iface/Syntax.hs
- compiler/GHC/Iface/Type.hs 0 additions, 9 deletionscompiler/GHC/Iface/Type.hs
- compiler/GHC/IfaceToCore.hs 0 additions, 1 deletioncompiler/GHC/IfaceToCore.hs
Loading
Please register or sign in to comment